Skip to content

Commit

Permalink
refactor: Segregate url creation services (#103)
Browse files Browse the repository at this point in the history
Jira: EPMDPEDP-12913
Related: #103
Change-Id: I9dc6b1bad74586add18bcad760b70c3b06cb08d4
  • Loading branch information
callmevladik committed Nov 23, 2023
1 parent d2698a3 commit 9df13e1
Show file tree
Hide file tree
Showing 28 changed files with 441 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { EDPCDPipelineStageKubeObject } from '../../../../../k8s/EDPCDPipelineSt
import { EDPCDPipelineStageKubeObjectInterface } from '../../../../../k8s/EDPCDPipelineStage/types';
import { useEDPComponentsURLsQuery } from '../../../../../k8s/EDPComponent/hooks/useEDPComponentsURLsQuery';
import { useResourceActionListContext } from '../../../../../providers/ResourceActionList/hooks';
import { GENERATE_URL_SERVICE } from '../../../../../services/url';
import { LinkCreationService } from '../../../../../services/link-creation';
import { rem } from '../../../../../utils/styling/rem';
import { routeEDPStageDetails } from '../../../../edp-stage-details/route';
import { EDPCDPipelineRouteParams } from '../../../types';
Expand Down Expand Up @@ -113,7 +113,7 @@ export const useColumns = (
<ResourceIconLink
icon={ICONS.ARGOCD}
tooltipTitle={'Open in ArgoCD'}
link={GENERATE_URL_SERVICE.createArgoCDStageLink(
link={LinkCreationService.argocd.createStageLink(
EDPComponentsURLS?.argocd,
CDPipelineName,
stage.spec.name
Expand All @@ -124,7 +124,7 @@ export const useColumns = (
<ResourceIconLink
icon={ICONS.GRAFANA}
tooltipTitle={'Open in Grafana'}
link={GENERATE_URL_SERVICE.createGrafanaLink(
link={LinkCreationService.grafana.createDashboardLink(
EDPComponentsURLS?.grafana,
stage.spec.namespace
)}
Expand All @@ -134,7 +134,7 @@ export const useColumns = (
<ResourceIconLink
icon={ICONS.KIBANA}
tooltipTitle={'Open in Kibana'}
link={GENERATE_URL_SERVICE.createKibanaLink(
link={LinkCreationService.kibana.createDashboardLink(
EDPComponentsURLS?.kibana,
stage.spec.namespace
)}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/edp-cdpipeline-details/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ResourceIconLink } from '../../components/ResourceIconLink';
import { ICONS } from '../../icons/iconify-icons-mapping';
import { useEDPComponentsURLsQuery } from '../../k8s/EDPComponent/hooks/useEDPComponentsURLsQuery';
import { ResourceActionListContextProvider } from '../../providers/ResourceActionList';
import { GENERATE_URL_SERVICE } from '../../services/url';
import { LinkCreationService } from '../../services/link-creation';
import { StageActionsMenu } from '../../widgets/StageActionsMenu';
import { routeEDPCDPipelineList } from '../edp-cdpipeline-list/route';
import { CDPipelineActions } from './components/CDPipelineActions';
Expand Down Expand Up @@ -42,7 +42,7 @@ export const PageView = () => {
<ResourceIconLink
icon={ICONS.ARGOCD}
tooltipTitle={'Open in ArgoCD'}
link={GENERATE_URL_SERVICE.createArgoCDPipelineLink(
link={LinkCreationService.argocd.createPipelineLink(
EDPComponentsURLS?.argocd,
name
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PIPELINE_RUN_REASON } from '../../../../../../../../k8s/PipelineRun/con
import { useCreateBuildPipelineRun } from '../../../../../../../../k8s/PipelineRun/hooks/useCreateBuildPipelineRun';
import { useStorageSizeQuery } from '../../../../../../../../k8s/TriggerTemplate/hooks/useStorageSizeQuery';
import { useResourceActionListContext } from '../../../../../../../../providers/ResourceActionList/hooks';
import { GENERATE_URL_SERVICE } from '../../../../../../../../services/url';
import { LinkCreationService } from '../../../../../../../../services/link-creation';
import { rem } from '../../../../../../../../utils/styling/rem';
import { EDPComponentDetailsRouteParams } from '../../../../../../types';
import { isDefaultBranch } from '../../../../utils';
Expand All @@ -29,7 +29,7 @@ export const Summary = ({ codebaseData, codebaseBranchData, pipelineRuns }: Summ

const sonarLink = React.useMemo(
() =>
GENERATE_URL_SERVICE.createSonarLink(
LinkCreationService.sonar.createDashboardLink(
EDPComponentsURLS?.sonar,
codebaseBranchData.metadata.name
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ApplicationKubeObjectInterface } from '../../../../../k8s/Application/t
import { getDeployedVersion } from '../../../../../k8s/Application/utils/getDeployedVersion';
import { useEDPComponentsURLsQuery } from '../../../../../k8s/EDPComponent/hooks/useEDPComponentsURLsQuery';
import { useDialogContext } from '../../../../../providers/Dialog/hooks';
import { GENERATE_URL_SERVICE } from '../../../../../services/url';
import { LinkCreationService } from '../../../../../services/link-creation';
import { PODS_LOG_VIEWER_DIALOG_NAME } from '../../../../../widgets/PodsLogViewer/constants';
import { PODS_TERMINAL_DIALOG_NAME } from '../../../../../widgets/PodsTerminal/constants';
import { routeEDPComponentDetails } from '../../../../edp-component-details/route';
Expand All @@ -48,7 +48,7 @@ export const useColumns = (
const { stage } = useDynamicDataContext();
const _createArgoCDLink = React.useCallback(
(argoApplication: ApplicationKubeObjectInterface) =>
GENERATE_URL_SERVICE.createArgoCDApplicationLink(
LinkCreationService.argocd.createApplicationLink(
EDPComponentsURLS?.argocd,
argoApplication.metadata.labels[APPLICATION_LABEL_SELECTOR_PIPELINE],
argoApplication.metadata.labels[APPLICATION_LABEL_SELECTOR_STAGE],
Expand Down Expand Up @@ -208,7 +208,7 @@ export const useColumns = (
<Grid item>
<ResourceIconLink
tooltipTitle={'Go to the Source Code'}
link={GENERATE_URL_SERVICE.createGitOpsValuesYamlFileLink(
link={LinkCreationService.git.createGitOpsValuesYamlFileLink(
gitOpsCodebase?.status.gitWebUrl,
CDPipelineName,
stage?.spec.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EDPCDPipelineStageSpecQualityGatesInterface } from '../../../../../k8s/
import { useEDPComponentsURLsQuery } from '../../../../../k8s/EDPComponent/hooks/useEDPComponentsURLsQuery';
import { PipelineRunKubeObject } from '../../../../../k8s/PipelineRun';
import { PipelineRunKubeObjectInterface } from '../../../../../k8s/PipelineRun/types';
import { GENERATE_URL_SERVICE } from '../../../../../services/url';
import { LinkCreationService } from '../../../../../services/link-creation';
import { routeEDPComponentDetails } from '../../../../edp-component-details/route';
import { EDPStageDetailsRouteParams } from '../../../types';

Expand Down Expand Up @@ -57,7 +57,7 @@ export const useColumns = (): TableColumn<{
render: ({ qualityGate: { stepName }, autotestPipelineRun }) => {
const tektonLink =
autotestPipelineRun &&
GENERATE_URL_SERVICE.createTektonPipelineRunLink(
LinkCreationService.tekton.createPipelineRunLink(
EDPComponentsURLS?.tekton,
autotestPipelineRun?.metadata?.namespace,
autotestPipelineRun?.metadata?.name
Expand Down
6 changes: 3 additions & 3 deletions src/pages/edp-stage-details/components/QualityGates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TASK_RUN_STEP_REASON, TASK_RUN_STEP_STATUS } from '../../../../k8s/Task
import { useStreamTaskRunListByPipelineNameAndPipelineType } from '../../../../k8s/TaskRun/hooks/useStreamTaskRunListByPipelineNameAndPipelineType';
import { TaskRunKubeObjectInterface } from '../../../../k8s/TaskRun/types';
import { useStorageSizeQuery } from '../../../../k8s/TriggerTemplate/hooks/useStorageSizeQuery';
import { GENERATE_URL_SERVICE } from '../../../../services/url';
import { LinkCreationService } from '../../../../services/link-creation';
import { ValueOf } from '../../../../types/global';
import { sortKubeObjectByCreationTimestamp } from '../../../../utils/sort/sortKubeObjectsByCreationTimestamp';
import { rem } from '../../../../utils/styling/rem';
Expand Down Expand Up @@ -105,7 +105,7 @@ const getResourceURLByResourceType = (
if (resourceType === 'taskrun') {
return (
resource &&
GENERATE_URL_SERVICE.createTektonTaskRunLink(
LinkCreationService.tekton.createTaskRunLink(
tektonBaseURL,
resource?.metadata?.namespace,
resource?.metadata?.name
Expand All @@ -114,7 +114,7 @@ const getResourceURLByResourceType = (
} else if (resourceType === 'pipelinerun') {
return (
resource &&
GENERATE_URL_SERVICE.createTektonPipelineRunLink(
LinkCreationService.tekton.createPipelineRunLink(
tektonBaseURL,
resource?.metadata?.namespace,
resource?.metadata?.name
Expand Down
8 changes: 4 additions & 4 deletions src/pages/edp-stage-details/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useStreamAutotestPipelineRunList } from '../../k8s/PipelineRun/hooks/us
import { useStreamAutotestRunnerPipelineRunList } from '../../k8s/PipelineRun/hooks/useStreamAutotestRunnerPipelineRunList';
import { useStreamPipelineRunListByTypeAndPipelineNameLabels } from '../../k8s/PipelineRun/hooks/useStreamPipelineRunListByTypeAndPipelineNameLabels';
import { FormContextProvider } from '../../providers/Form';
import { GENERATE_URL_SERVICE } from '../../services/url';
import { LinkCreationService } from '../../services/link-creation';
import { sortKubeObjectByCreationTimestamp } from '../../utils/sort/sortKubeObjectsByCreationTimestamp';
import { rem } from '../../utils/styling/rem';
import { routeEDPCDPipelineDetails } from '../edp-cdpipeline-details/route';
Expand Down Expand Up @@ -275,7 +275,7 @@ export const PageView = () => {
<ResourceIconLink
icon={ICONS.ARGOCD}
tooltipTitle={'Open in ArgoCD'}
link={GENERATE_URL_SERVICE.createArgoCDStageLink(
link={LinkCreationService.argocd.createStageLink(
EDPComponentsURLS?.argocd,
CDPipeline?.metadata?.name,
stageSpecName
Expand All @@ -286,7 +286,7 @@ export const PageView = () => {
<ResourceIconLink
icon={ICONS.GRAFANA}
tooltipTitle={'Open in Grafana'}
link={GENERATE_URL_SERVICE.createGrafanaLink(
link={LinkCreationService.grafana.createDashboardLink(
EDPComponentsURLS?.grafana,
stage?.spec.namespace
)}
Expand All @@ -296,7 +296,7 @@ export const PageView = () => {
<ResourceIconLink
icon={ICONS.KIBANA}
tooltipTitle={'Open in Kibana'}
link={GENERATE_URL_SERVICE.createKibanaLink(
link={LinkCreationService.kibana.createDashboardLink(
EDPComponentsURLS?.kibana,
stage?.spec.namespace
)}
Expand Down
36 changes: 36 additions & 0 deletions src/services/link-creation/argocd/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ArgoCDURLService } from './index';

describe('testing link-creation ArgoCDURLService', () => {
it('should successfully create argocd application url based on given argoCDURLOrigin, pipeline name, stage name and app name params', () => {
expect(
ArgoCDURLService.createApplicationLink(
'https://argocd-test.com/',
'test-pipeline-name',
'test-stage-name',
'test-app-name'
)
).toEqual(
'https://argocd-test.com/applications?labels=app.edp.epam.com%2Fpipeline%3Dtest-pipeline-name%2Capp.edp.epam.com%2Fstage%3Dtest-stage-name%2Capp.edp.epam.com%2Fapp-name%3Dtest-app-name'
);
});

it('should successfully create argocd pipeline url based on given argoCDURLOrigin and pipeline name param', () => {
expect(
ArgoCDURLService.createPipelineLink('https://argocd-test.com/', 'test-pipeline-name')
).toEqual(
'https://argocd-test.com/applications?labels=app.edp.epam.com%2Fpipeline%3Dtest-pipeline-name'
);
});

it('should successfully create argocd stage url based on given argoCDURLOrigin, pipeline name and stage name params', () => {
expect(
ArgoCDURLService.createStageLink(
'https://argocd-test.com/',
'test-pipeline-name',
'test-stage-name'
)
).toEqual(
'https://argocd-test.com/applications?labels=app.edp.epam.com%2Fpipeline%3Dtest-pipeline-name%2Capp.edp.epam.com%2Fstage%3Dtest-stage-name'
);
});
});
56 changes: 56 additions & 0 deletions src/services/link-creation/argocd/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
APPLICATION_LABEL_SELECTOR_APP_NAME,
APPLICATION_LABEL_SELECTOR_PIPELINE,
APPLICATION_LABEL_SELECTOR_STAGE,
} from '../../../k8s/Application/labels';
import { createURLObjectFromURLOrigin } from '../index';

export const ArgoCDURLService = {
createPipelineLink: (argoCDURLOrigin: string, pipelineName: string) => {
if (!argoCDURLOrigin) {
return;
}

const argoCDURLObject = createURLObjectFromURLOrigin(argoCDURLOrigin);
const argoCDApplicationsURLObject = new URL('/applications', argoCDURLObject);
argoCDApplicationsURLObject.searchParams.append(
'labels',
`${APPLICATION_LABEL_SELECTOR_PIPELINE}=${pipelineName}`
);

return argoCDApplicationsURLObject.href;
},
createApplicationLink: (
argoCDURLOrigin: string,
pipelineName: string,
stageName: string,
appName: string
) => {
if (!argoCDURLOrigin) {
return;
}

const argoCDURLObject = createURLObjectFromURLOrigin(argoCDURLOrigin);
const argoCDApplicationsURLObject = new URL('/applications', argoCDURLObject);
argoCDApplicationsURLObject.searchParams.append(
'labels',
`${APPLICATION_LABEL_SELECTOR_PIPELINE}=${pipelineName},${APPLICATION_LABEL_SELECTOR_STAGE}=${stageName},${APPLICATION_LABEL_SELECTOR_APP_NAME}=${appName}`
);

return argoCDApplicationsURLObject.href;
},
createStageLink: (argoCDURLOrigin: string, pipelineName: string, stageName: string) => {
if (!argoCDURLOrigin) {
return;
}

const argoCDURLObject = createURLObjectFromURLOrigin(argoCDURLOrigin);
const argoCDApplicationsURLObject = new URL('/applications', argoCDURLObject);
argoCDApplicationsURLObject.searchParams.append(
'labels',
`${APPLICATION_LABEL_SELECTOR_PIPELINE}=${pipelineName},${APPLICATION_LABEL_SELECTOR_STAGE}=${stageName}`
);

return argoCDApplicationsURLObject.href;
},
};
40 changes: 40 additions & 0 deletions src/services/link-creation/git/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { GIT_SERVERS } from '../../../constants/gitServers';
import { GitURLService } from './index';

describe('testing link-creation GitURLService', () => {
it('should successfully create git ops value file url based on given gitOpsWebUrl, pipeline name, stage name, app name and git server params', () => {
expect(
GitURLService.createGitOpsValuesYamlFileLink(
'https://git.test.com/test-project/test-env/edp-gitops',
'test-pipeline-name',
'test-stage-name',
'test-app-name',
GIT_SERVERS.GITHUB
)
).toEqual(
'https://git.test.com/test-project/test-env/edp-gitops/blob/main/test-pipeline-name/test-stage-name/test-app-name-values.yaml'
);
expect(
GitURLService.createGitOpsValuesYamlFileLink(
'https://git.test.com/test-project/test-env/edp-gitops',
'test-pipeline-name',
'test-stage-name',
'test-app-name',
GIT_SERVERS.GITLAB
)
).toEqual(
'https://git.test.com/test-project/test-env/edp-gitops/blob/main/test-pipeline-name/test-stage-name/test-app-name-values.yaml'
);
expect(
GitURLService.createGitOpsValuesYamlFileLink(
'https://test-gerrit.com/gitweb?p=edp-gitops.git',
'test-pipeline-name',
'test-stage-name',
'test-app-name',
GIT_SERVERS.GERRIT
)
).toEqual(
'https://test-gerrit.com/gitweb?p=edp-gitops.git&f=test-pipeline-name%2Ftest-stage-name%2Ftest-app-name-values.yaml&hb=refs%2Fheads%2Fmain&a=blob'
);
});
});
31 changes: 31 additions & 0 deletions src/services/link-creation/git/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { GIT_SERVERS } from '../../../constants/gitServers';
import { createURLObjectFromURLOrigin } from '../index';

export const GitURLService = {
createGitOpsValuesYamlFileLink: (
gitOpsWebUrl: string,
pipelineName: string,
stageName: string,
appName: string,
gitServer: GIT_SERVERS
) => {
if (!gitOpsWebUrl) {
return;
}

const gitHostURLObject = createURLObjectFromURLOrigin(gitOpsWebUrl);

if (gitServer === GIT_SERVERS.GERRIT) {
gitHostURLObject.searchParams.append(
'f',
`${pipelineName}/${stageName}/${appName}-values.yaml`
);
gitHostURLObject.searchParams.append('hb', 'refs/heads/main');
gitHostURLObject.searchParams.append('a', 'blob');

return gitHostURLObject.href;
} else if (gitServer === GIT_SERVERS.GITHUB || gitServer === GIT_SERVERS.GITLAB) {
return `${gitHostURLObject.href}/blob/main/${pipelineName}/${stageName}/${appName}-values.yaml`;
}
},
};
11 changes: 11 additions & 0 deletions src/services/link-creation/grafana/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GrafanaURLService } from './index';

describe('testing link-creation GrafanaURLService', () => {
it('should successfully create grafana url based on given grafanaURLOrigin and namespace params', () => {
expect(
GrafanaURLService.createDashboardLink('https://grafana-test.com', 'test-namespace')
).toEqual(
'https://grafana-test.com/d/85a562078cdf77779eaa1add43ccec1e/kubernetes-compute-resources-namespace-pods?orgId=1&refresh=10s&var-datasource=default&var-cluster=&var-namespace=test-namespace'
);
});
});
9 changes: 9 additions & 0 deletions src/services/link-creation/grafana/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const GrafanaURLService = {
createDashboardLink: (grafanaURLOrigin: string, namespace: string) => {
if (!grafanaURLOrigin) {
return;
}

return `${grafanaURLOrigin}/d/85a562078cdf77779eaa1add43ccec1e/kubernetes-compute-resources-namespace-pods?orgId=1&refresh=10s&var-datasource=default&var-cluster=&var-namespace=${namespace}`;
},
};
Loading

0 comments on commit 9df13e1

Please sign in to comment.