From d1f7ba58e3e97598ddd94fcab66db78ea0675a41 Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Fri, 26 Aug 2022 16:29:50 +0100 Subject: [PATCH] feat: created new output parameter Signed-off-by: Alisson Fabiano --- .changeset/pink-moons-smell.md | 44 +++++++++++++++++++ .../actions/builtin/publish/azure.test.ts | 22 +++++++++- .../actions/builtin/publish/azure.ts | 11 +++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .changeset/pink-moons-smell.md diff --git a/.changeset/pink-moons-smell.md b/.changeset/pink-moons-smell.md new file mode 100644 index 0000000000..9c74340f74 --- /dev/null +++ b/.changeset/pink-moons-smell.md @@ -0,0 +1,44 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Added repositoryId return when creating a repository in Azure + +```diff +output: { + type: 'object', + properties: { + remoteUrl: { + title: 'A URL to the repository with the provider', + type: 'string', + }, + repoContentsUrl: { + title: 'A URL to the root of the repository', + type: 'string', + }, ++ repositoryId: { ++ title: 'The Id of the created repository', ++ type: 'string', ++ }, + }, +}, + + +const remoteUrl = returnedRepo.remoteUrl; + +if (!remoteUrl) { + throw new InputError( + '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'); ++} + + +ctx.output('remoteUrl', remoteUrl); +ctx.output('repoContentsUrl', repoContentsUrl); ++ctx.output('repositoryId', repositoryId); +``` 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..b08a248a96 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 @@ -159,6 +159,21 @@ 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', @@ -298,9 +313,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 +329,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..12624eac54 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts @@ -44,6 +44,7 @@ export function createPublishAzureAction(options: { gitAuthorName?: string; gitAuthorEmail?: string; }>({ + supportsDryRun: true, id: 'publish:azure', description: 'Initializes a git repository of the content in the workspace, and publishes it to Azure.', @@ -104,6 +105,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 +165,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 +201,7 @@ export function createPublishAzureAction(options: { ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl); + ctx.output('repositoryId', repositoryId); }, }); }