Skip to content

Commit

Permalink
feat: add a flag to disable adding labels to new pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma committed Apr 16, 2022
1 parent 843827d commit 7ef4773
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions __snapshots__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Options:
--dry-run Prepare but do not take action[boolean] [default: false]
--label comma-separated list of labels to add to from release PR
[default: "autorelease: pending"]
--disable-labeling disable application of labels to pull requests
[boolean] [default: false]
--fork should the PR be created from a fork
[boolean] [default: false]
--draft-pull-request mark pull request as a draft [boolean] [default: false]
Expand Down Expand Up @@ -199,6 +201,8 @@ Options:
--label comma-separated list of labels to add to
from release PR
[default: "autorelease: pending"]
--disable-labeling disable application of labels to pull
requests [boolean] [default: false]
--fork should the PR be created from a fork
[boolean] [default: false]
--draft-pull-request mark pull request as a draft
Expand Down
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Extra options:
| `--draft-pull-request` | `boolean` | If set, create pull requests as drafts |
| `--label` | `string` | Comma-separated list of labels to apply to the release pull requests. Defaults to `autorelease: pending` |
| `--release-label` | `string` | Comma-separated list of labels to apply to the pull request after the release has been tagged. Defaults to `autorelease: tagged` |
| `--disable-labeling` | `boolean` | If set, labels will not be applied to pull requests |
| `--changelog-path` | `string` | Override the path to the managed CHANGELOG. Defaults to `CHANGELOG.md` |
| `--changelog-type` | [`ChangelogType`](/docs/customizing.md#changelog-types) | Strategy for building the changelog contents. Defaults to `default` |
| `--changelog-sections` | `string` | Comma-separated list of commit scopes to show in changelog headings |
Expand Down
9 changes: 9 additions & 0 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ interface ReleaseArgs {
interface PullRequestArgs {
draftPullRequest?: boolean;
label?: string;
disableLabeling?: boolean;
signoff?: string;
}

Expand Down Expand Up @@ -230,6 +231,11 @@ function pullRequestOptions(yargs: yargs.Argv): yargs.Argv {
default: 'autorelease: pending',
describe: 'comma-separated list of labels to add to from release PR',
})
.option('disable-labeling', {
describe: 'disable application of labels to pull requests',
type: 'boolean',
default: false,
})
.option('fork', {
describe: 'should the PR be created from a fork',
type: 'boolean',
Expand Down Expand Up @@ -757,6 +763,9 @@ function extractManifestOptions(
if (labels.length === 1 && labels[0] === '') labels = [];
manifestOptions.labels = labels;
}
if ('disableLabeling' in argv && argv.disableLabeling !== undefined) {
manifestOptions.disableLabeling = argv.disableLabeling;
}
if ('releaseLabel' in argv && argv.releaseLabel) {
manifestOptions.releaseLabels = argv.releaseLabel.split(',');
}
Expand Down
6 changes: 5 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,20 +891,24 @@ export class GitHub {
options?: {
signoffUser?: string;
fork?: boolean;
disableLabeling?: boolean;
}
): Promise<PullRequest> {
let message = releasePullRequest.title.toString();
if (options?.signoffUser) {
message = signoffCommitMessage(message, options.signoffUser);
}
const pullRequestLabels: string[] = options?.disableLabeling
? []
: releasePullRequest.labels;
return await this.createPullRequest(
{
headBranchName: releasePullRequest.headRefName,
baseBranchName: targetBranch,
number: -1,
title: releasePullRequest.title.toString(),
body: releasePullRequest.body.toString().slice(0, MAX_ISSUE_BODY_SIZE),
labels: releasePullRequest.labels,
labels: pullRequestLabels,
files: [],
},
targetBranch,
Expand Down
4 changes: 4 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export interface ManifestOptions {
signoff?: string;
manifestPath?: string;
labels?: string[];
disableLabeling?: boolean;
releaseLabels?: string[];
snapshotLabels?: string[];
draft?: boolean;
Expand Down Expand Up @@ -214,6 +215,7 @@ export class Manifest {
readonly fork: boolean;
private signoffUser?: string;
private labels: string[];
private disableLabeling?: boolean;
private releaseLabels: string[];
private snapshotLabels: string[];
private plugins: PluginType[];
Expand Down Expand Up @@ -277,6 +279,7 @@ export class Manifest {
this.releaseLabels =
manifestOptions?.releaseLabels || DEFAULT_RELEASE_LABELS;
this.labels = manifestOptions?.labels || DEFAULT_LABELS;
this.disableLabeling = manifestOptions?.disableLabeling || false;
this.snapshotLabels =
manifestOptions?.snapshotLabels || DEFAULT_SNAPSHOT_LABELS;
this.bootstrapSha = manifestOptions?.bootstrapSha;
Expand Down Expand Up @@ -826,6 +829,7 @@ export class Manifest {
{
fork: this.fork,
signoffUser: this.signoffUser,
disableLabeling: this.disableLabeling,
}
);
return newPullRequest;
Expand Down
21 changes: 21 additions & 0 deletions test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,27 @@ describe('CLI', () => {
sinon.assert.calledOnce(createPullRequestsStub);
});

it('handles --disable-labeling', async () => {
await parser.parseAsync(
'manifest-pr --repo-url=googleapis/release-please-cli --disable-labeling'
);

sinon.assert.calledOnceWithExactly(gitHubCreateStub, {
owner: 'googleapis',
repo: 'release-please-cli',
token: undefined,
});
sinon.assert.calledOnceWithExactly(
fromManifestStub,
fakeGitHub,
'main',
DEFAULT_RELEASE_PLEASE_CONFIG,
DEFAULT_RELEASE_PLEASE_MANIFEST,
sinon.match({disableLabeling: true})
);
sinon.assert.calledOnce(createPullRequestsStub);
});

// it('handles --draft', async () => {
// await parser.parseAsync(
// 'manifest-pr --repo-url=googleapis/release-please-cli --draft'
Expand Down

0 comments on commit 7ef4773

Please sign in to comment.