-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (86 loc) · 3.1 KB
/
pr-notifier.yml
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Post PR to Slack
on:
pull_request:
types:
- opened
- converted_to_draft
- ready_for_review
- reopened
- closed
pull_request_review:
types:
- submitted
env:
CONFIG: |
{
"opened": {
"icon": "${{ github.event.pull_request.draft && '📝' || '🆕' }}",
"status": "${{ github.event.pull_request.draft && 'opened as draft' || 'opened' }}"
},
"converted_to_draft": {
"icon": "📝",
"status": "converted to draft"
},
"ready_for_review": {
"icon": "👀",
"status": "ready for review"
},
"reopened": {
"icon": "🔄",
"status": "reopened"
},
"submitted": {
"icon": "${{ github.event.review.state == 'approved' && '✅' || '💬' }}",
"status": "${{ github.event.review.state == 'approved' && 'code review approved' || 'code review comments' }}"
},
"closed": {
"icon": "${{ github.event.pull_request.merged && '🚀' || '🗑️' }}",
"status": "${{ github.event.pull_request.merged && 'merged' || 'closed' }}"
}
}
jobs:
notify:
name: Slack notify
runs-on: ubuntu-24.04
if: ${{ !contains(github.event.pull_request.head.ref || github.head_ref || github.ref, 'dependabot/') }}
steps:
- name: Build Slack JSON
uses: actions/github-script@v7
id: payload
if: github.event.action != 'submitted' || github.event.review.state == 'approved'
env:
ACTION_ICON: ${{ fromJSON(env.CONFIG)[github.event.action].icon }}
ACTION_STATUS: ${{ fromJSON(env.CONFIG)[github.event.action].status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const title = ${{ toJson(github.event.pull_request.title) }}
const username = ${{ toJson(github.event.pull_request.user.login) }}
const profileUrl = ${{ toJson(github.event.pull_request.user.html_url) }}
const { pull_request } = context.payload
const { owner, repo } = context.repo
// Format as Slack mrkdwn
const titleFormatted = `<${pull_request.html_url}|*${title}* #${pull_request.number}>`
const profileFormatted = `<${profileUrl}|@${username}>`
// Payload output is JSON encoded
return {
channel: '${{ vars.SLACK_CHANNEL_ID }}',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `${owner}/*${repo}*: ${titleFormatted} by ${profileFormatted} ${{ env.ACTION_ICON }} ${{ env.ACTION_STATUS }}`
}
}
],
unfurl_links: false,
unfurl_media: false
}
- name: Post to Slack
uses: slackapi/[email protected]
if: github.event.action != 'submitted' || github.event.review.state == 'approved'
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: ${{ steps.payload.outputs.result }}