Skip to content

Commit 853bf7e

Browse files
authored
Merge pull request #1 from OvertureMaps/jmccall/create-linked-pr-action
[FEATURE] Add PR linked-issue check action and workflow
2 parents 8300542 + 9ba6a6e commit 853bf7e

4 files changed

Lines changed: 27 additions & 26 deletions

File tree

.github/actions/check-linked-issue/README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This action queries the GitHub GraphQL API for `closingIssuesReferences` on a
1010
pull request. It detects issues linked by:
1111

1212
- Body keywords: `Fixes #123`, `Closes #456`, `Resolves owner/repo#789`
13-
- Manual linking via the GitHub UI sidebar
13+
- Manual linking via the GitHub UI
1414

1515
If no linked issues are found, the step fails with a message guiding the author
1616
to link one.
@@ -78,20 +78,12 @@ jobs:
7878

7979
- name: Check for linked issue
8080
uses: ./.workflows/.github/actions/check-linked-issue
81+
with:
82+
minimumLinkedIssues: 2 # Require at least 2 linked issues (optional, default is 1)
8183

8284
# ... additional steps in the same job
8385
```
8486

85-
### Use the composite action within the workflows repo
86-
87-
When referencing the action from a workflow in this same repository, use a
88-
relative path without a checkout step:
89-
90-
```yaml
91-
steps:
92-
- uses: ./.github/actions/check-linked-issue
93-
```
94-
9587
## Reference
9688

9789
### Permissions
@@ -101,16 +93,19 @@ Requires the default `GITHUB_TOKEN` with:
10193
```yaml
10294
permissions:
10395
contents: read
96+
issues: read
10497
pull-requests: read
10598
```
10699
107-
For private repos, these permissions allow the token to read PR metadata and
108-
query linked issues. Cross-repo issue detection is limited to public repos and
109-
repos within the same organization that the token has access to.
110-
111100
### Inputs
112101
113-
This action has no inputs.
102+
- `minimumLinkedIssues` (optional): Minimum number of linked issues required for the PR. Default is `1`. Set this input to require more than one linked issue:
103+
104+
```yaml
105+
with:
106+
minimumLinkedIssues: 2
107+
```
108+
114109

115110
### Outputs
116111

.github/actions/check-linked-issue/action.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ description: >
55
closingIssuesReferences. Covers 'Fixes #123', 'Closes owner/repo#456',
66
and issues linked manually through the GitHub UI.
77
8+
inputs:
9+
minimumLinkedIssues:
10+
description: Minimum number of linked issues required
11+
required: false
12+
default: 1
13+
814
runs:
915
using: composite
1016
steps:
@@ -14,6 +20,7 @@ runs:
1420
script: |
1521
const prNumber = context.payload.pull_request.number;
1622
const { owner, repo } = context.repo;
23+
const minimumLinkedIssues = parseInt(core.getInput('minimumLinkedIssues')) || 1;
1724
1825
const query = `
1926
query($owner: String!, $repo: String!, $number: Int!) {
@@ -41,15 +48,18 @@ runs:
4148
const issues =
4249
result.repository.pullRequest.closingIssuesReferences.nodes;
4350
44-
if (!issues || issues.length === 0) {
51+
core.debug(`${JSON.stringify(result, null, 2)}`);
52+
53+
if (!issues || issues.length < minimumLinkedIssues) {
4554
core.setFailed(
46-
"This PR does not reference any linked issues. " +
55+
`❌ This PR does not reference enough linked issues (found ${issues.length}, required ${minimumLinkedIssues})!\n` +
4756
"Please link an issue using 'Fixes #123', " +
4857
"'Closes OvertureMaps/other-repo#123', or the GitHub UI " +
49-
"(https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)"
58+
"(https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)\n" +
59+
"After adding a linked issue, you may need to manually re-run this check from the Checks tab to update the status."
5060
);
5161
} else {
52-
core.info("Linked issues found:");
62+
core.info(`✅ ${issues.length} linked issues found out of ${minimumLinkedIssues} required:`);
5363
issues.forEach(issue => {
5464
core.info(` #${issue.number} - ${issue.title} (${issue.state}) ${issue.url}`);
5565
});

.github/workflows/check-issue.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ on:
2929

3030
permissions:
3131
contents: read
32+
issues: read
3233
pull-requests: read
3334

3435
jobs:
3536
check-linked-issue:
3637
name: Check Linked Issue
37-
runs-on: ubuntu-latest
38+
runs-on: ubuntu-slim
3839
steps:
3940
- name: Checkout workflows repo
4041
uses: actions/checkout@v4

.github/workflows/lint-python.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ on:
3232
required: false
3333
type: string
3434
default: "error"
35-
pull_request:
36-
types:
37-
- opened
38-
- reopened
39-
- synchronize
4035

4136
permissions:
4237
contents: read

0 commit comments

Comments
 (0)