Skip to content

Instantly share code, notes, and snippets.

@pataiji
Created February 2, 2015 05:19
Show Gist options
  • Save pataiji/eb1af598951eaee9da5e to your computer and use it in GitHub Desktop.
Save pataiji/eb1af598951eaee9da5e to your computer and use it in GitHub Desktop.
#!/bin/bash
to_ref='00000000000000000000000000'
channel='private-group'
username='stash'
text="*branch name* has new commits by *user name*"
icon=':stash:'
attachments=''
[[ $to_ref =~ ^0+$ ]] && continue
branch='master'
url="repo url"
to_ref_pref=`echo $to_ref | cut -c 1-10`
link=`printf '<%s/commits/%s|%s>' $url $to_ref $to_ref_pref`
message=`git log --format=%B -n 1 ${to_ref}`
title="[_${branch}_] ${link}: $message"
attachments="$attachments{
\"fallback\":\"$title\",
\"text\": \"$title\",
\"color\":\"#4083C4\",
\"mrkdwn_in\": [\"text\"]
},"
payload="payload={
\"channel\":\"$channel\",
\"username\":\"$username\",
\"text\":\"$text\",
\"icon_emoji\":\"$icon\",
\"attachments\":[${attachments%?}]
}
"
curl -X POST --data-urlencode "$payload" "incoming-webhook url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment