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

Commit d8637ea

Browse files
author
Andy McKay
authored
Merge pull request #2 from lionel1704/remove-label-feature
Add feature to remove labels
2 parents 7650ddc + db670cf commit d8637ea

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

README.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
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.
1+
Automatically adds or removes labels from issues. You define the labels you'd like to add and/or remove in the YAML file.
22

33
To add it to your workflow:
44

55
```
66
- uses: andymckay/[email protected]
77
with:
88
repo-token: "${{ secrets.GITHUB_TOKEN }}"
9-
labels: "needs-triage, bug"
9+
add-labels: "needs-triage, bug"
1010
```
1111

1212
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:
@@ -17,4 +17,19 @@ on:
1717
types: [opened]
1818
```
1919

20-
That's it.
20+
This action can also be used to remove labels from an issue. Just pass the label(s) to be removed separated by commas.
21+
22+
```
23+
- uses: andymckay/[email protected]
24+
with:
25+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
26+
remove-labels: "help-wanted"
27+
```
28+
29+
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:
30+
31+
```
32+
on:
33+
issues:
34+
types: [assigned]
35+
```

action.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
name: 'Simple Issue Labeler'
2-
description: 'Adds labels to new issues.'
2+
description: 'Adds and removes labels from issues.'
33
inputs:
44
repo-token:
55
description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
66
required: true
7-
labels:
7+
add-labels:
88
description: 'Labels to add to an issue, seperated by commas.'
9-
required: true
9+
required: false
10+
remove-labels:
11+
description: 'Labels to be removed from an issue, seperated by commas.'
12+
required: false
1013
branding:
1114
icon: zap-off
1215
color: orange

label.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
const github = require("@actions/github");
22
const core = require("@actions/core");
33

4-
const requested = core
5-
.getInput("labels")
4+
const labelsToAdd = core
5+
.getInput("add-labels")
6+
.split(",")
7+
.map(x => x.trim());
8+
9+
const labelsToRemove = core
10+
.getInput("remove-labels")
611
.split(",")
712
.map(x => x.trim());
813

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

1419
let labels = context.payload.issue.labels.map(label => label.name);
15-
for (let requestedLabel of requested) {
16-
if (!labels.includes(requestedLabel)) {
17-
labels.push(requestedLabel);
20+
for (let labelToAdd of labelsToAdd) {
21+
if (!labels.includes(labelToAdd)) {
22+
labels.push(labelToAdd);
1823
}
1924
}
25+
labels = labels.filter((value) => {
26+
return !labelsToRemove.includes(value);
27+
});
2028

2129
await octokit.issues.update({
2230
owner: context.payload.repository.owner.login,
@@ -31,7 +39,7 @@ label()
3139
.then(
3240
result => {
3341
// eslint-disable-next-line no-console
34-
console.log(`Labelled ${result} with ${requested}.`);
42+
console.log(`Updated labels in ${result}. Added: ${labelsToAdd}. Removed: ${labelsToRemove}.`);
3543
},
3644
err => {
3745
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)