From 2e01ccacfb2797720c1866a2541a6a528bd58cbb Mon Sep 17 00:00:00 2001 From: Romain Billon Date: Sat, 1 Jun 2024 21:36:43 +0200 Subject: [PATCH 1/5] feat: add forceEmptyGitAuthor option to GitHub pull request action This update introduces the `forceEmptyGitAuthor` option to the GitHub pull request action in the scaffolder-backend-module-github. This new boolean option allows for the author information to be omitted from commits, which is particularly useful when using a GitHub App, enabling commits to be verified on GitHub. Signed-off-by: Romain Billon --- .../src/actions/githubPullRequest.ts | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts index 213d24eca7..fb6a932f11 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts @@ -146,6 +146,7 @@ export const createPublishGithubPullRequestAction = ( forceFork?: boolean; gitAuthorName?: string; gitAuthorEmail?: string; + forceEmptyGitAuthor?: boolean; }>({ id: 'publish:github:pull-request', examples, @@ -246,6 +247,12 @@ export const createPublishGithubPullRequestAction = ( description: "Sets the default author email for the commit. The default value is the authenticated user or 'scaffolder@backstage.io'", }, + forceEmptyGitAuthor: { + type: 'boolean', + title: 'Force Empty Git Author', + description: + 'Forces the author to be empty. This is useful when using a Github App, it permit the commit to be verified on Github', + }, }, }, output: { @@ -287,6 +294,7 @@ export const createPublishGithubPullRequestAction = ( forceFork, gitAuthorEmail, gitAuthorName, + forceEmptyGitAuthor, } = ctx.input; const { owner, repo, host } = parseRepoUrl(repoUrl, integrations); @@ -384,26 +392,29 @@ export const createPublishGithubPullRequestAction = ( config?.getOptionalString('scaffolder.defaultAuthor.email'), }; - if (gitAuthorInfo.name || gitAuthorInfo.email) { - if (Array.isArray(createOptions.changes)) { - createOptions.changes = createOptions.changes.map(change => ({ - ...change, - author: { - name: gitAuthorInfo.name || 'Scaffolder', - email: gitAuthorInfo.email || 'scaffolder@backstage.io', - }, - })); - } else { - createOptions.changes = { - ...createOptions.changes, - author: { - name: gitAuthorInfo.name || 'Scaffolder', - email: gitAuthorInfo.email || 'scaffolder@backstage.io', - }, - }; + if (!forceEmptyGitAuthor) { + if (gitAuthorInfo.name || gitAuthorInfo.email) { + if (Array.isArray(createOptions.changes)) { + createOptions.changes = createOptions.changes.map(change => ({ + ...change, + author: { + name: gitAuthorInfo.name || 'Scaffolder', + email: gitAuthorInfo.email || 'scaffolder@backstage.io', + }, + })); + } else { + createOptions.changes = { + ...createOptions.changes, + author: { + name: gitAuthorInfo.name || 'Scaffolder', + email: gitAuthorInfo.email || 'scaffolder@backstage.io', + }, + }; + } } } + if (targetBranchName) { createOptions.base = targetBranchName; } From 403394ad878995b7d449f9de5e11330d85b0dd09 Mon Sep 17 00:00:00 2001 From: Romain Billon Date: Sat, 1 Jun 2024 21:43:15 +0200 Subject: [PATCH 2/5] chore: add changeset Signed-off-by: Romain Billon --- .changeset/young-apes-thank.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/young-apes-thank.md diff --git a/.changeset/young-apes-thank.md b/.changeset/young-apes-thank.md new file mode 100644 index 0000000000..570316b2e2 --- /dev/null +++ b/.changeset/young-apes-thank.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-github': minor +--- + +Allow empty author info in createPullRequest action for Github From f912f6150aeac2cabd0b90112786613779d7a3a9 Mon Sep 17 00:00:00 2001 From: Romain Billon Date: Sat, 1 Jun 2024 21:53:31 +0200 Subject: [PATCH 3/5] chore: add tests on github pull request action to force empty authors Signed-off-by: Romain Billon --- .../src/actions/githubPullRequest.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.test.ts b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.test.ts index 485f7dec14..ccb1efa29b 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.test.ts @@ -1026,5 +1026,40 @@ describe('createPublishGithubPullRequestAction', () => { ], }); }); + it('discards author name and email if forceEmptyGitAuthor is set', async () => { + input.forceEmptyGitAuthor = true; + const clientFactory = jest.fn(async () => fakeClient as any); + const githubCredentialsProvider: GithubCredentialsProvider = { + getCredentials: jest.fn(), + }; + + const instanceWithConfig = createPublishGithubPullRequestAction({ + integrations, + githubCredentialsProvider, + clientFactory, + }); + + await instanceWithConfig.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', + files: { + 'file.txt': { + content: Buffer.from('Hello there!').toString('base64'), + encoding: 'base64', + mode: '100644', + }, + }, + }, + ], + }); + }); }); }); From aee300c364ebd18265187b2b0f48008c07d44434 Mon Sep 17 00:00:00 2001 From: Romain Billon Date: Sat, 1 Jun 2024 22:11:22 +0200 Subject: [PATCH 4/5] chore: run yarn prettier:fix Signed-off-by: Romain Billon --- .../src/actions/githubPullRequest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts index fb6a932f11..7fe9d8e401 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts @@ -414,7 +414,6 @@ export const createPublishGithubPullRequestAction = ( } } - if (targetBranchName) { createOptions.base = targetBranchName; } From d76ab8b28c9b3c3e91ce2d507c47d7a684379e1d Mon Sep 17 00:00:00 2001 From: Romain Billon Date: Sat, 1 Jun 2024 22:21:29 +0200 Subject: [PATCH 5/5] chore: add api-reports Signed-off-by: Romain Billon --- plugins/scaffolder-backend-module-github/api-report.md | 1 + plugins/scaffolder-backend/api-report.md | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/scaffolder-backend-module-github/api-report.md b/plugins/scaffolder-backend-module-github/api-report.md index b1a1c80af5..2bb4342bbf 100644 --- a/plugins/scaffolder-backend-module-github/api-report.md +++ b/plugins/scaffolder-backend-module-github/api-report.md @@ -392,6 +392,7 @@ export const createPublishGithubPullRequestAction: ( forceFork?: boolean | undefined; gitAuthorName?: string | undefined; gitAuthorEmail?: string | undefined; + forceEmptyGitAuthor?: boolean | undefined; }, JsonObject >; diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index c141733ec4..4c7b11ea43 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -289,6 +289,7 @@ export const createPublishGithubPullRequestAction: ( forceFork?: boolean | undefined; gitAuthorName?: string | undefined; gitAuthorEmail?: string | undefined; + forceEmptyGitAuthor?: boolean | undefined; }, JsonObject >;