Merge pull request #13377 from alissonfabiano/af/add-param-output-azure-action

[Scaffolder Backend] add repository ID output in Azure publish action
This commit is contained in:
Ben Lambert
2022-08-31 11:28:10 +02:00
committed by GitHub
3 changed files with 43 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': minor
---
Added `repositoryId` output when create a repository in Azure
@@ -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',
);
});
});
@@ -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);
},
});
}