Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 17 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ packages/react-dev-overlay/lib/**
.github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/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/__tests__/**/*
packages/next-codemod/**/*.js
Expand Down
1 change: 0 additions & 1 deletion .github/actions/issue-labeler/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions .github/actions/issue-on-comment/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions .github/actions/issue-validator/.gitignore

This file was deleted.

7 changes: 7 additions & 0 deletions .github/actions/minus-one/index.mjs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions .github/actions/minus-one/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"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"
}
52 changes: 52 additions & 0 deletions .github/actions/minus-one/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// @ts-check
import { context } from '@actions/github'
import { info, setFailed } from '@actions/core'
import { graphql } from '@octokit/graphql'

function isUnhelpfulComment(text) {
// Borrowed from Refined GitHub:
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
if (!process.env.GITHUB_TOKEN) return
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved

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()
1 change: 1 addition & 0 deletions .github/actions/needs-triage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
659 changes: 659 additions & 0 deletions .github/actions/needs-triage/licenses.txt

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions .github/workflows/issue_on_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ on:
types: [created]

jobs:
issue-on-comment:
needs-triage:
runs-on: ubuntu-latest
steps:
- 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:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ yarn.lock
!/yarn.lock
test/node_modules
.pnpm-store/
.github/**/node_modules

# logs & pids
*.log
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ packages/next/src/bundles/webpack/packages/lazy-compilation-*.js
.github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/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/core/tests/loader/issue-32553/input.js
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore_staged
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ test/development/basic/hmr/components/parse-error.js
pnpm-lock.yaml
.github/actions/issue-validator/index.mjs
.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/**