Repository: avro
Updated Branches:
  refs/heads/master bedf2f21a -> 51a260a27


AVRO-1841: Add clientside githooks to do basic commit validation


Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/51a260a2
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/51a260a2
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/51a260a2

Branch: refs/heads/master
Commit: 51a260a27f3b2d6a046d2ed005eeff0dc7fa6e76
Parents: bedf2f2
Author: Niels Basjes <[email protected]>
Authored: Wed May 11 00:16:39 2016 +0200
Committer: Niels Basjes <[email protected]>
Committed: Wed May 11 00:16:39 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt               |  2 ++
 build.sh                  |  8 +++++++-
 share/githooks/commit-msg | 43 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/51a260a2/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index c33e743..bccaf17 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -40,6 +40,8 @@ Trunk (not yet released)
 
     AVRO-1840: Ensure that build.sh clean really cleans all generated files 
(nielsbasjes)
 
+    AVRO-1841: Add clientside githooks to do basic commit validation 
(nielsbasjes) 
+
   BUG FIXES
 
     AVRO-1493. Java: Avoid the "Turkish Locale Problem". Schema fingerprints 
are

http://git-wip-us.apache.org/repos/asf/avro/blob/51a260a2/build.sh
----------------------------------------------------------------------
diff --git a/build.sh b/build.sh
index 93654db..c0c31df 100755
--- a/build.sh
+++ b/build.sh
@@ -22,7 +22,7 @@ cd `dirname "$0"`     # connect to root
 VERSION=`cat share/VERSION.txt`
 
 function usage {
-  echo "Usage: $0 {test|dist|sign|clean|docker|rat}"
+  echo "Usage: $0 {test|dist|sign|clean|docker|rat|githooks}"
   exit 1
 }
 
@@ -235,6 +235,12 @@ UserSpecificDocker
       mvn test -Dmaven.main.skip=true -Dmaven.test.skip=true -DskipTests=true 
-P rat -pl :avro-toplevel
       ;;
 
+    githooks)
+      echo "Installing AVRO git hooks."
+      cp share/githooks/* .git/hooks
+      find .git/hooks/ -type f | fgrep -v sample | xargs chmod 755
+      ;;
+
     *)
       usage
       ;;

http://git-wip-us.apache.org/repos/asf/avro/blob/51a260a2/share/githooks/commit-msg
----------------------------------------------------------------------
diff --git a/share/githooks/commit-msg b/share/githooks/commit-msg
new file mode 100644
index 0000000..07bbcc8
--- /dev/null
+++ b/share/githooks/commit-msg
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# Client side pre-commit hook to assist the committers to ensure the commit 
messages
+# follow the chosen convention.
+
+LOGMESSAGE_FORMAT='^AVRO-[1-9][0-9]*: .*'
+COMMIT_MSG_FILE=$1
+
+echo "=========================="
+echo "Doing basic commit validation"
+
+echo -n "= Single line commit message: "
+COMMIT_LINES=$(cat ${COMMIT_MSG_FILE} | wc -l)
+if [ ${COMMIT_LINES} -eq 1 ];
+then
+  echo "Ok"
+else
+  echo "Fail: Found ${COMMIT_LINES} lines"
+  exit 1
+fi
+
+echo -n "= Commit message format: "
+if grep -q "${LOGMESSAGE_FORMAT}" ${COMMIT_MSG_FILE}
+then
+    echo "Ok"
+else
+    echo "Fail: Must be in this format: ${LOGMESSAGE_FORMAT}"
+    exit 1
+fi
+
+ISSUE_ID=$(head -1 ${COMMIT_MSG_FILE} | cut -d':' -f1)
+
+echo -n "= CHANGES.txt mentions ${ISSUE_ID}: "
+if grep -q "${ISSUE_ID}[^0-9]" CHANGES.txt
+then
+    echo "Ok"
+else
+    echo "Fail"
+    exit 1
+fi
+echo "=========================="
+
+exit 0

Reply via email to