Skip to content

Commit

Permalink
chore: debug label matching
Browse files Browse the repository at this point in the history
  • Loading branch information
djzager committed Jun 29, 2022
1 parent 8e71430 commit bb4dfba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
22 changes: 14 additions & 8 deletions lib/github-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
22 changes: 14 additions & 8 deletions src/github-issue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from "@actions/core";
import { components } from "@octokit/openapi-types";
import * as github from "@actions/github";

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
});
}
}

}
Expand Down

0 comments on commit bb4dfba

Please sign in to comment.