From f3a263ba121843b2c42270112ba07fd13ec13cbb Mon Sep 17 00:00:00 2001 From: Adam Amer <136176500+adamamer20@users.noreply.github.com> Date: Wed, 10 Jan 2024 21:41:16 +0100 Subject: [PATCH] Update and rename dependency-check.yml to pr-dependency-check.yml --- ...ency-check.yml => pr-dependency-check.yml} | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) rename .github/workflows/{dependency-check.yml => pr-dependency-check.yml} (68%) diff --git a/.github/workflows/dependency-check.yml b/.github/workflows/pr-dependency-check.yml similarity index 68% rename from .github/workflows/dependency-check.yml rename to .github/workflows/pr-dependency-check.yml index 733027d..400c235 100644 --- a/.github/workflows/dependency-check.yml +++ b/.github/workflows/pr-dependency-check.yml @@ -1,4 +1,4 @@ -name: Dependency Check +name: PR Dependency Check on: pull_request: types: [opened, synchronize, reopened, edited] @@ -14,42 +14,46 @@ jobs: script: | const github = require('@actions/github'); const core = require('@actions/core'); - const issueRegex = /depends on #(\d+)/ig; - + // Updated regex to match multiple issue numbers + const issueRegex = /depends on #(\d+(?:\s+#\d+)*)/ig; + async function run() { const token = core.getInput('github-token', { required: true }); const octokit = github.getOctokit(token); const { context } = github; - + // Get the PR description const { data: pullRequest } = await octokit.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, }); - + const description = pullRequest.body; let match; let blockingIssues = []; - + // Find issues mentioned in the description while ((match = issueRegex.exec(description)) !== null) { - const issueNumber = match[1]; - const { data: issue } = await octokit.rest.issues.get({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueNumber, - }); - - if (issue.state === 'open') { - blockingIssues.push(issueNumber); + const issues = match[1].split(/\s+#/); + for (const issueNumber of issues) { + const { data: issue } = await octokit.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: parseInt(issueNumber), + }); + + if (issue.state === 'open') { + blockingIssues.push(issueNumber); + } } } - + if (blockingIssues.length > 0) { core.setFailed(`Cannot merge PR because these issues are not resolved: #${blockingIssues.join(', #')}`); } } - + run().catch(error => core.setFailed(error.message)); +