Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Last active April 19, 2018 14:52
Show Gist options
  • Save dgoguerra/b0efe48f7d3168481180a238b7f909ef to your computer and use it in GitHub Desktop.
Save dgoguerra/b0efe48f7d3168481180a238b7f909ef to your computer and use it in GitHub Desktop.
slack deploy info webhook
SITE=domain.com
GITHUB_REPO=owner/repo
BRANCH=$(git symbolic-ref --short HEAD)
COMMIT_SHA=$(git log --pretty="%h" -n1 HEAD)
COMMIT_URL=https://github.com/$GITHUB_REPO/commit/$SHA
COMMIT_MSG=$(git log --format=%B -n 1)
COMMIT_TITLE=$(git log --format='Commit %h by %an %ar' -n 1)
GITHUB_REPO_URL=https://github.com/$GITHUB_REPO
GITHUB_COMMIT_URL=https://github.com/$GITHUB_REPO/commits/$COMMIT_SHA
TEXT="Deployed <$GITHUB_COMMIT_URL|$BRANCH> of <$GITHUB_REPO_URL|$GITHUB_REPO> on $SITE"
PAYLOAD='{
"text": "'$TEXT'",
"attachments": [
{
"fallback": "'$COMMIT_TITLE'",
"color": "#2d9ee0",
"fields": [
{
"title": "'$COMMIT_TITLE'",
"value": "'$COMMIT_MSG'",
"short": false
}
]
}
]
}'
curl -X POST --data-urlencode 'payload='"$PAYLOAD" https://hooks.slack.com/services/TOKEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment