1- import { context , getOctokit } from '@actions/github'
21import { info , setFailed } from '@actions/core'
2+ import { getOctokit } from '@actions/github'
33import { WebClient } from '@slack/web-api'
4- import { formattedDate , daysAgo } from './lib/utils'
4+ import { daysAgo } from './lib/utils'
55import { SlimIssue } from './types'
66
7- function generateBlocks ( issues : SlimIssue [ ] ) {
8- const blocks = [
9- {
10- type : 'section' ,
11- text : {
12- type : 'mrkdwn' ,
13- text : '*A list of the top 15 issues sorted by the most reactions over the last 30 days.' ,
14- } ,
15- } ,
16- {
17- type : 'divider' ,
18- } ,
19- ]
7+ const DAYS_WINDOW = 60
208
21- let text = ''
9+ function generateText ( issues : SlimIssue [ ] ) {
10+ let text = `*A list of the top 10 issues sorted by the most reactions over the last ${ DAYS_WINDOW } days:*\n\n`
2211
23- issues . forEach ( ( issue , i ) => {
24- text += `${ i + 1 } . [<${ issue . html_url } |#${ issue . number } >, ${
25- issue ?. reactions ?. total_count || 0
26- } reactions, ${ formattedDate ( issue . created_at ) } ]: ${ issue . title } \n`
27- } )
12+ // Format date as "X days ago"
13+ const formattedDaysAgo = ( dateString : string ) => {
14+ const date = new Date ( dateString )
15+ const now = new Date ( )
16+ const diffTime = Math . abs ( now . getTime ( ) - date . getTime ( ) )
17+ const diffDays = Math . ceil ( diffTime / ( 1000 * 60 * 60 * 24 ) )
18+ return `${ diffDays } day${ diffDays > 1 ? 's' : '' } ago`
19+ }
2820
29- blocks . push ( {
30- type : 'section' ,
31- text : {
32- type : 'mrkdwn' ,
33- text : text ,
34- } ,
21+ issues . forEach ( ( issue ) => {
22+ text += `• ${ issue ?. reactions ?. total_count || 0 } 👍 ${ issue . title } - <${ issue . html_url } |#${ issue . number } >, ${ formattedDaysAgo ( issue . created_at ) } \n`
3523 } )
3624
37- return blocks
25+ return text . trim ( )
3826}
3927
4028export async function run ( ) {
@@ -45,11 +33,10 @@ export async function run() {
4533 const octoClient = getOctokit ( process . env . GITHUB_TOKEN )
4634 const slackClient = new WebClient ( process . env . SLACK_TOKEN )
4735
48- const { owner, repo } = context . repo
4936 const { data } = await octoClient . rest . search . issuesAndPullRequests ( {
5037 order : 'desc' ,
51- per_page : 15 ,
52- q : `repo:${ owner } / ${ repo } is:issue is:open created:>=${ daysAgo ( 30 ) } ` ,
38+ per_page : 10 ,
39+ q : `repo:payloadcms/payload is:issue is:open created:>=${ daysAgo ( DAYS_WINDOW ) } ` ,
5340 sort : 'reactions' ,
5441 } )
5542
@@ -58,18 +45,12 @@ export async function run() {
5845 return
5946 }
6047
61- console . log (
62- data . items
63- . map (
64- ( i ) =>
65- `#${ i . number } : ${ i . title } , reactions: ${ i . reactions ?. total_count } - link: ${ i . html_url } ` ,
66- )
67- . join ( '\n' ) ,
68- )
48+ const messageText = generateText ( data . items )
49+ console . log ( messageText )
6950
7051 await slackClient . chat . postMessage ( {
71- blocks : generateBlocks ( data . items ) ,
72- channel : '#test-notifications ' ,
52+ text : messageText ,
53+ channel : '#dev-feed ' ,
7354 icon_emoji : ':github:' ,
7455 username : 'GitHub Notifier' ,
7556 } )
0 commit comments