Commit 5003de7b authored by Balázs Orbán's avatar Balázs Orbán

chore: fix issue verifier issues

parent cd02e5cf
This diff is collapsed.
// @ts-check // @ts-check
// @ts-expect-error
import * as github from '@actions/github' import * as github from '@actions/github'
// @ts-expect-error
import * as core from '@actions/core' import * as core from '@actions/core'
import { readFileSync } from 'node:fs' import { readFileSync } from 'node:fs'
import { join } from 'node:path' import { join } from 'node:path'
const verifyCanaryLabel = 'please verify canary' const verifyCanaryLabel = 'please verify canary'
const addReproductionLabel = 'please add a complete reproduction' const addReproductionLabel = 'please add a complete reproduction'
const bugLabel = 'template: bug'
const __dirname = const __dirname =
'/home/runner/work/next.js/next.js/.github/actions/issue-validator' '/home/runner/work/next.js/next.js/.github/actions/issue-validator'
...@@ -19,20 +22,42 @@ const __dirname = ...@@ -19,20 +22,42 @@ const __dirname =
* color :string * color :string
* default :boolean * default :boolean
* }} Label * }} Label
*
* @typedef {{
* labels: Label[]
* pull_request: any
* issue?: {body: string, number: number}
* label: Label
* }} Payload
*
* @typedef {{
* payload: Payload
* repo: any
* }} Context
*/ */
async function run() { async function run() {
try { try {
/** @type {Context} */
const { payload, repo } = github.context const { payload, repo } = github.context
const { issue, pull_request } = payload const {
issue,
pull_request,
label: { name: newLabel },
} = payload
if (pull_request || !issue?.body || !process.env.GITHUB_TOKEN) return if (pull_request || !issue?.body || !process.env.GITHUB_TOKEN) return
/** @type {Label} */ const labels = payload.labels.map((l) => l.name)
const newLabel = payload.label const isBugReport =
const { body, number: issueNumber } = issue labels.includes(bugLabel) || newLabel === bugLabel || !labels.length
const client = github.getOctokit(process.env.GITHUB_TOKEN).rest
const issueCommon = { ...repo, issue_number: issueNumber } if (
!(isBugReport && issue.number > 43554) &&
![verifyCanaryLabel, addReproductionLabel].includes(newLabel)
) {
return core.info('Not a bug report or not manually labeled')
}
/** @param {string|null|undefined} link */ /** @param {string|null|undefined} link */
async function hasRepro(link) { async function hasRepro(link) {
...@@ -49,29 +74,50 @@ async function run() { ...@@ -49,29 +74,50 @@ async function run() {
return response.ok return response.ok
} }
const hasValidRepro = await hasRepro( const hasValidRepro =
body.match(/will be addressed faster\n\n(.*)\n\n### To Reproduce/i)?.[1] isBugReport &&
) (await hasRepro(
issue.body.match(
/will be addressed faster\n\n(.*)\n\n### To Reproduce/i
)?.[1]
))
const client = github.getOctokit(process.env.GITHUB_TOKEN).rest
const issueCommon = { ...repo, issue_number: issue.number }
if (!hasValidRepro || newLabel.name === addReproductionLabel) { if (newLabel === addReproductionLabel || !hasValidRepro) {
await client.issues.createComment({ await Promise.all([
...issueCommon, client.issues.addLabels({
body: readFileSync(join(__dirname, 'repro.md'), 'utf8'), ...issueCommon,
}) labels: [addReproductionLabel],
}),
client.issues.createComment({
...issueCommon,
body: readFileSync(join(__dirname, 'repro.md'), 'utf8'),
}),
])
return core.info( return core.info(
'Commented on issue, because it did not have a sufficient reproduction.' 'Commented on issue, because it did not have a sufficient reproduction.'
) )
} }
const isVerifyCanaryChecked = body.match( const isVerifyCanaryChecked =
/- \[x\] I verified that the issue exists in the latest Next.js canary release/i isBugReport &&
) issue.body.match(
/- \[x\] I verified that the issue exists in the latest Next.js canary release/i
)
if (!isVerifyCanaryChecked || newLabel.name === verifyCanaryLabel) { if (newLabel === verifyCanaryLabel || !isVerifyCanaryChecked) {
await client.issues.createComment({ await Promise.all([
...issueCommon, client.issues.addLabels({
body: readFileSync(join(__dirname, 'canary.md'), 'utf8'), ...issueCommon,
}) labels: [verifyCanaryLabel],
}),
client.issues.createComment({
...issueCommon,
body: readFileSync(join(__dirname, 'canary.md'), 'utf8'),
}),
])
return core.info( return core.info(
'Commented on issue, because it was not verified against canary.' 'Commented on issue, because it was not verified against canary.'
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment