Unverified Commit 9c362864 authored by Sam Ko's avatar Sam Ko Committed by GitHub

Upgrade popular-issues and popular-prs workflows (#63436)

## Changes

- Add links to source code
- Add creation dates for issues and PRs

Closes NEXT-2850
parent a7527a1a
// format date to <month|short> <day|numeric>, <year|numeric>
export function formattedDate(createdAt) {
const date = new Date(createdAt)
return date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
})
}
// Get the date 90 days ago (YYYY-MM-DD)
export function ninetyDaysAgo() {
const date = new Date()
date.setDate(date.getDate() - 90)
return date.toISOString().split('T')[0]
}
// @ts-check // @ts-check
import { context, getOctokit } from '@actions/github' import { context, getOctokit } from '@actions/github'
import { setFailed, info } from '@actions/core' import { info, setFailed } from '@actions/core'
import { WebClient } from '@slack/web-api' import { WebClient } from '@slack/web-api'
import { formattedDate, ninetyDaysAgo } from '../lib/util.mjs'
function generateBlocks(issues) { function generateBlocks(issues) {
const blocks = [ const blocks = [
...@@ -9,7 +10,7 @@ function generateBlocks(issues) { ...@@ -9,7 +10,7 @@ function generateBlocks(issues) {
type: 'section', type: 'section',
text: { text: {
type: 'mrkdwn', type: 'mrkdwn',
text: '*A list of the top 15 issues sorted by most :+1: reactions over the last 90 days.*\n_Note: This :github2: workflow will run every Monday at 1PM UTC (9AM EST)._', text: '*A list of the top 15 issues sorted by most :+1: reactions over the last 90 days.*\n_Note: This :github2: <https://github.com/vercel/next.js/blob/canary/.github/workflows/issue_popular.yml|workflow> → <https://github.com/vercel/next.js/blob/canary/.github/actions/next-repo-info/src/popular-issues.mjs|action> will run every Monday at 1PM UTC (9AM EST)._',
}, },
}, },
{ {
...@@ -18,10 +19,11 @@ function generateBlocks(issues) { ...@@ -18,10 +19,11 @@ function generateBlocks(issues) {
] ]
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` }, ${formattedDate(issue.created_at)}]: ${issue.title}\n`
}) })
blocks.push({ blocks.push({
...@@ -43,16 +45,11 @@ async function run() { ...@@ -43,16 +45,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)
// 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',
per_page: 15, per_page: 15,
q: `repo:${owner}/${repo} is:issue is:open created:>=${ninetyDaysAgo}`, q: `repo:${owner}/${repo} is:issue is:open created:>=${ninetyDaysAgo()}`,
sort: 'reactions-+1', sort: 'reactions-+1',
}) })
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { context, getOctokit } from '@actions/github' 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'
import { formattedDate, ninetyDaysAgo } from '../lib/util.mjs'
function generateBlocks(prs) { function generateBlocks(prs) {
let text = '' let text = ''
...@@ -17,7 +18,7 @@ function generateBlocks(prs) { ...@@ -17,7 +18,7 @@ function generateBlocks(prs) {
if (pr.reactions['+1'] > 1) { if (pr.reactions['+1'] > 1) {
text += `${i + 1}. [<${pr.html_url}|#${pr.number}>, :+1: ${ text += `${i + 1}. [<${pr.html_url}|#${pr.number}>, :+1: ${
pr.reactions['+1'] pr.reactions['+1']
}]: ${pr.title}\n` }, ${formattedDate(pr.created_at)}]: ${pr.title}\n`
count++ count++
} }
}) })
...@@ -26,7 +27,7 @@ function generateBlocks(prs) { ...@@ -26,7 +27,7 @@ function generateBlocks(prs) {
type: 'section', type: 'section',
text: { text: {
type: 'mrkdwn', type: 'mrkdwn',
text: `*A list of the top ${count} PRs sorted by most :+1: reactions (> 1) over the last 90 days.*\n_Note: This :github2: workflow will run every Monday at 1PM UTC (9AM EST)._`, text: `*A list of the top ${count} PRs sorted by most :+1: reactions (> 1) over the last 90 days.*\n_Note: This :github2: <https://github.com/vercel/next.js/blob/canary/.github/workflows/pull_request_popular.yml|workflow> → <https://github.com/vercel/next.js/blob/canary/.github/actions/next-repo-info/src/popular-prs.mjs|action> will run every Monday at 1PM UTC (9AM EST)._`,
}, },
}) })
...@@ -49,16 +50,11 @@ async function run() { ...@@ -49,16 +50,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)
// 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',
per_page: 15, per_page: 15,
q: `repo:${owner}/${repo} is:pr is:open created:>=${ninetyDaysAgo}`, q: `repo:${owner}/${repo} is:pr is:open created:>=${ninetyDaysAgo()}`,
sort: 'reactions-+1', sort: 'reactions-+1',
}) })
......
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