diff --git a/.github/helpers/src/issue-checker.ts b/.github/helpers/src/issue-checker.ts index 8b96e5cb3..070020eca 100644 --- a/.github/helpers/src/issue-checker.ts +++ b/.github/helpers/src/issue-checker.ts @@ -2,6 +2,7 @@ import { Command } from 'commander'; import { getOctokit, context } from '@actions/github'; +import { info } from '@actions/core'; const program = new Command(); type Octo = ReturnType; @@ -37,35 +38,60 @@ program } const client = getOctokit(args.token); - checkIssues(client, args.pr); + checkIssues(client, parseInt(args.pr)); }); await program.parseAsync(); async function checkIssues(client: Octo, pr: number) { const pullRequests = await client.graphql( - `query { - repository (owner: "${context.repo.owner}", name: "${context.repo.repo}"){ - pullRequest (number: ${pr}) { - closingIssuesReferences (first: 1){ - totalCount - } - } - } -} -` - .replaceAll('\n', '') - .trim() + ` + query($owner: String!, $name: String!, $pr: Int!) { + repository(owner: $owner, name: $name) { + pullRequest(number: $pr) { + id + number + title + timelineItems(first: 100, itemTypes: [CONNECTED_EVENT]) { + __typename + ... on PullRequestTimelineItemsConnection{ + totalCount + nodes { + __typename + ... on ConnectedEvent { + source { + __typename + ... on PullRequest { + number + } + } + subject { + __typename + ... on PullRequest { + number + } + } + } + } + } + } + } + } + }`, + { owner: context.repo.owner, name: context.repo.repo, pr: pr } ); - const linkedIssues: number = (pullRequests as any).repository.pullRequest.closingIssuesReferences.totalCount; + const linkedIssues: number = (pullRequests as any).repository.pullRequest.timelineItems.totalCount; if (linkedIssues === 0) { + info(`No linked issues adding comment to pr ${pr}`); const comment = await client.rest.issues.createComment({ issue_number: pr, body: noLinkedIssueMessage, owner: context.issue.owner, repo: context.issue.repo, }); + return; } + info(`Linked issues: ${linkedIssues}`); } diff --git a/.github/workflows/pr-issue-check.yml b/.github/workflows/pr-issue-check.yml index a8833fbfa..92adea3f2 100644 --- a/.github/workflows/pr-issue-check.yml +++ b/.github/workflows/pr-issue-check.yml @@ -1,8 +1,24 @@ name: Verify linked issue # This action works with pull requests and pushes +permissions: + { + contents: read, + actions: read, + checks: read, + deployments: read, + discussions: read, + id-token: write, + issues: write, + packages: read, + pages: read, + pull-requests: write, + repository-projects: read, + security-events: read, + statuses: read, + } on: - workflow_dispatch: + pull_request: jobs: issue-check: @@ -15,7 +31,7 @@ jobs: # Make sure the actual branch is checked out when running on pull requests ref: ${{ github.head_ref }} - - run: npm run first-time-setup + - name: pnpm setup + run: npm run first-time-setup - - run: pnpm tsx ./.github/helpers/src/issue-checker.ts issue -T ${{ github.token }} -P 1 - # ${{github.event.number}} + - run: pnpm tsx ./.github/helpers/src/issue-checker.ts issue -T ${{ github.token }} -P ${{github.event.number}}