Skip to content

Commit

Permalink
ci: re add issue checker with new query 🤠🚨 (#567)
Browse files Browse the repository at this point in the history
* chore: test

* ci: retry

* ci:

* ci: retry with PAT

* ci:

* ci:

* ci:

* chore:

* ci:

* ci:

* ci:

* ci: scope permissions
  • Loading branch information
Gustav-Eikaas authored Dec 21, 2023
1 parent 4c46b86 commit bdeb70b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
54 changes: 40 additions & 14 deletions .github/helpers/src/issue-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof getOctokit>;
Expand Down Expand Up @@ -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}`);
}
24 changes: 20 additions & 4 deletions .github/workflows/pr-issue-check.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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}}

0 comments on commit bdeb70b

Please sign in to comment.