fix(gitops): clean trailing slash [EE-6346] (#10777)

Co-authored-by: testa113 <testa113>
pull/10807/head
Ali 2023-12-07 13:43:01 +13:00 committed by GitHub
parent a2d6d6002c
commit 4e8b371fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 16 deletions

View File

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

View File

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

View File

@ -19,8 +19,3 @@ export function getValidEditorTypes(
? _.intersection(...endpointTypes.map((type) => right[type])) ? _.intersection(...endpointTypes.map((type) => right[type]))
: [EditorType.Compose, EditorType.Kubernetes]; : [EditorType.Compose, EditorType.Kubernetes];
} }
export function removeTrailingGitExtension(url: string) {
// the url could have the .git extension. Remove it if it does.
return url.replace(/\.git$/, '');
}

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.', '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
}