1- name : Check Linked Issue
1+ name : Ensure PR has linked issue
22
33on :
44 pull_request :
@@ -31,12 +31,13 @@ jobs:
3131 }
3232 `;
3333
34- const { repository: { pullRequest: pr } } = await github.graphql(query, {
34+ const result = await github.graphql(query, {
3535 owner: context.repo.owner,
3636 repo: context.repo.repo,
37- number: context.issue.number
37+ number: context.issue.number,
3838 });
3939
40+ const pr = result.repository.pullRequest;
4041 const textToCheck = `${pr.title} ${pr.body || ''}`;
4142
4243 const issuePatterns = [
@@ -47,19 +48,15 @@ jobs:
4748
4849 const linkedIssues = new Set();
4950
50- // Find linked issues from patterns
5151 for (const pattern of issuePatterns) {
5252 for (const match of textToCheck.matchAll(pattern)) {
5353 if (match[1]) linkedIssues.add(match[1]);
5454 }
5555 }
5656
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()));
6159
62- // Check if no issues are linked
6360 if (linkedIssues.size === 0) {
6461 await github.rest.issues.createComment({
6562 owner: context.repo.owner,
7067
7168Hi 👋 This pull request does not appear to be linked to any open issue yet.
7269
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 .
7471
7572# ## ✔️ How to fix this
7673
@@ -82,16 +79,16 @@ Linking your PR to an issue helps keep the project tidy and ensures the issue is
8279
8380Once linked, this check will pass automatically on your next push or when you re-run the workflow.
8481
85- Thanks for helping maintainers ! 🙌
82+ Thanks for helping maintain the project ! 🙌
8683`
8784 });
8885 core.setFailed('❌ No linked issue found.');
8986 return;
9087 }
9188
89+ // Now check if the linked issues are open
9290 let openIssues = 0;
9391
94- // Check status of each linked issue
9592 for (const issueNumber of linkedIssues) {
9693 const issueQuery = `
9794 query($owner : String!, $repo: String!, $number: Int!) {
@@ -102,19 +99,17 @@ Thanks for helping maintainers! 🙌
10299 }
103100 }
104101 ` ;
105-
106- const { repository: { issue } } = await github.graphql(issueQuery, {
102+ const issueResult = await github.graphql(issueQuery, {
107103 owner: context.repo.owner,
108104 repo: context.repo.repo,
109- number: parseInt(issueNumber, 10)
105+ number: parseInt(issueNumber, 10),
110106 });
111107
112- if (issue.state === 'OPEN') {
108+ if (issueResult.repository. issue.state === 'OPEN') {
113109 openIssues++;
114110 }
115111 }
116112
117- // If only one issue is linked and it's closed, fail the check
118113 if (linkedIssues.size === 1 && openIssues === 0) {
119114 await github.rest.issues.createComment({
120115 owner: context.repo.owner,
@@ -136,7 +131,8 @@ Thanks for keeping the project healthy! 🚀
136131`
137132 });
138133 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