Skip to content

Commit

Permalink
ci(actions): fix regex, and catch issue not found error on blocked is…
Browse files Browse the repository at this point in the history
…sue action (#10135)

**Related Issue:** #10132 

## Summary
Changes the regex to better match the "Blocked issue:" so that randomly
mentioned issues don't get matched and attempted to be unblocked.

Also, catches the issue not found error in case somehow a issue that
doesn't actually exist gets listed as blocked.

[Codepen to test
regex](https://codepen.io/Ditwan-Price/pen/QWXmmRL?editors=0012)
  • Loading branch information
DitwanP authored Aug 21, 2024
1 parent 0e897a7 commit d3bd115
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions .github/scripts/addUnblockedComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module.exports = async ({ github, context }) => {
const payload = /** @type {import('@octokit/webhooks-types').IssuesLabeledEvent} */ (context.payload);
const { ISSUE_VERIFIERS } = process.env;
const issueBody = payload.issue.body;
const blockedIssuesRegex = /(?!Blocked issues:\s)(#\d+)/gi;
const blockedIssuesRegex = /Blocked issues:\s*(#\d+(?:,\s*#\d+)*)/i;

if (!issueBody) {
console.log("No issue body was found");
console.log("No issue body was found.");
return;
}

Expand All @@ -23,7 +23,7 @@ module.exports = async ({ github, context }) => {

// If "Blocked issues" line is matched in the body then create a comment on each issue listed
if (blockedIssues) {
const issueNumbers = blockedIssues.map((number) => number.slice(1));
const issueNumbers = blockedIssues[1].split(",").map((num) => num.trim().slice(1));

for (const issueNumber of issueNumbers) {
const issueProps = {
Expand All @@ -32,10 +32,19 @@ module.exports = async ({ github, context }) => {
issue_number: Number(issueNumber),
};

await github.rest.issues.createComment({
...issueProps,
body: `Issue #${context.issue.number} has been closed, this issue is ready for re-evaluation. \n\ncc ${verifiers}`,
});
try {
await github.rest.issues.createComment({
...issueProps,
body: `Issue #${context.issue.number} has been closed, this issue is ready for re-evaluation. \n\ncc ${verifiers}`,
});
} catch (error) {
if (error.status === 404) {
console.log(`Issue #${issueNumber} does not exist.`);
continue;
} else {
throw error;
}
}

try {
await github.rest.issues.removeLabel({
Expand Down

0 comments on commit d3bd115

Please sign in to comment.