Skip to content

Commit

Permalink
feat: remove label when found
Browse files Browse the repository at this point in the history
  • Loading branch information
djzager committed Jun 29, 2022
1 parent afeb669 commit 8e71430
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/actions/require-matching-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ async function run() {
const regexp = new RegExp(inputs.regexp);
if (ghIssue.hasLabelRegexp(regexp)) {
core.info("Issue has label matching expression. Do nothing.");
await ghIssue.removeLabel(inputs.missingLabel);
return;
}
core.info(`Adding label ${inputs.missingLabel}.`);
await ghIssue.addLabels([inputs.missingLabel]);
Expand Down
9 changes: 9 additions & 0 deletions lib/github-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,14 @@ class GitHubIssue {
labels: labels,
});
}
// remove a particular label from an issue
async removeLabel(label) {
await github.getOctokit(this.token).rest.issues.removeLabel({
owner: this.owner,
repo: this.repo,
issue_number: this.number,
name: label,
});
}
}
exports.GitHubIssue = GitHubIssue;
2 changes: 2 additions & 0 deletions src/actions/require-matching-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ async function run() {
const regexp = new RegExp(inputs.regexp);
if (ghIssue.hasLabelRegexp(regexp)) {
core.info("Issue has label matching expression. Do nothing.");
await ghIssue.removeLabel(inputs.missingLabel);
return;
}

core.info(`Adding label ${inputs.missingLabel}.`);
Expand Down
11 changes: 11 additions & 0 deletions src/github-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class GitHubIssue {
});
}


// addComment creates a comment with ${body}
async addComment(body: string) {
await github.getOctokit(this.token).rest.issues.createComment({
Expand All @@ -149,6 +150,16 @@ class GitHubIssue {
});
}

// remove a particular label from an issue
async removeLabel(label: string) {
await github.getOctokit(this.token).rest.issues.removeLabel({
owner: this.owner,
repo: this.repo,
issue_number: this.number,
name: label,
});
}

}

export { GitHubIssue };

0 comments on commit 8e71430

Please sign in to comment.