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 #5 from konradpabjan/master
Browse files Browse the repository at this point in the history
Check for assignees and new labels on an issue
  • Loading branch information
Andy McKay authored Oct 18, 2019
2 parents dcf6789 + 6983773 commit 5c59dab
Show file tree
Hide file tree
Showing 6,076 changed files with 505,236 additions and 10 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Automatically adds or removes labels from issues. You define the labels you'd like to add and/or remove 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. You can also specify if an issue should be ignored if an assignee has been added.

To add it to your workflow:

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

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

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.

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"
ignore-if-assigned: false
```

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:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
remove-labels:
description: 'Labels to be removed from an issue, seperated by commas.'
required: false
ignore-if-assigned:
description: "True/False value to indicate if no labels should be added or removed if there is an asignee to the issue"
required: true
branding:
icon: zap-off
color: orange
Expand Down
33 changes: 26 additions & 7 deletions label.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,52 @@ const labelsToRemove = core

async function label() {
const myToken = core.getInput("repo-token");
const ignoreIfAssigned = core.getInput("ignore-if-assigned");
const octokit = new github.GitHub(myToken);
const context = github.context;
const repoName = context.payload.repository.name;
const ownerName = context.payload.repository.owner.login;
const issueNumber = context.payload.issue.number;

let labels = context.payload.issue.labels.map(label => label.name);
// query for the most recent information about the issue. Between the issue being created and
// the action running, labels or asignees could have been added
var updatedIssueInformation = await octokit.issues.get({
owner: ownerName,
repo: repoName,
issue_number: issueNumber
});

if (ignoreIfAssigned) {
// check if the issue has been assigned to anyone
if (updatedIssueInformation.data.assignees.length != 0) {
return "No action being taken. Ignoring because one or more assignees have been added to the issue";
}
}

let labels = updatedIssueInformation.data.labels.map(label => label.name);
for (let labelToAdd of labelsToAdd) {
if (!labels.includes(labelToAdd)) {
labels.push(labelToAdd);
}
}
labels = labels.filter((value) => {
labels = labels.filter(value => {
return !labelsToRemove.includes(value);
});

await octokit.issues.update({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.issue.number,
owner: ownerName,
repo: repoName,
issue_number: issueNumber,
labels: labels
});
return context.payload.issue.number;
return `Updated labels in ${context.payload.issue.number}. Added: ${labelsToAdd}. Removed: ${labelsToRemove}.`;
}

label()
.then(
result => {
// eslint-disable-next-line no-console
console.log(`Updated labels in ${result}. Added: ${labelsToAdd}. Removed: ${labelsToRemove}.`);
console.log(result);
},
err => {
// eslint-disable-next-line no-console
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/eslint

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/prettier

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/rimraf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions node_modules/@babel/code-frame/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions node_modules/@babel/code-frame/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

173 changes: 173 additions & 0 deletions node_modules/@babel/code-frame/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions node_modules/@babel/code-frame/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c59dab

Please sign in to comment.