Ability to fetch the README file from a different AZD path, using an annotation on the entity

Signed-off-by: David Roberts <David.Roberts@orbis.com>
This commit is contained in:
David Roberts
2024-02-07 11:43:08 +00:00
parent dd44104e9f
commit 308b0eef3c
7 changed files with 26 additions and 3 deletions
@@ -189,6 +189,9 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
if (opts.org) {
queryString.append('org', opts.org);
}
if (opts.path) {
queryString.append('path', opts.path);
}
return await this.get(
`readme/${encodeURIComponent(opts.project)}/${encodeURIComponent(
opts.repo,
+9 -2
View File
@@ -30,8 +30,15 @@ export function useReadme(entity: Entity): {
const api = useApi(azureDevOpsApiRef);
const { value, loading, error } = useAsync(() => {
const { project, repo, host, org } = getAnnotationValuesFromEntity(entity);
return api.getReadme({ project, repo: repo as string, host, org });
const { project, repo, host, org, readmePath } =
getAnnotationValuesFromEntity(entity);
return api.getReadme({
project,
repo: repo as string,
host,
org,
path: readmePath,
});
}, [api]);
return {
@@ -18,6 +18,7 @@ import { Entity } from '@backstage/catalog-model';
import {
AZURE_DEVOPS_PROJECT_ANNOTATION,
AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION,
AZURE_DEVOPS_README_ANNOTATION,
AZURE_DEVOPS_REPO_ANNOTATION,
AZURE_DEVOPS_HOST_ORG_ANNOTATION,
} from '@backstage/plugin-azure-devops-common';
@@ -28,6 +29,7 @@ export function getAnnotationValuesFromEntity(entity: Entity): {
definition?: string;
host?: string;
org?: string;
readmePath?: string;
} {
const hostOrg = getHostOrg(entity.metadata.annotations);
const projectRepo = getProjectRepo(entity.metadata.annotations);
@@ -35,12 +37,15 @@ export function getAnnotationValuesFromEntity(entity: Entity): {
entity.metadata.annotations?.[AZURE_DEVOPS_PROJECT_ANNOTATION];
const definition =
entity.metadata.annotations?.[AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION];
const readmePath =
entity.metadata.annotations?.[AZURE_DEVOPS_README_ANNOTATION];
if (definition) {
if (project) {
return {
project,
definition,
readmePath: readmePath,
...hostOrg,
};
}
@@ -49,6 +54,7 @@ export function getAnnotationValuesFromEntity(entity: Entity): {
project: projectRepo.project,
repo: projectRepo.repo,
definition,
readmePath: readmePath,
...hostOrg,
};
}
@@ -60,6 +66,7 @@ export function getAnnotationValuesFromEntity(entity: Entity): {
return {
project: projectRepo.project,
repo: projectRepo.repo,
readmePath: readmePath,
...hostOrg,
};
}