-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Segregate url creation services (#103)
Jira: EPMDPEDP-12913 Related: #103 Change-Id: I9dc6b1bad74586add18bcad760b70c3b06cb08d4
- Loading branch information
1 parent
d2698a3
commit 9df13e1
Showing
28 changed files
with
441 additions
and
380 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
}, | ||
}; |
Oops, something went wrong.