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

chore: verify missing/invalid/private reproduction links (#54724)

### What?

This PR adds a new action that verifies if the reproduction link is correct _after_ the issue has been created. If it is not, we close the issue and comment on it with the correct steps to take. Check out the [rendered comment here](https://github.com/balazsorban44/next.js/blob/chore/gh-invalid-link-checker/.github/actions/issue-validator/repro-link/invalid-link.md).

Additionally, this PR also does some refactoring to simplify our GitHub actions related to issues.

Tests:

Issue that was supposed to be closed:
 - https://github.com/balazsorban44/next.js/issues/48
   - Issue comment: https://github.com/balazsorban44/next.js/issues/48#issuecomment-1698836121 
   - Issue opened action: https://github.com/balazsorban44/next.js/actions/runs/6023209630
   - Issue labeled action: https://github.com/balazsorban44/next.js/actions/runs/6023209629

Issue that was not supposed to be closed (closed manually afterward):
 - https://github.com/balazsorban44/next.js/issues/49
   - Issue opened action: https://github.com/balazsorban44/next.js/actions/runs/6023214256
   - Issue labeled action: https://github.com/balazsorban44/next.js/actions/runs/6023214258


### Why?

Unfortunately, GitHub is currently missing the [functionality to require a valid reproduction link](https://github.com/orgs/community/discussions/10227) in issue templates. Even if that was supported, this PR adds functionality that could not be covered with a regex validation. Namely, we check if the reproduction is a private repo or not, and potentially could also check the structure to see if it's an actual Next.js project.

### How?

If the link is not in the expected section, not a GitHub, CodeSandbox, or Replay.io link, or does not return an OK response (eg.: private repo/sandbox), the issue is closed/commented.

Related:
- https://github.com/orgs/community/discussions/4629
- https://github.com/orgs/community/discussions/10227Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
parent 962ce0dc
...@@ -20,7 +20,7 @@ packages/react-refresh-utils/**/*.js ...@@ -20,7 +20,7 @@ packages/react-refresh-utils/**/*.js
packages/react-dev-overlay/lib/** packages/react-dev-overlay/lib/**
**/__tmp__/** **/__tmp__/**
.github/actions/next-stats-action/.work .github/actions/next-stats-action/.work
.github/actions/issue-labeler/lib/index.js .github/actions/issue-validator/*/index.mjs
.github/actions/validate-docs-links/lib/index.js .github/actions/validate-docs-links/lib/index.js
.github/actions/needs-triage/index.js .github/actions/needs-triage/index.js
.github/actions/*/index.mjs .github/actions/*/index.mjs
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"private": true,
"name": "issue-labeler",
"type": "module",
"exports": "./lib/index.js",
"scripts": {
"build": "pnpm types && ncc -m -o ./lib build src/index.ts --license licenses.txt",
"types": "tsc"
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1"
},
"devDependencies": {
"@types/node": "^18.15.3",
"@vercel/ncc": "0.36.1",
"typescript": "5.1.6"
}
}
{
"compilerOptions": {
"noEmit": true,
"target": "esnext",
"moduleResolution": "node",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Please verify that your issue can be recreated with `next@canary`. Please verify that your issue can be recreated with `next@canary`.
### **Why was this issue marked with the `please verify canary` label?** ### Why was this issue marked with the `please verify canary` label?
We noticed the provided reproduction was using an older version of Next.js, instead of `canary`. We noticed the provided reproduction was using an older version of Next.js, instead of `canary`.
...@@ -8,25 +8,25 @@ The canary version of Next.js ships daily and includes all features and fixes th ...@@ -8,25 +8,25 @@ The canary version of Next.js ships daily and includes all features and fixes th
If the issue does not reproduce with the `canary` version, then it has already been fixed and this issue can be closed. If the issue does not reproduce with the `canary` version, then it has already been fixed and this issue can be closed.
### **How can I quickly verify if my issue has been fixed in `canary`?** ### How can I quickly verify if my issue has been fixed in `canary`?
The safest way is to install `next@canary` in your project and test it, but you can also search through [closed Next.js issues](https://github.com/vercel/next.js/issues?q=is%3Aissue+is%3Aclosed) for duplicates or check the [Next.js releases](https://github.com/vercel/next.js/releases). You can also use the GitHub templates (preferred) for [App Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) and [Pages Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages), or the [CodeSandbox: App Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template) or [CodeSandbox: Pages Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template-pages) templates to create a reproduction with `canary` from scratch. The safest way is to install `next@canary` in your project and test it, but you can also search through [closed Next.js issues](https://github.com/vercel/next.js/issues?q=is%3Aissue+is%3Aclosed) for duplicates or check the [Next.js releases](https://github.com/vercel/next.js/releases). You can also use the GitHub templates (preferred) for [App Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template) and [Pages Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages), or the [CodeSandbox: App Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template) or [CodeSandbox: Pages Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template-pages) templates to create a reproduction with `canary` from scratch.
### **My issue has been open for a long time, why do I need to verify `canary` now?** ### My issue has been open for a long time, why do I need to verify `canary` now?
Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases. Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases.
### **What happens if I don't verify against the canary version of Next.js?** ### What happens if I don't verify against the canary version of Next.js?
An issue with the `please verify canary` that receives no meaningful activity (e.g. new comments that acknowledge verification against `canary`) will be automatically closed and locked after 30 days. An issue with the `please verify canary` that receives no meaningful activity (e.g. new comments that acknowledge verification against `canary`) will be automatically closed and locked after 30 days.
If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using `next@canary`. If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using `next@canary`.
### **I did not open this issue, but it is relevant to me, what can I do to help?** ### I did not open this issue, but it is relevant to me, what can I do to help?
Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the :+1: reaction on the topmost comment (please **do not** comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize. Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the :+1: reaction on the topmost comment (please **do not** comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.
### **I think my reproduction is good enough, why aren't you looking into it quicker?** ### I think my reproduction is good enough, why aren't you looking into it quicker?
We look into every Next.js issue and constantly monitor open issues for new comments. We look into every Next.js issue and constantly monitor open issues for new comments.
...@@ -34,7 +34,7 @@ However, sometimes we might miss one or two due to the popularity/high traffic o ...@@ -34,7 +34,7 @@ However, sometimes we might miss one or two due to the popularity/high traffic o
Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it. Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.
### **Useful Resources** ### Useful Resources
- [How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc) - [How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc)
- [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) - [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
......
...@@ -478,6 +478,30 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ...@@ -478,6 +478,30 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
nextjs-project
The MIT License (MIT)
Copyright (c) 2023 Vercel, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
node-fetch node-fetch
MIT MIT
The MIT License (MIT) The MIT License (MIT)
......
We cannot recreate the issue with the provided information. **Please add a reproduction in order for us to be able to investigate.** We cannot recreate the issue with the provided information. **Please add a reproduction in order for us to be able to investigate.**
### **Why was this issue marked with the `please add a complete reproduction` label?** ### Why was this issue marked with the `please add a complete reproduction` label?
To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository ([template for App Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template), [template for Pages Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages)), but you can also use these templates: [CodeSandbox: App Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template) or [CodeSandbox: Pages Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template-pages). To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository ([template for App Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template), [template for Pages Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages)), but you can also use these templates: [CodeSandbox: App Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template) or [CodeSandbox: Pages Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template-pages).
...@@ -10,21 +10,21 @@ Please test your reproduction against the latest version of Next.js (`next@canar ...@@ -10,21 +10,21 @@ Please test your reproduction against the latest version of Next.js (`next@canar
If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the `canary` version of `next` that introduced the issue. Check out our [releases](https://github.com/vercel/next.js/releases), and try to find the first `canary` release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of `next` by running `npm install next@<version>`. If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the `canary` version of `next` that introduced the issue. Check out our [releases](https://github.com/vercel/next.js/releases), and try to find the first `canary` release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of `next` by running `npm install next@<version>`.
### **I added a link, why was it still marked?** ### I added a link, why was it still marked?
Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "[example.com](http://example.com/)", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links. Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "[example.com](http://example.com/)", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.
### **What happens if I don't provide a sufficient minimal reproduction?** ### What happens if I don't provide a sufficient minimal reproduction?
Issues with the `please add a complete reproduction` label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days. Issues with the `please add a complete reproduction` label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.
If your issue has _not_ been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction. If your issue has _not_ been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.
### **I did not open this issue, but it is relevant to me, what can I do to help?** ### I did not open this issue, but it is relevant to me, what can I do to help?
Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the :+1: reaction on the topmost comment (please **do not** comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize. Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the :+1: reaction on the topmost comment (please **do not** comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.
### **I think my reproduction is good enough, why aren't you looking into it quicker?** ### I think my reproduction is good enough, why aren't you looking into it quicker?
We look into every Next.js issue and constantly monitor open issues for new comments. We look into every Next.js issue and constantly monitor open issues for new comments.
...@@ -32,7 +32,7 @@ However, sometimes we might miss one or two due to the popularity/high traffic o ...@@ -32,7 +32,7 @@ However, sometimes we might miss one or two due to the popularity/high traffic o
Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it. Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.
### **Useful Resources** ### Useful Resources
- [How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc) - [How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc)
- [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) - [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
......
...@@ -15,7 +15,7 @@ An ideal minimal reproduction (_unless relevant_): ...@@ -15,7 +15,7 @@ An ideal minimal reproduction (_unless relevant_):
- only includes the code necessary to reproduce the issue - only includes the code necessary to reproduce the issue
- is tested against `next@canary` to make sure your issue has not already been fixed - is tested against `next@canary` to make sure your issue has not already been fixed
Generally, the person looking into the reproduction should not require to have prior knowledge of your codebase to be able to help. **In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.**
If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the `canary` version of `next` that introduced the issue. Check out our [releases](https://github.com/vercel/next.js/releases), and try to find the first `canary` release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of `next` by running `npm install next@<version>`. If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the `canary` version of `next` that introduced the issue. Check out our [releases](https://github.com/vercel/next.js/releases), and try to find the first `canary` release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of `next` by running `npm install next@<version>`.
......
{ {
"private": true, "private": true,
"exports": "./index.mjs", "description": "A set of scripts to help with Next.js issue management",
"scripts": { "scripts": {
"build": "ncc -m -o . build src/index.mjs --license licenses.txt" "build:autolabel": "ncc -m --license licenses.txt build src/autolabel.mjs -o autolabel",
"build:clarify": "ncc -m --license licenses.txt build src/clarify.mjs -o clarify",
"build:repro-link": "ncc -m --license licenses.txt build src/repro-link.mjs -o repro-link",
"build": "pnpm build:autolabel && pnpm build:clarify && pnpm build:repro-link"
}, },
"devDependencies": { "devDependencies": {
"@vercel/ncc": "0.34.0", "@vercel/ncc": "0.34.0",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
We could not detect a valid reproduction link. **Make sure to follow the bug report template carefully.**
### Why was this issue closed?
To be able to investigate, we need access to a reproduction to identify what triggered the issue. We need a link to a **public** GitHub repository ([template for App Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template), [template for Pages Router](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template-pages)), but you can also use these templates: [CodeSandbox: App Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template) or [CodeSandbox: Pages Router](https://codesandbox.io/s/github/vercel/next.js/tree/canary/examples/reproduction-template-pages).
The bug template that you filled out has a section called "Link to the code that reproduces this issue or a replay of the bug", which is where you should provide the link to the reproduction.
- If you did not provide a link or the link you provided is not valid, we will close the issue.
- If you provide a link to a private repository, we will close the issue.
- If you provide a link to a repository but not in the correct section, we will close the issue.
### What should I do?
Depending on the reason the issue was closed, you can do the following:
- If you did not provide a link, please open a new issue with a link to a reproduction.
- If you provided a link to a private repository, please open a new issue with a link to a public repository.
- If you provided a link to a repository but not in the correct section, please open a new issue with a link to a reproduction in the correct section.
**In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.**
### My repository is private and cannot make it public
In most cases, a private repo will not be a sufficient **minimal reproduction**, as this codebase might contain a lot of unrelated parts that would make our investigation take longer. Please do **not** make it public. Instead, create a new repository using the templates above, adding the relevant code to reproduce the issue. Common things to look out for:
- Remove any code that is not related to the issue. (pages, API routes, components, etc.)
- Remove any dependencies that are not related to the issue.
- Remove any third-party service that would require us to sign up for an account to reproduce the issue.
- Remove any environment variables that are not related to the issue.
- Remove private packages that we do not have access to.
- If the issue is not related to a monorepo specifically, try to reproduce the issue without a complex monorepo setup
### I did not open this issue, but it is relevant to me, what can I do to help?
Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps by opening a new issue.
### I think my reproduction is good enough, why aren't you looking into it quickly?
We look into every Next.js issue and constantly monitor open issues for new comments.
However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.
Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.
### Useful Resources
- [How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc)
- [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
- [Reporting a Next.js bug](https://github.com/vercel/next.js/blob/canary/.github/ISSUE_TEMPLATE/1.bug_report.yml)
- [Next.js Triaging issues](https://github.com/vercel/next.js/blob/canary/contributing/repository/triaging.md)
This diff is collapsed.
/**
* This action will automatically add labels to issues based on the area(s) of Next.js that are affected.
*/
// @ts-check
import { setFailed, debug } from '@actions/core' import { setFailed, debug } from '@actions/core'
import { context, getOctokit } from '@actions/github' import { context, getOctokit } from '@actions/github'
type GitHubClient = ReturnType<typeof getOctokit>['rest'] /** @typedef {ReturnType<typeof getOctokit>['rest']} GitHubClient */
async function run() { async function run() {
const token = process.env.GITHUB_TOKEN const token = process.env.GITHUB_TOKEN
...@@ -23,8 +28,11 @@ async function run() { ...@@ -23,8 +28,11 @@ async function run() {
debug(`Loaded labels: ${Array.from(labels.keys()).join(', ')}`) debug(`Loaded labels: ${Array.from(labels.keys()).join(', ')}`)
/** List of labels to add */ /**
const toAdd: string[] = [] * List of labels to add
* @type {string[]}
*/
const toAdd = []
// https://github.com/vercel/next.js/blame/canary/.github/ISSUE_TEMPLATE/1.bug_report.yml // https://github.com/vercel/next.js/blame/canary/.github/ISSUE_TEMPLATE/1.bug_report.yml
...@@ -56,8 +64,10 @@ async function run() { ...@@ -56,8 +64,10 @@ async function run() {
debug(`Added labels to issue #${issue_number}: ${toAdd.join(', ')}`) debug(`Added labels to issue #${issue_number}: ${toAdd.join(', ')}`)
} }
/** Load label descriptions from the repo. */ /** Load label descriptions from the repo.
async function loadAreaLabels(client: GitHubClient) { * @param {GitHubClient} client
*/
async function loadAreaLabels(client) {
try { try {
const { data } = await client.issues.listLabelsForRepo({ const { data } = await client.issues.listLabelsForRepo({
owner: context.repo.owner, owner: context.repo.owner,
...@@ -65,7 +75,8 @@ async function loadAreaLabels(client: GitHubClient) { ...@@ -65,7 +75,8 @@ async function loadAreaLabels(client: GitHubClient) {
per_page: 100, per_page: 100,
}) })
const labels = new Map<string, string>() /** @type {Map<string, string>}*/
const labels = new Map()
// Only load labels that start with `area:` and have a description // Only load labels that start with `area:` and have a description
for (const label of data) { for (const label of data) {
if (label.name.startsWith('area:') && label.description) { if (label.name.startsWith('area:') && label.description) {
...@@ -79,11 +90,12 @@ async function loadAreaLabels(client: GitHubClient) { ...@@ -79,11 +90,12 @@ async function loadAreaLabels(client: GitHubClient) {
} }
} }
async function addLabels( /**
client: GitHubClient, * @param {GitHubClient} client
issue_number: number, * @param {number} issue_number
labels: string[] * @param {string[]} labels
) { */
async function addLabels(client, issue_number, labels) {
try { try {
const formatted = labels.map((l) => `"${l}"`).join(', ') const formatted = labels.map((l) => `"${l}"`).join(', ')
debug(`Adding label(s) (${formatted}) to issue #${issue_number}`) debug(`Adding label(s) (${formatted}) to issue #${issue_number}`)
......
/**
* This action will comment on issues that have incorrect/missing/outdated reproductions.
*/
// @ts-check
import { context, getOctokit } from '@actions/github'
import { setFailed, info } from '@actions/core'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const __dirname = `${process.env.GITHUB_WORKSPACE}/.github/actions/issue-validator/clarify`
const labelActions = {
'please add a complete reproduction': {
file: 'repro.md',
comment:
'Commented on issue, because it did not have a sufficient reproduction.',
},
'please simplify reproduction': {
file: 'simplify-repro.md',
comment: 'Commented on issue, because it had a complex reproduction.',
},
'please verify canary': {
file: 'canary.md',
comment: 'Commented on issue, because it was not verified against canary.',
},
}
/**
* @typedef {{
* id :number
* node_id :string
* url :string
* name :string
* description :string
* color :string
* default :boolean
* }} Label
*
* @typedef {{
* pull_request: any
* issue?: {body: string, number: number, labels: Label[]}
* label: Label
* }} Payload
*
* @typedef {{
* payload: Payload
* repo: any
* }} Context
*/
async function run() {
const { payload, repo } = context
const {
issue,
pull_request,
label: { name: newLabel },
} = payload
if (pull_request || !issue?.body || !process.env.GITHUB_TOKEN) return
/** @type {string[]} */
const labels = issue.labels.map((l) => l.name)
const labelActionKeys = Object.keys(labelActions)
if (
!labelActionKeys.includes(newLabel) &&
!labels.some((label) => labelActionKeys.includes(label))
) {
return info('Not manually labeled or already labeled.')
}
const { rest: client } = getOctokit(process.env.GITHUB_TOKEN)
const issueCommon = { ...repo, issue_number: issue.number }
const { file, comment } = labelActions[newLabel]
await client.issues.addLabels({ ...issueCommon, labels: [newLabel] })
const body = readFileSync(join(__dirname, file), 'utf8')
await client.issues.createComment({ ...issueCommon, body })
info(comment)
}
run().catch(setFailed)
// @ts-check
// @ts-expect-error
import * as github from '@actions/github'
// @ts-expect-error
import * as core from '@actions/core'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const verifyCanaryLabel = 'please verify canary'
const addReproductionLabel = 'please add a complete reproduction'
const addMimimalReproductionLabel = 'please simplify reproduction'
// const bugLabel = 'template: bug'
const __dirname =
'/home/runner/work/next.js/next.js/.github/actions/issue-validator'
/**
* @typedef {{
* id :number
* node_id :string
* url :string
* name :string
* description :string
* color :string
* default :boolean
* }} Label
*
* @typedef {{
* pull_request: any
* issue?: {body: string, number: number, labels: Label[]}
* label: Label
* }} Payload
*
* @typedef {{
* payload: Payload
* repo: any
* }} Context
*/
async function run() {
try {
/** @type {Context} */
const { payload, repo } = github.context
const {
issue,
pull_request,
label: { name: newLabel },
} = payload
if (pull_request || !issue?.body || !process.env.GITHUB_TOKEN) return
const labels = issue.labels.map((l) => l.name)
// const isBugReport =
// labels.includes(bugLabel) || newLabel === bugLabel || !labels.length
if (
// !(isBugReport && issue.number > 43554) &&
![
verifyCanaryLabel,
addReproductionLabel,
addMimimalReproductionLabel,
].includes(newLabel) &&
!(
labels.includes(verifyCanaryLabel) ||
labels.includes(addReproductionLabel) ||
labels.includes(addReproductionLabel)
)
) {
return core.info(
'Not a bug report or not manually labeled or already labeled.'
)
}
// /** @param {string|null|undefined} link */
// async function hasRepro(link) {
// if (!link) return false
// try {
// const url = new URL(link)
// if (['example.com'].includes(url.hostname)) {
// return false
// }
// } catch {
// return false
// }
// const response = await fetch(link)
// return response.ok
// }
// const hasValidRepro =
// 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 (
newLabel === addReproductionLabel
// || !hasValidRepro
) {
await Promise.all([
client.issues.addLabels({
...issueCommon,
labels: [addReproductionLabel],
}),
client.issues.createComment({
...issueCommon,
body: readFileSync(join(__dirname, 'repro.md'), 'utf8'),
}),
])
return core.info(
'Commented on issue, because it did not have a sufficient reproduction.'
)
}
if (newLabel === addMimimalReproductionLabel) {
await Promise.all([
client.issues.addLabels({
...issueCommon,
labels: [addMimimalReproductionLabel],
}),
client.issues.createComment({
...issueCommon,
body: readFileSync(join(__dirname, 'simplify-repro.md'), 'utf8'),
}),
])
return core.info(
'Commented on issue, because it had a complex reproduction.'
)
}
// const isVerifyCanaryChecked =
// isBugReport &&
// issue.body.match(
// /- \[x\] I verified that the issue exists in the latest Next.js canary release/i
// )
if (
newLabel === verifyCanaryLabel
// || !isVerifyCanaryChecked
) {
await Promise.all([
client.issues.addLabels({
...issueCommon,
labels: [verifyCanaryLabel],
}),
client.issues.createComment({
...issueCommon,
body: readFileSync(join(__dirname, 'canary.md'), 'utf8'),
}),
])
return core.info(
'Commented on issue, because it was not verified against canary.'
)
}
} catch (error) {
core.setFailed(error.message)
}
}
run()
/**
* This closes an issue if it doesn't have an expected reproduction.
*/
// @ts-check
import { setFailed } from '@actions/core'
import { context, getOctokit } from '@actions/github'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const __dirname = `${process.env.GITHUB_WORKSPACE}/.github/actions/issue-validator/repro-link`
async function run() {
const token = process.env.GITHUB_TOKEN
if (!token) throw new Error('No GITHUB_TOKEN provided')
const { issue } = context.payload
if (!issue) return console.log('Not an issue, exiting')
const { body: issue_body } = issue
if (!issue_body) return console.log('Could not get issue body, exiting')
const start =
'### Link to the code that reproduces this issue or a replay of the bug'
const end = '### To Reproduce'
const linkRe = new RegExp(`${start}(.*)${end}`, 'is')
const match = issue_body.match(linkRe)?.[1]?.trim()
if (await hasRepro(match)) {
console.log(`Issue #${issue.number} contains a valid reproduction link`)
return
}
// A client to load data from GitHub
const { rest: client } = getOctokit(token)
console.log(
`Issue #${issue.number} does not contain a valid reproduction link, closing/commenting`
)
// Close the issue
await client.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
})
// Comment on the issue
await client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: readFileSync(join(__dirname, 'invalid-link.md'), 'utf8'),
})
// Lock to avoid piling up comments/reactions we do not monitor
await client.issues.lock({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
})
}
run().catch(setFailed)
/** @param {string|null|undefined} link */
async function hasRepro(link) {
if (!link) return false
try {
const url = new URL(link)
if (
!['github.com', 'codesandbox.io', 'app.replay.io'].includes(url.hostname)
)
return false
const { status } = await fetch(link)
// Verify that it's not a private repo/sandbox
// We allow 500, in case it's downtime on one of the services
return status < 400 || status >= 500
} catch {
return false
}
}
...@@ -6,27 +6,6 @@ settings: ...@@ -6,27 +6,6 @@ settings:
importers: importers:
.: {}
actions/issue-labeler:
dependencies:
'@actions/core':
specifier: ^1.10.0
version: 1.10.0
'@actions/github':
specifier: ^5.1.1
version: 5.1.1
devDependencies:
'@types/node':
specifier: ^18.15.3
version: 18.16.19
'@vercel/ncc':
specifier: 0.36.1
version: 0.36.1
typescript:
specifier: 5.1.6
version: 5.1.6
actions/issue-validator: actions/issue-validator:
dependencies: dependencies:
'@actions/core': '@actions/core':
...@@ -396,11 +375,6 @@ packages: ...@@ -396,11 +375,6 @@ packages:
hasBin: true hasBin: true
dev: true dev: true
/@vercel/ncc@0.36.1:
resolution: {integrity: sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==}
hasBin: true
dev: true
/argparse@1.0.10: /argparse@1.0.10:
resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==} resolution: {integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==}
dependencies: dependencies:
......
# https://github.com/github/issue-labeler#create-workflow
name: Label issues - GH Labeler
on:
issues:
types: [opened]
jobs:
triage:
if: |
${{ github.event.label.name == 'template: bug' }}
name: Triage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: 'Run issue labeler'
run: node ./.github/actions/issue-labeler/lib
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Validate issue name: Validate issue
on: on:
issues: issues:
types: [labeled] types: [opened, labeled]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs: jobs:
validate: issue-opened:
if: "${{ contains(github.event.issue.labels.*.name, 'template: bug') && github.event.action == 'opened' }}"
name: Issue opened
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: 'Autolabel based on affected areas'
run: node ./.github/actions/issue-validator/autolabel/index.mjs
- name: 'Close without valid reproduction link'
run: node ./.github/actions/issue-validator/repro-link/index.mjs
issue-labeled:
if: "${{ contains(github.event.issue.labels.*.name, 'template: bug') && github.event.action == 'labeled' }}"
name: Issue labeled
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-node@v3 - uses: actions/setup-node@v3
with: with:
node-version: 18 node-version: 18
- name: 'Run issue validator' - name: 'Clarify reproduction steps'
run: node ./.github/actions/issue-validator/index.mjs run: node ./.github/actions/issue-validator/clarify/index.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...@@ -16,7 +16,7 @@ packages/next/src/bundles/webpack/packages/*.runtime.js ...@@ -16,7 +16,7 @@ packages/next/src/bundles/webpack/packages/*.runtime.js
packages/next/src/bundles/webpack/packages/lazy-compilation-*.js packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
.github/actions/next-stats-action/.work .github/actions/next-stats-action/.work
.github/actions/issue-labeler/lib/index.js .github/actions/issue-validator/*/index.mjs
.github/actions/validate-docs-links/lib/index.js .github/actions/validate-docs-links/lib/index.js
.github/actions/needs-triage/index.js .github/actions/needs-triage/index.js
.github/actions/*/index.mjs .github/actions/*/index.mjs
......
...@@ -9,7 +9,7 @@ packages/next-codemod/transforms/__testfixtures__/**/* ...@@ -9,7 +9,7 @@ packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/* packages/next-codemod/transforms/__tests__/**/*
test/development/basic/hmr/components/parse-error.js test/development/basic/hmr/components/parse-error.js
pnpm-lock.yaml pnpm-lock.yaml
.github/actions/issue-labeler/lib/index.js .github/actions/issue-validator/*/index.mjs
.github/actions/validate-docs-links/lib/index.js .github/actions/validate-docs-links/lib/index.js
.github/actions/needs-triage/index.js .github/actions/needs-triage/index.js
.github/actions/*/index.mjs .github/actions/*/index.mjs
......
...@@ -29,5 +29,6 @@ And go through the prepared reproduction steps once again, and check if the issu ...@@ -29,5 +29,6 @@ And go through the prepared reproduction steps once again, and check if the issu
- [Video: How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc) - [Video: How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc)
- [Contributing to Next.js](https://github.com/vercel/next.js/blob/canary/contributing.md) - [Contributing to Next.js](https://github.com/vercel/next.js/blob/canary/contributing.md)
- [Triaging issues](https://github.com/vercel/next.js/blob/canary/contributing/repository/triaging.md) - [Triaging issues](https://github.com/vercel/next.js/blob/canary/contributing/repository/triaging.md)
- [Verifiying canary](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/canary.md) - [Verifiying canary](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/clarify/canary.md)
- [Adding a reproduction](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/repro.md) - [Adding a reproduction](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/clarify/repro.md)
- [Simplifying a reproduction](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/clarify/simplify-repro.md)
...@@ -58,5 +58,6 @@ If you want to report a bug on GitHub, you should upgrade to the newest canary r ...@@ -58,5 +58,6 @@ If you want to report a bug on GitHub, you should upgrade to the newest canary r
- [Video: How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc) - [Video: How to Contribute to Open Source (Next.js)](https://www.youtube.com/watch?v=cuoNzXFLitc)
- [Contributing to Next.js](https://github.com/vercel/next.js/blob/canary/contributing.md) - [Contributing to Next.js](https://github.com/vercel/next.js/blob/canary/contributing.md)
- [Triaging issues](https://github.com/vercel/next.js/blob/canary/contributing/repository/triaging.md) - [Triaging issues](https://github.com/vercel/next.js/blob/canary/contributing/repository/triaging.md)
- [Verifying canary](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/canary.md) - [Verifying canary](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/clarify/canary.md)
- [Adding a reproduction](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/repro.md) - [Adding a reproduction](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/clarify/repro.md)
- [Simplifying a reproduction](https://github.com/vercel/next.js/blob/canary/.github/actions/issue-validator/clarify/simplify-repro.md)
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