From d77bc7982afbee351c62a74618be21a6a17ac486 Mon Sep 17 00:00:00 2001 From: Gustav Eikaas Date: Wed, 20 Dec 2023 15:01:43 +0100 Subject: [PATCH] revert: :rewind: --- .github/helpers/package.json | 1 - .github/helpers/src/issue-checker.ts | 37 +++++++++++----------------- .github/workflows/pr-issue-check.yml | 2 +- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.github/helpers/package.json b/.github/helpers/package.json index 349e50791..b186100ef 100644 --- a/.github/helpers/package.json +++ b/.github/helpers/package.json @@ -6,7 +6,6 @@ "dependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "@octokit/graphql": "^7.0.2", "commander": "^11.1.0", "markdown-table": "^3.0.3", "tsx": "^4.6.2" diff --git a/.github/helpers/src/issue-checker.ts b/.github/helpers/src/issue-checker.ts index c374b9795..8b96e5cb3 100644 --- a/.github/helpers/src/issue-checker.ts +++ b/.github/helpers/src/issue-checker.ts @@ -2,7 +2,6 @@ import { Command } from 'commander'; import { getOctokit, context } from '@actions/github'; -import { setSecret } from '@actions/core'; const program = new Command(); type Octo = ReturnType; @@ -37,38 +36,30 @@ program throw new Error('Missing pr number'); } - setSecret(args.token); - const client = getOctokit(args.token); - checkIssues(client, parseInt(args.pr), args.token); + checkIssues(client, args.pr); }); await program.parseAsync(); -async function checkIssues(client: Octo, pr: number, token: string) { - const pullRequests = await client.graphql({ - query: `query($owner: String!, $name: String!, $number: Int!) { - repository (owner: $owner, name: $name){ - pullRequest (number: $number) { - closingIssuesReferences (first: 1){ - totalCount - } +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 } } - } - `, - owner: context.repo.owner, - name: context.repo.repo, - number: pr, - headers: { - authorization: token, - }, - }); + } +} +` + .replaceAll('\n', '') + .trim() + ); const linkedIssues: number = (pullRequests as any).repository.pullRequest.closingIssuesReferences.totalCount; - console.log(JSON.stringify(pullRequests)); - if (linkedIssues === 0) { const comment = await client.rest.issues.createComment({ issue_number: pr, diff --git a/.github/workflows/pr-issue-check.yml b/.github/workflows/pr-issue-check.yml index 015b66e2d..a8833fbfa 100644 --- a/.github/workflows/pr-issue-check.yml +++ b/.github/workflows/pr-issue-check.yml @@ -1,6 +1,6 @@ name: Verify linked issue -permissions: write-all +# This action works with pull requests and pushes on: workflow_dispatch: