From 0579396bcede5f59421b126462ba42ff7aad333e Mon Sep 17 00:00:00 2001 From: "pballandras@coveo.com" Date: Tue, 21 Mar 2023 15:10:17 -0400 Subject: [PATCH] Add commit message as parameter test as well Signed-off-by: pballandras@coveo.com --- .../builtin/publish/githubPullRequest.test.ts | 52 +++++++++++++++++++ .../builtin/publish/githubPullRequest.ts | 9 +++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts index 70fff20446..7750277728 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.test.ts @@ -545,4 +545,56 @@ describe('createPublishGithubPullRequestAction', () => { expect(ctx.output).toHaveBeenCalledWith('pullRequestNumber', 123); }); }); + + describe('with commit message', () => { + let input: GithubPullRequestActionInput; + let ctx: ActionContext; + + beforeEach(() => { + input = { + repoUrl: 'github.com?owner=myorg&repo=myrepo', + title: 'Create my new app', + branchName: 'new-app', + description: 'This PR is really good', + commitMessage: 'Create my new app, but in the commit message', + }; + + mockFs({ + [workspacePath]: { 'file.txt': 'Hello there!' }, + }); + + ctx = { + createTemporaryDirectory: jest.fn(), + output: jest.fn(), + logger: getRootLogger(), + logStream: new Writable(), + input, + workspacePath, + }; + }); + + it('creates a pull request', async () => { + await instance.handler(ctx); + + expect(fakeClient.createPullRequest).toHaveBeenCalledWith({ + owner: 'myorg', + repo: 'myrepo', + title: 'Create my new app', + head: 'new-app', + body: 'This PR is really good', + changes: [ + { + commit: 'Create my new app, but in the commit message', + files: { + 'file.txt': { + content: Buffer.from('Hello there!').toString('base64'), + encoding: 'base64', + mode: '100644', + }, + }, + }, + ], + }); + }); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts index b8c0068d70..28fe89318b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts @@ -136,6 +136,7 @@ export const createPublishGithubPullRequestAction = ( token?: string; reviewers?: string[]; teamReviewers?: string[]; + commitMessage?: string; }>({ id: 'publish:github:pull-request', schema: { @@ -202,6 +203,11 @@ export const createPublishGithubPullRequestAction = ( description: 'The teams that will be added as reviewers to the pull request', }, + commitMessage: { + type: 'string', + title: 'Commit Message', + description: 'The commit message for the PR commit', + }, }, }, output: { @@ -233,6 +239,7 @@ export const createPublishGithubPullRequestAction = ( token: providedToken, reviewers, teamReviewers, + commitMessage, } = ctx.input; const { owner, repo, host } = parseRepoUrl(repoUrl, integrations); @@ -298,7 +305,7 @@ export const createPublishGithubPullRequestAction = ( changes: [ { files, - commit: title, + commit: commitMessage || title, }, ], body: description,