@@ -7,16 +7,35 @@ import { SlimIssue } from './types'
7
7
const DAYS_WINDOW = 7
8
8
const TRIAGE_LABEL = 'status: needs-triage'
9
9
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`
12
12
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`
15
19
} )
16
20
17
21
return text . trim ( )
18
22
}
19
23
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
+ }
20
39
export async function run ( ) {
21
40
try {
22
41
if ( ! process . env . GITHUB_TOKEN ) throw new TypeError ( 'GITHUB_TOKEN not set' )
@@ -37,11 +56,18 @@ export async function run() {
37
56
return
38
57
}
39
58
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 )
41
67
console . log ( messageText )
42
68
43
69
await slackClient . chat . postMessage ( {
44
- text : generateText ( data . items ) ,
70
+ text : messageText ,
45
71
channel : process . env . DEBUG === 'true' ? '#test-slack-notifications' : '#dev-feed' ,
46
72
icon_emoji : ':github:' ,
47
73
username : 'GitHub Notifier' ,
0 commit comments