Unverified Commit 295bcebd authored by Sam Ko's avatar Sam Ko Committed by GitHub

chore(github): improve triaging issues with ai (#68995)

## Why?

We need to update the triage guidelines, so random issues are not
flagged to the team.

## How?

- Moved `triage_guidelines.txt` to an external source, so we don't have
to constantly create a PR
- Added a `VERCEL_PROTECTION_BYPASS` secret to to Next.js repo
- Refactor `generateText()` by moving some logic to `system`
- Minor refactors to `main()`
parent e101bd8d
**Triage Guidelines:**
Hard rules:
- Ignore the bug, Documentation labels.
- Ignore the url to the code that reproduces the issue.
Questions to ask:
- Is the issue reproducible on the latest version of Next.js? If not, it's not a severe issue.
- Is there a body of text that explains the issue? If not, it's not a severe issue.
- Is the issue related to an experimental feature? If yes, it's not a severe issue.
- Did build/compile times increase drastically? If yes, it's a severe issue.
- Is there a significant performance regression? If yes, it's a severe issue.
- Is CSS not working as expected? If yes, it's a severe issue.
- Are multiple stages (next dev, next start, deploy) affected? If yes, it's likely a severe issue.
import { WebClient } from '@slack/web-api' import { WebClient } from '@slack/web-api'
import * as path from 'node:path'
import { readFileSync } from 'node:fs'
import { info, setFailed } from '@actions/core' import { info, setFailed } from '@actions/core'
import { context } from '@actions/github' import { context } from '@actions/github'
import { generateText, tool } from 'ai' import { generateText, tool } from 'ai'
...@@ -13,47 +11,67 @@ import { issueSchema } from '../lib/types' ...@@ -13,47 +11,67 @@ import { issueSchema } from '../lib/types'
async function main() { async function main() {
if (!process.env.OPENAI_API_KEY) throw new TypeError('OPENAI_API_KEY not set') if (!process.env.OPENAI_API_KEY) throw new TypeError('OPENAI_API_KEY not set')
if (!process.env.SLACK_TOKEN) throw new TypeError('SLACK_TOKEN not set') if (!process.env.SLACK_TOKEN) throw new TypeError('SLACK_TOKEN not set')
if (!process.env.VERCEL_PROTECTION_BYPASS)
throw new TypeError('VERCEL_PROTECTION_BYPASS not set')
const slackClient = new WebClient(process.env.SLACK_TOKEN) const slackClient = new WebClient(process.env.SLACK_TOKEN)
const model = 'gpt-4o' const model = 'gpt-4o'
const channel = '#next-info' const channel = '#next-info'
const issue = context.payload.issue const issue = context.payload.issue
const filePath = path.join(
process.cwd(),
'.github/actions/next-repo-actions/lib/triage_guidelines.txt'
)
const fileText = readFileSync(filePath, 'utf8')
let latestVersion let latestVersion: string
let latestCanaryVersion let latestCanaryVersion: string
let html_url: string
let number: number
let title: string
try { try {
latestVersion = await getLatestVersion() latestVersion = await getLatestVersion()
latestCanaryVersion = await getLatestCanaryVersion() latestCanaryVersion = await getLatestCanaryVersion()
const res = await fetch(
'https://next-triage.vercel.sh/api/triage-guidelines',
{
method: 'GET',
headers: {
'x-vercel-protection-bypass': `${process.env.VERCEL_PROTECTION_BYPASS}`,
},
}
)
const guidelines = await res.text()
const result = await generateText({ const result = await generateText({
model: openai(model), model: openai(model),
maxAutomaticRoundtrips: 1, maxAutomaticRoundtrips: 1,
tools: { tools: {
report_to_slack: tool({ report_to_slack: tool({
description: 'Report to Slack if a GitHub issue is severe enough.', description: 'Report to Slack.',
parameters: issueSchema, parameters: issueSchema,
execute: async ({ issue }) => ({ execute: async ({ issue }) => {
html_url: issue.html_url, html_url = issue.html_url
number: issue.number, number = issue.number
title: issue.title, title = issue.title
}),
return { html_url, number, title }
},
}), }),
}, },
prompt: `${JSON.stringify(issue)}\n${fileText}\nlatestVersion: ${latestVersion}\nlatestCanaryVersion: ${latestCanaryVersion}\nWith the above GitHub issue (JSON), the triage guidelines for determining whether an issue is severe, and the latest versions of Next.js, can you determine whether the given issue is severe enough to report to Slack? If severe enough, report to Slack with an approximately 300 character summary (don't repeat the triage guidelines while doing so) of why you think it is severe enough to report to Slack. If not severe enough, do not report to Slack.`, system:
`Your job is to determine the severity of a GitHub issue using the triage guidelines and the latest versions of Next.js.` +
`Succinctly explain why you chose the severity, without paraphrasing the triage guidelines.` +
`Here are the triage guidelines: ${guidelines}` +
`Here is the latest version of Next.js: ${latestVersion}` +
`Here is the latest canary version of Next.js: ${latestCanaryVersion}`,
prompt: `${JSON.stringify(issue)}\nDetermine the severity of the above GitHub issue. If the severity is severe, report it to Slack.`,
}) })
// the ai determined that the issue was severe enough to report on slack // the ai determined that the issue was severe enough to report on slack
if (result.roundtrips.length > 1) { if (result.roundtrips.length > 1) {
const blocks = BlockCollection([ const blocks = BlockCollection([
Section({ Section({
text: `:github2: <${result.roundtrips[0].toolResults[0].result.html_url}|#${result.roundtrips[0].toolResults[0].result.number}>: ${result.roundtrips[0].toolResults[0].result.title}\n_Note: This issue was summarized and reported on Slack with the *${model}* model._`, text: `:github2: <${html_url}|#${number}>: ${title}\n_Note: This issue was evaluated and reported on Slack with *${model}*._`,
}), }),
Divider(), Divider(),
Section({ Section({
...@@ -67,10 +85,12 @@ async function main() { ...@@ -67,10 +85,12 @@ async function main() {
icon_emoji: ':github:', icon_emoji: ':github:',
username: 'GitHub Notifier', username: 'GitHub Notifier',
}) })
} else {
// the ai will also provide a reason why the issue was not severe enough to report on slack
info(`${result.text}`)
} }
// the ai will also provide a reason why the issue was not severe enough to report on slack
info(
`result.text: ${result.text}\nhtml_url: ${html_url}\nnumber: ${number}\ntitle: ${title}`
)
} catch (error) { } catch (error) {
setFailed(error) setFailed(error)
} }
......
...@@ -16,3 +16,4 @@ jobs: ...@@ -16,3 +16,4 @@ jobs:
env: env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
VERCEL_PROTECTION_BYPASS: ${{ secrets.VERCEL_PROTECTION_BYPASS }}
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