Unverified Commit a11364b3 authored by Sam Ko's avatar Sam Ko Committed by GitHub

chore(github): add improvements to bankrupt-issues (#67028)

## Why?

- Add link to the run itself instead of just the workflow
- Add `title` and `url` to each issue when logged in run
parent 0c6dac46
......@@ -3,6 +3,8 @@ import { context, getOctokit } from '@actions/github'
import { WebClient } from '@slack/web-api'
import { BlockCollection, Section } from 'slack-block-builder'
type Issue = { title: string; number: number; url: string }
async function main() {
if (!process.env.GITHUB_TOKEN) throw new TypeError('GITHUB_TOKEN not set')
if (!process.env.CREATED) throw new TypeError('CREATED not set')
......@@ -11,12 +13,14 @@ async function main() {
const octokit = getOctokit(process.env.GITHUB_TOKEN)
const slackClient = new WebClient(process.env.SLACK_TOKEN)
const { runId } = context
const { owner, repo } = context.repo
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
const createdQuery = process.env.CREATED
const dateRange = createdQuery.split('..').join(' to ')
const body = `
We are in the process of closing issues dating from ${dateRange} to improve our focus on the most relevant and actionable problems.
We are in the process of closing issues dating from **${dateRange}** to improve our focus on the most relevant and actionable problems.
**_Why are we doing this?_**
......@@ -24,7 +28,7 @@ Stale issues often lack recent updates and clear reproductions, making them diff
**_Why these issues?_**
Issues dating from ${dateRange} are likely to be outdated and less relevant to the current state of the codebase. By closing these older stale issues, we can better focus our efforts on more recent and relevant problems, ensuring a more effective and streamlined workflow.
Issues dating from **${dateRange}** are likely to be outdated and less relevant to the current state of the codebase. By closing these older stale issues, we can better focus our efforts on more recent and relevant problems, ensuring a more effective and streamlined workflow.
If your issue is still relevant, please reopen it using our [bug report template](https://github.com/vercel/next.js/issues/new?assignees=&labels=bug&projects=&template=1.bug_report.yml). Be sure to include any important context from the original issue in your new report.
......@@ -34,26 +38,26 @@ Best regards,
The Next.js Team
`
let issues: number[] = []
const issues: Issue[] = []
try {
const { data } = await octokit.rest.search.issuesAndPullRequests({
q: `repo:${owner}/${repo} is:issue is:open created:${createdQuery}`,
})
issues = data.items.map((issue) => {
return issue.number
})
data.items.forEach((issue) =>
issues.push({ title: issue.title, number: issue.number, url: issue.url })
)
info(`issues = ${issues}`)
info(`issues = ${JSON.stringify(issues)}`)
info(`${issues.length} issues found! Attempting to close these issues...`)
issues.forEach(async (issue_number) => {
issues.forEach(async (issue) => {
// assign the issue to samcx
await octokit.rest.issues.addAssignees({
owner,
repo,
issue_number,
issue_number: issue.number,
assignees: ['samcx'],
})
......@@ -61,7 +65,7 @@ The Next.js Team
await octokit.rest.issues.createComment({
owner,
repo,
issue_number,
issue_number: issue.number,
body,
})
......@@ -69,7 +73,7 @@ The Next.js Team
await octokit.rest.issues.update({
owner,
repo,
issue_number,
issue_number: issue.number,
state: 'closed',
})
})
......@@ -78,7 +82,7 @@ The Next.js Team
const blocks = BlockCollection([
Section({
text: `We just bankrupted *${issues.length}* issues from ${dateRange}.\n_Note: This :github2: <https://github.com/vercel/next.js/actions/workflows/issue_bankrupt.yml|workflow> is ran manually with an inputed created query. To see which issues were closed, check the latest workflow <https://github.com/vercel/next.js/actions/workflows/issue_bankrupt.yml|run>._`,
text: `We just bankrupted *${issues.length}* issues from ${dateRange}.\n_Note: This :github2: <https://github.com/vercel/next.js/actions/workflows/issue_bankrupt.yml|workflow> is ran manually with an inputed created query. To see which issues were closed, check the latest <${runUrl}|workflow run>._`,
}),
])
......
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