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

feat: add a flag to disable adding labels to new pull requests #1399

Merged
merged 1 commit into from
Apr 18, 2022
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
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"]
--skip-labeling skip 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"]
--skip-labeling skip 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` |
| `--skip-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;
skipLabeling?: 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('skip-labeling', {
describe: 'skip 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 ('skipLabeling' in argv && argv.skipLabeling !== undefined) {
manifestOptions.skipLabeling = argv.skipLabeling;
}
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;
skipLabeling?: boolean;
}
): Promise<PullRequest> {
let message = releasePullRequest.title.toString();
if (options?.signoffUser) {
message = signoffCommitMessage(message, options.signoffUser);
}
const pullRequestLabels: string[] = options?.skipLabeling
? []
: 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[];
skipLabeling?: 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 skipLabeling?: 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.skipLabeling = manifestOptions?.skipLabeling || 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,
skipLabeling: this.skipLabeling,
}
);
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 --skip-labeling', async () => {
await parser.parseAsync(
'manifest-pr --repo-url=googleapis/release-please-cli --skip-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({skipLabeling: true})
);
sinon.assert.calledOnce(createPullRequestsStub);
});

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