1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/bash
- #
- #
- # This script is copyright Oz N Tiram <nahumoz@gmail.com>
- # It is distributed under the terms of GPLv3
- # To use this hook rename it to post-update
- # Also you need the following software packages installed
- # Take a look also in the companion config file
- # post-push.conf, you should edit it before using this hook
- #
- # * curl
- # * openssl
- #
- # you can control the script by editing post-update.conf
- # ~~~ HERE BE DRAGONS ! ~~~
- source ./hooks/post-update.conf
- TO_SUBMIT="["
- for HEAD in $@; do
- # We love bash too, but there a really fancy basename
- BRANCH=`basename $HEAD`
- REST_OF_JSON=$(git --no-pager log -n 1 --format='{"branch": "XXXBRANCHXXX", "ssh_url": "XXXSSH_URLXXX", "hashes":{"commit":"%H", "tree":"%T", "parents":"%P"},"author":{"date":"%ai","name":"%an","email":"%ae"},"committer":{"date":"%ci","name":"%cn","email":"%ce"},"repository":{"name":"XXXREPO_NAMEXXX"}}')
- REST_OF_JSON=${REST_OF_JSON/XXXBRANCHXXX/${BRANCH}}
- REST_OF_JSON=${REST_OF_JSON/XXXSSH_URLXXX/${SSH_URL}}
- REST_OF_JSON=${REST_OF_JSON/XXXREPO_NAMEXXX/${REPO_NAME}}
- JSON_TO_SUBMIT=$REST_OF_JSON
- TO_SUBMIT=$TO_SUBMIT$JSON_TO_SUBMIT","
- JSON_TO_SUBMIT=""
- done
- # BASH sorcery to remove the last character
- TO_SUBMIT=${TO_SUBMIT%?}"]"
- all=`mktemp`
- echo $TO_SUBMIT > $all
- SECRET=$(echo -n $TO_SUBMIT | openssl dgst -sha1 -hmac $SECRET_KEY)
- # Why does this produce a different digest?
- # SECRET1=$(openssl dgst -sha1 -hmac $SECRET_KEY $all)
- SECRET=`echo $SECRET | cut -d'=' -f2`
- curl -H "Content-Type: application/json" -H "${SECRET_KEY_NAME}:${SECRET}" \
- -X POST http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
- if [ $? -eq 0 ]; then
- rm $all
- fi
|