Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from lionel1704/remove-label-feature
Browse files Browse the repository at this point in the history
Add feature to remove labels
  • Loading branch information
Andy McKay authored Oct 1, 2019
2 parents 7650ddc + db670cf commit d8637ea
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Automatically labels issues, by adding new labels to the issue. You define the labels you'd like to add to your issues in the YAML file.
Automatically adds or removes labels from issues. You define the labels you'd like to add and/or remove in the YAML file.

To add it to your workflow:

```
- uses: andymckay/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
labels: "needs-triage, bug"
add-labels: "needs-triage, bug"
```

This adds the `needs-triage` and `bug` labels to the issue. The most common approach is to do this when issues are created, you can do this with the following in your workflow file:
Expand All @@ -17,4 +17,19 @@ on:
types: [opened]
```

That's it.
This action can also be used to remove labels from an issue. Just pass the label(s) to be removed separated by commas.

```
- uses: andymckay/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
remove-labels: "help-wanted"
```

An example use-case would be, to remove the `help-wanted` label when an issue is assigned to someone. For this, the workflow file would look like:

```
on:
issues:
types: [assigned]
```
9 changes: 6 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: 'Simple Issue Labeler'
description: 'Adds labels to new issues.'
description: 'Adds and removes labels from issues.'
inputs:
repo-token:
description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
required: true
labels:
add-labels:
description: 'Labels to add to an issue, seperated by commas.'
required: true
required: false
remove-labels:
description: 'Labels to be removed from an issue, seperated by commas.'
required: false
branding:
icon: zap-off
color: orange
Expand Down
20 changes: 14 additions & 6 deletions label.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const github = require("@actions/github");
const core = require("@actions/core");

const requested = core
.getInput("labels")
const labelsToAdd = core
.getInput("add-labels")
.split(",")
.map(x => x.trim());

const labelsToRemove = core
.getInput("remove-labels")
.split(",")
.map(x => x.trim());

Expand All @@ -12,11 +17,14 @@ async function label() {
const context = github.context;

let labels = context.payload.issue.labels.map(label => label.name);
for (let requestedLabel of requested) {
if (!labels.includes(requestedLabel)) {
labels.push(requestedLabel);
for (let labelToAdd of labelsToAdd) {
if (!labels.includes(labelToAdd)) {
labels.push(labelToAdd);
}
}
labels = labels.filter((value) => {
return !labelsToRemove.includes(value);
});

await octokit.issues.update({
owner: context.payload.repository.owner.login,
Expand All @@ -31,7 +39,7 @@ label()
.then(
result => {
// eslint-disable-next-line no-console
console.log(`Labelled ${result} with ${requested}.`);
console.log(`Updated labels in ${result}. Added: ${labelsToAdd}. Removed: ${labelsToRemove}.`);
},
err => {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit d8637ea

Please sign in to comment.