Skip to content
27 changes: 11 additions & 16 deletions .github/actions/check-linked-issue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This action queries the GitHub GraphQL API for `closingIssuesReferences` on a
pull request. It detects issues linked by:

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

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

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

# ... additional steps in the same job
```

### Use the composite action within the workflows repo

When referencing the action from a workflow in this same repository, use a
relative path without a checkout step:

```yaml
steps:
- uses: ./.github/actions/check-linked-issue
```

## Reference

### Permissions
Expand All @@ -101,16 +93,19 @@ Requires the default `GITHUB_TOKEN` with:
```yaml
permissions:
contents: read
issues: read
pull-requests: read
```

For private repos, these permissions allow the token to read PR metadata and
query linked issues. Cross-repo issue detection is limited to public repos and
repos within the same organization that the token has access to.

### Inputs

This action has no inputs.
- `minimumLinkedIssues` (optional): Minimum number of linked issues required for the PR. Default is `1`. Set this input to require more than one linked issue:

```yaml
with:
minimumLinkedIssues: 2
```


### Outputs

Expand Down
18 changes: 14 additions & 4 deletions .github/actions/check-linked-issue/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ description: >
closingIssuesReferences. Covers 'Fixes #123', 'Closes owner/repo#456',
and issues linked manually through the GitHub UI.

inputs:
minimumLinkedIssues:
description: Minimum number of linked issues required
required: false
default: 1

runs:
using: composite
steps:
Expand All @@ -14,6 +20,7 @@ runs:
script: |
const prNumber = context.payload.pull_request.number;
const { owner, repo } = context.repo;
const minimumLinkedIssues = parseInt(core.getInput('minimumLinkedIssues')) || 1;

const query = `
query($owner: String!, $repo: String!, $number: Int!) {
Expand Down Expand Up @@ -41,15 +48,18 @@ runs:
const issues =
result.repository.pullRequest.closingIssuesReferences.nodes;

if (!issues || issues.length === 0) {
core.debug(`${JSON.stringify(result, null, 2)}`);

if (!issues || issues.length < minimumLinkedIssues) {
core.setFailed(
"This PR does not reference any linked issues. " +
`❌ This PR does not reference enough linked issues (found ${issues.length}, required ${minimumLinkedIssues})!\n` +
"Please link an issue using 'Fixes #123', " +
"'Closes OvertureMaps/other-repo#123', or the GitHub UI " +
"(https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)"
"(https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue)\n" +
"After adding a linked issue, you may need to manually re-run this check from the Checks tab to update the status."
);
} else {
core.info("Linked issues found:");
core.info(`✅ ${issues.length} linked issues found out of ${minimumLinkedIssues} required:`);
issues.forEach(issue => {
core.info(` #${issue.number} - ${issue.title} (${issue.state}) ${issue.url}`);
});
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/check-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ on:

permissions:
contents: read
issues: read
pull-requests: read

jobs:
check-linked-issue:
name: Check Linked Issue
runs-on: ubuntu-latest
runs-on: ubuntu-slim
steps:
- name: Checkout workflows repo
uses: actions/checkout@v4
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ on:
required: false
type: string
default: "error"
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
contents: read
Expand Down