Skip to content

Commit

Permalink
Create new action that will auto-label issues that have some activity…
Browse files Browse the repository at this point in the history
… after we mark them as "verify-canary" or "add repro"" (#44815)
  • Loading branch information
jankaifer committed Jan 13, 2023
1 parent 98df70e commit f0c7e72
Show file tree
Hide file tree
Showing 18 changed files with 10,462 additions and 3 deletions.
File renamed without changes.
9,220 changes: 9,220 additions & 0 deletions .github/actions/issue-on-comment/index.js

Large diffs are not rendered by default.

478 changes: 478 additions & 0 deletions .github/actions/issue-on-comment/package-lock.json

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions .github/actions/issue-on-comment/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as github from '@actions/github'
import * as core from '@actions/core'

const LABELS = {
VERIFY_CANARY: 'please verify canary',
ADD_REPRODUCTION: 'please add a complete reproduction',
NEEDS_TRIAGE: 'type: needs triage',
}

const labelsRequireUserInput = [LABELS.VERIFY_CANARY, LABELS.ADD_REPRODUCTION]

function assertNotNullable<T>(value: T): asserts value is NonNullable<T> {
if (value === undefined || value === null)
throw new Error('Unexpected nullable value')
}

async function run() {
try {
const { payload, repo } = github.context
const { issue, comment } = payload

assertNotNullable(issue)
assertNotNullable(comment)

if (!process.env.GITHUB_TOKEN) return

const client = github.getOctokit(process.env.GITHUB_TOKEN).rest
const issueCommon = { ...repo, issue_number: issue.number }

const issueLabels: string[] = issue.labels.map((label: any) => label.name)

if (labelsRequireUserInput.some((label) => issueLabels.includes(label))) {
if (comment.user.type !== 'Bot') {
client.issues.addLabels({
...issueCommon,
labels: [LABELS.NEEDS_TRIAGE],
})
}
}
} catch (error: any) {
core.setFailed(error.message)
}
}

run()
2 changes: 2 additions & 0 deletions .github/actions/issue-on-label/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!package-lock.json
lib/
6 changes: 6 additions & 0 deletions .github/actions/issue-on-label/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'Issue auto label'
description: 'vercel/next.js specific auto-labeling action'
author: 'Next.js team'
runs:
using: 'node16'
main: 'index.js'
File renamed without changes.
659 changes: 659 additions & 0 deletions .github/actions/issue-on-label/licenses.txt

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions .github/actions/issue-on-label/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"private": true,
"exports": "./index.js",
"files": [
"src"
],
"scripts": {
"types": "tsc",
"pack": "ncc -m -o . build lib/index.js --license licenses.txt",
"build": "npm run types && npm run pack"
},
"devDependencies": {
"@types/node": "^18.11.0",
"@vercel/ncc": "0.34.0",
"typescript": "^4.4.4"
},
"dependencies": {
"@actions/core": "1.10.0",
"@actions/github": "5.1.1"
},
"packageManager": "npm@9.2.0"
}
File renamed without changes.
13 changes: 13 additions & 0 deletions .github/actions/issue-on-label/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"typeRoots": ["./node_modules/@types"]
},
"exclude": ["node_modules", "../../../node_modules"]
}
14 changes: 14 additions & 0 deletions .github/workflows/issue_on_comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: On issue comment

on:
issue_comment:
types: [created]

jobs:
issue-on-comment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/issue-on-comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Label issues - custom
name: On issue label

on:
issues:
types: [labeled]

jobs:
auto-label:
issue-on-label:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/issue-auto-label
- uses: ./.github/actions/issue-on-label
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit f0c7e72

Please sign in to comment.