From: Ward Vandewege Date: Tue, 13 Jun 2017 18:41:59 +0000 (-0400) Subject: Add two git hooks to respectively enforce or warn about the DCO signoff X-Git-Url: https://git.arvados.org/arvados-dev.git/commitdiff_plain/7a5ba380aebe7b6fb04ee6fb719a299d035ab4f4 Add two git hooks to respectively enforce or warn about the DCO signoff line in each git commit. refs #2411 Arvados-DCO-1.1-Signed-off-by: Ward Vandewege --- diff --git a/git/hooks/enforce-dco-signoff.rb b/git/hooks/enforce-dco-signoff.rb new file mode 100755 index 0000000..2ed8e61 --- /dev/null +++ b/git/hooks/enforce-dco-signoff.rb @@ -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 index 0000000..0a22912 --- /dev/null +++ b/git/hooks/warn-dco-signoff.rb @@ -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