Browse Source

a much better way to create the json

 * instead of appending substrings, use git log --format
   and then change the place holders with bash string manipulation
Oz N Tiram 9 năm trước cách đây
mục cha
commit
3f6ff6668d
1 tập tin đã thay đổi với 7 bổ sung17 xóa
  1. 7 17
      hooks/post-update.sh

+ 7 - 17
hooks/post-update.sh

@@ -12,31 +12,21 @@
 #  * curl
 #  * openssl
 #
-#  You control the script by editing post-update.conf
-#
+# 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`
-	# CUT, UNIX, No bash
-	# BRANCH=$(echo $HEAD |cut -d / -f 3)
-	# FUCK, BASHSIMS
-	#echo $HEAD
-	#IFS="/"
-	#BRANCH=($HEAD)
-	#BRANCH=${BRANCH[2]}
-	REST_OF_JSON=$(git --no-pager log -n 1 --format='{"hashes":{"commit":"%H", "tree":"%T", "parents":"%P"},"author":{"date":"%ai","name":"%an","email":"%ae"},"committer":{"date":"%ci","name":"%cn","email":"%ce"}')
-	REST_OF_JSON=$REST_OF_JSON,\"branch\":\""${BRANCH}"\",
-	REST_OF_JSON=$REST_OF_JSON,\"giturl\":\"$GITURL\",
-	JSON_TO_SUBMIT=$JSON_TO_SUBMIT{\"$BRANCH\":$REST_OF_JSON\}
-	JSON_TO_SUBMIT=$JSON_TO_SUBMIT}
-	REST_OF_JSON=""
+	REST_OF_JSON=$(git --no-pager log -n 1 --format='{"branch": "XXXBRANCHXXX", "giturl": "XXXGITURLXXX", "hashes":{"commit":"%H", "tree":"%T", "parents":"%P"},"author":{"date":"%ai","name":"%an","email":"%ae"},"committer":{"date":"%ci","name":"%cn","email":"%ce"}}')
+        REST_OF_JSON=${REST_OF_JSON/XXXBRANCHXXX/${BRANCH}}
+        REST_OF_JSON=${REST_OF_JSON/XXXGITURLXXX/${GITURL}}
+	JSON_TO_SUBMIT=$REST_OF_JSON
 	TO_SUBMIT=$TO_SUBMIT$JSON_TO_SUBMIT","
 	JSON_TO_SUBMIT=""
 done
@@ -50,7 +40,7 @@ SECRET=$(echo -n $TO_SUBMIT | openssl dgst -sha1 -hmac $SECRET_KEY)
 # 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}" \
-	http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
+	-X POST http://${SUBMIT_HOST}:${SUBMIT_PORT}/ --data @$all
 if [ $? -eq 0 ]; then
    rm $all
 fi