From 6d2f4688686bcad0da33d0d6de51399cd18219a9 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Thu, 28 Dec 2023 13:35:53 -0500 Subject: [PATCH 1/4] Add draft option to publish PRs as drafts --- .../cherrypickAndCreateTargetPullRequest.ts | 1 + src/lib/github/v3/createPullRequest.ts | 1 + src/options/ConfigOptions.ts | 1 + src/options/cliArgs.ts | 5 +++++ src/options/options.test.ts | 1 + src/options/options.ts | 1 + 6 files changed, 10 insertions(+) diff --git a/src/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.ts b/src/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.ts index da9095ab..ab03e784 100644 --- a/src/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.ts +++ b/src/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.ts @@ -77,6 +77,7 @@ export async function cherrypickAndCreateTargetPullRequest({ body: getPullRequestBody({ options, commits, targetBranch }), head: `${repoForkOwner}:${backportBranch}`, // eg. sqren:backport/7.x/pr-75007 base: targetBranch, // eg. 7.x + draft: options.draft, }; const targetPullRequest = await createPullRequest({ options, prPayload }); diff --git a/src/lib/github/v3/createPullRequest.ts b/src/lib/github/v3/createPullRequest.ts index 71dd90a3..fe5114a3 100644 --- a/src/lib/github/v3/createPullRequest.ts +++ b/src/lib/github/v3/createPullRequest.ts @@ -19,6 +19,7 @@ export interface PullRequestPayload { body: string; head: string; base: string; + draft: boolean; [key: string]: unknown; } diff --git a/src/options/ConfigOptions.ts b/src/options/ConfigOptions.ts index a94a1e32..b591c29e 100644 --- a/src/options/ConfigOptions.ts +++ b/src/options/ConfigOptions.ts @@ -33,6 +33,7 @@ type Options = Partial<{ commitPaths: string[]; details: boolean; dir: string; + draft: boolean; dryRun: boolean; editor: string; fork: boolean; diff --git a/src/options/cliArgs.ts b/src/options/cliArgs.ts index 11f7db58..9e2a6652 100644 --- a/src/options/cliArgs.ts +++ b/src/options/cliArgs.ts @@ -124,6 +124,11 @@ export function getOptionsFromCliArgs(processArgs: readonly string[]) { type: 'boolean', }) + .option('draft', { + description: 'Publish pull request as draft', + type: 'boolean', + }) + .option('dryRun', { description: 'Run backport locally without pushing to Github', type: 'boolean', diff --git a/src/options/options.test.ts b/src/options/options.test.ts index 9fc2b502..5cf79808 100644 --- a/src/options/options.test.ts +++ b/src/options/options.test.ts @@ -217,6 +217,7 @@ describe('getOptions', () => { dateSince: null, dateUntil: null, details: false, + draft: false, editor: 'code', fork: true, gitHostname: 'github.com', diff --git a/src/options/options.ts b/src/options/options.ts index abd84095..5431c58a 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -40,6 +40,7 @@ export const defaultConfigOptions = { dateSince: null, dateUntil: null, details: false, + draft: false, fork: true, gitHostname: 'github.com', interactive: true, From 366ba0e1f497dafd397c3f0fd9be6704411b230e Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Thu, 28 Dec 2023 13:51:06 -0500 Subject: [PATCH 2/4] Update some tests and logs for draft field --- src/lib/github/v3/createPullRequest.ts | 5 +++-- .../github/v4/enablePullRequestAutoMerge.mutation.test.ts | 1 + src/lib/github/v4/fetchExistingPullRequest.private.test.ts | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/github/v3/createPullRequest.ts b/src/lib/github/v3/createPullRequest.ts index fe5114a3..c02e57c6 100644 --- a/src/lib/github/v3/createPullRequest.ts +++ b/src/lib/github/v3/createPullRequest.ts @@ -34,12 +34,13 @@ export async function createPullRequest({ number: number; didUpdate: boolean; }> { + const msg = `Creating ${options.draft ? 'draft ' : ''}pull request`; logger.info( - `Creating PR with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`, + `${msg} with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`, ); const { accessToken, githubApiBaseUrlV3 } = options; - const spinner = ora(options.interactive, `Creating pull request`).start(); + const spinner = ora(options.interactive, msg).start(); if (options.dryRun) { spinner.succeed(); diff --git a/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts b/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts index aa6d7ec8..cd001374 100644 --- a/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts +++ b/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts @@ -64,6 +64,7 @@ async function createPr({ owner: TEST_REPO_OWNER, repo: TEST_REPO_NAME, title: 'my pr title', + draft: true, }; const { number } = await createPullRequest({ options, prPayload }); diff --git a/src/lib/github/v4/fetchExistingPullRequest.private.test.ts b/src/lib/github/v4/fetchExistingPullRequest.private.test.ts index db3be519..6da9842b 100644 --- a/src/lib/github/v4/fetchExistingPullRequest.private.test.ts +++ b/src/lib/github/v4/fetchExistingPullRequest.private.test.ts @@ -18,6 +18,7 @@ describe('fetchExistingPullRequest', () => { body: 'My PR body', head: 'sqren:backport/7.8/pr-foo', base: '7.8', + draft: false, }; const res = await fetchExistingPullRequest({ options, prPayload }); @@ -39,6 +40,7 @@ describe('fetchExistingPullRequest', () => { body: 'My PR body', head: 'sqren:backport/7.8/pr-9', base: '7.8', + draft: false, }; const res = await fetchExistingPullRequest({ options, prPayload }); From 581498ffaae3b7cfb3139b9297ce9a760d264240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Tue, 9 Apr 2024 21:25:48 +0200 Subject: [PATCH 3/4] fix jest test --- src/test/e2e/cli/entrypoint.cli.private.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/e2e/cli/entrypoint.cli.private.test.ts b/src/test/e2e/cli/entrypoint.cli.private.test.ts index 7fe9991d..cde5b990 100644 --- a/src/test/e2e/cli/entrypoint.cli.private.test.ts +++ b/src/test/e2e/cli/entrypoint.cli.private.test.ts @@ -64,6 +64,7 @@ Options: --dateUntil, --until ISO-8601 date for filtering commits [string] --dir Path to temporary backport repo [string] --details Show details about each commit [boolean] + --draft Publish pull request as draft [boolean] --dryRun Run backport locally without pushing to Github [boolean] --editor Editor to be opened during conflict resolution From 905060d0ee52aa21e33934daa273b553a8499cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Tue, 9 Apr 2024 22:01:27 +0200 Subject: [PATCH 4/4] fix jest test --- src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts b/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts index cd001374..e1d6c251 100644 --- a/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts +++ b/src/lib/github/v4/enablePullRequestAutoMerge.mutation.test.ts @@ -64,7 +64,7 @@ async function createPr({ owner: TEST_REPO_OWNER, repo: TEST_REPO_NAME, title: 'my pr title', - draft: true, + draft: false, }; const { number } = await createPullRequest({ options, prPayload });