forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix issue labeler (vercel#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)) ---------
- Loading branch information
1 parent
cf66c2d
commit 1a47872
Showing
11 changed files
with
784 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"target": "esnext", | ||
"moduleResolution": "node", | ||
"rootDir": "./src", | ||
"strict": true, | ||
"noImplicitAny": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters