add remove-labels option for clearing existing labels

This commit is contained in:
Nick Cooper 2021-08-24 22:56:46 -04:00
parent 7380612b49
commit 2389b42070
6 changed files with 54 additions and 34 deletions

View file

@ -57,7 +57,8 @@ All inputs are **optional**. If not set, sensible defaults will be used.
| `push-to-fork` | A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | | | `push-to-fork` | A fork of the checked-out parent repository to which the pull request branch will be pushed. e.g. `owner/repo-fork`. The pull request will be created to merge the fork's branch into the parent's base. See [push pull request branches to a fork](docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | |
| `title` | The title of the pull request. | `Changes by create-pull-request action` | | `title` | The title of the pull request. | `Changes by create-pull-request action` |
| `body` | The body of the pull request. | `Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action` | | `body` | The body of the pull request. | `Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action` |
| `labels` | A comma or newline-separated list of labels. | | | `labels` | A comma or newline-separated list of labels to add. | |
| `remove-labels` | If true, will remove all existing labels. | `false` |
| `assignees` | A comma or newline-separated list of assignees (GitHub usernames). | | | `assignees` | A comma or newline-separated list of assignees (GitHub usernames). | |
| `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | | | `reviewers` | A comma or newline-separated list of reviewers (GitHub usernames) to request a review from. | |
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | | | `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) may be required. See [this issue](https://github.com/peter-evans/create-pull-request/issues/155). | |

View file

@ -1,39 +1,39 @@
name: 'Create Pull Request' name: "Create Pull Request"
description: 'Creates a pull request for changes to your repository in the actions workspace' description: "Creates a pull request for changes to your repository in the actions workspace"
inputs: inputs:
token: token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)' description: "GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)"
default: ${{ github.token }} default: ${{ github.token }}
path: path:
description: > description: >
Relative path under $GITHUB_WORKSPACE to the repository. Relative path under $GITHUB_WORKSPACE to the repository.
Defaults to $GITHUB_WORKSPACE. Defaults to $GITHUB_WORKSPACE.
commit-message: commit-message:
description: 'The message to use when committing changes.' description: "The message to use when committing changes."
default: '[create-pull-request] automated change' default: "[create-pull-request] automated change"
committer: committer:
description: > description: >
The committer name and email address in the format `Display Name <email@address.com>`. The committer name and email address in the format `Display Name <email@address.com>`.
Defaults to the GitHub Actions bot user. Defaults to the GitHub Actions bot user.
default: 'GitHub <noreply@github.com>' default: "GitHub <noreply@github.com>"
author: author:
description: > description: >
The author name and email address in the format `Display Name <email@address.com>`. The author name and email address in the format `Display Name <email@address.com>`.
Defaults to the user who triggered the workflow run. Defaults to the user who triggered the workflow run.
default: '${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>' default: "${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
signoff: signoff:
description: 'Add `Signed-off-by` line by the committer at the end of the commit log message.' description: "Add `Signed-off-by` line by the committer at the end of the commit log message."
default: false default: false
branch: branch:
description: 'The pull request branch name.' description: "The pull request branch name."
default: 'create-pull-request/patch' default: "create-pull-request/patch"
delete-branch: delete-branch:
description: > description: >
Delete the `branch` when closing pull requests, and when undeleted after merging. Delete the `branch` when closing pull requests, and when undeleted after merging.
Recommend `true`. Recommend `true`.
default: false default: false
branch-suffix: branch-suffix:
description: 'The branch suffix type when using the alternative branching strategy.' description: "The branch suffix type when using the alternative branching strategy."
base: base:
description: > description: >
The pull request base branch. The pull request base branch.
@ -44,36 +44,39 @@ inputs:
e.g. `owner/repo-fork`. e.g. `owner/repo-fork`.
The pull request will be created to merge the fork's branch into the parent's base. The pull request will be created to merge the fork's branch into the parent's base.
title: title:
description: 'The title of the pull request.' description: "The title of the pull request."
default: 'Changes by create-pull-request action' default: "Changes by create-pull-request action"
body: body:
description: 'The body of the pull request.' description: "The body of the pull request."
default: 'Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action' default: "Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action"
labels: labels:
description: 'A comma or newline separated list of labels.' description: "A comma or newline separated list of labels to add."
remove-labels:
description: "If true, remove all existing labels."
default: false
assignees: assignees:
description: 'A comma or newline separated list of assignees (GitHub usernames).' description: "A comma or newline separated list of assignees (GitHub usernames)."
reviewers: reviewers:
description: 'A comma or newline separated list of reviewers (GitHub usernames) to request a review from.' description: "A comma or newline separated list of reviewers (GitHub usernames) to request a review from."
team-reviewers: team-reviewers:
description: > description: >
A comma or newline separated list of GitHub teams to request a review from. A comma or newline separated list of GitHub teams to request a review from.
Note that a `repo` scoped Personal Access Token (PAT) may be required. Note that a `repo` scoped Personal Access Token (PAT) may be required.
milestone: milestone:
description: 'The number of the milestone to associate the pull request with.' description: "The number of the milestone to associate the pull request with."
draft: draft:
description: 'Create a draft pull request' description: "Create a draft pull request"
default: false default: false
outputs: outputs:
pull-request-number: pull-request-number:
description: 'The pull request number' description: "The pull request number"
pull-request-url: pull-request-url:
description: 'The URL of the pull request.' description: "The URL of the pull request."
pull-request-operation: pull-request-operation:
description: 'The pull request operation performed by the action, `created`, `updated` or `closed`.' description: "The pull request operation performed by the action, `created`, `updated` or `closed`."
runs: runs:
using: 'node12' using: "node12"
main: 'dist/index.js' main: "dist/index.js"
branding: branding:
icon: 'git-pull-request' icon: "git-pull-request"
color: 'gray-dark' color: "gray-dark"

12
dist/index.js vendored
View file

@ -263,9 +263,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createPullRequest = void 0; exports.createPullRequest = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const create_or_update_branch_1 = __nccwpck_require__(8363); const create_or_update_branch_1 = __nccwpck_require__(8363);
const github_helper_1 = __nccwpck_require__(446);
const git_command_manager_1 = __nccwpck_require__(738);
const git_auth_helper_1 = __nccwpck_require__(2565); const git_auth_helper_1 = __nccwpck_require__(2565);
const git_command_manager_1 = __nccwpck_require__(738);
const github_helper_1 = __nccwpck_require__(446);
const utils = __importStar(__nccwpck_require__(918)); const utils = __importStar(__nccwpck_require__(918));
function createPullRequest(inputs) { function createPullRequest(inputs) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -984,6 +984,11 @@ class GitHubHelper {
core.info(`Applying milestone '${inputs.milestone}'`); core.info(`Applying milestone '${inputs.milestone}'`);
yield this.octokit.rest.issues.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, milestone: inputs.milestone })); yield this.octokit.rest.issues.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, milestone: inputs.milestone }));
} }
// Remove labels
if (inputs.removeLabels) {
core.info(`Removing ALL labels`);
yield this.octokit.rest.issues.removeAllLabels(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number }));
}
// Apply labels // Apply labels
if (inputs.labels.length > 0) { if (inputs.labels.length > 0) {
core.info(`Applying labels '${inputs.labels}'`); core.info(`Applying labels '${inputs.labels}'`);
@ -1061,8 +1066,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const create_pull_request_1 = __nccwpck_require__(3780);
const util_1 = __nccwpck_require__(1669); const util_1 = __nccwpck_require__(1669);
const create_pull_request_1 = __nccwpck_require__(3780);
const utils = __importStar(__nccwpck_require__(918)); const utils = __importStar(__nccwpck_require__(918));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -1082,6 +1087,7 @@ function run() {
title: core.getInput('title'), title: core.getInput('title'),
body: core.getInput('body'), body: core.getInput('body'),
labels: utils.getInputAsArray('labels'), labels: utils.getInputAsArray('labels'),
removeLabels: core.getInput('remove-labels') === 'true',
assignees: utils.getInputAsArray('assignees'), assignees: utils.getInputAsArray('assignees'),
reviewers: utils.getInputAsArray('reviewers'), reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'),

View file

@ -4,9 +4,9 @@ import {
getWorkingBaseAndType, getWorkingBaseAndType,
WorkingBaseType WorkingBaseType
} from './create-or-update-branch' } from './create-or-update-branch'
import {GitHubHelper} from './github-helper'
import {GitCommandManager} from './git-command-manager'
import {GitAuthHelper} from './git-auth-helper' import {GitAuthHelper} from './git-auth-helper'
import {GitCommandManager} from './git-command-manager'
import {GitHubHelper} from './github-helper'
import * as utils from './utils' import * as utils from './utils'
export interface Inputs { export interface Inputs {
@ -24,6 +24,7 @@ export interface Inputs {
title: string title: string
body: string body: string
labels: string[] labels: string[]
removeLabels: boolean
assignees: string[] assignees: string[]
reviewers: string[] reviewers: string[]
teamReviewers: string[] teamReviewers: string[]

View file

@ -129,6 +129,14 @@ export class GitHubHelper {
milestone: inputs.milestone milestone: inputs.milestone
}) })
} }
// Remove labels
if (inputs.removeLabels) {
core.info(`Removing ALL labels`)
await this.octokit.rest.issues.removeAllLabels({
...this.parseRepository(baseRepository),
issue_number: pull.number
})
}
// Apply labels // Apply labels
if (inputs.labels.length > 0) { if (inputs.labels.length > 0) {
core.info(`Applying labels '${inputs.labels}'`) core.info(`Applying labels '${inputs.labels}'`)

View file

@ -1,6 +1,6 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Inputs, createPullRequest} from './create-pull-request'
import {inspect} from 'util' import {inspect} from 'util'
import {createPullRequest, Inputs} from './create-pull-request'
import * as utils from './utils' import * as utils from './utils'
async function run(): Promise<void> { async function run(): Promise<void> {
@ -20,6 +20,7 @@ async function run(): Promise<void> {
title: core.getInput('title'), title: core.getInput('title'),
body: core.getInput('body'), body: core.getInput('body'),
labels: utils.getInputAsArray('labels'), labels: utils.getInputAsArray('labels'),
removeLabels: core.getInput('remove-labels') === 'true',
assignees: utils.getInputAsArray('assignees'), assignees: utils.getInputAsArray('assignees'),
reviewers: utils.getInputAsArray('reviewers'), reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'), teamReviewers: utils.getInputAsArray('team-reviewers'),