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 @@ ...@@ -8700,20 +8700,23 @@
const r = 'template: bug' const r = 'template: bug'
const s = 'please add a complete reproduction' const s = 'please add a complete reproduction'
const i = !!process.env.DEBUG const i = !!process.env.DEBUG
const json = (e) => JSON.stringify(e, null, 2)
async function run() { async function run() {
try { try {
const { const { payload: p, repo: d } = e.context
payload: { issue: p, pull_request: d }, const { issue: o, pull_request: n } = p
repo: o, if (n || !o?.body) return
} = e.context const l = p.label
if (d || !p?.body) return const { body: m, number: u } = o
const { body: n, labels: l, number: m } = p const c = o.labels
a.info( 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 v = l.name === r
const c = l.some((e) => e.name === t) const h = c.some((e) => e.name === t)
if (!u || !c) { if (!v && !h) {
return a.info( return a.info(
'Issue is ignored, because it is not a bug report or is not manually labeled' 'Issue is ignored, because it is not a bug report or is not manually labeled'
) )
...@@ -8721,68 +8724,68 @@ ...@@ -8721,68 +8724,68 @@
if (!process.env.GITHUB_TOKEN) { if (!process.env.GITHUB_TOKEN) {
throw new Error('GITHUB_TOKEN is not set') 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) { function notifyOnIssue(e, p) {
const d = { ...o, issue_number: m } const t = { ...d, issue_number: u }
if (i) { if (i) {
a.info('Skipping comment/label because we are in DEBUG mode') 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
} }
return Promise.all([ return Promise.all([
v.issues.addLabels({ ...d, labels: [e] }), g.issues.addLabels({ ...t, labels: [e] }),
v.issues.createComment({ ...d, body: p }), 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' '- [X] I verified that the issue exists in Next.js canary release'
) )
if (!h || c) { if (!w || h) {
await notifyOnIssue( await notifyOnIssue(
t, 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.' '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( return a.info(
`Commented on issue, because it was ${ `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/) .match(/### Link to reproduction\n\n(?<url>.*)\n/)
?.groups?.url.trim() ?.groups?.url.trim()
if (!g || !(await fetch(g)).ok) { if (!_ || !(await fetch(_)).ok) {
await notifyOnIssue( await notifyOnIssue(
s, 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.' '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( 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:', 'Operating System:',
'Binaries:', 'Binaries:',
'Relevant packages:', 'Relevant packages:',
].every((e) => n.includes(e)) ].every((e) => m.includes(e))
if (!w) { if (!T) {
return a.info( return a.info(
'Could not detect `next info` output, skipping as version detection might be unreliable' '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+)/ /Relevant packages:\n next: (?<version>\d+\.\d+\.\d+)/
)?.groups?.version )?.groups?.version
a.info(`Reported Next.js version: ${_}`) a.info(`Reported Next.js version: ${E}`)
if (!_) { if (!E) {
return return
} }
const { tag_name: T } = await (await v.repos.listReleases(o)).data[0] const { tag_name: b } = await (await g.repos.listReleases(d)).data[0]
a.info(`Last Next.js version, based on GitHub releases: ${T}`) a.info(`Last Next.js version, based on GitHub releases: ${b}`)
if (T.includes('canary') && _ !== T) { if (b.includes('canary') && E !== b) {
await notifyOnIssue( await notifyOnIssue(
t, 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( return a.info(
`Commented on issue, because it was not verified against canary` `Commented on issue, because it was not verified against canary`
......
...@@ -6,31 +6,48 @@ const verifyCanaryLabel = 'please verify canary' ...@@ -6,31 +6,48 @@ const verifyCanaryLabel = 'please verify canary'
const bugReportLabel = 'template: bug' const bugReportLabel = 'template: bug'
const addReproductionLabel = 'please add a complete reproduction' const addReproductionLabel = 'please add a complete reproduction'
const debug = !!process.env.DEBUG 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() { async function run() {
try { try {
const { const { payload, repo } = github.context
payload: { issue, pull_request }, const { issue, pull_request } = payload
repo,
} = github.context
if (pull_request || !issue?.body) return 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( core.info(
`Validating issue ${issueNumber}: `Validating issue ${issueNumber}:
Label(s): ${labels.join(', ')} Labels:
New: ${json(newLabel)}
All: ${json(labels)}
Body: ${body}` Body: ${body}`
) )
const isBugReport = labels.some((label) => label.name === bugReportLabel) const isBugReport = newLabel.name === bugReportLabel
const isManuallyLabeled = labels.some( const isManuallyLabeled = labels.some(
(label) => label.name === verifyCanaryLabel (label) => label.name === verifyCanaryLabel
) )
if (!isBugReport || !isManuallyLabeled) { if (!isBugReport && !isManuallyLabeled) {
return core.info( return core.info(
'Issue is ignored, because it is not a bug report or is not manually labeled' 'Issue is ignored, because it is not a bug report or is not manually labeled'
) )
...@@ -51,7 +68,7 @@ async function run() { ...@@ -51,7 +68,7 @@ async function run() {
if (debug) { if (debug) {
core.info('Skipping comment/label because we are in DEBUG mode') 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 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