mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
use octokit method (#59)
This commit is contained in:
parent
bd2c7fd13a
commit
3bebc5877c
4 changed files with 26 additions and 51 deletions
3
.github/workflows/integration.yml
vendored
3
.github/workflows/integration.yml
vendored
|
|
@ -36,8 +36,7 @@ jobs:
|
||||||
name: Dogfood
|
name: Dogfood
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
issues: write
|
pull-requests: write
|
||||||
pull-requests: read
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
|
||||||
33
package-lock.json
generated
33
package-lock.json
generated
|
|
@ -18,7 +18,7 @@
|
||||||
"@types/node": "^18.11.9",
|
"@types/node": "^18.11.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
||||||
"@typescript-eslint/parser": "^5.42.0",
|
"@typescript-eslint/parser": "^5.42.0",
|
||||||
"@zeit/ncc": "^0.22.3",
|
"@vercel/ncc": "^0.34.0",
|
||||||
"eslint": "^8.26.0",
|
"eslint": "^8.26.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-import-resolver-typescript": "^3.5.2",
|
"eslint-import-resolver-typescript": "^3.5.2",
|
||||||
|
|
@ -971,6 +971,15 @@
|
||||||
"url": "https://opencollective.com/typescript-eslint"
|
"url": "https://opencollective.com/typescript-eslint"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@vercel/ncc": {
|
||||||
|
"version": "0.34.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz",
|
||||||
|
"integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"ncc": "dist/ncc/cli.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@xmldom/xmldom": {
|
"node_modules/@xmldom/xmldom": {
|
||||||
"version": "0.8.5",
|
"version": "0.8.5",
|
||||||
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.5.tgz",
|
||||||
|
|
@ -980,16 +989,6 @@
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@zeit/ncc": {
|
|
||||||
"version": "0.22.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
|
|
||||||
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==",
|
|
||||||
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
|
|
||||||
"dev": true,
|
|
||||||
"bin": {
|
|
||||||
"ncc": "dist/ncc/cli.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@zxing/text-encoding": {
|
"node_modules/@zxing/text-encoding": {
|
||||||
"version": "0.9.0",
|
"version": "0.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz",
|
||||||
|
|
@ -7741,18 +7740,18 @@
|
||||||
"eslint-visitor-keys": "^3.3.0"
|
"eslint-visitor-keys": "^3.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@vercel/ncc": {
|
||||||
|
"version": "0.34.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz",
|
||||||
|
"integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@xmldom/xmldom": {
|
"@xmldom/xmldom": {
|
||||||
"version": "0.8.5",
|
"version": "0.8.5",
|
||||||
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.5.tgz",
|
||||||
"integrity": "sha512-0dpjDLeCXYThL2YhqZcd/spuwoH+dmnFoND9ZxZkAYxp1IJUB2GP16ow2MJRsjVxy8j1Qv8BJRmN5GKnbDKCmQ==",
|
"integrity": "sha512-0dpjDLeCXYThL2YhqZcd/spuwoH+dmnFoND9ZxZkAYxp1IJUB2GP16ow2MJRsjVxy8j1Qv8BJRmN5GKnbDKCmQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@zeit/ncc": {
|
|
||||||
"version": "0.22.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
|
|
||||||
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"@zxing/text-encoding": {
|
"@zxing/text-encoding": {
|
||||||
"version": "0.9.0",
|
"version": "0.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@
|
||||||
"@types/node": "^18.11.9",
|
"@types/node": "^18.11.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
||||||
"@typescript-eslint/parser": "^5.42.0",
|
"@typescript-eslint/parser": "^5.42.0",
|
||||||
"@zeit/ncc": "^0.22.3",
|
"@vercel/ncc": "^0.34.0",
|
||||||
"eslint": "^8.26.0",
|
"eslint": "^8.26.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-import-resolver-typescript": "^3.5.2",
|
"eslint-import-resolver-typescript": "^3.5.2",
|
||||||
|
|
|
||||||
39
src/main.ts
39
src/main.ts
|
|
@ -1,7 +1,7 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import { HttpClient } from '@actions/http-client'
|
import { HttpClient } from '@actions/http-client'
|
||||||
import { Endpoints, RequestHeaders } from '@octokit/types'
|
import { Endpoints } from '@octokit/types'
|
||||||
import fs from 'node:fs/promises'
|
import fs from 'node:fs/promises'
|
||||||
|
|
||||||
type ListCommitPullsResponseData =
|
type ListCommitPullsResponseData =
|
||||||
|
|
@ -10,32 +10,6 @@ type CreateIssueCommentResponseData =
|
||||||
Endpoints['POST /repos/{owner}/{repo}/issues/{issue_number}/comments']['response']['data']
|
Endpoints['POST /repos/{owner}/{repo}/issues/{issue_number}/comments']['response']['data']
|
||||||
type IssuesListCommentsResponseData =
|
type IssuesListCommentsResponseData =
|
||||||
Endpoints['GET /repos/{owner}/{repo}/issues/comments']['response']['data']
|
Endpoints['GET /repos/{owner}/{repo}/issues/comments']['response']['data']
|
||||||
interface ListCommitPullsParams {
|
|
||||||
repoToken: string
|
|
||||||
owner: string
|
|
||||||
repo: string
|
|
||||||
commitSha: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const listCommitPulls = async (
|
|
||||||
params: ListCommitPullsParams,
|
|
||||||
): Promise<ListCommitPullsResponseData | null> => {
|
|
||||||
const { repoToken, owner, repo, commitSha } = params
|
|
||||||
|
|
||||||
const http = new HttpClient('http-client-add-pr-comment')
|
|
||||||
|
|
||||||
const additionalHeaders: RequestHeaders = {
|
|
||||||
accept: 'application/vnd.github.groot-preview+json',
|
|
||||||
authorization: `token ${repoToken}`,
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await http.getJson<ListCommitPullsResponseData>(
|
|
||||||
`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}/pulls`,
|
|
||||||
additionalHeaders,
|
|
||||||
)
|
|
||||||
|
|
||||||
return body.result
|
|
||||||
}
|
|
||||||
|
|
||||||
const getIssueNumberFromCommitPullsList = (
|
const getIssueNumberFromCommitPullsList = (
|
||||||
commitPullsList: ListCommitPullsResponseData,
|
commitPullsList: ListCommitPullsResponseData,
|
||||||
|
|
@ -151,6 +125,7 @@ const run = async (): Promise<void> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [owner, repo] = repoFullName.split('/')
|
const [owner, repo] = repoFullName.split('/')
|
||||||
|
const octokit = github.getOctokit(repoToken)
|
||||||
|
|
||||||
let issueNumber
|
let issueNumber
|
||||||
|
|
||||||
|
|
@ -160,8 +135,12 @@ const run = async (): Promise<void> => {
|
||||||
issueNumber = pullRequest.number
|
issueNumber = pullRequest.number
|
||||||
} else {
|
} else {
|
||||||
// If this is not a pull request, attempt to find a PR matching the sha
|
// If this is not a pull request, attempt to find a PR matching the sha
|
||||||
const commitPullsList = await listCommitPulls({ repoToken, owner, repo, commitSha })
|
const commitPullsList = await octokit.rest.repos.listPullRequestsAssociatedWithCommit({
|
||||||
issueNumber = commitPullsList && getIssueNumberFromCommitPullsList(commitPullsList)
|
owner,
|
||||||
|
repo,
|
||||||
|
commit_sha: commitSha,
|
||||||
|
})
|
||||||
|
issueNumber = commitPullsList.data && getIssueNumberFromCommitPullsList(commitPullsList.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!issueNumber) {
|
if (!issueNumber) {
|
||||||
|
|
@ -172,8 +151,6 @@ const run = async (): Promise<void> => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const octokit = github.getOctokit(repoToken)
|
|
||||||
|
|
||||||
let shouldCreateComment = true
|
let shouldCreateComment = true
|
||||||
|
|
||||||
if (!allowRepeats) {
|
if (!allowRepeats) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue