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

chore: add GitHub Action to manage "+1" comments (#52866)

### What?

Adds a GitHub Action that automatically marks unhelpful comments as "off-topic".

You can test it by adding off-topic comments to this issue: https://github.com/balazsorban44/next.js/issues/21

https://github.com/balazsorban44/next.js/blob/17e3ec30689a2323161260c9b03bb7f51ed008f9/.github/actions/minus-one/src/index.mjs#L6

### Why?

A common problem is when an issue thread receives "+1" comments, it usually encourages others to do the same. This makes the thread harder and harder for maintainers to read, without adding value to the discussion.

### How?

When an issue receives a comment, we compare it to a list that we determine as off-topic. If it matches, we hide the comment.

See: https://docs.github.com/en/graphql/reference/mutations#minimizecomment
parent 84005941
...@@ -23,7 +23,8 @@ packages/react-dev-overlay/lib/** ...@@ -23,7 +23,8 @@ packages/react-dev-overlay/lib/**
.github/actions/issue-validator/index.mjs .github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/lib/index.js .github/actions/issue-labeler/lib/index.js
.github/actions/validate-docs-links/lib/index.js .github/actions/validate-docs-links/lib/index.js
.github/actions/issue-on-comment/index.js .github/actions/needs-triage/index.js
.github/actions/minus-one/index.mjs
packages/next-codemod/transforms/__testfixtures__/**/* packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/* packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js packages/next-codemod/**/*.js
......
node_modules/
\ No newline at end of file
!package-lock.json
lib/
\ No newline at end of file
!dist
!package-lock.json
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"private": true,
"description": "Manage +1 comments on GitHub issues",
"exports": "./index.mjs",
"files": [
"src"
],
"scripts": {
"build": "ncc -m -o . build src/index.mjs --license licenses.txt"
},
"devDependencies": {
"@vercel/ncc": "0.34.0"
},
"dependencies": {
"@actions/core": "1.10.0",
"@actions/github": "5.1.1",
"@octokit/graphql": "7.0.1"
},
"packageManager": "npm@9.2.0"
}
// @ts-check
import { context } from '@actions/github'
import { info, setFailed } from '@actions/core'
import { graphql } from '@octokit/graphql'
if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN not set')
/**
MIT License
Copyright (c) Sindre Sorhus sindresorhus@gmail.com (sindresorhus.com)
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.
*/
function isUnhelpfulComment(text) {
// Borrowed from Refined GitHub:
// https://github.com/refined-github/refined-github/blob/c864a20b57bb433aaf3952f88d83c9fc481ae6ff/source/helpers/is-low-quality-comment.ts#L2-L3
return (
text.replace(
/[\s,.!?👍👎👌🙏]+|[\u{1F3FB}-\u{1F3FF}]|[+-]\d+|⬆️|ditt?o|me|too|t?here|on|same|this|issues?|please|pl[sz]|any|updates?|bump|question|solution|following/giu,
''
) === ''
)
}
async function run() {
try {
const { comment } = context.payload
if (!comment) return
const { node_id: subjectId, body } = comment
if (isUnhelpfulComment(body)) {
await graphql(
`
mutation minimize($subjectId: ID!) {
minimizeComment(
input: { subjectId: $subjectId, classifier: OFF_TOPIC }
) {
minimizedComment {
isMinimized
}
}
}
`,
{
subjectId,
headers: { authorization: `token ${process.env.GITHUB_TOKEN}` },
}
)
info(`Comment (${body.slice(0, 15)}) was minimized.`)
}
} catch (error) {
setFailed(error)
}
}
run()
lib/
\ No newline at end of file
This diff is collapsed.
{ {
"name": "issue-on-comment", "name": "needs-triage",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
......
...@@ -5,10 +5,21 @@ on: ...@@ -5,10 +5,21 @@ on:
types: [created] types: [created]
jobs: jobs:
issue-on-comment: needs-triage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/actions/issue-on-comment - uses: ./.github/actions/needs-triage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
minus-one:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: 'Manage +1 comments'
run: node ./.github/actions/minus-one/index.mjs
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
...@@ -11,6 +11,7 @@ yarn.lock ...@@ -11,6 +11,7 @@ yarn.lock
!/yarn.lock !/yarn.lock
test/node_modules test/node_modules
.pnpm-store/ .pnpm-store/
.github/**/node_modules
# logs & pids # logs & pids
*.log *.log
......
...@@ -19,7 +19,8 @@ packages/next/src/bundles/webpack/packages/lazy-compilation-*.js ...@@ -19,7 +19,8 @@ packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
.github/actions/issue-validator/index.mjs .github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/lib/index.js .github/actions/issue-labeler/lib/index.js
.github/actions/validate-docs-links/lib/index.js .github/actions/validate-docs-links/lib/index.js
.github/actions/issue-on-comment/index.js .github/actions/needs-triage/index.js
.github/actions/minus-one/index.mjs
packages/next-swc/crates/**/tests/**/output* packages/next-swc/crates/**/tests/**/output*
packages/next-swc/crates/core/tests/loader/issue-32553/input.js packages/next-swc/crates/core/tests/loader/issue-32553/input.js
......
...@@ -11,5 +11,6 @@ test/development/basic/hmr/components/parse-error.js ...@@ -11,5 +11,6 @@ test/development/basic/hmr/components/parse-error.js
pnpm-lock.yaml pnpm-lock.yaml
.github/actions/issue-validator/index.mjs .github/actions/issue-validator/index.mjs
.github/actions/validate-docs-links/lib/index.js .github/actions/validate-docs-links/lib/index.js
.github/actions/issue-on-comment/index.js .github/actions/needs-triage/index.js
.github/actions/minus-one/index.mjs
**/convex/_generated/** **/convex/_generated/**
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