diff --git a/plugins/azure-devops/README.md b/plugins/azure-devops/README.md
index db1af06a01..1737b72af7 100644
--- a/plugins/azure-devops/README.md
+++ b/plugins/azure-devops/README.md
@@ -71,25 +71,47 @@ To get the Azure Pipelines component working you'll need to do the following two
yarn add @backstage/plugin-azure-devops
```
-2. Second we need to add the `EntityAzurePipelinesContent` extension to the entity page in your app:
+2. Second we need to add the `EntityAzurePipelinesContent` extension to the entity page in your app. How to do this will depend on which annotation you are using in your entities:
- ```tsx
- // In packages/app/src/components/catalog/EntityPage.tsx
- import {
- EntityAzurePipelinesContent,
- isAzureDevOpsAvailable,
- } from '@backstage/plugin-azure-devops';
+ 1. If you are using the `dev.azure.com/project-repo` annotation then you'll want to do the following:
- // For example in the CI/CD section
- const cicdContent = (
-
- // ...
-
-
-
- // ...
-
- ```
+ ```tsx
+ // In packages/app/src/components/catalog/EntityPage.tsx
+ import {
+ EntityAzurePipelinesContent,
+ isAzureDevOpsAvailable,
+ } from '@backstage/plugin-azure-devops';
+
+ // For example in the CI/CD section
+ const cicdContent = (
+
+ // ...
+
+
+
+ // ...
+
+ ```
+
+ 2. If you are using the `dev.azure.com/project-definition` annotation then you'll want to do this:
+
+ ```tsx
+ // In packages/app/src/components/catalog/EntityPage.tsx
+ import {
+ EntityAzurePipelinesContent,
+ isAzurePipelinesAvailable,
+ } from '@backstage/plugin-azure-devops';
+
+ // For example in the CI/CD section
+ const cicdContent = (
+
+ // ...
+
+
+
+ // ...
+
+ ```
**Notes:**
diff --git a/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx b/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx
index 5957e82eef..3e8babdd25 100644
--- a/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx
+++ b/plugins/azure-devops/src/components/EntityPageAzurePipelines/EntityPageAzurePipelines.tsx
@@ -16,7 +16,7 @@
import { BuildTable } from '../BuildTable/BuildTable';
import React from 'react';
-import { useAnnotationFromEntity } from '../../hooks/useAnnotationFromEntity';
+import { getAnnotationFromEntity } from '../../utils/getAnnotationFromEntity';
import { useBuildRuns } from '../../hooks/useBuildRuns';
import { useEntity } from '@backstage/plugin-catalog-react';
@@ -27,7 +27,7 @@ export const EntityPageAzurePipelines = ({
}) => {
const { entity } = useEntity();
- const { project, repo, definition } = useAnnotationFromEntity(entity);
+ const { project, repo, definition } = getAnnotationFromEntity(entity);
const { items, loading, error } = useBuildRuns(
project,
diff --git a/plugins/azure-devops/src/hooks/useAnnotationFromEntity.ts b/plugins/azure-devops/src/utils/getAnnotationFromEntity.ts
similarity index 57%
rename from plugins/azure-devops/src/hooks/useAnnotationFromEntity.ts
rename to plugins/azure-devops/src/utils/getAnnotationFromEntity.ts
index 06e3f58549..5509a72fef 100644
--- a/plugins/azure-devops/src/hooks/useAnnotationFromEntity.ts
+++ b/plugins/azure-devops/src/utils/getAnnotationFromEntity.ts
@@ -14,30 +14,34 @@
* limitations under the License.
*/
-import { Entity } from '@backstage/catalog-model';
import {
AZURE_DEVOPS_DEFINITION_ANNOTATION,
AZURE_DEVOPS_REPO_ANNOTATION,
} from '../constants';
-export function useAnnotationFromEntity(entity: Entity): {
+import { Entity } from '@backstage/catalog-model';
+
+export function getAnnotationFromEntity(entity: Entity): {
project: string;
repo?: string;
definition?: string;
} {
- if (entity.metadata.annotations?.[AZURE_DEVOPS_DEFINITION_ANNOTATION]) {
- const { project, definition } = getProjectDefinition(
- entity.metadata.annotations?.[AZURE_DEVOPS_DEFINITION_ANNOTATION],
- );
+ let annotation =
+ entity.metadata.annotations?.[AZURE_DEVOPS_DEFINITION_ANNOTATION];
+ if (annotation) {
+ const { project, definition } = getProjectDefinition(annotation);
const repo = undefined;
return { project, repo, definition };
}
- const { project, repo } = getProjectRepo(
- entity.metadata.annotations?.[AZURE_DEVOPS_REPO_ANNOTATION] ?? '',
- );
- const definition = undefined;
- return { project, repo, definition };
+ annotation = entity.metadata.annotations?.[AZURE_DEVOPS_REPO_ANNOTATION];
+ if (annotation) {
+ const { project, repo } = getProjectRepo(annotation);
+ const definition = undefined;
+ return { project, repo, definition };
+ }
+
+ throw new Error('No supported Azure DevOps annotation was found');
}
function getProjectDefinition(annotation: string): {
@@ -52,18 +56,6 @@ function getProjectDefinition(annotation: string): {
);
}
- if (!project) {
- throw new Error(
- 'Project Name for annotation dev.azure.com/project-definition was not found; expected format is: /',
- );
- }
-
- if (!definition) {
- throw new Error(
- 'Definition Name for annotation dev.azure.com/project-definition was not found; expected format is: /',
- );
- }
-
return { project, definition };
}
@@ -79,17 +71,5 @@ function getProjectRepo(annotation: string): {
);
}
- if (!project) {
- throw new Error(
- 'Project Name for annotation dev.azure.com/project-repo was not found; expected format is: /',
- );
- }
-
- if (!repo) {
- throw new Error(
- 'Repo Name for annotation dev.azure.com/project-repo was not found; expected format is: /',
- );
- }
-
return { project, repo };
}
diff --git a/plugins/azure-devops/src/utils/index.ts b/plugins/azure-devops/src/utils/index.ts
index f2214e8106..8655b261c3 100644
--- a/plugins/azure-devops/src/utils/index.ts
+++ b/plugins/azure-devops/src/utils/index.ts
@@ -17,3 +17,4 @@
export * from './arrayHas';
export * from './equalsIgnoreCase';
export * from './getDurationFromDates';
+export * from './getAnnotationFromEntity';