Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft option to publish PRs as drafts #489

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. sqren: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: 'sqren: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: 'sqren: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
Loading