Unverified Commit 7b73f113 authored by Sam Ko's avatar Sam Ko Committed by GitHub

chore: add issue_popular workflow (#60543)

## Description
Add a new GitHub workflow that outputs the top 15 :github2: issues (most reactions) in
the last month.

Closes NEXT-2071
parent 68cecd6a
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"private": true,
"description": "Notify Next.js team about pending PRs and popular issues",
"scripts": {
"build": "pnpm build-pr && pnpm build-issues",
"build-pr": "ncc build src/pr-approved.mjs -m -o dist-pr --license licenses.txt",
"build-issues": "ncc build src/popular-issues.mjs -m -o dist-issues --license licenses.txt"
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "6.0.0",
"@slack/web-api": "^6.11.2"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1"
}
}
// @ts-check
import { context, getOctokit } from '@actions/github'
import { setFailed, info } from '@actions/core'
import { WebClient } from '@slack/web-api'
// Get the date one month ago (YYYY-MM-DD)
function getOneMonthAgoDate() {
const date = new Date()
date.setMonth(date.getMonth() - 1)
return date.toISOString().split('T')[0]
}
function generateBlocks(issues) {
const blocks = [
{ type: 'section', text: { type: 'mrkdwn', text: '*Top 15 issues:*' } },
{ type: 'divider' },
]
issues.forEach((issue) => {
blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: `• <${issue.html_url}|#${issue.number}>: ${issue.title}`,
},
})
})
return blocks
}
async function run() {
try {
if (!process.env.GITHUB_TOKEN) throw new TypeError('GITHUB_TOKEN not set')
if (!process.env.SLACK_TOKEN) throw new TypeError('SLACK_TOKEN not set')
const octoClient = getOctokit(process.env.GITHUB_TOKEN)
const slackClient = new WebClient(process.env.SLACK_TOKEN)
const { owner, repo } = context.repo
const oneMonthAgo = getOneMonthAgoDate()
const { data } = await octoClient.rest.search.issuesAndPullRequests({
per_page: 15,
q: `repo:${owner}/${repo} is:issue is:open created:>=${oneMonthAgo} sort:reactions-+1-desc`,
})
if (data.items.length > 0) {
await slackClient.chat.postMessage({
blocks: generateBlocks(data.items),
channel: '#next-js-repo-udpates',
icon_emoji: ':github:',
username: 'GitHub',
})
info(`Posted to Slack!`)
}
info(`No popular issues`)
} catch (error) {
setFailed(error)
}
}
run()
This diff is collapsed.
{
"private": true,
"description": "Notify Next.js team about pending PRs",
"exports": "./index.mjs",
"files": [
"src"
],
"scripts": {
"build": "ncc build src/index.mjs -m -o dist --license licenses.txt"
},
"devDependencies": {
"@vercel/ncc": "0.34.0"
},
"dependencies": {
"@actions/core": "1.10.0",
"@actions/github": "5.1.1",
"@slack/web-api": "^6.9.0"
}
}
This diff is collapsed.
name: Notify about the top 15 issues (most reacted) in the last month
on:
schedule:
- cron: '0 13 * * 1' # Every Monday at 1PM UTC (9AM EST)
workflow_dispatch:
jobs:
pr-approved-open:
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: corepack enable
- name: 'Send notification to Slack'
run: node ./.github/actions/next-repo-info/dist-issues/index.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
...@@ -16,7 +16,7 @@ jobs: ...@@ -16,7 +16,7 @@ jobs:
node-version: 18 node-version: 18
- run: corepack enable - run: corepack enable
- name: 'Send notification to Slack' - name: 'Send notification to Slack'
run: node ./.github/actions/pr-approved-open/dist/index.mjs run: node ./.github/actions/next-repo-info/dist-pr/index.mjs
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
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