From 09cfc3cf467d3e81630d1ff0973d0a57122575fd Mon Sep 17 00:00:00 2001 From: Tarak Nath Tatwa Date: Wed, 23 Aug 2023 10:59:44 +0530 Subject: [PATCH] feedback changes Signed-off-by: Tarak Nath Tatwa --- .changeset/tiny-bulldogs-grow.md | 5 +++++ plugins/azure-devops/README.md | 2 +- plugins/azure-devops/src/constants.ts | 1 + .../src/utils/getAnnotationFromEntity.ts | 14 +++++++++----- plugins/azure-devops/src/utils/isAzureLocation.ts | 7 +++++-- 5 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .changeset/tiny-bulldogs-grow.md diff --git a/.changeset/tiny-bulldogs-grow.md b/.changeset/tiny-bulldogs-grow.md new file mode 100644 index 0000000000..b6b54d5b57 --- /dev/null +++ b/.changeset/tiny-bulldogs-grow.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-azure-devops': minor +--- + +the project and repository details can be obtained using the `backstage.io/managed-by-location` annotation diff --git a/plugins/azure-devops/README.md b/plugins/azure-devops/README.md index 5055180be1..cc0f4c67f3 100644 --- a/plugins/azure-devops/README.md +++ b/plugins/azure-devops/README.md @@ -65,7 +65,7 @@ spec: backstage.io/managed-by-location: https://dev.azure.com/{org}/{project}/_git/{repo}?path=/.catalog/component.yml ``` -if `dev.azure.com/project-repo` annotation is not provided and `dev.azure.com/project` not exits then to extract the project and repo information we can use `backstage.io/managed-by-location` annotation if location contains `dev.azure.com` in url to enable CICD tab. +In cases where the annotations `dev.azure.com/project-repo` or `dev.azure.com/project` are not present, **the project and repository details can be obtained using the `backstage.io/managed-by-location` annotation**. This method comes into play when the URL within the location includes `dev.azure.com`, which then triggers the activation of the CICD tab. #### Azure Pipelines Only diff --git a/plugins/azure-devops/src/constants.ts b/plugins/azure-devops/src/constants.ts index 128b593145..bfc6603abf 100644 --- a/plugins/azure-devops/src/constants.ts +++ b/plugins/azure-devops/src/constants.ts @@ -20,3 +20,4 @@ export const AZURE_DEVOPS_PROJECT_ANNOTATION = 'dev.azure.com/project'; export const AZURE_DEVOPS_REPO_ANNOTATION = 'dev.azure.com/project-repo'; export const AZURE_DEVOPS_PROJECT_LOCATION = 'backstage.io/managed-by-location'; export const AZURE_DEVOPS_DEFAULT_TOP: number = 10; +export const AZURE_DEVOPS_URL_FORMAT = 'https://dev.azure.com'; diff --git a/plugins/azure-devops/src/utils/getAnnotationFromEntity.ts b/plugins/azure-devops/src/utils/getAnnotationFromEntity.ts index 14f19668f0..70cff6da0d 100644 --- a/plugins/azure-devops/src/utils/getAnnotationFromEntity.ts +++ b/plugins/azure-devops/src/utils/getAnnotationFromEntity.ts @@ -19,8 +19,11 @@ import { AZURE_DEVOPS_PROJECT_ANNOTATION, AZURE_DEVOPS_REPO_ANNOTATION, AZURE_DEVOPS_PROJECT_LOCATION, + AZURE_DEVOPS_URL_FORMAT, } from '../constants'; +import parseGitUrl from 'git-url-parse'; + import { Entity } from '@backstage/catalog-model'; export function getAnnotationFromEntity(entity: Entity): { @@ -40,14 +43,15 @@ export function getAnnotationFromEntity(entity: Entity): { entity.metadata.annotations?.[AZURE_DEVOPS_PROJECT_ANNOTATION]; const location = entity.metadata.annotations?.[AZURE_DEVOPS_PROJECT_LOCATION]; - const isAzureDevUrl = location?.includes('dev.azure.com'); + const isAzureDevUrl = location?.includes(AZURE_DEVOPS_URL_FORMAT); if (!project && location && isAzureDevUrl) { - const locInfoArr = location - .substring(location.indexOf('//') + 2) - .split('/'); + const { name: repo, owner } = parseGitUrl(location); + + const projArrData = owner.split('/'); + + const proj = projArrData[projArrData.length - 2]; - const [proj, repo] = [locInfoArr[2], locInfoArr[4].split('?')[0]]; const definition = undefined; return { project: proj, repo, definition }; } diff --git a/plugins/azure-devops/src/utils/isAzureLocation.ts b/plugins/azure-devops/src/utils/isAzureLocation.ts index 7398c08fd0..d9d4cd6fdf 100644 --- a/plugins/azure-devops/src/utils/isAzureLocation.ts +++ b/plugins/azure-devops/src/utils/isAzureLocation.ts @@ -14,11 +14,14 @@ * limitations under the License. */ import { Entity } from '@backstage/catalog-model'; -import { AZURE_DEVOPS_PROJECT_LOCATION } from '../constants'; +import { + AZURE_DEVOPS_PROJECT_LOCATION, + AZURE_DEVOPS_URL_FORMAT, +} from '../constants'; export const isDevAzureLocation = (entity: Entity): boolean => { const location = entity.metadata.annotations?.[AZURE_DEVOPS_PROJECT_LOCATION]; - if (location) return location.includes('dev.azure.com'); + if (location) return location.includes(AZURE_DEVOPS_URL_FORMAT); return false; };