Skip to content

Commit bbff65c

Browse files
authored
ci: add linked PRs to new issue notifications (#14059)
New issues message will now show if the issue has a linked PR.
1 parent c8661da commit bbff65c

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

.github/actions/activity/dist/new-issues/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/activity/src/new-issues.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,35 @@ import { SlimIssue } from './types'
77
const DAYS_WINDOW = 7
88
const 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+
}
2039
export 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

Comments
 (0)