Skip to content

Commit 705d091

Browse files
authored
feat: adds link to ci run (#59)
1 parent e64afea commit 705d091

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/utils/githubCIUtils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Formats GitHub CI information as a markdown link for notifications
3+
* Returns undefined if not running in GitHub Actions
4+
*/
5+
export const formatGitHubCIInfo = (): string | undefined => {
6+
const repository = process.env.GITHUB_REPOSITORY
7+
const runId = process.env.GITHUB_RUN_ID
8+
9+
if (!repository || !runId) {
10+
return undefined
11+
}
12+
13+
const runUrl = `https://github.com/${repository}/actions/runs/${runId}`
14+
return `[Message Source](${runUrl})`
15+
}
16+
17+
/**
18+
* Checks if the current environment is GitHub Actions
19+
*/
20+
export const isGitHubActions = (): boolean => {
21+
return !!(process.env.GITHUB_REPOSITORY && process.env.GITHUB_RUN_ID)
22+
}

packages/utils/postSlackMessage.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { WebClient } from '@slack/web-api'
22
import { sanitizeSlackMessage } from './sanitizeSlackMessage'
3+
import { formatGitHubCIInfo } from './githubCIUtils'
34

45
export const postSlackMessage = ({
56
slackToken,
@@ -12,10 +13,14 @@ export const postSlackMessage = ({
1213
}) => {
1314
const web = new WebClient(slackToken)
1415

15-
console.log(`>>> Posting message to Slack -> ${message}`)
16+
// Append GitHub CI run information if available
17+
const ciInfo = formatGitHubCIInfo()
18+
const messageWithCIInfo = ciInfo ? `${message}\n\n${ciInfo}` : message
19+
20+
console.log(`>>> Posting message to Slack -> ${messageWithCIInfo}`)
1621

1722
return web.chat.postMessage({
18-
text: sanitizeSlackMessage(message),
23+
text: sanitizeSlackMessage(messageWithCIInfo),
1924
channel: slackChannel,
2025
unfurl_links: false,
2126
})

0 commit comments

Comments
 (0)