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:
parent
c6505a6647
commit
bb680ef20a
4 changed files with 49 additions and 36 deletions
35
app/react/portainer/gitops/GitCommitLink.tsx
Normal file
35
app/react/portainer/gitops/GitCommitLink.tsx
Normal 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>
|
||||
);
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue