Skip to content

Commit 2a58e7c

Browse files
chore: add GitHub Action to manage +1 comments (#11645)
1 parent dba5043 commit 2a58e7c

File tree

8 files changed

+1342
-0
lines changed

8 files changed

+1342
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/src/corePluginList.js
88
/oxide/crates/node/index.js
99
/oxide/crates/node/index.d.ts
10+
.github/actions/minus-one/index.mjs

.github/actions/minus-one/index.mjs

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

.github/actions/minus-one/licenses.txt

Lines changed: 659 additions & 0 deletions
Large diffs are not rendered by default.

.github/actions/minus-one/package-lock.json

Lines changed: 572 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"private": true,
3+
"description": "Manage +1 comments on GitHub issues",
4+
"author": "Balázs Orbán <[email protected]>",
5+
"exports": "./index.mjs",
6+
"files": [
7+
"src"
8+
],
9+
"scripts": {
10+
"build": "ncc -m -o . build src/index.mjs --license licenses.txt"
11+
},
12+
"devDependencies": {
13+
"@vercel/ncc": "0.34.0"
14+
},
15+
"dependencies": {
16+
"@actions/core": "1.10.0",
17+
"@actions/github": "5.1.1",
18+
"@octokit/graphql": "7.0.1"
19+
},
20+
"packageManager": "[email protected]"
21+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// @ts-check
2+
import { context } from '@actions/github'
3+
import { info, setFailed } from '@actions/core'
4+
import { graphql } from '@octokit/graphql'
5+
6+
if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN not set')
7+
8+
/**
9+
MIT License
10+
11+
Copyright (c) Sindre Sorhus [email protected] (sindresorhus.com)
12+
13+
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:
14+
15+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
16+
17+
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.
18+
*/
19+
function isUnhelpfulComment(text) {
20+
// Borrowed from Refined GitHub:
21+
// https://github.com/refined-github/refined-github/blob/c864a20b57bb433aaf3952f88d83c9fc481ae6ff/source/helpers/is-low-quality-comment.ts#L2-L3
22+
return (
23+
text.replace(
24+
/[\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,
25+
''
26+
) === ''
27+
)
28+
}
29+
30+
async function run() {
31+
try {
32+
const { comment } = context.payload
33+
if (!comment) return
34+
35+
const { node_id: subjectId, body } = comment
36+
37+
if (isUnhelpfulComment(body)) {
38+
await graphql(
39+
`
40+
mutation minimize($subjectId: ID!) {
41+
minimizeComment(
42+
input: { subjectId: $subjectId, classifier: OFF_TOPIC }
43+
) {
44+
minimizedComment {
45+
isMinimized
46+
}
47+
}
48+
}
49+
`,
50+
{
51+
subjectId,
52+
headers: { authorization: `token ${process.env.GITHUB_TOKEN}` },
53+
}
54+
)
55+
56+
info(`Comment (${body.slice(0, 15)}) was minimized.`)
57+
}
58+
} catch (error) {
59+
setFailed(error)
60+
}
61+
}
62+
63+
run()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: On issue comment
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
minus-one:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
13+
with:
14+
node-version: 18
15+
- name: 'Manage +1 comments'
16+
run: node ./.github/actions/minus-one/index.mjs
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/node_modules
2+
.github/**/node_modules
23
/coverage
34
/cli
45
/lib

0 commit comments

Comments
 (0)