Skip to content

Commit 9d57c4d

Browse files
bfopsjdetter
andauthored
CI - Ping PR author directly if checks fail (#3671)
# Description of Changes When a merged PR fails checks, ping the PR author as well. # API and ABI breaking changes None. CI only. # Expected complexity level and risk 2 # Testing Demo message (not on an actual PR merge): <img width="508" height="202" alt="image" src="https://github.com/user-attachments/assets/69c16cf8-cad3-4744-8054-ea2b2d74cee0" /> --------- Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent ee69be7 commit 9d57c4d

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

.github/workflows/discord-posts.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
PR_NUMBER: ${{ github.event.pull_request.number }}
2828
PR_URL: ${{ github.event.pull_request.html_url }}
2929
MENTION_ON_FAILURE: ${{ secrets.DEV_OPS_ROLE_ID }}
30+
DISCORD_USER_MAP: ${{ secrets.DISCORD_USER_MAP }}
3031
run: |
3132
message="PR merged: [(#${PR_NUMBER}) ${PR_TITLE}](<${PR_URL}>)"
3233
# Note that anything besides success is treated as a failure (e.g. if the check did not run at all, or if it is still pending).
@@ -39,6 +40,18 @@ jobs:
3940
' |
4041
jq -r '"\(.workflow) / \(.name): \(.state)"'
4142
)"
43+
44+
# Lookup PR author's Discord ID from the provided JSON map (if any)
45+
author_discord_id="$(
46+
jq -r \
47+
--arg u "${{ github.event.pull_request.user.login }}" \
48+
'try .[$u] catch empty' \
49+
<<<"${DISCORD_USER_MAP}"
50+
)"
51+
if [ -z "${author_discord_id}" ]; then
52+
echo "Warning: PR author not found not found in USER_LOOKUP_JSON"
53+
fi
54+
4255
message+=$'\n'
4356
if [[ -z "${FAILED_CHECKS}" ]]; then
4457
message+='All checks passed.'
@@ -47,7 +60,11 @@ jobs:
4760
message+=$'\n'
4861
# This uses special Discord syntax for pinging a particular role.
4962
# Note the '&' - this is the difference between pinging a *role* and pinging a *person*.
50-
message+=" (cc <@&${MENTION_ON_FAILURE}>)"
63+
message+=" (cc <@&${MENTION_ON_FAILURE}>"
64+
if [[ -n "${author_discord_id}" ]]; then
65+
message+=" <@${author_discord_id}>"
66+
fi
67+
message+=")"
5168
fi
5269
# Use `jq` to construct the json data blob in the format required by the webhook.
5370
data="$(jq --null-input --arg msg "$message" '.content=$msg')"

0 commit comments

Comments
 (0)