Skip to content

Instantly share code, notes, and snippets.

@ifnull
Last active November 1, 2021 17:35
Show Gist options
  • Save ifnull/b83aadfc2996a9b217c0956b16624b97 to your computer and use it in GitHub Desktop.
Save ifnull/b83aadfc2996a9b217c0956b16624b97 to your computer and use it in GitHub Desktop.
Simple `git pull` Deployment Slack Notification
#!/bin/sh
# WARNING: Putting your git repo in your web root can be dangerous.
SLACK_WEBHOOK_URL=$(git config --get hooks.slack.deploy-webhook-url)
SLACK_USERNAME="Git Deploy Bot (Develop)"
REPO_PATH="$(dirname ${BASH_SOURCE[0]})/.."
GIT_ORIG_HEAD=$(git rev-parse ORIG_HEAD | awk '{print $1}')
GIT_HEAD=$(git rev-parse HEAD | awk '{print $1}')
GIT_ORIG_HEAD_SHORT=${GIT_ORIG_HEAD:0:9}
GIT_HEAD_SHORT=${GIT_HEAD:0:9}
# Create message
GIT_MESSAGE="Deploy ($GIT_ORIG_HEAD_SHORT..$GIT_HEAD_SHORT):\n"
GIT_MESSAGE+=\`\`\`"$(git log --pretty=format:'%h %cr %cn %Cgreen%s%Creset' ORIG_HEAD..HEAD)"\`\`\`
# Send to Slack
curl -s -X POST --data "payload={ \"username\": \"${SLACK_USERNAME}\", \"text\": \"${GIT_MESSAGE}\"}" ${SLACK_WEBHOOK_URL} > /dev/null
# Create an Incoming Webhooks intengration here to get a webhook URL: https://***.slack.com/apps/manage/custom-integrations
git config hooks.slack.deploy-webhook-url 'https://hooks.slack.com/services/*****/*****/*****'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment