Skip to content

Commit

Permalink
feat: allow configuration of triaged labels
Browse files Browse the repository at this point in the history
  • Loading branch information
djzager committed Jun 29, 2022
1 parent 309acc4 commit 9039c75
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 127 deletions.
24 changes: 7 additions & 17 deletions lib/actions/reconcile-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ const commentPrefix = "This issue synced with";
async function reconcileIssue() {
const inputs = {
token: core.getInput("token"),
jiraBaseUrl: core.getInput("jiraBaseUrl"),
jiraToken: core.getInput("jiraToken"),
jiraProject: core.getInput("jiraProject"),
jiraBaseUrl: core.getInput("jiraBaseUrl", { required: true }),
jiraToken: core.getInput("jiraToken", { required: true }),
jiraProject: core.getInput("jiraProject", { required: true }),
requireMissingLabels: core.getInput("requireMissingLabels", { required: true }).split(","),
additionalLabels: core.getInput("additionalLabels").split(","),
};
// First, make sure we are looking at the right thing.
Expand Down Expand Up @@ -89,20 +90,9 @@ async function reconcileIssue() {
await ghIssue.ensureComment(`${commentPrefix}: ${htmlUrl}`);
return;
}
// We will only write to Jira, GH Issues that have been triaged.
// https://www.kubernetes.dev/docs/guide/issue-triage/
if (!ghIssue.isTriageAccepted()) {
core.info("This issue needs triage");
try {
if (ghIssue.isNeedsTriage()) {
core.info("This issue already marked as needing triage");
return;
}
ghIssue.markNeedsTriage();
}
catch (error) {
core.setFailed(`Failed to set GitHub Issue ${owner}/${repo}#${number} as needing triage: ${error}`);
}
const requiredMissingLabels = inputs.requireMissingLabels.filter((label) => ghIssue.hasLabel(label));
if (requiredMissingLabels) {
core.info(`This issue has ${requiredMissingLabels} that indicate this issue is not triaged.`);
return;
}
// jiraIssueParams are the primary fields we are concerned with updating
Expand Down
32 changes: 11 additions & 21 deletions lib/github-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ class GitHubIssue {
isBug() {
return this.getLabels().includes("kind/bug");
}
hasLabelRegexp(regexp) {
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");
}
isNeedsTriage() {
return this.getLabels().includes("needs-triage");
}
async markNeedsTriage() {
await github.getOctokit(this.token).rest.issues.addLabels({
owner: this.owner,
repo: this.repo,
issue_number: this.number,
labels: ["needs-triage"],
});
}
// ensureComment creates a comment with ${body} if it cannot
// be found in the issue's comments.
async ensureComment(body) {
Expand Down Expand Up @@ -129,6 +110,16 @@ class GitHubIssue {
body: body,
});
}
hasLabel(label) {
const labels = this.getLabels();
core.debug(`Looking for label ${label} in ${labels}`);
return labels.includes(label);
}
hasLabelRegexp(regexp) {
const labels = this.getLabels();
core.debug(`Looking for label matching regexp ${regexp.toString()} in ${labels}`);
return labels.find((label) => regexp.test(label)) !== undefined;
}
// addLabel adds a label to the issue
async addLabels(labels) {
await github.getOctokit(this.token).rest.issues.addLabels({
Expand All @@ -140,8 +131,7 @@ class GitHubIssue {
}
// remove a particular label from an issue, but only if it has the label
async removeLabel(label) {
const labels = this.getLabels();
if (labels.includes(label)) {
if (this.hasLabel(label)) {
await github.getOctokit(this.token).rest.issues.removeLabel({
owner: this.owner,
repo: this.repo,
Expand Down
5 changes: 5 additions & 0 deletions reconcile-issue/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ inputs:
jiraProject:
description: Key of the project (ie. MIG)
required: true
requireMissingLabels:
description: |
Comma separated list of labels the GitHub Issue must NOT have in order
to be considered triaged.
default: 'needs-triage'
additionalLabels:
description: |
Comma separated list of labels that should be added to Jira issues.
Expand Down
27 changes: 8 additions & 19 deletions src/actions/reconcile-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const commentPrefix = "This issue synced with";
async function reconcileIssue() {
const inputs = {
token: core.getInput("token"),
jiraBaseUrl: core.getInput("jiraBaseUrl"),
jiraToken: core.getInput("jiraToken"),
jiraProject: core.getInput("jiraProject"),
jiraBaseUrl: core.getInput("jiraBaseUrl", { required: true }),
jiraToken: core.getInput("jiraToken", { required: true }),
jiraProject: core.getInput("jiraProject", { required: true }),
requireMissingLabels: core.getInput("requireMissingLabels", { required: true }).split(","),
additionalLabels: core.getInput("additionalLabels").split(","),
};

Expand Down Expand Up @@ -80,22 +81,10 @@ async function reconcileIssue() {
return;
}

// We will only write to Jira, GH Issues that have been triaged.
// https://www.kubernetes.dev/docs/guide/issue-triage/
if (!ghIssue.isTriageAccepted()) {
core.info("This issue needs triage");
try {
if (ghIssue.isNeedsTriage()) {
core.info("This issue already marked as needing triage");
return;
}
ghIssue.markNeedsTriage();
} catch (error) {
core.setFailed(
`Failed to set GitHub Issue ${owner}/${repo}#${number} as needing triage: ${error}`
);
}
return;
const requiredMissingLabels = inputs.requireMissingLabels.filter((label) => ghIssue.hasLabel(label));
if (requiredMissingLabels) {
core.info(`This issue has ${requiredMissingLabels} that indicate this issue is not triaged.`);
return
}

// jiraIssueParams are the primary fields we are concerned with updating
Expand Down
38 changes: 13 additions & 25 deletions src/github-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,6 @@ class GitHubIssue {
return this.getLabels().includes("kind/bug");
}

hasLabelRegexp(regexp: RegExp): boolean {
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 {
return this.getLabels().includes("triage/accepted");
}

isNeedsTriage(): boolean {
return this.getLabels().includes("needs-triage");
}

async markNeedsTriage() {
await github.getOctokit(this.token).rest.issues.addLabels({
owner: this.owner,
repo: this.repo,
issue_number: this.number,
labels: ["needs-triage"],
});
}

// ensureComment creates a comment with ${body} if it cannot
// be found in the issue's comments.
async ensureComment(body: string) {
Expand Down Expand Up @@ -143,6 +120,18 @@ class GitHubIssue {
});
}

hasLabel(label: string): boolean {
const labels = this.getLabels();
core.debug(`Looking for label ${label} in ${labels}`);
return labels.includes(label);
}

hasLabelRegexp(regexp: RegExp): boolean {
const labels = this.getLabels();
core.debug(`Looking for label matching regexp ${regexp.toString()} in ${labels}`);
return labels.find((label) => regexp.test(label)) !== undefined;
}

// addLabel adds a label to the issue
async addLabels(labels: string[]) {
await github.getOctokit(this.token).rest.issues.addLabels({
Expand All @@ -155,8 +144,7 @@ class GitHubIssue {

// remove a particular label from an issue, but only if it has the label
async removeLabel(label: string) {
const labels = this.getLabels();
if (labels.includes(label)) {
if (this.hasLabel(label)) {
await github.getOctokit(this.token).rest.issues.removeLabel({
owner: this.owner,
repo: this.repo,
Expand Down
25 changes: 25 additions & 0 deletions workflows/reconcile_gh_issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- reopened
- closed
- labeled
- unlabeled

# This prevents potential race conditions by only allowing this action to handle
# one update at a time for a given issue.
Expand All @@ -21,6 +22,30 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: needs-triage
uses: konveyor/github-actions/require-matching-label@main
with:
missingComment: |
This issue is currently awaiting triage.
If contributors determine this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.
The `triage/accepted` label can be added by org members by writing `/triage accepted` in a comment.
missingLabel: "needs-triage"
regexp: "^triage/accepted$"

- name: needs-kind
uses: konveyor/github-actions/require-matching-label@main
with:
missingLabel: "needs-kind"
regexp: "^kind/"

- name: needs-priority
uses: konveyor/github-actions/require-matching-label@main
with:
missingLabel: "needs-priority"
regexp: "^priority/"

- name: Reconcile Issue
id: create
uses: konveyor/github-actions/reconcile-issue@main
Expand Down
45 changes: 0 additions & 45 deletions workflows/require_matching_label.yaml

This file was deleted.

0 comments on commit 9039c75

Please sign in to comment.