diff --git a/.changeset/nasty-doors-grab.md b/.changeset/nasty-doors-grab.md new file mode 100644 index 0000000000..971843d053 --- /dev/null +++ b/.changeset/nasty-doors-grab.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-azure': patch +--- + +Use `GitRepository.webUrl` instead of `GitRepository.remoteUrl` to set the value of `repoContentsUrl` as `remoteUrl` can sometimes return an URL with the wrong format (e.g. `https://@dev.azure.com///\_git/`). diff --git a/plugins/scaffolder-backend-module-azure/src/actions/azure.examples.test.ts b/plugins/scaffolder-backend-module-azure/src/actions/azure.examples.test.ts index e00362c457..35868274fd 100644 --- a/plugins/scaffolder-backend-module-azure/src/actions/azure.examples.test.ts +++ b/plugins/scaffolder-backend-module-azure/src/actions/azure.examples.test.ts @@ -72,6 +72,7 @@ describe('publish:azure examples', () => { it('should call initRepoAndPush with the correct values', async () => { mockGitClient.createRepository.mockResolvedValue({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', }); @@ -94,6 +95,7 @@ describe('publish:azure examples', () => { it('should call initRepoAndPush with a changed default branch', async () => { mockGitClient.createRepository.mockResolvedValue({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', }); diff --git a/plugins/scaffolder-backend-module-azure/src/actions/azure.test.ts b/plugins/scaffolder-backend-module-azure/src/actions/azure.test.ts index a23eebb93a..a21520f751 100644 --- a/plugins/scaffolder-backend-module-azure/src/actions/azure.test.ts +++ b/plugins/scaffolder-backend-module-azure/src/actions/azure.test.ts @@ -131,6 +131,7 @@ describe('publish:azure', () => { it('should not throw if there is a token provided through ctx.input', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'http://google.com', + webUrl: 'http://google.com', id: '709e891c-dee7-4f91-b963-534713c0737f', })); @@ -158,6 +159,7 @@ describe('publish:azure', () => { it('should throw if there is no remoteUrl returned', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: null, + webUrl: 'http://google.com', id: '709e891c-dee7-4f91-b963-534713c0737f', })); await expect( @@ -173,6 +175,7 @@ describe('publish:azure', () => { it('should throw if there is no repositoryId returned', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'http://google.com', + webUrl: 'http://google.com', id: null, })); await expect( @@ -185,9 +188,26 @@ describe('publish:azure', () => { ).rejects.toThrow(/No Id returned/); }); + it('should throw if there is no repoContentsUrl returned', async () => { + mockGitClient.createRepository.mockImplementation(() => ({ + remoteUrl: 'http://google.com', + webUrl: null, + id: '709e891c-dee7-4f91-b963-534713c0737f', + })); + await expect( + action.handler({ + ...mockContext, + input: { + repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org', + }, + }), + ).rejects.toThrow(/No web URL returned/); + }); + it('should call the azureApis with the correct values', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'http://google.com', + webUrl: 'http://google.com', id: '709e891c-dee7-4f91-b963-534713c0737f', })); @@ -214,6 +234,7 @@ describe('publish:azure', () => { it('should call initRepoAndPush with the correct values', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', })); @@ -233,6 +254,7 @@ describe('publish:azure', () => { it('should call initRepoAndPush with the correct default branch', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', })); @@ -283,6 +305,7 @@ describe('publish:azure', () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', })); @@ -324,6 +347,7 @@ describe('publish:azure', () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', })); @@ -343,6 +367,7 @@ describe('publish:azure', () => { it('should call output with the remoteUrl the repoContentsUrl and the repositoryId', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + webUrl: 'https://dev.azure.com/organization/project/_git/repo', id: '709e891c-dee7-4f91-b963-534713c0737f', })); diff --git a/plugins/scaffolder-backend-module-azure/src/actions/azure.ts b/plugins/scaffolder-backend-module-azure/src/actions/azure.ts index e90cfeade4..bd75cedc65 100644 --- a/plugins/scaffolder-backend-module-azure/src/actions/azure.ts +++ b/plugins/scaffolder-backend-module-azure/src/actions/azure.ts @@ -187,9 +187,13 @@ export function createPublishAzureAction(options: { throw new InputError('No Id returned from create repository for Azure'); } - // blam: Repo contents is serialized into the path, - // so it's just the base path I think - const repoContentsUrl = remoteUrl; + const repoContentsUrl = returnedRepo.webUrl; + + if (!repoContentsUrl) { + throw new InputError( + 'No web URL returned from create repository for Azure', + ); + } const gitAuthorInfo = { name: gitAuthorName