Skip to content

Instantly share code, notes, and snippets.

@kas-cor
Created May 7, 2018 18:29
Show Gist options
  • Save kas-cor/8a8a9f6f316361b96cee189ba6480642 to your computer and use it in GitHub Desktop.
Save kas-cor/8a8a9f6f316361b96cee189ba6480642 to your computer and use it in GitHub Desktop.
Git Hook udpate send notify to Slack channel use IFTTT WebHooks
#!/bin/bash
iftttkey=""
iftttevent=""
if [ "$3" = "0000000000000000000000000000000000000000" ]; then
type=delete
else
type=$(git cat-file -t $3)
fi
if [ "$type" = "commit" ]; then
branch=`echo $1 | sed 's|.*/heads/||'`
repo=`echo $(pwd) | sed 's|.*/git/||'`
info=`echo $(git cat-file -p $3) | sed 's|.*committer ||' | tr '<' '(' | tr '>' ')'`
author=`echo $info | sed -r 's/\).+//'`
text=`echo $info | sed 's|.*+0300 ||'`
generate_post_data()
{
cat <<EOF
{
"value1": "Repository $repo, branch $branch",
"value2": "$author)\n$text",
"value3": "$old"
}
EOF
}
curl -s -o /dev/null -X POST -H "Content-Type: application/json" -d "$(generate_post_data)" https://maker.ifttt.com/trigger/$iftttevent/with/key/$iftttkey
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment