Changes based on feedback
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -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 = (
|
||||
<EntitySwitch>
|
||||
// ...
|
||||
<EntitySwitch.Case if={isAzureDevOpsAvailable}>
|
||||
<EntityAzurePipelinesContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
// ...
|
||||
</EntitySwitch>
|
||||
```
|
||||
```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 = (
|
||||
<EntitySwitch>
|
||||
// ...
|
||||
<EntitySwitch.Case if={isAzureDevOpsAvailable}>
|
||||
<EntityAzurePipelinesContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
// ...
|
||||
</EntitySwitch>
|
||||
```
|
||||
|
||||
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 = (
|
||||
<EntitySwitch>
|
||||
// ...
|
||||
<EntitySwitch.Case if={isAzurePipelinesAvailable}>
|
||||
<EntityAzurePipelinesContent defaultLimit={25} />
|
||||
</EntitySwitch.Case>
|
||||
// ...
|
||||
</EntitySwitch>
|
||||
```
|
||||
|
||||
**Notes:**
|
||||
|
||||
|
||||
+2
-2
@@ -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,
|
||||
|
||||
+15
-35
@@ -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: <project-name>/<definition-name>',
|
||||
);
|
||||
}
|
||||
|
||||
if (!definition) {
|
||||
throw new Error(
|
||||
'Definition Name for annotation dev.azure.com/project-definition was not found; expected format is: <project-name>/<definition-name>',
|
||||
);
|
||||
}
|
||||
|
||||
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: <project-name>/<repo-name>',
|
||||
);
|
||||
}
|
||||
|
||||
if (!repo) {
|
||||
throw new Error(
|
||||
'Repo Name for annotation dev.azure.com/project-repo was not found; expected format is: <project-name>/<repo-name>',
|
||||
);
|
||||
}
|
||||
|
||||
return { project, repo };
|
||||
}
|
||||
@@ -17,3 +17,4 @@
|
||||
export * from './arrayHas';
|
||||
export * from './equalsIgnoreCase';
|
||||
export * from './getDurationFromDates';
|
||||
export * from './getAnnotationFromEntity';
|
||||
|
||||
Reference in New Issue
Block a user