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. 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 >; 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..6706ad9c06 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 pull request 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,