From 87258bac1f935a0d8282c47bf7d1de00a86deb67 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Mon, 16 Mar 2026 11:28:28 -0400 Subject: [PATCH] Enhance issue reference validation in PRs by improving regex matching and error handling for missing issues (#1066) --- .github/workflows/adventurelog-bot.yml | 40 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/.github/workflows/adventurelog-bot.yml b/.github/workflows/adventurelog-bot.yml index fcc1ec71..26f3b383 100644 --- a/.github/workflows/adventurelog-bot.yml +++ b/.github/workflows/adventurelog-bot.yml @@ -35,7 +35,7 @@ jobs: } const body = pr.body || ""; - const match = body.match(/#(\d+)/); + const match = body.match(/\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)\b/i); if (!match) { @@ -56,17 +56,41 @@ jobs: return; } - const issueNumber = match[1]; + const issueNumber = Number(match[1]); - const { data: issue } = await github.rest.issues.get({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueNumber - }); + let issue; + + try { + ({ data: issue } = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber + })); + } catch (error) { + if (error.status === 404) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: `šŸ¤– **AdventureLog Bot**\n\n🚫 This PR was automatically closed because the referenced issue #${issueNumber} was not found.\n\nPlease link a valid issue in this repository using \`Closes #issue-number\`.` + }); + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number, + state: "closed" + }); + + return; + } + + throw error; + } const labels = issue.labels.map(l => l.name); - if (!labels.includes("ready")) { + if (!labels.includes("ready") && !labels.includes("in progress")) { await github.rest.issues.createComment({ owner: context.repo.owner,