1
- name : Check Linked Issue
1
+ name : Ensure PR has linked issue
2
2
3
3
on :
4
4
pull_request :
@@ -31,12 +31,13 @@ jobs:
31
31
}
32
32
`;
33
33
34
- const { repository: { pullRequest: pr } } = await github.graphql(query, {
34
+ const result = await github.graphql(query, {
35
35
owner: context.repo.owner,
36
36
repo: context.repo.repo,
37
- number: context.issue.number
37
+ number: context.issue.number,
38
38
});
39
39
40
+ const pr = result.repository.pullRequest;
40
41
const textToCheck = `${pr.title} ${pr.body || ''}`;
41
42
42
43
const issuePatterns = [
@@ -47,19 +48,15 @@ jobs:
47
48
48
49
const linkedIssues = new Set();
49
50
50
- // Find linked issues from patterns
51
51
for (const pattern of issuePatterns) {
52
52
for (const match of textToCheck.matchAll(pattern)) {
53
53
if (match[1]) linkedIssues.add(match[1]);
54
54
}
55
55
}
56
56
57
- // Add issues from GitHub's closing references
58
- pr.closingIssuesReferences.nodes.forEach(node => {
59
- linkedIssues.add(node.number.toString());
60
- });
57
+ // Add issues from closingIssuesReferences
58
+ pr.closingIssuesReferences.nodes.forEach(node => linkedIssues.add(node.number.toString()));
61
59
62
- // Check if no issues are linked
63
60
if (linkedIssues.size === 0) {
64
61
await github.rest.issues.createComment({
65
62
owner: context.repo.owner,
70
67
71
68
Hi 👋 This pull request does not appear to be linked to any open issue yet.
72
69
73
- Linking your PR to an issue helps keep the project tidy and ensures the issue is closed automatically.
70
+ Linking your PR to an issue helps keep the project tidy and ensures the issue is closed automatically when the PR merges .
74
71
75
72
# ## ✔️ How to fix this
76
73
@@ -82,16 +79,16 @@ Linking your PR to an issue helps keep the project tidy and ensures the issue is
82
79
83
80
Once linked, this check will pass automatically on your next push or when you re-run the workflow.
84
81
85
- Thanks for helping maintainers ! 🙌
82
+ Thanks for helping maintain the project ! 🙌
86
83
`
87
84
});
88
85
core.setFailed('❌ No linked issue found.');
89
86
return;
90
87
}
91
88
89
+ // Now check if the linked issues are open
92
90
let openIssues = 0;
93
91
94
- // Check status of each linked issue
95
92
for (const issueNumber of linkedIssues) {
96
93
const issueQuery = `
97
94
query($owner : String!, $repo: String!, $number: Int!) {
@@ -102,19 +99,17 @@ Thanks for helping maintainers! 🙌
102
99
}
103
100
}
104
101
` ;
105
-
106
- const { repository: { issue } } = await github.graphql(issueQuery, {
102
+ const issueResult = await github.graphql(issueQuery, {
107
103
owner: context.repo.owner,
108
104
repo: context.repo.repo,
109
- number: parseInt(issueNumber, 10)
105
+ number: parseInt(issueNumber, 10),
110
106
});
111
107
112
- if (issue.state === 'OPEN') {
108
+ if (issueResult.repository. issue.state === 'OPEN') {
113
109
openIssues++;
114
110
}
115
111
}
116
112
117
- // If only one issue is linked and it's closed, fail the check
118
113
if (linkedIssues.size === 1 && openIssues === 0) {
119
114
await github.rest.issues.createComment({
120
115
owner: context.repo.owner,
@@ -136,7 +131,8 @@ Thanks for keeping the project healthy! 🚀
136
131
`
137
132
});
138
133
core.setFailed('❌ Linked issue is closed.');
139
- } else {
140
- console.log(` ✅ PR is linked to issue(s): ${Array.from(linkedIssues).join(', ')}`);
141
- console.log(`✅ Number of open issues : ${openIssues}`);
142
- }
134
+ return;
135
+ }
136
+
137
+ console.log(` ✅ Linked issues: ${Array.from(linkedIssues).join(', ')}`);
138
+ console.log(`✅ Open issues found : ${openIssues}`);
0 commit comments