From 0579396bcede5f59421b126462ba42ff7aad333e Mon Sep 17 00:00:00 2001 From: "pballandras@coveo.com" Date: Tue, 21 Mar 2023 15:10:17 -0400 Subject: [PATCH 1/4] 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, From d7c8c222e258e59a2b16808d2102e297675d8247 Mon Sep 17 00:00:00 2001 From: "pballandras@coveo.com" Date: Wed, 22 Mar 2023 09:49:09 -0400 Subject: [PATCH 2/4] Add changeset Signed-off-by: pballandras@coveo.com --- .changeset/slow-ravens-destroy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slow-ravens-destroy.md diff --git a/.changeset/slow-ravens-destroy.md b/.changeset/slow-ravens-destroy.md new file mode 100644 index 0000000000..a75793f86f --- /dev/null +++ b/.changeset/slow-ravens-destroy.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Allow for a commit message to differ from the PR title when publishing a GitHub pull request. From a761c531585777cdb09731ba9a75280b71d9fcbc Mon Sep 17 00:00:00 2001 From: "pballandras@coveo.com" Date: Wed, 22 Mar 2023 10:48:16 -0400 Subject: [PATCH 3/4] Add api report change Signed-off-by: pballandras@coveo.com --- plugins/scaffolder-backend/api-report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index 2faaeca7cc..5b12455d0f 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -559,6 +559,7 @@ export const createPublishGithubPullRequestAction: ( token?: string | undefined; reviewers?: string[] | undefined; teamReviewers?: string[] | undefined; + commitMessage?: string | undefined; }, JsonObject >; From e78f083cb2f6a31f3ecc1ae223f987856ea9181c Mon Sep 17 00:00:00 2001 From: Philippe Ballandras Date: Thu, 30 Mar 2023 13:49:13 -0400 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Boris Bera Signed-off-by: Philippe Ballandras --- .../scaffolder/actions/builtin/publish/githubPullRequest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 28fe89318b..6706ad9c06 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts @@ -206,7 +206,7 @@ export const createPublishGithubPullRequestAction = ( commitMessage: { type: 'string', title: 'Commit Message', - description: 'The commit message for the PR commit', + description: 'The commit message for the pull request commit', }, }, }, @@ -305,7 +305,7 @@ export const createPublishGithubPullRequestAction = ( changes: [ { files, - commit: commitMessage || title, + commit: commitMessage ?? title, }, ], body: description,