-
Notifications
You must be signed in to change notification settings - Fork 6
54 lines (47 loc) · 1.89 KB
/
issues-dependency-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Updated regex to match multiple issue numbers
const issueRegex = /depends on #(\d+(?:\s+#\d+)*)/ig;
async function run() {
const { context } = github;
// Get the PR description
const { data: pullRequest } = await github.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 github.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));