From 61f7a1911b36dd523a27297a5210f9093441b4a2 Mon Sep 17 00:00:00 2001 From: Deepankumar Loganathan Date: Thu, 15 Feb 2024 21:04:09 +0100 Subject: [PATCH 1/4] fixed Azure DevOps ADR file path Signed-off-by: Deepankumar Loganathan --- plugins/adr/src/components/AdrReader/AdrReader.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/adr/src/components/AdrReader/AdrReader.tsx b/plugins/adr/src/components/AdrReader/AdrReader.tsx index 6b07eee4cd..f41b1b1fdb 100644 --- a/plugins/adr/src/components/AdrReader/AdrReader.tsx +++ b/plugins/adr/src/components/AdrReader/AdrReader.tsx @@ -45,8 +45,18 @@ export const AdrReader = (props: { const scmIntegrations = useApi(scmIntegrationsApiRef); const adrApi = useApi(adrApiRef); const adrLocationUrl = getAdrLocationUrl(entity, scmIntegrations); + let url = `${adrLocationUrl.replace(/\/$/, '')}`; + const adrUrlPath = url.match(/path=\/.*\&/); + if (adrUrlPath) { + // Azure DevOps SCM handle the path in URL Params + const adrPath = adrUrlPath![0].replace(/\&$/, ''); + const regex = new RegExp(`${adrPath}`); + url = url.replace(regex, `${adrPath}/${adr}}`); + } else { + // Other SCM tools + url = `${url}/${adr}`; + } - const url = `${adrLocationUrl.replace(/\/$/, '')}/${adr}`; const { value, loading, error } = useAsync( async () => adrApi.readAdr(url), [url], From 533563474d98fecd3615fd2f2442a0aea112f3ab Mon Sep 17 00:00:00 2001 From: Deepankumar Loganathan Date: Fri, 16 Feb 2024 09:35:35 +0100 Subject: [PATCH 2/4] changeset updated Signed-off-by: Deepankumar Loganathan --- .changeset/clever-eagles-boil.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clever-eagles-boil.md diff --git a/.changeset/clever-eagles-boil.md b/.changeset/clever-eagles-boil.md new file mode 100644 index 0000000000..6e69d2db2f --- /dev/null +++ b/.changeset/clever-eagles-boil.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-adr': patch +--- + +Fixed Azure DevOps ADR file path From 2e925ed0764a67ef667cdb73e6fdff9a1db9c502 Mon Sep 17 00:00:00 2001 From: Deepankumar Loganathan Date: Tue, 20 Feb 2024 22:18:12 +0100 Subject: [PATCH 3/4] fixed ADR file path in UrlResolver Signed-off-by: Deepankumar Loganathan --- plugins/adr-common/api-report.md | 1 + plugins/adr-common/src/index.ts | 8 ++++++++ .../adr/src/components/AdrReader/AdrReader.tsx | 17 +++-------------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/plugins/adr-common/api-report.md b/plugins/adr-common/api-report.md index a36854f0e7..f12a086359 100644 --- a/plugins/adr-common/api-report.md +++ b/plugins/adr-common/api-report.md @@ -25,6 +25,7 @@ export const ANNOTATION_ADR_LOCATION = 'backstage.io/adr-location'; export const getAdrLocationUrl: ( entity: Entity, scmIntegration: ScmIntegrationRegistry, + adrFilePath?: String, ) => string; // @public diff --git a/plugins/adr-common/src/index.ts b/plugins/adr-common/src/index.ts index 97c82b2047..7b441d091c 100644 --- a/plugins/adr-common/src/index.ts +++ b/plugins/adr-common/src/index.ts @@ -57,11 +57,19 @@ 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}`); } + if (adrFilePath) { + return scmIntegration.resolveUrl({ + url: `${getAdrLocationDir(entity)!.replace(/\/$/, '')}/${adrFilePath}`, + base: getEntitySourceLocation(entity).target, + }); + } + return scmIntegration.resolveUrl({ url: getAdrLocationDir(entity)!, base: getEntitySourceLocation(entity).target, diff --git a/plugins/adr/src/components/AdrReader/AdrReader.tsx b/plugins/adr/src/components/AdrReader/AdrReader.tsx index f41b1b1fdb..2169165288 100644 --- a/plugins/adr/src/components/AdrReader/AdrReader.tsx +++ b/plugins/adr/src/components/AdrReader/AdrReader.tsx @@ -44,22 +44,11 @@ export const AdrReader = (props: { const { entity } = useEntity(); const scmIntegrations = useApi(scmIntegrationsApiRef); const adrApi = useApi(adrApiRef); - const adrLocationUrl = getAdrLocationUrl(entity, scmIntegrations); - let url = `${adrLocationUrl.replace(/\/$/, '')}`; - const adrUrlPath = url.match(/path=\/.*\&/); - if (adrUrlPath) { - // Azure DevOps SCM handle the path in URL Params - const adrPath = adrUrlPath![0].replace(/\&$/, ''); - const regex = new RegExp(`${adrPath}`); - url = url.replace(regex, `${adrPath}/${adr}}`); - } else { - // Other SCM tools - url = `${url}/${adr}`; - } + const adrLocationUrl = getAdrLocationUrl(entity, scmIntegrations, adr); const { value, loading, error } = useAsync( - async () => adrApi.readAdr(url), - [url], + async () => adrApi.readAdr(adrLocationUrl), + [adrLocationUrl], ); const adrContent = useMemo(() => { From 329e210003bc66c71326162c2a79446bbff4d1f6 Mon Sep 17 00:00:00 2001 From: Deepankumar Loganathan Date: Wed, 21 Feb 2024 19:46:23 +0100 Subject: [PATCH 4/4] added adrFileLocationUrl for adr file read Signed-off-by: Deepankumar Loganathan --- plugins/adr-common/src/index.ts | 9 ++++----- plugins/adr/src/components/AdrReader/AdrReader.tsx | 7 ++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/adr-common/src/index.ts b/plugins/adr-common/src/index.ts index 7b441d091c..85d61cd270 100644 --- a/plugins/adr-common/src/index.ts +++ b/plugins/adr-common/src/index.ts @@ -63,15 +63,14 @@ export const getAdrLocationUrl = ( throw new Error(`Missing ADR annotation: ${ANNOTATION_ADR_LOCATION}`); } + let url = getAdrLocationDir(entity)!.replace(/\/$/, ''); + if (adrFilePath) { - return scmIntegration.resolveUrl({ - url: `${getAdrLocationDir(entity)!.replace(/\/$/, '')}/${adrFilePath}`, - base: getEntitySourceLocation(entity).target, - }); + url = `${url}/${adrFilePath}`; } return scmIntegration.resolveUrl({ - url: getAdrLocationDir(entity)!, + url, base: getEntitySourceLocation(entity).target, }); }; diff --git a/plugins/adr/src/components/AdrReader/AdrReader.tsx b/plugins/adr/src/components/AdrReader/AdrReader.tsx index 2169165288..d0dd8b7444 100644 --- a/plugins/adr/src/components/AdrReader/AdrReader.tsx +++ b/plugins/adr/src/components/AdrReader/AdrReader.tsx @@ -44,11 +44,12 @@ export const AdrReader = (props: { const { entity } = useEntity(); const scmIntegrations = useApi(scmIntegrationsApiRef); const adrApi = useApi(adrApiRef); - const adrLocationUrl = getAdrLocationUrl(entity, scmIntegrations, adr); + const adrLocationUrl = getAdrLocationUrl(entity, scmIntegrations); + const adrFileLocationUrl = getAdrLocationUrl(entity, scmIntegrations, adr); const { value, loading, error } = useAsync( - async () => adrApi.readAdr(adrLocationUrl), - [adrLocationUrl], + async () => adrApi.readAdr(adrFileLocationUrl), + [adrFileLocationUrl], ); const adrContent = useMemo(() => {