Merge pull request #23007 from deepan10/adr-issue-22102

Fixed: ADR file path in Azure DevOps
This commit is contained in:
Ben Lambert
2024-02-26 16:40:53 +01:00
committed by GitHub
4 changed files with 17 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-adr': patch
---
Fixed Azure DevOps ADR file path
+1
View File
@@ -25,6 +25,7 @@ export const ANNOTATION_ADR_LOCATION = 'backstage.io/adr-location';
export const getAdrLocationUrl: (
entity: Entity,
scmIntegration: ScmIntegrationRegistry,
adrFilePath?: String,
) => string;
// @public
+8 -1
View File
@@ -57,13 +57,20 @@ export const isAdrAvailable = (entity: Entity) =>
export const getAdrLocationUrl = (
entity: Entity,
scmIntegration: ScmIntegrationRegistry,
adrFilePath?: String,
) => {
if (!isAdrAvailable(entity)) {
throw new Error(`Missing ADR annotation: ${ANNOTATION_ADR_LOCATION}`);
}
let url = getAdrLocationDir(entity)!.replace(/\/$/, '');
if (adrFilePath) {
url = `${url}/${adrFilePath}`;
}
return scmIntegration.resolveUrl({
url: getAdrLocationDir(entity)!,
url,
base: getEntitySourceLocation(entity).target,
});
};
@@ -45,11 +45,11 @@ export const AdrReader = (props: {
const scmIntegrations = useApi(scmIntegrationsApiRef);
const adrApi = useApi(adrApiRef);
const adrLocationUrl = getAdrLocationUrl(entity, scmIntegrations);
const adrFileLocationUrl = getAdrLocationUrl(entity, scmIntegrations, adr);
const url = `${adrLocationUrl.replace(/\/$/, '')}/${adr}`;
const { value, loading, error } = useAsync(
async () => adrApi.readAdr(url),
[url],
async () => adrApi.readAdr(adrFileLocationUrl),
[adrFileLocationUrl],
);
const adrContent = useMemo(() => {