From d1f7ba58e3e97598ddd94fcab66db78ea0675a41 Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Fri, 26 Aug 2022 16:29:50 +0100 Subject: [PATCH 1/3] 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); }, }); } From ad72417ac05f007f57d481ccb4d77af8eee2117e Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Fri, 26 Aug 2022 17:08:35 +0100 Subject: [PATCH 2/3] fix: adjust tests Signed-off-by: Alisson Fabiano --- .../src/scaffolder/actions/builtin/publish/azure.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) 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 b08a248a96..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({ @@ -177,6 +179,7 @@ describe('publish:azure', () => { 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); @@ -197,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); @@ -215,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({ @@ -261,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); @@ -298,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); From 1b1dadc92bc0bd783663dc2df7501f2e23d3b675 Mon Sep 17 00:00:00 2001 From: Alisson Fabiano Date: Mon, 29 Aug 2022 09:37:58 +0100 Subject: [PATCH 3/3] chore: adjust changeset and removed dryRun suports Signed-off-by: Alisson Fabiano --- .changeset/pink-moons-smell.md | 41 +------------------ .../actions/builtin/publish/azure.ts | 1 - 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/.changeset/pink-moons-smell.md b/.changeset/pink-moons-smell.md index 9c74340f74..77475295be 100644 --- a/.changeset/pink-moons-smell.md +++ b/.changeset/pink-moons-smell.md @@ -2,43 +2,4 @@ '@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); -``` +Added `repositoryId` output when create a repository in Azure 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 12624eac54..60b13b717d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/azure.ts @@ -44,7 +44,6 @@ 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.',