@@ -7,16 +7,35 @@ import { SlimIssue } from './types'
77const DAYS_WINDOW = 7
88const TRIAGE_LABEL = 'status: needs-triage'
99
10- function generateText ( issues : SlimIssue [ ] ) {
11- let text = `*A list of issues opened in the last ${ DAYS_WINDOW } with \`status: needs-triage\`:*\n\n`
10+ function generateText ( issues : { issue : SlimIssue ; linkedPRUrl ?: string } [ ] ) {
11+ let text = `*A list of issues opened in the last ${ DAYS_WINDOW } days with \`status: needs-triage\`:*\n\n`
1212
13- issues . forEach ( ( issue ) => {
14- text += `• ${ issue . title } - (<${ issue . html_url } |#${ issue . number } >)\n`
13+ issues . forEach ( ( { issue, linkedPRUrl } ) => {
14+ text += `• ${ issue . title } - (<${ issue . html_url } |#${ issue . number } >)`
15+ if ( linkedPRUrl ) {
16+ text += ` - <${ linkedPRUrl } |:link: Linked PR>`
17+ }
18+ text += `\n`
1519 } )
1620
1721 return text . trim ( )
1822}
1923
24+ async function getLinkedPRUrl (
25+ octoClient : ReturnType < typeof getOctokit > ,
26+ issue : SlimIssue ,
27+ ) : Promise < string | undefined > {
28+ const { data : events } = await octoClient . rest . issues . listEventsForTimeline ( {
29+ owner : 'payloadcms' ,
30+ repo : 'payload' ,
31+ issue_number : issue . number ,
32+ } )
33+
34+ const crossReferencedEvent = events . find (
35+ ( event ) => event . event === 'cross-referenced' && event . source ?. issue ?. pull_request ,
36+ )
37+ return crossReferencedEvent ?. source ?. issue ?. html_url
38+ }
2039export async function run ( ) {
2140 try {
2241 if ( ! process . env . GITHUB_TOKEN ) throw new TypeError ( 'GITHUB_TOKEN not set' )
@@ -37,11 +56,18 @@ export async function run() {
3756 return
3857 }
3958
40- const messageText = generateText ( data . items )
59+ const issuesWithLinkedPRs = await Promise . all (
60+ data . items . map ( async ( issue ) => {
61+ const linkedPRUrl = await getLinkedPRUrl ( octoClient , issue )
62+ return { issue, linkedPRUrl }
63+ } ) ,
64+ )
65+
66+ const messageText = generateText ( issuesWithLinkedPRs )
4167 console . log ( messageText )
4268
4369 await slackClient . chat . postMessage ( {
44- text : generateText ( data . items ) ,
70+ text : messageText ,
4571 channel : process . env . DEBUG === 'true' ? '#test-slack-notifications' : '#dev-feed' ,
4672 icon_emoji : ':github:' ,
4773 username : 'GitHub Notifier' ,
0 commit comments