diff --git a/.changeset/mighty-geckos-kiss.md b/.changeset/mighty-geckos-kiss.md new file mode 100644 index 0000000000..0761d8b257 --- /dev/null +++ b/.changeset/mighty-geckos-kiss.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-node': patch +--- + +Update `patchMkdocsYmlPrebuild` to modify `repo_url` and `edit_uri` independently. diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index 3589b71c60..6ee3870845 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -295,7 +295,32 @@ describe('helpers', () => { 'edit_uri: https://github.com/backstage/backstage/edit/main/docs', ); expect(updatedMkdocsYml.toString()).not.toContain( - 'https://github.com/neworg/newrepo', + 'edit_uri: https://github.com/neworg/newrepo', + ); + }); + + it('should add edit_uri to mkdocs.yml with existing repo_url', async () => { + const parsedLocationAnnotation: ParsedLocationAnnotation = { + type: 'url', + target: 'https://github.com/neworg/newrepo/tree/main/', + }; + + await patchMkdocsYmlPreBuild( + mockDir.resolve('mkdocs_with_repo_url.yml'), + mockLogger, + parsedLocationAnnotation, + scmIntegrations, + ); + + const updatedMkdocsYml = await fs.readFile( + mockDir.resolve('mkdocs_with_repo_url.yml'), + ); + + expect(updatedMkdocsYml.toString()).toContain( + 'edit_uri: https://github.com/neworg/newrepo/edit/main/docs', + ); + expect(updatedMkdocsYml.toString()).toContain( + 'repo_url: https://github.com/backstage/backstage', ); }); diff --git a/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts b/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts index 762a1c267a..fb95c19a9c 100644 --- a/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts +++ b/plugins/techdocs-node/src/stages/generate/mkdocsPatchers.ts @@ -108,7 +108,7 @@ export const patchMkdocsYmlPreBuild = async ( scmIntegrations: ScmIntegrationRegistry, ) => { await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => { - if (!('repo_url' in mkdocsYml) && !('edit_uri' in mkdocsYml)) { + if (!('repo_url' in mkdocsYml) || !('edit_uri' in mkdocsYml)) { // Add edit_uri and/or repo_url to mkdocs.yml if it is missing. // This will enable the Page edit button generated by MkDocs. // If the either has been set, keep the original value @@ -119,8 +119,8 @@ export const patchMkdocsYmlPreBuild = async ( ); if (result.repo_url || result.edit_uri) { - mkdocsYml.repo_url = result.repo_url; - mkdocsYml.edit_uri = result.edit_uri; + mkdocsYml.repo_url = mkdocsYml.repo_url || result.repo_url; + mkdocsYml.edit_uri = mkdocsYml.edit_uri || result.edit_uri; logger.info( `Set ${JSON.stringify(