Skip to content

Commit 9ba6a6e

Browse files
committed
Add minimumLinkedIssues input to action
Introduce a new optional input `minimumLinkedIssues` (default 1) to the check-linked-issue action and parse it in the composite script so callers can require more than one linked issue. Update action.yml to declare the input and adjust messaging to show found vs required counts. Update README to document the new input and example usage, and add `issues: read` permission to the recommended permissions block. Signed-off-by: John McCall <john@overturemaps.org>
1 parent 484f0dc commit 9ba6a6e

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 6 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,6 +78,8 @@ 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
```
@@ -91,16 +93,19 @@ Requires the default `GITHUB_TOKEN` with:
9193
```yaml
9294
permissions:
9395
contents: read
96+
issues: read
9497
pull-requests: read
9598
```
9699
97-
For private repos, these permissions allow the token to read PR metadata and
98-
query linked issues. Cross-repo issue detection is limited to public repos and
99-
repos within the same organization that the token has access to.
100-
101100
### Inputs
102101
103-
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+
104109

105110
### Outputs
106111

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

Lines changed: 9 additions & 3 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,7 +20,7 @@ runs:
1420
script: |
1521
const prNumber = context.payload.pull_request.number;
1622
const { owner, repo } = context.repo;
17-
const minimumLinkedIssues = 1;
23+
const minimumLinkedIssues = parseInt(core.getInput('minimumLinkedIssues')) || 1;
1824
1925
const query = `
2026
query($owner: String!, $repo: String!, $number: Int!) {
@@ -46,14 +52,14 @@ runs:
4652
4753
if (!issues || issues.length < minimumLinkedIssues) {
4854
core.setFailed(
49-
`❌ This PR does not reference any linked issues, but should have at least ${minimumLinkedIssues}!\n` +
55+
`❌ This PR does not reference enough linked issues (found ${issues.length}, required ${minimumLinkedIssues})!\n` +
5056
"Please link an issue using 'Fixes #123', " +
5157
"'Closes OvertureMaps/other-repo#123', or the GitHub UI " +
5258
"(https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)\n" +
5359
"After adding a linked issue, you may need to manually re-run this check from the Checks tab to update the status."
5460
);
5561
} else {
56-
core.info(`✅ ${issues.length} linked issues found:`);
62+
core.info(`✅ ${issues.length} linked issues found out of ${minimumLinkedIssues} required:`);
5763
issues.forEach(issue => {
5864
core.info(` #${issue.number} - ${issue.title} (${issue.state}) ${issue.url}`);
5965
});

0 commit comments

Comments
 (0)