feat(scaffolder-backend): add sourcePath option to publish:gerrit action

Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
This commit is contained in:
Thomas Cardonne
2022-07-12 16:35:02 +02:00
parent af42c73a83
commit 945a27fa6a
4 changed files with 65 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Add sourcePath option to publish:gerrit action
+1
View File
@@ -316,6 +316,7 @@ export function createPublishGerritAction(options: {
gitCommitMessage?: string | undefined;
gitAuthorName?: string | undefined;
gitAuthorEmail?: string | undefined;
sourcePath?: string | undefined;
}>;
// @public
@@ -137,6 +137,57 @@ describe('publish:gerrit', () => {
'https://gerrithost.org/repo/+/refs/heads/master',
);
});
it('can correctly create a new project with a specific sourcePath', async () => {
expect.assertions(5);
server.use(
rest.put('https://gerrithost.org/a/projects/repo', (req, res, ctx) => {
expect(req.headers.get('Authorization')).toBe(
'Basic Z2Vycml0dXNlcjp1c2VydG9rZW4=',
);
expect(req.body).toEqual({
create_empty_commit: false,
owners: ['owner'],
description,
parent: 'workspace',
});
return res(
ctx.status(201),
ctx.set('Content-Type', 'application/json'),
ctx.json({}),
);
}),
);
await action.handler({
...mockContext,
input: {
...mockContext.input,
repoUrl: 'gerrithost.org?workspace=workspace&owner=owner&repo=repo',
sourcePath: 'repository/',
},
});
expect(initRepoAndPush).toHaveBeenCalledWith({
dir: `${mockContext.workspacePath}/repository/`,
remoteUrl: 'https://gerrithost.org/a/repo',
defaultBranch: 'master',
auth: { username: 'gerrituser', password: 'usertoken' },
logger: mockContext.logger,
commitMessage: expect.stringContaining('initial commit\n\nChange-Id:'),
gitAuthorInfo: {},
});
expect(mockContext.output).toHaveBeenCalledWith(
'remoteUrl',
'https://gerrithost.org/a/repo',
);
expect(mockContext.output).toHaveBeenCalledWith(
'repoContentsUrl',
'https://gerrithost.org/repo/+/refs/heads/master',
);
});
afterEach(() => {
jest.resetAllMocks();
});
@@ -92,6 +92,7 @@ export function createPublishGerritAction(options: {
gitCommitMessage?: string;
gitAuthorName?: string;
gitAuthorEmail?: string;
sourcePath?: string;
}>({
id: 'publish:gerrit',
description:
@@ -129,6 +130,11 @@ export function createPublishGerritAction(options: {
type: 'string',
description: `Sets the default author email for the commit.`,
},
sourcePath: {
title: 'Source Path',
type: 'string',
description: `Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.`,
},
},
},
output: {
@@ -153,6 +159,7 @@ export function createPublishGerritAction(options: {
gitAuthorName,
gitAuthorEmail,
gitCommitMessage = 'initial commit',
sourcePath,
} = ctx.input;
const { repo, host, owner, workspace } = parseRepoUrl(
repoUrl,
@@ -199,7 +206,7 @@ export function createPublishGerritAction(options: {
const remoteUrl = `${integrationConfig.config.cloneUrl}/a/${repo}`;
await initRepoAndPush({
dir: getRepoSourceDirectory(ctx.workspacePath, undefined),
dir: getRepoSourceDirectory(ctx.workspacePath, sourcePath),
remoteUrl,
auth,
defaultBranch,