Commit 2da0ca21 authored by Balázs Orbán's avatar Balázs Orbán

chore: tweak issue validator action

parent e685214c
......@@ -8700,20 +8700,23 @@
const r = 'template: bug'
const s = 'please add a complete reproduction'
const i = !!process.env.DEBUG
const json = (e) => JSON.stringify(e, null, 2)
async function run() {
try {
const {
payload: { issue: p, pull_request: d },
repo: o,
} = e.context
if (d || !p?.body) return
const { body: n, labels: l, number: m } = p
const { payload: p, repo: d } = e.context
const { issue: o, pull_request: n } = p
if (n || !o?.body) return
const l = p.label
const { body: m, number: u } = o
const c = o.labels
a.info(
`Validating issue ${m}:\n Label(s): ${l.join(', ')}\n Body: ${n}`
`Validating issue ${u}:\n Labels:\n New: ${json(
l
)}\n All: ${json(c)}\n Body: ${m}`
)
const u = l.some((e) => e.name === r)
const c = l.some((e) => e.name === t)
if (!u || !c) {
const v = l.name === r
const h = c.some((e) => e.name === t)
if (!v && !h) {
return a.info(
'Issue is ignored, because it is not a bug report or is not manually labeled'
)
......@@ -8721,68 +8724,68 @@
if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN is not set')
}
const v = e.getOctokit(process.env.GITHUB_TOKEN).rest
const g = e.getOctokit(process.env.GITHUB_TOKEN).rest
function notifyOnIssue(e, p) {
const d = { ...o, issue_number: m }
const t = { ...d, issue_number: u }
if (i) {
a.info('Skipping comment/label because we are in DEBUG mode')
a.info(JSON.stringify({ label: e, comment: p }, null, 2))
a.info(json({ label: e, comment: p }))
return
}
return Promise.all([
v.issues.addLabels({ ...d, labels: [e] }),
v.issues.createComment({ ...d, body: p }),
g.issues.addLabels({ ...t, labels: [e] }),
g.issues.createComment({ ...t, body: p }),
])
}
const h = n.includes(
const w = m.includes(
'- [X] I verified that the issue exists in Next.js canary release'
)
if (!h || c) {
if (!w || h) {
await notifyOnIssue(
t,
'Please verify your issue reproduces with `next@canary`. The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. Think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running `npm install next@canary`. If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.'
)
return a.info(
`Commented on issue, because it was ${
c ? 'manually labeled' : 'not verified against canary'
h ? 'manually labeled' : 'not verified against canary'
}`
)
}
const g = n
const _ = m
.match(/### Link to reproduction\n\n(?<url>.*)\n/)
?.groups?.url.trim()
if (!g || !(await fetch(g)).ok) {
if (!_ || !(await fetch(_)).ok) {
await notifyOnIssue(
s,
'The link to the reproduction appears to be incorrect/unreachable. Please add a link to the reproduction of the issue. This is a required field. If your project is private, you can invite @balazsorban44 to the repository so the Next.js team can investigate further.'
)
return a.info(
`Commented on issue, because the reproduction url (${g}) was not reachable`
`Commented on issue, because the reproduction url (${_}) was not reachable`
)
}
const w = [
const T = [
'Operating System:',
'Binaries:',
'Relevant packages:',
].every((e) => n.includes(e))
if (!w) {
].every((e) => m.includes(e))
if (!T) {
return a.info(
'Could not detect `next info` output, skipping as version detection might be unreliable'
)
}
const _ = n.match(
const E = m.match(
/Relevant packages:\n next: (?<version>\d+\.\d+\.\d+)/
)?.groups?.version
a.info(`Reported Next.js version: ${_}`)
if (!_) {
a.info(`Reported Next.js version: ${E}`)
if (!E) {
return
}
const { tag_name: T } = await (await v.repos.listReleases(o)).data[0]
a.info(`Last Next.js version, based on GitHub releases: ${T}`)
if (T.includes('canary') && _ !== T) {
const { tag_name: b } = await (await g.repos.listReleases(d)).data[0]
a.info(`Last Next.js version, based on GitHub releases: ${b}`)
if (b.includes('canary') && E !== b) {
await notifyOnIssue(
t,
`The reported Next.js version did not match the latest \`next@canary\` version (${T}). The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. Think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running \`npm install next@canary\`. If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.`
`The reported Next.js version did not match the latest \`next@canary\` version (${b}). The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. Think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running \`npm install next@canary\`. If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.`
)
return a.info(
`Commented on issue, because it was not verified against canary`
......
......@@ -6,31 +6,48 @@ const verifyCanaryLabel = 'please verify canary'
const bugReportLabel = 'template: bug'
const addReproductionLabel = 'please add a complete reproduction'
const debug = !!process.env.DEBUG
const json = (o) => JSON.stringify(o, null, 2)
/**
* @typedef {{
* id :number
* node_id :string
* url :string
* name :string
* description :string
* color :string
* default :boolean
* }} Label
*/
async function run() {
try {
const {
payload: { issue, pull_request },
repo,
} = github.context
const { payload, repo } = github.context
const { issue, pull_request } = payload
if (pull_request || !issue?.body) return
const { body, labels, number: issueNumber } = issue
/** @type {Label} */
const newLabel = payload.label
const { body, number: issueNumber } = issue
/** @type {Label[]} */
const labels = issue.labels
core.info(
`Validating issue ${issueNumber}:
Label(s): ${labels.join(', ')}
Labels:
New: ${json(newLabel)}
All: ${json(labels)}
Body: ${body}`
)
const isBugReport = labels.some((label) => label.name === bugReportLabel)
const isBugReport = newLabel.name === bugReportLabel
const isManuallyLabeled = labels.some(
(label) => label.name === verifyCanaryLabel
)
if (!isBugReport || !isManuallyLabeled) {
if (!isBugReport && !isManuallyLabeled) {
return core.info(
'Issue is ignored, because it is not a bug report or is not manually labeled'
)
......@@ -51,7 +68,7 @@ async function run() {
if (debug) {
core.info('Skipping comment/label because we are in DEBUG mode')
core.info(JSON.stringify({ label, comment }, null, 2))
core.info(json({ label, comment }))
return
}
......
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