Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update hook for git to push embed message to Discord webhook (with Gavatar Avatar support)
#!/bin/bash
# --- SETTINGS
webhookUrl="WEBHOOK_URL"
# ------------
refname=$1
oldrev=$2
newrev=$3
message=$(git log -1 --pretty=%B)
author=$(git log -1 --format='%an <%ae>')
authorMail=$(git log -1 --format='%ae')
mailToLower=$(echo "$authorMail" | tr '[:upper:]' '[:lower:]')
mailAsMD5=$(printf '%s' "$mailToLower" | md5sum | awk '{print $1}')
gavatarUrl="https://www.gravatar.com/avatar/$mailAsMD5"
curl $webhookUrl \
-X POST \
-H "Content-Type: application/json" \
-d \
'{
"avatar_url": "https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png",
"username": "git Notify",
"embeds": [
{
"color": 240116,
"author": {
"name": "'"$author"'",
"icon_url": "'$gavatarUrl'"
},
"title": "Git Update",
"fields": [
{"name": "old rev","value": "`'$oldrev'`"},
{"name": "new rev","value": "`'$newrev'`"},
{"name": "commit message","value": "'"$message"'"}
]
}
]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.