diff --git a/.changeset/pink-moons-smell.md b/.changeset/pink-moons-smell.md new file mode 100644 index 0000000000..77475295be --- /dev/null +++ b/.changeset/pink-moons-smell.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Added `repositoryId` output when create a repository in Azure diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts index ee901453e1..ca5e40bdb0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.test.ts @@ -122,6 +122,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', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await action.handler({ @@ -148,6 +149,7 @@ describe('publish:azure', () => { it('should throw if there is no remoteUrl returned', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: null, + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await expect( action.handler({ @@ -159,9 +161,25 @@ describe('publish:azure', () => { ).rejects.toThrow(/No remote URL returned/); }); + it('should throw if there is no repositoryId returned', async () => { + mockGitClient.createRepository.mockImplementation(() => ({ + remoteUrl: 'http://google.com', + id: null, + })); + await expect( + action.handler({ + ...mockContext, + input: { + repoUrl: 'dev.azure.com?repo=bob&owner=owner&organization=org', + }, + }), + ).rejects.toThrow(/No Id returned/); + }); + it('should call the azureApis with the correct values', async () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'http://google.com', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await action.handler(mockContext); @@ -182,6 +200,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', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await action.handler(mockContext); @@ -200,6 +219,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', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await action.handler({ @@ -246,6 +266,7 @@ describe('publish:azure', () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await customAuthorAction.handler(mockContext); @@ -283,6 +304,7 @@ describe('publish:azure', () => { mockGitClient.createRepository.mockImplementation(() => ({ remoteUrl: 'https://dev.azure.com/organization/project/_git/repo', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await customAuthorAction.handler(mockContext); @@ -298,9 +320,10 @@ describe('publish:azure', () => { }); }); - it('should call output with the remoteUrl and the repoContentsUrl', async () => { + 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', + id: '709e891c-dee7-4f91-b963-534713c0737f', })); await action.handler(mockContext); @@ -313,5 +336,9 @@ describe('publish:azure', () => { 'repoContentsUrl', 'https://dev.azure.com/organization/project/_git/repo', ); + expect(mockContext.output).toHaveBeenCalledWith( + 'repositoryId', + '709e891c-dee7-4f91-b963-534713c0737f', + ); }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts index 447b39573c..60b13b717d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts @@ -104,6 +104,10 @@ export function createPublishAzureAction(options: { title: 'A URL to the root of the repository', type: 'string', }, + repositoryId: { + title: 'The Id of the created repository', + type: 'string', + }, }, }, }, @@ -160,6 +164,11 @@ export function createPublishAzureAction(options: { 'No remote URL returned from create repository for Azure', ); } + const repositoryId = returnedRepo.id; + + if (!repositoryId) { + 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 @@ -191,6 +200,7 @@ export function createPublishAzureAction(options: { ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); + ctx.output('repositoryId', repositoryId); }, }); }