generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsend-release-notification.ts
50 lines (44 loc) · 1.18 KB
/
send-release-notification.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type {Block, DividerBlock, HeaderBlock, SectionBlock} from '@slack/types'
import type {OauthV2AccessResponse} from '@slack/web-api/dist/response'
import axios from 'axios'
import {markdownToBlocks} from '@instantish/mack'
interface Repository {
repo: string
owner: string
}
interface Release {
html_url: string
name: string
body: string
}
interface SendReleaseParameters {
slackWebhookUrl: string
release: Release
repo: Repository
}
export async function sendReleaseNotification({
slackWebhookUrl,
release,
repo
}: SendReleaseParameters): Promise<OauthV2AccessResponse> {
const introBlock: HeaderBlock = {
type: 'header',
text: {
type: 'plain_text',
text: `🎉 New Release: ${release.name}`
}
}
const linkBlock: SectionBlock = {
type: 'section',
text: {
type: 'mrkdwn',
text: `<${release.html_url}>`
}
}
const dividerBlock: DividerBlock = {type: 'divider'}
const bodyBlocks: Block[] = await markdownToBlocks(release.body)
return await axios.post(slackWebhookUrl, {
text: `${release.name} has been released in ${repo.owner}/${repo.repo}`,
blocks: [introBlock, linkBlock, dividerBlock, ...bodyBlocks]
})
}