Skip to content

Commit

Permalink
added pr dependency-check
Browse files Browse the repository at this point in the history
  • Loading branch information
adamamer20 committed Jan 13, 2024
1 parent 6247050 commit 5eef752
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/issues-dependency-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Issues Dependency Check
on:
pull_request:
types: [opened, synchronize, reopened, edited]
pull_request_review:
types: [submitted, edited, dismissed]
jobs:
check-dependencies:
runs-on: ubuntu-latest
steps:
- name: Check for unresolved dependencies
uses: actions/github-script@v7
with:
script: |
// 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 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 5eef752

Please sign in to comment.