diff --git a/lib/github-issue.js b/lib/github-issue.js index facb901..445285b 100644 --- a/lib/github-issue.js +++ b/lib/github-issue.js @@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitHubIssue = void 0; +const core = __importStar(require("@actions/core")); const github = __importStar(require("@actions/github")); // our opinionated view of a GitHub Issue. // https://docs.github.com/en/rest/issues/issues#get-an-issue @@ -75,7 +76,9 @@ class GitHubIssue { return this.getLabels().includes("kind/bug"); } hasLabelRegexp(regexp) { - return this.getLabels().find((label) => regexp.test(label)) !== undefined; + const labels = this.getLabels(); + core.debug(`Looking for label matching regexp ${regexp.toString()} in ${labels}`); + return labels.find((label) => regexp.test(label)) !== undefined; } isTriageAccepted() { return this.getLabels().includes("triage/accepted"); @@ -135,14 +138,17 @@ class GitHubIssue { labels: labels, }); } - // remove a particular label from an issue + // remove a particular label from an issue, but only if it has the label async removeLabel(label) { - await github.getOctokit(this.token).rest.issues.removeLabel({ - owner: this.owner, - repo: this.repo, - issue_number: this.number, - name: label, - }); + const labels = this.getLabels(); + if (labels.includes(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/github-issue.ts b/src/github-issue.ts index 8fe8150..9dbec7b 100644 --- a/src/github-issue.ts +++ b/src/github-issue.ts @@ -1,3 +1,4 @@ +import * as core from "@actions/core"; import { components } from "@octokit/openapi-types"; import * as github from "@actions/github"; @@ -74,7 +75,9 @@ class GitHubIssue { } hasLabelRegexp(regexp: RegExp): boolean { - return this.getLabels().find((label) => regexp.test(label)) !== undefined; + const labels = this.getLabels(); + core.debug(`Looking for label matching regexp ${regexp.toString()} in ${labels}`); + return labels.find((label) => regexp.test(label)) !== undefined; } isTriageAccepted(): boolean { @@ -150,14 +153,17 @@ class GitHubIssue { }); } - // remove a particular label from an issue + // remove a particular label from an issue, but only if it has the label async removeLabel(label: string) { - await github.getOctokit(this.token).rest.issues.removeLabel({ - owner: this.owner, - repo: this.repo, - issue_number: this.number, - name: label, - }); + const labels = this.getLabels(); + if (labels.includes(label)) { + await github.getOctokit(this.token).rest.issues.removeLabel({ + owner: this.owner, + repo: this.repo, + issue_number: this.number, + name: label, + }); + } } }