Add two git hooks to respectively enforce or warn about the DCO signoff
authorWard Vandewege <ward@curoverse.com>
Tue, 13 Jun 2017 18:41:59 +0000 (14:41 -0400)
committerWard Vandewege <ward@curoverse.com>
Tue, 13 Jun 2017 18:41:59 +0000 (14:41 -0400)
line in each git commit.

refs #2411

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curoverse.com>

git/hooks/enforce-dco-signoff.rb [new file with mode: 0755]
git/hooks/warn-dco-signoff.rb [new file with mode: 0755]

diff --git a/git/hooks/enforce-dco-signoff.rb b/git/hooks/enforce-dco-signoff.rb
new file mode 100755 (executable)
index 0000000..2ed8e61
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env ruby
+
+# This script can be installed as a git update hook.
+
+# It can also be installed as a gitolite 'hooklet' in the
+# hooks/common/update.secondary.d/ directory.
+
+# NOTE: this script runs under the same assumptions as the 'update' hook, so
+# the starting directory must be maintained and arguments must be passed on.
+
+$refname = ARGV[0]
+$oldrev  = ARGV[1]
+$newrev  = ARGV[2]
+$user    = ENV['USER']
+
+puts "Enforcing DCO signoff... \n(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
+
+$regex = /\[ref: (\d+)\]/
+
+$arvados_DCO = /Arvados-DCO-1.1-Signed-off-by:/
+
+# enforced DCO signoff in commit message
+def check_message_format
+  all_revs    = `git rev-list --first-parent #{$oldrev}..#{$newrev}`.split("\n")
+  broken = false
+  all_revs.each do |rev|
+    message = `git cat-file commit #{rev} | sed '1,/^$/d' | grep -E "Arvados-DCO-1.1-Signed-off-by: .+@.+\..+"`
+    puts message
+    if ! $arvados_DCO.match(message)
+      puts "\n[POLICY] Rejected commit: missing Arvados-DCO-1.1-Signed-off-by line"
+      puts "\n******************************************************************\n"
+      puts "\nOffending commit: #{rev}\n"
+      puts "\nOffending commit message:\n\n"
+      puts `git cat-file commit #{rev} | sed '1,/^$/d'`
+      puts "\n******************************************************************\n"
+      puts "\n\n"
+      puts "\nFor more information, see\n"
+      puts "\n  https://dev.arvados.org/projects/arvados/wiki/Developer_Certificate_Of_Origin\n"
+      puts "\n\n"
+      broken = true
+    end
+  end
+
+  if broken
+    exit 1
+  end
+end
+
+check_message_format
diff --git a/git/hooks/warn-dco-signoff.rb b/git/hooks/warn-dco-signoff.rb
new file mode 100755 (executable)
index 0000000..0a22912
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+
+# This script can be installed as a git update hook.
+
+# It can also be installed as a gitolite 'hooklet' in the
+# hooks/common/update.secondary.d/ directory.
+
+# NOTE: this script runs under the same assumptions as the 'update' hook, so
+# the starting directory must be maintained and arguments must be passed on.
+
+$refname = ARGV[0]
+$oldrev  = ARGV[1]
+$newrev  = ARGV[2]
+$user    = ENV['USER']
+
+puts "Checking for DCO signoff... \n(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
+
+$regex = /\[ref: (\d+)\]/
+
+$arvados_DCO = /Arvados-DCO-1.1-Signed-off-by:/
+
+# warn for missing DCO signoff in commit message
+def check_message_format
+  all_revs    = `git rev-list --first-parent #{$oldrev}..#{$newrev}`.split("\n")
+  broken = false
+  all_revs.each do |rev|
+    message = `git cat-file commit #{rev} | sed '1,/^$/d' | grep -E "Arvados-DCO-1.1-Signed-off-by: .+@.+\..+"`
+    puts message
+    if ! $arvados_DCO.match(message)
+      puts "\n[POLICY] WARNING: missing Arvados-DCO-1.1-Signed-off-by line"
+      puts "\n******************************************************************\n"
+      puts "\nOffending commit: #{rev}\n"
+      puts "\nOffending commit message:\n\n"
+      puts `git cat-file commit #{rev} | sed '1,/^$/d'`
+      puts "\n******************************************************************\n"
+      puts "\n\n"
+      puts "\nFor more information, see\n"
+      puts "\n  https://dev.arvados.org/projects/arvados/wiki/Developer_Certificate_Of_Origin\n"
+      puts "\n\n"
+    end
+  end
+
+  if broken
+    exit 1
+  end
+end
+
+check_message_format