1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 05:45:22 +02:00

fix(git): incorrect git commit url for bitbucket [EE-6446] (#10855)

This commit is contained in:
Oscar Zhou 2024-01-12 08:22:50 +13:00 committed by GitHub
parent c6505a6647
commit bb680ef20a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 36 deletions

View file

@ -0,0 +1,35 @@
function cleanGitRepoUrl(url: string) {
return url
.trim() // remove leading and trailing whitespace
.replace(/\/$/, '') // if there's a trailing slash, remove it
.replace(/\.git$/, ''); // if there's a trailing .git extension, remove it
}
function getGitRepoCommitUrl(url: string, hash: string) {
const cleanedUrl = cleanGitRepoUrl(url);
if (cleanedUrl.startsWith('https://bitbucket.org')) {
return `${cleanedUrl}/commits/${hash}`;
}
// this is a fallback for any other git repo
// the tested repo includes gitlab, github, and azure devops
return `${cleanedUrl}/commit/${hash}`;
}
interface Props {
baseURL: string;
commitHash: string;
}
export function GitCommitLink({ baseURL, commitHash }: Props) {
return (
<a
href={getGitRepoCommitUrl(baseURL, commitHash)}
target="_blank"
rel="noopener noreferrer"
>
{commitHash.slice(0, 7)}
</a>
);
}

View file

@ -32,10 +32,3 @@ export function confirmEnableTLSVerify() {
'Enabling the verification of TLS certificates without ensuring the correct configuration of your Certificate Authority (CA) for self-signed certificates can result in deployment failures.',
});
}
export function cleanGitRepoUrl(url: string) {
return url
.trim() // remove leading and trailing whitespace
.replace(/\/$/, '') // if there's a trailing slash, remove it
.replace(/\.git$/, ''); // if there's a trailing .git extension, remove it
}