From 294d55580d1b96c372b19f86a8b272a30137eb75 Mon Sep 17 00:00:00 2001 From: David Zager Date: Wed, 29 Jun 2022 13:26:20 -0400 Subject: [PATCH] feat: remove label when found --- lib/actions/require-matching-label.js | 1 + lib/github-issue.js | 9 +++++++++ src/actions/require-matching-label.ts | 1 + src/github-issue.ts | 11 +++++++++++ 4 files changed, 22 insertions(+) diff --git a/lib/actions/require-matching-label.js b/lib/actions/require-matching-label.js index 141adf4..c150582 100644 --- a/lib/actions/require-matching-label.js +++ b/lib/actions/require-matching-label.js @@ -65,6 +65,7 @@ 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); } core.info(`Adding label ${inputs.missingLabel}.`); await ghIssue.addLabels([inputs.missingLabel]); diff --git a/lib/github-issue.js b/lib/github-issue.js index cc6f698..facb901 100644 --- a/lib/github-issue.js +++ b/lib/github-issue.js @@ -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; diff --git a/src/actions/require-matching-label.ts b/src/actions/require-matching-label.ts index 9beb94f..6464a52 100644 --- a/src/actions/require-matching-label.ts +++ b/src/actions/require-matching-label.ts @@ -52,6 +52,7 @@ 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); } core.info(`Adding label ${inputs.missingLabel}.`); diff --git a/src/github-issue.ts b/src/github-issue.ts index 0401a78..8fe8150 100644 --- a/src/github-issue.ts +++ b/src/github-issue.ts @@ -129,6 +129,7 @@ class GitHubIssue { }); } + // addComment creates a comment with ${body} async addComment(body: string) { await github.getOctokit(this.token).rest.issues.createComment({ @@ -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 };