-
Notifications
You must be signed in to change notification settings - Fork 11
65 lines (57 loc) · 2.4 KB
/
Copy pathpr-notifications.yml
File metadata and controls
65 lines (57 loc) · 2.4 KB
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
name: Pull Request Notifications
on:
pull_request:
branches:
- production
types: [ready_for_review]
jobs:
notify_slack:
runs-on: ubuntu-latest
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: "acf-ohs-ttahub--contractor-customer-team"
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- name: Get PR body
uses: actions/github-script@v7
id: get-body
with:
result-encoding: string
script: return context.payload.pull_request.body;
- name: Notify Slack when a PR to production is opened
run: |
echo "${{ steps.get-body.outputs.result }}" > pr_body.md
extract_section() {
awk -v section="$1" '
BEGIN {found=0}
$0 ~ section {found=1; next}
/^## / && found {exit}
found {print}
' pr_body.md | head -c 600
}
DESC=$(extract_section "^## Description of change")
TEST=$(extract_section "^## How to test")
ISSUES=$(extract_section "^## Issue")
PR_LINK="https://github.com/$GITHUB_REPOSITORY/pull/$PR_NUMBER"
JSON=$(jq -n \
--arg channel "$SLACK_CHANNEL" \
--arg pr_number "#$PR_NUMBER" \
--arg pr_link "$PR_LINK" \
--arg title "$PR_TITLE" \
--arg desc "> $(echo "$DESC" | sed 's/^/> /')" \
--arg issues "$(echo "$ISSUES" | sed 's/^/> /')" \
'{
channel: $channel,
blocks: [
{ type: "section", text: { type: "mrkdwn", text: ":rocket: A production PR <\($pr_link)|\($pr_number)> is now open!" } },
{ type: "section", text: { type: "mrkdwn", text: "*Title:*\n\($title)" } },
{ type: "section", text: { type: "mrkdwn", text: "*Description of change:*\n\($desc)" } },
{ type: "section", text: { type: "mrkdwn", text: "*Issues:*\n\($issues)" } },
{ type: "section", text: { type: "mrkdwn", text: ":link: <\($pr_link)|View PR on GitHub>" } }
]
}')
curl -X POST -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-H 'Content-type: application/json;charset=utf-8' \
--data "$JSON" https://slack.com/api/chat.postMessage