Changes based on feedback
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
+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