fixed ADR file path in UrlResolver
Signed-off-by: Deepankumar Loganathan <deepan0433@gmail.com>
This commit is contained in:
Generated
+1
@@ -25,6 +25,7 @@ export const ANNOTATION_ADR_LOCATION = 'backstage.io/adr-location';
|
||||
export const getAdrLocationUrl: (
|
||||
entity: Entity,
|
||||
scmIntegration: ScmIntegrationRegistry,
|
||||
adrFilePath?: String,
|
||||
) => string;
|
||||
|
||||
// @public
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user