Unverified Commit 0ac8ad07 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

chore: tweak issue validator (#38600)

- Do not comment/label if `next info` wasn't used, as we might not be able to detect the versions reliably.
- Ignore all issues that do not have the `template: bug` label or weren't labeled manually. (This might slip through a few issues that did not follow our template like [Reference in new issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue#creating-an-issue-from-a-comment) but that's minimal overhead already)
- Added note when the reproduction URL is unreachable to invite me to the private repository.
- Turned on DEBUG mode (no comments/labels, only logs) for now, so we can verify the behavior and find issues.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 5841aac8
...@@ -8699,57 +8699,90 @@ ...@@ -8699,57 +8699,90 @@
const t = 'please verify canary' const t = 'please verify canary'
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
async function run() { async function run() {
try { try {
const { const {
payload: { issue: p, pull_request: d }, payload: { issue: p, pull_request: d },
repo: i, repo: o,
} = e.context } = e.context
if (d || !p?.body) return if (d || !p?.body) return
const { body: o, labels: n, number: l } = p const { body: n, labels: l, number: m } = p
const m = n.some((e) => e.name === t) const u = l.some((e) => e.name === r)
const u = n.some((e) => e.name === r) const c = l.some((e) => e.name === t)
if (!u || !c) {
return a.info(
`issue ${m} is ignored, because it is not a bug report or is not manually labeled`
)
}
if (!process.env.GITHUB_TOKEN) { if (!process.env.GITHUB_TOKEN) {
return a.setFailed('GITHUB_TOKEN is not set') throw new Error('GITHUB_TOKEN is not set')
} }
const c = e.getOctokit(process.env.GITHUB_TOKEN).rest const v = e.getOctokit(process.env.GITHUB_TOKEN).rest
function notifyOnIssue(e, p) { function notifyOnIssue(e, p) {
const a = { ...i, issue_number: l } const d = { ...o, issue_number: m }
if (i) {
a.info('Skipping comment/label because we are in DEBUG mode')
a.info(JSON.stringify({ label: e, comment: p }, null, 2))
return
}
return Promise.all([ return Promise.all([
c.issues.addLabels({ ...a, labels: [e] }), v.issues.addLabels({ ...d, labels: [e] }),
c.issues.createComment({ ...a, body: p }), v.issues.createComment({ ...d, body: p }),
]) ])
} }
const v = o.includes( const h = n.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 (!v || m) { if (!h || c) {
return 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(
`Commented on issue ${m}, because it was ${
c ? 'manually labeled' : 'not verified against canary'
}`
)
} }
if (!u) return const g = n
const h = o
.match(/### Link to reproduction\n\n(?<url>.*)\n/) .match(/### Link to reproduction\n\n(?<url>.*)\n/)
?.groups?.url.trim() ?.groups?.url.trim()
if (!h || !(await (await fetch(h)).ok)) { if (!g || !(await fetch(g)).ok) {
return 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.' '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 ${m}, because it the reproduction url (${g}) was not reachable.`
)
}
const w = [
'Operating System:',
'Binaries:',
'Relevant packages:',
].every((e) => n.includes(e))
if (!w) {
return a.info(
'Could not detect `next info` output, skipping as version detection might be unreliable'
) )
} }
const g = o.match( const _ = n.match(
/Relevant packages:\n next: (?<version>\d+\.\d+\.\d+)/ /Relevant packages:\n next: (?<version>\d+\.\d+\.\d+)/
)?.groups?.version )?.groups?.version
if (!g) { a.info(`Reported Next.js version: ${_}`)
if (!_) {
return return
} }
const { tag_name: w } = await (await c.repos.listReleases(i)).data[0] const { tag_name: T } = await (await v.repos.listReleases(o)).data[0]
if (w.includes('canary') && g !== w) { a.info(`Last Next.js version, based on GitHub releases: ${T}`)
return await notifyOnIssue( if (T.includes('canary') && _ !== T) {
await notifyOnIssue(
t, t,
`The reported Next.js version did not match the latest \`next@canary\` version (${w}). 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 (${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.`
)
return a.info(
`Commented on issue ${m}, because it was not verified against canary.`
) )
} }
} catch (e) { } catch (e) {
......
...@@ -5,6 +5,7 @@ import * as core from '@actions/core' ...@@ -5,6 +5,7 @@ import * as core from '@actions/core'
const verifyCanaryLabel = 'please verify canary' 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
async function run() { async function run() {
try { try {
...@@ -17,17 +18,22 @@ async function run() { ...@@ -17,17 +18,22 @@ async function run() {
const { body, labels, number: issueNumber } = issue const { body, labels, number: issueNumber } = issue
const isBugReport = labels.some((label) => label.name === bugReportLabel)
const isManuallyLabeled = labels.some( const isManuallyLabeled = labels.some(
(label) => label.name === verifyCanaryLabel (label) => label.name === verifyCanaryLabel
) )
const isBugReport = labels.some((label) => label.name === bugReportLabel) if (!isBugReport || !isManuallyLabeled) {
return core.info(
`issue ${issueNumber} is ignored, because it is not a bug report or is not manually labeled`
)
}
if (!process.env.GITHUB_TOKEN) { if (!process.env.GITHUB_TOKEN) {
return core.setFailed('GITHUB_TOKEN is not set') throw new Error('GITHUB_TOKEN is not set')
} }
// @ts-ignore
const client = github.getOctokit(process.env.GITHUB_TOKEN).rest const client = github.getOctokit(process.env.GITHUB_TOKEN).rest
/** /**
...@@ -37,6 +43,12 @@ async function run() { ...@@ -37,6 +43,12 @@ async function run() {
function notifyOnIssue(label, comment) { function notifyOnIssue(label, comment) {
const issueCommon = { ...repo, issue_number: issueNumber } const issueCommon = { ...repo, issue_number: issueNumber }
if (debug) {
core.info('Skipping comment/label because we are in DEBUG mode')
core.info(JSON.stringify({ label, comment }, null, 2))
return
}
return Promise.all([ return Promise.all([
client.issues.addLabels({ ...issueCommon, labels: [label] }), client.issues.addLabels({ ...issueCommon, labels: [label] }),
client.issues.createComment({ ...issueCommon, body: comment }), client.issues.createComment({ ...issueCommon, body: comment }),
...@@ -47,26 +59,41 @@ async function run() { ...@@ -47,26 +59,41 @@ async function run() {
'- [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 ( if (!isVerifyCanaryChecked || isManuallyLabeled) {
!isVerifyCanaryChecked || // This can happen if the issue was from a comment in another issue or discussion. await notifyOnIssue(
isManuallyLabeled
) {
return await notifyOnIssue(
verifyCanaryLabel, verifyCanaryLabel,
'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 core.info(
`Commented on issue ${issueNumber}, because it was ${
isManuallyLabeled ? 'manually labeled' : 'not verified against canary'
}`
)
} }
if (!isBugReport) return
const reproductionUrl = body const reproductionUrl = body
.match(/### Link to reproduction\n\n(?<url>.*)\n/) .match(/### Link to reproduction\n\n(?<url>.*)\n/)
?.groups?.url.trim() ?.groups?.url.trim()
if (!reproductionUrl || !(await (await fetch(reproductionUrl)).ok)) { if (!reproductionUrl || !(await fetch(reproductionUrl)).ok) {
return await notifyOnIssue( await notifyOnIssue(
addReproductionLabel, addReproductionLabel,
'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.' '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 core.info(
`Commented on issue ${issueNumber}, because it the reproduction url (${reproductionUrl}) was not reachable.`
)
}
const containsNextInfoOutput = [
'Operating System:',
'Binaries:',
'Relevant packages:',
].every((i) => body.includes(i))
if (!containsNextInfoOutput) {
return core.info(
'Could not detect `next info` output, skipping as version detection might be unreliable'
) )
} }
...@@ -74,6 +101,8 @@ async function run() { ...@@ -74,6 +101,8 @@ async function run() {
/Relevant packages:\n next: (?<version>\d+\.\d+\.\d+)/ /Relevant packages:\n next: (?<version>\d+\.\d+\.\d+)/
)?.groups?.version )?.groups?.version
core.info(`Reported Next.js version: ${reportedNextVersion}`)
if (!reportedNextVersion) { if (!reportedNextVersion) {
// REVIEW: Should we add a label here? // REVIEW: Should we add a label here?
return return
...@@ -83,11 +112,16 @@ async function run() { ...@@ -83,11 +112,16 @@ async function run() {
await client.repos.listReleases(repo) await client.repos.listReleases(repo)
).data[0] ).data[0]
core.info(`Last Next.js version, based on GitHub releases: ${lastVersion}`)
if (lastVersion.includes('canary') && reportedNextVersion !== lastVersion) { if (lastVersion.includes('canary') && reportedNextVersion !== lastVersion) {
return await notifyOnIssue( await notifyOnIssue(
verifyCanaryLabel, verifyCanaryLabel,
`The reported Next.js version did not match the latest \`next@canary\` version (${lastVersion}). 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 (${lastVersion}). 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 core.info(
`Commented on issue ${issueNumber}, because it was not verified against canary.`
)
} }
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
......
...@@ -11,3 +11,4 @@ jobs: ...@@ -11,3 +11,4 @@ jobs:
- uses: ./.github/actions/issue-validator - uses: ./.github/actions/issue-validator
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEBUG: 1
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