From f062a98710cb35cee316a699ae303defa77c48c5 Mon Sep 17 00:00:00 2001 From: Kevin L Date: Mon, 10 Jun 2024 12:57:46 -0400 Subject: [PATCH 1/5] Use webUrl instead of remoteUrl to set the value of repoContentsUrl. Signed-off-by: Kevin L --- .../src/actions/azure.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 From b4169eef06e2179865cce5a14c6113903bc24f10 Mon Sep 17 00:00:00 2001 From: Kevin L Date: Mon, 10 Jun 2024 13:14:32 -0400 Subject: [PATCH 2/5] Add changeset file Signed-off-by: Kevin L --- .changeset/nasty-doors-grab.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nasty-doors-grab.md diff --git a/.changeset/nasty-doors-grab.md b/.changeset/nasty-doors-grab.md new file mode 100644 index 0000000000..46165f1616 --- /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/). From d2f74008774d627154ee10e402e949e28d176445 Mon Sep 17 00:00:00 2001 From: Kevin L Date: Tue, 11 Jun 2024 07:17:46 -0400 Subject: [PATCH 3/5] Fix test suites for Azure Scaffolder Signed-off-by: Kevin L --- .../src/actions/azure.examples.test.ts | 2 ++ .../src/actions/azure.test.ts | 7 +++++++ 2 files changed, 9 insertions(+) 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..34b226dbbf 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', })); @@ -188,6 +189,7 @@ describe('publish:azure', () => { 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 +216,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 +236,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 +287,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 +329,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 +349,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', })); From 2e1a8159ea713e45e2aae23e96257aaedae852a8 Mon Sep 17 00:00:00 2001 From: Kevin L Date: Tue, 11 Jun 2024 07:25:18 -0400 Subject: [PATCH 4/5] Add test for repoContentsUrl Signed-off-by: Kevin L --- .../src/actions/azure.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 34b226dbbf..a21520f751 100644 --- a/plugins/scaffolder-backend-module-azure/src/actions/azure.test.ts +++ b/plugins/scaffolder-backend-module-azure/src/actions/azure.test.ts @@ -159,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( @@ -174,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( @@ -186,6 +188,22 @@ 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', From a07d10fc866cb6c1730b82e15eec45254d09fb9d Mon Sep 17 00:00:00 2001 From: Ben Lambert Date: Wed, 12 Jun 2024 16:49:58 +0200 Subject: [PATCH 5/5] Update nasty-doors-grab.md Signed-off-by: Ben Lambert --- .changeset/nasty-doors-grab.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/nasty-doors-grab.md b/.changeset/nasty-doors-grab.md index 46165f1616..971843d053 100644 --- a/.changeset/nasty-doors-grab.md +++ b/.changeset/nasty-doors-grab.md @@ -2,4 +2,4 @@ '@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/). +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/`).