Skip to content

Commit b9e0e21

Browse files
ci: add Slack notification for merged PRs
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 15db569 commit b9e0e21

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: PR Merge Slack Notifier
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
7+
8+
jobs:
9+
notify:
10+
if: github.event.pull_request.merged == true
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Send Slack notification
14+
env:
15+
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
16+
PR_URL: ${{ github.event.pull_request.html_url }}
17+
PR_TITLE: ${{ github.event.pull_request.title }}
18+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
19+
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
20+
run: |
21+
if [ -z "${WEBHOOK_URL}" ]; then
22+
echo "Slack webhook URL not provided." >&2
23+
exit 1
24+
fi
25+
26+
if ! command -v jq >/dev/null 2>&1; then
27+
echo "jq is required but not available" >&2
28+
exit 1
29+
fi
30+
31+
SHORT_SHA="${MERGE_SHA:0:7}"
32+
33+
payload=$(jq -n \
34+
--arg url "$PR_URL" \
35+
--arg title "$PR_TITLE" \
36+
--arg author "$PR_AUTHOR" \
37+
--arg sha "$SHORT_SHA" \
38+
'{
39+
text: ("PR merged: " + $title),
40+
unfurl_links: false,
41+
unfurl_media: false,
42+
blocks: [
43+
{
44+
type: "section",
45+
text: {
46+
type: "mrkdwn",
47+
text: ("*<" + $url + "|" + $title + ">*\nMerged by " + $author + " • `" + $sha + "`")
48+
}
49+
}
50+
]
51+
}')
52+
53+
curl -X POST -H 'Content-type: application/json' --data "$payload" "$WEBHOOK_URL"

0 commit comments

Comments
 (0)