Skip to content

Commit

Permalink
Update and rename dependency-check.yml to pr-dependency-check.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
adamamer20 authored Jan 10, 2024
1 parent b9722e0 commit f3a263b
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Dependency Check
name: PR Dependency Check
on:
pull_request:
types: [opened, synchronize, reopened, edited]
Expand All @@ -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));

0 comments on commit f3a263b

Please sign in to comment.