Skip to content

Add B2C use-case docs for notification template management #231

Add B2C use-case docs for notification template management

Add B2C use-case docs for notification template management #231

name: "💬 PR Chat Notification"
# Uses pull_request_target (not pull_request) so the GOOGLE_CHAT_WEBHOOK secret is
# available for PRs opened from forks, which is exactly the case this workflow targets.
# Only PR metadata is read; PR code is never checked out or run.
on:
pull_request_target:
types: [opened, reopened]
jobs:
notify-google-chat:
if: |
!contains(format(',{0},', vars.PROJECT_MAINTAINERS), format(',{0},', github.actor))
runs-on: ubuntu-latest
steps:
- name: Send Notification to Google Chat
env:
GOOGLE_CHAT_WEBHOOK: ${{ secrets.GOOGLE_CHAT_WEBHOOK }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_CREATOR: ${{ github.event.pull_request.user.login }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_BASE: ${{ github.event.pull_request.base.ref }}
PR_ACTION: ${{ github.event.action }}
run: |
if [ -z "$GOOGLE_CHAT_WEBHOOK" ]; then
echo "GOOGLE_CHAT_WEBHOOK secret is not set. Skipping notification."
exit 1
fi
# Set header title based on the action (opened or reopened).
if [ "$PR_ACTION" = "reopened" ]; then
header_title="Github PR - Reopened"
else
header_title="Github PR - Opened"
fi
jq -n \
--arg title "$PR_TITLE" \
--arg creator "$PR_CREATOR" \
--arg url "$PR_URL" \
--arg base "$PR_BASE" \
--arg header "$header_title" \
'{
"cards": [{
"header": {
"title": $header,
"imageUrl": "https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/72x72/1f500.png",
"imageStyle": "AVATAR"
},
"sections": [{
"widgets": [
{
"keyValue": {
"topLabel": "Title",
"content": $title
}
},
{
"keyValue": {
"topLabel": "Target Branch",
"content": $base
}
},
{
"keyValue": {
"topLabel": "Created By",
"content": $creator
}
},
{
"buttons": [{
"textButton": {
"text": "VIEW PR",
"onClick": {
"openLink": {
"url": $url
}
}
}
}]
}
]
}]
}]
}' > payload.json
curl -X POST -H "Content-Type: application/json" \
-d @payload.json \
"$GOOGLE_CHAT_WEBHOOK"