Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/utils/githubCIUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Formats GitHub CI information as a markdown link for notifications
* Returns undefined if not running in GitHub Actions
*/
export const formatGitHubCIInfo = (): string | undefined => {
const repository = process.env.GITHUB_REPOSITORY
const runId = process.env.GITHUB_RUN_ID

if (!repository || !runId) {
return undefined
}

const runUrl = `https://github.com/${repository}/actions/runs/${runId}`
return `[Message Source](${runUrl})`
}

/**
* Checks if the current environment is GitHub Actions
*/
export const isGitHubActions = (): boolean => {
return !!(process.env.GITHUB_REPOSITORY && process.env.GITHUB_RUN_ID)
}
9 changes: 7 additions & 2 deletions packages/utils/postSlackMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WebClient } from '@slack/web-api'
import { sanitizeSlackMessage } from './sanitizeSlackMessage'
import { formatGitHubCIInfo } from './githubCIUtils'

export const postSlackMessage = ({
slackToken,
Expand All @@ -12,10 +13,14 @@ export const postSlackMessage = ({
}) => {
const web = new WebClient(slackToken)

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

console.log(`>>> Posting message to Slack -> ${messageWithCIInfo}`)

return web.chat.postMessage({
text: sanitizeSlackMessage(message),
text: sanitizeSlackMessage(messageWithCIInfo),
channel: slackChannel,
unfurl_links: false,
})
Expand Down