Skip to content

Commit

Permalink
Add draft option to publish PRs as drafts (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-h-chamberlain authored Apr 9, 2024
1 parent 237195c commit cbbe072
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export async function cherrypickAndCreateTargetPullRequest({
body: getPullRequestBody({ options, commits, targetBranch }),
head: `${repoForkOwner}:${backportBranch}`, // eg. sorenlouv:backport/7.x/pr-75007
base: targetBranch, // eg. 7.x
draft: options.draft,
};

const targetPullRequest = await createPullRequest({ options, prPayload });
Expand Down
6 changes: 4 additions & 2 deletions src/lib/github/v3/createPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface PullRequestPayload {
body: string;
head: string;
base: string;
draft: boolean;
[key: string]: unknown;
}

Expand All @@ -33,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async function createPr({
owner: TEST_REPO_OWNER,
repo: TEST_REPO_NAME,
title: 'my pr title',
draft: false,
};

const { number } = await createPullRequest({ options, prPayload });
Expand Down
2 changes: 2 additions & 0 deletions src/lib/github/v4/fetchExistingPullRequest.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('fetchExistingPullRequest', () => {
body: 'My PR body',
head: 'sorenlouv:backport/7.8/pr-foo',
base: '7.8',
draft: false,
};

const res = await fetchExistingPullRequest({ options, prPayload });
Expand All @@ -39,6 +40,7 @@ describe('fetchExistingPullRequest', () => {
body: 'My PR body',
head: 'sorenlouv:backport/7.8/pr-9',
base: '7.8',
draft: false,
};
const res = await fetchExistingPullRequest({ options, prPayload });

Expand Down
1 change: 1 addition & 0 deletions src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Options = Partial<{
commitPaths: string[];
details: boolean;
dir: string;
draft: boolean;
dryRun: boolean;
editor: string;
fork: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ describe('getOptions', () => {
dateSince: null,
dateUntil: null,
details: false,
draft: false,
editor: 'code',
fork: true,
gitHostname: 'github.com',
Expand Down
1 change: 1 addition & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const defaultConfigOptions = {
dateSince: null,
dateUntil: null,
details: false,
draft: false,
fork: true,
gitHostname: 'github.com',
interactive: true,
Expand Down
1 change: 1 addition & 0 deletions src/test/e2e/cli/entrypoint.cli.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cbbe072

Please sign in to comment.