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

chore: update next-repo-info actions (#60559)

## Description
A few changes to
https://github.com/vercel/next.js/tree/canary/.github/actions/next-repo-info
and related workflows.

## Changes
- Update `generateBlocks()` function
- Fix Slack channel title typo
- Fix `issuesAndPullRequests({ ... })` API call


Closes NEXT-2077
parent bb105ef4
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,9 +2,8 @@
"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"
"build-issues": "ncc build src/popular-issues.mjs -m -o dist/issues --license licenses.txt",
"build-prs": "ncc build src/pr-approved.mjs -m -o dist/prs --license licenses.txt"
},
"dependencies": {
"@actions/core": "^1.10.1",
......
......@@ -12,17 +12,27 @@ function getOneMonthAgoDate() {
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}`,
text: 'A list of the top 15 issues sorted by most :+1: reactions over the last 30 days.*\n_Note: This :github: workflow will run every Monday at 1PM UTC (9AM EST)._',
},
})
},
{
type: 'divider',
},
]
let text = ''
issues.forEach((issue) => {
text += `• <${issue.html_url}|#${issue.number}>: ${issue.title}\n`
})
blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: text,
},
})
return blocks
}
......@@ -35,25 +45,27 @@ async function run() {
const octoClient = getOctokit(process.env.GITHUB_TOKEN)
const slackClient = new WebClient(process.env.SLACK_TOKEN)
const { owner, repo } = context.repo
const oneMonthAgo = getOneMonthAgoDate()
const { owner, repo } = context.repo
const { data } = await octoClient.rest.search.issuesAndPullRequests({
order: 'desc',
per_page: 15,
q: `repo:${owner}/${repo} is:issue is:open created:>=${oneMonthAgo} sort:reactions-+1-desc`,
q: `repo:${owner}/${repo} is:issue is:open created:>=${oneMonthAgo}`,
sort: 'reactions-+1',
})
if (data.items.length > 0) {
await slackClient.chat.postMessage({
blocks: generateBlocks(data.items),
channel: '#next-js-repo-udpates',
channel: '#next-js-repo-updates',
icon_emoji: ':github:',
username: 'GitHub',
username: 'GitHub Notifier',
})
info(`Posted to Slack!`)
} else {
info(`No popular issues`)
}
info(`No popular issues`)
} catch (error) {
setFailed(error)
}
......
......@@ -12,18 +12,18 @@ async function run() {
const slackClient = new WebClient(process.env.SLACK_TOKEN)
const { owner, repo } = context.repo
const prs = await octoClient.rest.search.issuesAndPullRequests({
const { data } = await octoClient.rest.search.issuesAndPullRequests({
q: `repo:${owner}/${repo}+is:pr+is:open+review:approved -is:draft`,
})
const pendingPRs = prs.data.total_count
const pendingPRs = data.total_count
if (pendingPRs) {
await slackClient.chat.postMessage({
channel: '#next-js-repo-udpates',
text: `Pending PRs for Next.js: There are <https://github.com/vercel/next.js/pulls?q=is%3Apr+is%3Aopen+review%3Aapproved+-is%3Adraft|${prs.data.items.length} PRs> awaiting merge.`,
username: 'GitHub',
channel: '#next-js-repo-updates',
icon_emoji: ':github:',
text: `Pending PRs for Next.js: There are <https://github.com/vercel/next.js/pulls?q=is%3Apr+is%3Aopen+review%3Aapproved+-is%3Adraft|${prs.data.items.length} PRs> awaiting merge.`,
username: 'Github Notifier',
})
info(`Posted to Slack: ${pendingPRs} pending PRs`)
......
......@@ -6,7 +6,7 @@ on:
workflow_dispatch:
jobs:
pr-approved-open:
popular-issues:
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
steps:
......@@ -16,7 +16,7 @@ jobs:
node-version: 18
- run: corepack enable
- name: 'Send notification to Slack'
run: node ./.github/actions/next-repo-info/dist-issues/index.mjs
run: node ./.github/actions/next-repo-info/dist/issues/index.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
......@@ -6,7 +6,7 @@ on:
workflow_dispatch:
jobs:
pr-approved-open:
pr-approved:
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
steps:
......@@ -16,7 +16,7 @@ jobs:
node-version: 18
- run: corepack enable
- name: 'Send notification to Slack'
run: node ./.github/actions/next-repo-info/dist-pr/index.mjs
run: node ./.github/actions/next-repo-info/dist/prs/index.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_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