fix(gitops): correct commit hash link [EE-6346] (#10800)

pull/10764/head^2
Ali 2023-12-08 12:56:35 +13:00 committed by GitHub
parent 9978b88ed4
commit 0e59cf76ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import UpToDate from '@/assets/ico/icon_up-to-date.svg?c';
import { isoDateFromTimestamp } from '@/portainer/filters/filters';
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
import { getDashboardRoute } from '@/react/portainer/environments/utils';
import { cleanGitRepoUrl } from '@/react/portainer/gitops/utils';
import { Button } from '@@/buttons';
import { Icon } from '@@/Icon';
@ -187,7 +188,9 @@ function TargetVersionCell({
{row.original.TargetCommitHash ? (
<div>
<a
href={`${row.original.GitConfigURL}/commit/${row.original.TargetCommitHash}`}
href={`${cleanGitRepoUrl(row.original.GitConfigURL)}/commit/${
row.original.TargetCommitHash
}`}
target="_blank"
rel="noreferrer"
>
@ -236,7 +239,9 @@ function DeployedVersionCell({
<div>
{statusIcon}
<a
href={`${row.original.GitConfigURL}/commit/${row.original.TargetCommitHash}`}
href={`${cleanGitRepoUrl(row.original.GitConfigURL)}/commit/${
row.original.TargetCommitHash
}`}
target="_blank"
rel="noreferrer"
>

View File

@ -3,6 +3,7 @@ import _ from 'lodash';
import { isoDateFromTimestamp } from '@/portainer/filters/filters';
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
import { cleanGitRepoUrl } from '@/react/portainer/gitops/utils';
import { buildNameColumn } from '@@/datatables/NameCell';
import { Link } from '@@/Link';
@ -151,7 +152,9 @@ export const columns = _.compact([
<div className="text-center">
<a
target="_blank"
href={`${item.GitConfig.URL}/commit/${item.GitConfig.ConfigHash}`}
href={`${cleanGitRepoUrl(item.GitConfig.URL)}/commit/${
item.GitConfig.ConfigHash
}`}
rel="noreferrer"
>
{item.GitConfig.ConfigHash.slice(0, 7)}

View File

@ -32,3 +32,10 @@ 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
}