diff --git a/.github/actions/check-linked-issue/README.md b/.github/actions/check-linked-issue/README.md index c667538..02c4676 100644 --- a/.github/actions/check-linked-issue/README.md +++ b/.github/actions/check-linked-issue/README.md @@ -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. @@ -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 @@ -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 diff --git a/.github/actions/check-linked-issue/action.yml b/.github/actions/check-linked-issue/action.yml index 7e7d9a5..c2b7351 100644 --- a/.github/actions/check-linked-issue/action.yml +++ b/.github/actions/check-linked-issue/action.yml @@ -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: @@ -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!) { @@ -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}`); }); diff --git a/.github/workflows/check-issue.yml b/.github/workflows/check-issue.yml index 6d42dbb..a353720 100644 --- a/.github/workflows/check-issue.yml +++ b/.github/workflows/check-issue.yml @@ -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 diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index 2968e9c..cfc66d8 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -32,11 +32,6 @@ on: required: false type: string default: "error" - pull_request: - types: - - opened - - reopened - - synchronize permissions: contents: read