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

Commit 5c59dab

Browse files
author
Andy McKay
authored
Merge pull request #5 from konradpabjan/master
Check for assignees and new labels on an issue
2 parents dcf6789 + 6983773 commit 5c59dab

File tree

6,076 files changed

+505236
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

6,076 files changed

+505236
-10
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Automatically adds or removes labels from issues. You define the labels you'd like to add and/or remove 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. You can also specify if an issue should be ignored if an assignee has been added.
22

33
To add it to your workflow:
44

@@ -7,6 +7,7 @@ To add it to your workflow:
77
with:
88
repo-token: "${{ secrets.GITHUB_TOKEN }}"
99
add-labels: "needs-triage, bug"
10+
ignore-if-assigned: true
1011
```
1112

1213
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,13 +18,16 @@ on:
1718
types: [opened]
1819
```
1920

21+
The parameter `ignore-if-assigned` checks at the time of the action running if the issue has been assigned to anyone. If set to `True` and the issue is assigned to anyone, then no labels will be added or removed. This can be helpful for new issues that immediatly get labels or assignees and don't require any action to be taken.
22+
2023
This action can also be used to remove labels from an issue. Just pass the label(s) to be removed separated by commas.
2124

2225
```
2326
- uses: andymckay/[email protected]
2427
with:
2528
repo-token: "${{ secrets.GITHUB_TOKEN }}"
2629
remove-labels: "help-wanted"
30+
ignore-if-assigned: false
2731
```
2832

2933
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:

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
remove-labels:
1111
description: 'Labels to be removed from an issue, seperated by commas.'
1212
required: false
13+
ignore-if-assigned:
14+
description: "True/False value to indicate if no labels should be added or removed if there is an asignee to the issue"
15+
required: true
1316
branding:
1417
icon: zap-off
1518
color: orange

label.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,52 @@ const labelsToRemove = core
1313

1414
async function label() {
1515
const myToken = core.getInput("repo-token");
16+
const ignoreIfAssigned = core.getInput("ignore-if-assigned");
1617
const octokit = new github.GitHub(myToken);
1718
const context = github.context;
19+
const repoName = context.payload.repository.name;
20+
const ownerName = context.payload.repository.owner.login;
21+
const issueNumber = context.payload.issue.number;
1822

19-
let labels = context.payload.issue.labels.map(label => label.name);
23+
// query for the most recent information about the issue. Between the issue being created and
24+
// the action running, labels or asignees could have been added
25+
var updatedIssueInformation = await octokit.issues.get({
26+
owner: ownerName,
27+
repo: repoName,
28+
issue_number: issueNumber
29+
});
30+
31+
if (ignoreIfAssigned) {
32+
// check if the issue has been assigned to anyone
33+
if (updatedIssueInformation.data.assignees.length != 0) {
34+
return "No action being taken. Ignoring because one or more assignees have been added to the issue";
35+
}
36+
}
37+
38+
let labels = updatedIssueInformation.data.labels.map(label => label.name);
2039
for (let labelToAdd of labelsToAdd) {
2140
if (!labels.includes(labelToAdd)) {
2241
labels.push(labelToAdd);
2342
}
2443
}
25-
labels = labels.filter((value) => {
44+
labels = labels.filter(value => {
2645
return !labelsToRemove.includes(value);
2746
});
2847

2948
await octokit.issues.update({
30-
owner: context.payload.repository.owner.login,
31-
repo: context.payload.repository.name,
32-
issue_number: context.payload.issue.number,
49+
owner: ownerName,
50+
repo: repoName,
51+
issue_number: issueNumber,
3352
labels: labels
3453
});
35-
return context.payload.issue.number;
54+
return `Updated labels in ${context.payload.issue.number}. Added: ${labelsToAdd}. Removed: ${labelsToRemove}.`;
3655
}
3756

3857
label()
3958
.then(
4059
result => {
4160
// eslint-disable-next-line no-console
42-
console.log(`Updated labels in ${result}. Added: ${labelsToAdd}. Removed: ${labelsToRemove}.`);
61+
console.log(result);
4362
},
4463
err => {
4564
// eslint-disable-next-line no-console

node_modules/.bin/acorn

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/eslint

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/esparse

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/esvalidate

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/js-yaml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/mkdirp

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/prettier

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/rimraf

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@babel/code-frame/LICENSE

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@babel/code-frame/README.md

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@babel/code-frame/lib/index.js

+173
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@babel/code-frame/package.json

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)