From 1ba7f03f4932fa80923a0eecdf9e70de16b9bddc Mon Sep 17 00:00:00 2001 From: Abel Rodriguez Date: Wed, 24 Jan 2024 14:14:06 -0600 Subject: [PATCH 1/5] add forceFork input to createPullRequest Signed-off-by: Abel Rodriguez --- .../src/actions/githubPullRequest.test.ts | 53 +++++++++++++++++++ .../src/actions/githubPullRequest.ts | 8 +++ 2 files changed, 61 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 c5b1038a01..3fe4f62e04 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.test.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.test.ts @@ -687,4 +687,57 @@ describe('createPublishGithubPullRequestAction', () => { }); }); }); + + describe('with force fork', () => { + 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', + forceFork: true, + }; + + mockDir.setContent({ + [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', + files: { + 'file.txt': { + content: Buffer.from('Hello there!').toString('base64'), + encoding: 'base64', + mode: '100644', + }, + }, + }, + ], + forceFork: true, + }); + }); + }); }); diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts index 2d8dc7ce8d..6a5c939905 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubPullRequest.ts @@ -135,6 +135,7 @@ export const createPublishGithubPullRequestAction = ( teamReviewers?: string[]; commitMessage?: string; update?: boolean; + forceFork?: boolean; }>({ id: 'publish:github:pull-request', examples, @@ -217,6 +218,11 @@ export const createPublishGithubPullRequestAction = ( title: 'Update', description: 'Update pull request if already exists', }, + forceFork: { + type: 'boolean', + title: 'Force Fork', + description: 'Create pull request from a fork', + }, }, }, output: { @@ -255,6 +261,7 @@ export const createPublishGithubPullRequestAction = ( teamReviewers, commitMessage, update, + forceFork, } = ctx.input; const { owner, repo, host } = parseRepoUrl(repoUrl, integrations); @@ -327,6 +334,7 @@ export const createPublishGithubPullRequestAction = ( head: branchName, draft, update, + forceFork, }; if (targetBranchName) { createOptions.base = targetBranchName; From fd5eb1c176dd855882dc997231d41e1ab2d753d3 Mon Sep 17 00:00:00 2001 From: Abel Rodriguez Date: Wed, 24 Jan 2024 14:32:23 -0600 Subject: [PATCH 2/5] add changeset Signed-off-by: Abel Rodriguez --- .changeset/calm-items-double.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/calm-items-double.md diff --git a/.changeset/calm-items-double.md b/.changeset/calm-items-double.md new file mode 100644 index 0000000000..c16f989845 --- /dev/null +++ b/.changeset/calm-items-double.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Allow to force the creation of a pull request from a forked repository From 838b74fe6a8c7c9a0bbdc6dbac1fb9beeabc84b4 Mon Sep 17 00:00:00 2001 From: Abel Rodriguez Date: Wed, 24 Jan 2024 14:41:43 -0600 Subject: [PATCH 3/5] update api reports Signed-off-by: Abel Rodriguez --- 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 920be79d12..42aee02014 100644 --- a/plugins/scaffolder-backend-module-github/api-report.md +++ b/plugins/scaffolder-backend-module-github/api-report.md @@ -374,6 +374,7 @@ export const createPublishGithubPullRequestAction: ( teamReviewers?: string[] | undefined; commitMessage?: string | undefined; update?: boolean | undefined; + forceFork?: boolean | undefined; }, JsonObject >; diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index c928e5341e..b231267ede 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -266,6 +266,7 @@ export const createPublishGithubPullRequestAction: ( teamReviewers?: string[] | undefined; commitMessage?: string | undefined; update?: boolean | undefined; + forceFork?: boolean | undefined; }, JsonObject >; From 6f704931fb0aa4331c06d807a80430eb6a62a3d0 Mon Sep 17 00:00:00 2001 From: Abel Rodriguez Date: Wed, 24 Jan 2024 14:49:09 -0600 Subject: [PATCH 4/5] update changeset Signed-off-by: Abel Rodriguez --- .changeset/calm-items-double.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/calm-items-double.md b/.changeset/calm-items-double.md index c16f989845..8245fb06c4 100644 --- a/.changeset/calm-items-double.md +++ b/.changeset/calm-items-double.md @@ -1,4 +1,5 @@ --- +'@backstage/plugin-scaffolder-backend-module-github': minor '@backstage/plugin-scaffolder-backend': minor --- From 701ace47b98a2fa53813d5c8bb21b8c685b1a007 Mon Sep 17 00:00:00 2001 From: Abel Rodriguez Date: Thu, 25 Jan 2024 15:14:28 -0600 Subject: [PATCH 5/5] remove unexpected changeset Signed-off-by: Abel Rodriguez --- .changeset/calm-items-double.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.changeset/calm-items-double.md b/.changeset/calm-items-double.md index 8245fb06c4..3db8ad57d9 100644 --- a/.changeset/calm-items-double.md +++ b/.changeset/calm-items-double.md @@ -1,6 +1,5 @@ --- '@backstage/plugin-scaffolder-backend-module-github': minor -'@backstage/plugin-scaffolder-backend': minor --- Allow to force the creation of a pull request from a forked repository