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

chore: fix issue labeler (#47206)

### What?

A fork of https://github.com/github/issue-labeler that we pull in and
maintain.

### Why?

The official issue labeler had some issues which I tried to fix in PRs
and eventually got merged upstream, but the release cycle was a bit
slow, and that GitHub action had many parts we did not really need
anyway. So it makes sense to maintain it ourselves.

### How?

This PR removes the
https://github.com/vercel/next.js/blob/canary/.github/issue-labeler.yml
config file, which in our case is just a sublist of
https://github.com/vercel/next.js/labels anyway. Instead, we can pull in
the labels from GitHub directly and filter out those that we want to
apply to issues. This will keep things more in sync.

fix NEXT-750 ([link](https://linear.app/vercel/issue/NEXT-750))

---------
parent cf66c2dc
......@@ -20,6 +20,7 @@ packages/react-dev-overlay/lib/**
**/__tmp__/**
.github/actions/next-stats-action/.work
.github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/lib/index.js
packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js
......
node_modules/
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
{
"private": true,
"name": "issue-labeler",
"type": "module",
"exports": "./lib/index.js",
"scripts": {
"build": "pnpm types && pnpm 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"
}
}
import { setFailed, debug } from '@actions/core'
import { context, getOctokit } from '@actions/github'
type GitHubClient = ReturnType<typeof getOctokit>['rest']
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, number: issue_number, title: issue_title } = issue
if (!issue_number) return console.log('Could not get issue number, exiting')
if (!issue_body) return console.log('Could not get issue body, exiting')
if (!issue_title) return console.log('Could not get issue title, exiting')
// A client to load data from GitHub
const { rest: client } = getOctokit(token)
// Load our regex rules from the repo labels
const labels = await loadAreaLabels(client)
debug(`Loaded labels: ${Array.from(labels.keys()).join(', ')}`)
/** List of labels to add */
const toAdd: string[] = []
// https://github.com/vercel/next.js/blame/canary/.github/ISSUE_TEMPLATE/1.bug_report.yml
const matchSection = issue_body
.split('Which area(s) of Next.js are affected? (leave empty if unsure)')[1]
?.split('Link to the code that reproduces this issue')[0]
if (!matchSection) {
console.log(
`Issue #${issue_number} does not contain a match section, likely not a bug template, exiting`
)
return
}
debug(`Match section: ${matchSection}`)
for (const [label, description] of labels.entries()) {
if (matchSection.includes(description)) {
toAdd.push(label)
}
}
debug(`Labels to add: ${toAdd.join(', ')}`)
if (!toAdd.length) return console.log('No labels to add, exiting')
await addLabels(client, issue_number, toAdd)
debug(`Added labels to issue #${issue_number}: ${toAdd.join(', ')}`)
}
/** Load label descriptions from the repo. */
async function loadAreaLabels(client: GitHubClient) {
try {
const { data } = await client.issues.listLabelsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
})
const labels = new Map<string, string>()
// Only load labels that start with `area:` and have a description
for (const label of data) {
if (label.name.startsWith('area:') && label.description) {
labels.set(label.name, label.description)
}
}
return labels
} catch (error) {
console.error('Error loading labels: ' + error)
throw error
}
}
async function addLabels(
client: GitHubClient,
issue_number: number,
labels: string[]
) {
try {
const formatted = labels.map((l) => `"${l}"`).join(', ')
debug(`Adding label(s) (${formatted}) to issue #${issue_number}`)
return await client.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
labels,
})
} catch (error) {
console.error(`Could not add label(s) ${labels} to issue #${issue_number}`)
throw error
}
}
run().catch(setFailed)
{
"compilerOptions": {
"noEmit": true,
"target": "esnext",
"moduleResolution": "node",
"rootDir": "./src",
"strict": true,
"noImplicitAny": true
}
}
# https://github.com/github/issue-labeler#basic-examples
# Should match the list "Which area(s) of Next.js are affected?" in:
# https://github.com/vercel/next.js/blob/canary/.github/ISSUE_TEMPLATE/1.bug_report.yml
'area: app': 'App directory (appDir: true)'
'area: create-next-app': 'CLI (create-next-app)'
'area: data fetching': 'Data fetching (gS(S)P, getInitialProps)'
'area: Edge': 'Middleware / Edge (API routes, runtime)'
'area: ESLint': 'ESLint (eslint-config-next)'
'area: export': 'Static HTML Export (next export)'
'area: Font Optimization': 'Font optimization (@next/font)'
'area: I18n': 'Internationalzation (i18n)'
'area: Jest': 'Jest (next/jest)'
'area: MDX': 'MDX (@next/mdx)'
'area: Metadata': 'Metadata (metadata, generateMetadata, next/head, head.js)'
'area: next/dynamic': 'Dynamic imports (next/dynamic)'
'area: next/image': 'Image optmization (next/image, next/legacy/image)'
'area: next/script': 'Script optimizatzion (next/script)'
'area: package manager': 'Package manager (npm, pnpm, Yarn)'
'area: Routing': 'Routing (next/router, next/navigation, next/link)'
'area: standalone mode': 'Standalone mode (output: "standalone")'
'area: SWC Minify': 'SWC minifier (swcMinify: true)'
'area: SWC transforms': 'SWC transpilation'
'area: Turbopack': 'Turbopack (--turbo)'
'area: TypeScript': 'TypeScript'
# Less used/old/redundant labels
# area: AMP
# area: API routes
# area: Application Code
# area: Codemods
# area: Compiler Performance
# area: Compiler
# area: Concurrent Features
# area: Debugger
# area: Developer Experience
# area: Ecosystem
# area: experimental
# area: Middleware
# area: Reliability
# area: Repository Maintenance
# area: Server Components
# area: Static Generation
# area: styled-jsx
# area: Tracing
# area: URL Imports
......@@ -13,9 +13,10 @@ jobs:
name: Triage
runs-on: ubuntu-latest
steps:
- uses: github/issue-labeler@v3.0
- uses: actions/setup-node@v3
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
configuration-path: '.github/issue-labeler.yml'
enable-versioned-regex: 0
sync-labels: 0
node-version: 18
- name: 'Run issue labeler'
run: node ./.github/actions/issue-labeler/lib
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
......@@ -12,6 +12,7 @@ packages/react-dev-overlay/lib/**
lerna.json
.github/actions/next-stats-action/.work
.github/actions/issue-validator/index.mjs
.github/actions/issue-labeler/lib/index.js
packages/next-swc/crates/**/*
packages/next-swc/target/**/*
packages/next-swc/native/**/*
......
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