github.com/bdwilliams/libcompose@v0.3.1-0.20160826154243-d81a9bdacff0/script/validate-dco (about) 1 #!/bin/bash 2 3 source "$(dirname "$BASH_SOURCE")/.validate" 4 5 adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }') 6 dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }') 7 notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')" 8 9 : ${adds:=0} 10 : ${dels:=0} 11 12 # "Username may only contain alphanumeric characters or dashes and cannot begin with a dash" 13 githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+' 14 15 # https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work 16 dcoPrefix='Signed-off-by:' 17 dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$" 18 19 check_dco() { 20 grep -qE "$dcoRegex" 21 } 22 23 if [ $adds -eq 0 -a $dels -eq 0 ]; then 24 echo '0 adds, 0 deletions; nothing to validate! :)' 25 elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then 26 echo 'Congratulations! DCO small-patch-exception material!' 27 else 28 commits=( $(validate_log --format='format:%H%n') ) 29 badCommits=() 30 for commit in "${commits[@]}"; do 31 if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then 32 # no content (ie, Merge commit, etc) 33 continue 34 fi 35 if ! git log -1 --format='format:%B' "$commit" | check_dco; then 36 badCommits+=( "$commit" ) 37 fi 38 done 39 if [ ${#badCommits[@]} -eq 0 ]; then 40 echo "Congratulations! All commits are properly signed with the DCO!" 41 else 42 { 43 echo "These commits do not have a proper '$dcoPrefix' marker:" 44 for commit in "${badCommits[@]}"; do 45 echo " - $commit" 46 done 47 echo 48 echo 'Please amend each commit to include a properly formatted DCO marker.' 49 echo 50 echo 'Visit the following URL for information about the Docker DCO:' 51 echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work' 52 echo 53 } >&2 54 false 55 fi 56 fi