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

chore: add pull_request_popular workflow (#61760)

## Description

Add a GitHub Workflow that notifies us (internally) about the top 15
:pr:s (most reacted) in the last 90
days.

Closes NEXT-2387
parent 77ade436
...@@ -249,6 +249,30 @@ MIT ...@@ -249,6 +249,30 @@ MIT
@slack/web-api @slack/web-api
MIT MIT
MIT License
Copyright (c) 2014- Slack Technologies, LLC
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@vercel/ncc @vercel/ncc
MIT MIT
...@@ -663,27 +687,15 @@ SOFTWARE. ...@@ -663,27 +687,15 @@ SOFTWARE.
is-stream is-stream
MIT MIT
The MIT License (MIT) MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
mime-db mime-db
......
This diff is collapsed.
This diff is collapsed.
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
"private": true, "private": true,
"description": "Notify Next.js team about pending PRs and popular issues", "description": "Notify Next.js team about pending PRs and popular issues",
"scripts": { "scripts": {
"build-issues": "ncc build src/popular-issues.mjs -m -o dist/issues --license licenses.txt" "build": "pnpm build-issues && pnpm build-prs",
"build-issues": "ncc build src/popular-issues.mjs -m -o dist/issues --license licenses.txt",
"build-prs": "ncc build src/popular-prs.mjs -m -o dist/prs --license licenses.txt"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.10.1", "@actions/core": "^1.10.1",
"@actions/github": "6.0.0", "@actions/github": "6.0.0",
"@slack/web-api": "^6.11.2" "@slack/web-api": "^7.0.1"
}, },
"devDependencies": { "devDependencies": {
"@vercel/ncc": "^0.38.1" "@vercel/ncc": "^0.38.1"
......
...@@ -3,13 +3,6 @@ import { context, getOctokit } from '@actions/github' ...@@ -3,13 +3,6 @@ import { context, getOctokit } from '@actions/github'
import { setFailed, info } from '@actions/core' import { setFailed, info } from '@actions/core'
import { WebClient } from '@slack/web-api' import { WebClient } from '@slack/web-api'
// Get the date 90 days ago (YYYY-MM-DD)
function getNinetyDaysAgoDate() {
const date = new Date()
date.setDate(date.getDate() - 90)
return date.toISOString().split('T')[0]
}
function generateBlocks(issues) { function generateBlocks(issues) {
const blocks = [ const blocks = [
{ {
...@@ -23,12 +16,14 @@ function generateBlocks(issues) { ...@@ -23,12 +16,14 @@ function generateBlocks(issues) {
type: 'divider', type: 'divider',
}, },
] ]
let text = '' let text = ''
issues.forEach((issue, i) => { issues.forEach((issue, i) => {
text += `${i + 1}. [<${issue.html_url}|#${issue.number}>, :+1: ${ text += `${i + 1}. [<${issue.html_url}|#${issue.number}>, :+1: ${
issue.reactions['+1'] issue.reactions['+1']
}]: ${issue.title}\n` }]: ${issue.title}\n`
}) })
blocks.push({ blocks.push({
type: 'section', type: 'section',
text: { text: {
...@@ -36,6 +31,7 @@ function generateBlocks(issues) { ...@@ -36,6 +31,7 @@ function generateBlocks(issues) {
text: text, text: text,
}, },
}) })
return blocks return blocks
} }
...@@ -47,7 +43,11 @@ async function run() { ...@@ -47,7 +43,11 @@ async function run() {
const octoClient = getOctokit(process.env.GITHUB_TOKEN) const octoClient = getOctokit(process.env.GITHUB_TOKEN)
const slackClient = new WebClient(process.env.SLACK_TOKEN) const slackClient = new WebClient(process.env.SLACK_TOKEN)
const ninetyDaysAgo = getNinetyDaysAgoDate() // Get the date 90 days ago (YYYY-MM-DD)
const date = new Date()
date.setDate(date.getDate() - 90)
const ninetyDaysAgo = date.toISOString().split('T')[0]
const { owner, repo } = context.repo const { owner, repo } = context.repo
const { data } = await octoClient.rest.search.issuesAndPullRequests({ const { data } = await octoClient.rest.search.issuesAndPullRequests({
order: 'desc', order: 'desc',
......
// @ts-check
import { context, getOctokit } from '@actions/github'
import { setFailed, info } from '@actions/core'
import { WebClient } from '@slack/web-api'
function generateBlocks(prs) {
const blocks = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: '*A list of the top 15 PRs sorted by most :+1: reactions over the last 90 days.*\n_Note: This :github2: workflow will run every Monday at 1PM UTC (9AM EST)._',
},
},
{
type: 'divider',
},
]
let text = ''
prs.forEach((pr, i) => {
text += `${i + 1}. [<${pr.html_url}|#${pr.number}>, :+1: ${
pr.reactions['+1']
}]: ${pr.title}\n`
})
blocks.push({
type: 'section',
text: {
type: 'mrkdwn',
text: text,
},
})
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)
// Get the date 90 days ago (YYYY-MM-DD)
const date = new Date()
date.setDate(date.getDate() - 90)
const ninetyDaysAgo = date.toISOString().split('T')[0]
const { owner, repo } = context.repo
const { data } = await octoClient.rest.search.issuesAndPullRequests({
order: 'desc',
per_page: 15,
q: `repo:${owner}/${repo} is:pr is:open created:>=${ninetyDaysAgo}`,
sort: 'reactions-+1',
})
if (data.items.length > 0) {
await slackClient.chat.postMessage({
blocks: generateBlocks(data.items),
channel: '#team-next-js',
icon_emoji: ':github:',
username: 'GitHub Notifier',
})
info(`Posted to Slack!`)
} else {
info(`No popular PRs`)
}
} catch (error) {
setFailed(error)
}
}
run()
...@@ -65,8 +65,8 @@ importers: ...@@ -65,8 +65,8 @@ importers:
specifier: 6.0.0 specifier: 6.0.0
version: 6.0.0 version: 6.0.0
'@slack/web-api': '@slack/web-api':
specifier: ^6.11.2 specifier: ^7.0.1
version: 6.11.2 version: 7.0.1
devDependencies: devDependencies:
'@vercel/ncc': '@vercel/ncc':
specifier: ^0.38.1 specifier: ^0.38.1
...@@ -398,9 +398,9 @@ packages: ...@@ -398,9 +398,9 @@ packages:
'@octokit/openapi-types': 12.11.0 '@octokit/openapi-types': 12.11.0
dev: false dev: false
/@slack/logger@3.0.0: /@slack/logger@4.0.0:
resolution: {integrity: sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==} resolution: {integrity: sha512-Wz7QYfPAlG/DR+DfABddUZeNgoeY7d1J39OCR2jR+v7VBsB8ezulDK5szTnDDPDwLH5IWhLvXIHlCFZV7MSKgA==}
engines: {node: '>= 12.13.0', npm: '>= 6.12.0'} engines: {node: '>= 18', npm: '>= 8.6.0'}
dependencies: dependencies:
'@types/node': 18.16.19 '@types/node': 18.16.19
dev: false dev: false
...@@ -410,21 +410,21 @@ packages: ...@@ -410,21 +410,21 @@ packages:
engines: {node: '>= 12.13.0', npm: '>= 6.12.0'} engines: {node: '>= 12.13.0', npm: '>= 6.12.0'}
dev: false dev: false
/@slack/web-api@6.11.2: /@slack/web-api@7.0.1:
resolution: {integrity: sha512-s4qCQGXasr8jpCf/+6+V/smq+Z2RX7EIBnJeO/xe7Luie1nyBihFMgjICNyvzWoWBdaGntSnn5CcZdFm4ItBWg==} resolution: {integrity: sha512-xXm3Eq7fDT5FQQlQH8tP4WzoyZXFMnbCSydFF5VZwi+LwIYIJ8yV5ujqvh5zE9XW15SPcPYb6cGEOOg1vAC65w==}
engines: {node: '>= 12.13.0', npm: '>= 6.12.0'} engines: {node: '>= 18', npm: '>= 8.6.0'}
dependencies: dependencies:
'@slack/logger': 3.0.0 '@slack/logger': 4.0.0
'@slack/types': 2.11.0 '@slack/types': 2.11.0
'@types/is-stream': 1.1.0
'@types/node': 18.16.19 '@types/node': 18.16.19
axios: 1.6.5 axios: 1.6.7
eventemitter3: 3.1.2 eventemitter3: 5.0.1
form-data: 2.5.1 form-data: 4.0.0
is-electron: 2.2.2 is-electron: 2.2.2
is-stream: 1.1.0 is-stream: 2.0.1
p-queue: 6.6.2 p-queue: 6.6.2
p-retry: 4.6.2 p-retry: 4.6.2
retry: 0.13.1
transitivePeerDependencies: transitivePeerDependencies:
- debug - debug
dev: false dev: false
...@@ -433,12 +433,6 @@ packages: ...@@ -433,12 +433,6 @@ packages:
resolution: {integrity: sha512-J/rMZa7RqiH/rT29TEVZO4nBoDP9XJOjnbbIofg7GQKs4JIduEO3WLpte+6WeUz/TcrXKlY+bM7FYrp8yFB+3g==} resolution: {integrity: sha512-J/rMZa7RqiH/rT29TEVZO4nBoDP9XJOjnbbIofg7GQKs4JIduEO3WLpte+6WeUz/TcrXKlY+bM7FYrp8yFB+3g==}
dev: true dev: true
/@types/is-stream@1.1.0:
resolution: {integrity: sha512-jkZatu4QVbR60mpIzjINmtS1ZF4a/FqdTUTBeQDVOQ2PYyidtwFKr0B5G6ERukKwliq+7mIXvxyppwzG5EgRYg==}
dependencies:
'@types/node': 18.16.19
dev: false
/@types/node@18.16.19: /@types/node@18.16.19:
resolution: {integrity: sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==} resolution: {integrity: sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==}
...@@ -497,10 +491,10 @@ packages: ...@@ -497,10 +491,10 @@ packages:
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
dev: false dev: false
/axios@1.6.5: /axios@1.6.7:
resolution: {integrity: sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==} resolution: {integrity: sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==}
dependencies: dependencies:
follow-redirects: 1.15.4 follow-redirects: 1.15.5
form-data: 4.0.0 form-data: 4.0.0
proxy-from-env: 1.1.0 proxy-from-env: 1.1.0
transitivePeerDependencies: transitivePeerDependencies:
...@@ -611,14 +605,14 @@ packages: ...@@ -611,14 +605,14 @@ packages:
hasBin: true hasBin: true
dev: false dev: false
/eventemitter3@3.1.2:
resolution: {integrity: sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==}
dev: false
/eventemitter3@4.0.7: /eventemitter3@4.0.7:
resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==}
dev: false dev: false
/eventemitter3@5.0.1:
resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==}
dev: false
/execa@2.0.3: /execa@2.0.3:
resolution: {integrity: sha512-iM124nlyGSrXmuyZF1EMe83ESY2chIYVyDRZKgmcDynid2Q2v/+GuE7gNMl6Sy9Niwf4MC0DDxagOxeMPjuLsw==} resolution: {integrity: sha512-iM124nlyGSrXmuyZF1EMe83ESY2chIYVyDRZKgmcDynid2Q2v/+GuE7gNMl6Sy9Niwf4MC0DDxagOxeMPjuLsw==}
engines: {node: ^8.12.0 || >=9.7.0} engines: {node: ^8.12.0 || >=9.7.0}
...@@ -645,8 +639,8 @@ packages: ...@@ -645,8 +639,8 @@ packages:
resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==}
dev: false dev: false
/follow-redirects@1.15.4: /follow-redirects@1.15.5:
resolution: {integrity: sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==} resolution: {integrity: sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==}
engines: {node: '>=4.0'} engines: {node: '>=4.0'}
peerDependencies: peerDependencies:
debug: '*' debug: '*'
...@@ -655,15 +649,6 @@ packages: ...@@ -655,15 +649,6 @@ packages:
optional: true optional: true
dev: false dev: false
/form-data@2.5.1:
resolution: {integrity: sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==}
engines: {node: '>= 0.12'}
dependencies:
asynckit: 0.4.0
combined-stream: 1.0.8
mime-types: 2.1.35
dev: false
/form-data@4.0.0: /form-data@4.0.0:
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
engines: {node: '>= 6'} engines: {node: '>= 6'}
...@@ -843,11 +828,6 @@ packages: ...@@ -843,11 +828,6 @@ packages:
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
dev: false dev: false
/is-stream@1.1.0:
resolution: {integrity: sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==}
engines: {node: '>=0.10.0'}
dev: false
/is-stream@2.0.1: /is-stream@2.0.1:
resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==}
engines: {node: '>=8'} engines: {node: '>=8'}
......
name: Notify about the top 15 issues (most reacted) in the last month name: Notify about the top 15 issues (most reacted) in the last 90 days
on: on:
schedule: schedule:
......
name: Notify about the top 15 PRs (most reacted) in the last 90 days
on:
schedule:
- cron: '0 13 * * 1' # Every Monday at 1PM UTC (9AM EST)
workflow_dispatch:
jobs:
popular-issues:
if: github.repository_owner == 'vercel'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: corepack enable
- name: 'Send notification to Slack'
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