File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11import { WebClient } from '@slack/web-api'
22import { sanitizeSlackMessage } from './sanitizeSlackMessage'
3+ import { formatGitHubCIInfo } from './githubCIUtils'
34
45export 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 } )
You can’t perform that action at this time.
0 commit comments