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