File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ before_install:
1818matrix :
1919 fast_finish : true
2020 include :
21+ - rvm : 2.5.3
22+ env : CHECK="commits"
2123 - rvm : 2.5.3
2224 env : CHECK="validate lint spec"
2325 - rvm : 2.5.3
Original file line number Diff line number Diff line change @@ -41,3 +41,33 @@ task :gen_nodeset do
4141 end
4242 puts nodeset
4343end
44+
45+ desc "verify that commit messages match CONTRIBUTING.md requirements"
46+ task ( :commits ) do
47+ # This rake task looks at the summary from every commit from this branch not
48+ # in the branch targeted for a PR. This is accomplished by using the
49+ # TRAVIS_COMMIT_RANGE environment variable, which is present in travis CI and
50+ # populated with the range of commits the PR contains. If not available, this
51+ # falls back to `master..HEAD` as a next best bet as `master` is unlikely to
52+ # ever be absent.
53+ commit_range = ENV [ 'TRAVIS_COMMIT_RANGE' ] . nil? ? 'master..HEAD' : ENV [ 'TRAVIS_COMMIT_RANGE' ] . sub ( /\. \. \. / , '..' )
54+ puts "Checking commits #{ commit_range } "
55+ %x{git log --no-merges --pretty=%s #{ commit_range } } . each_line do |commit_summary |
56+ # This regex tests for the currently supported commit summary tokens.
57+ # The exception tries to explain it in more full.
58+ if /^\( (maint|packaging|doc|docs|modules-\d +)\) |revert/i . match ( commit_summary ) . nil?
59+ raise "\n \n \n \t This commit summary didn't match CONTRIBUTING.md guidelines:\n " \
60+ "\n \t \t #{ commit_summary } \n " \
61+ "\t The commit summary (i.e. the first line of the commit message) should start with one of:\n " \
62+ "\t \t (MODULES-<digits>) # this is most common and should be a ticket at tickets.puppet.com\n " \
63+ "\t \t (docs)\n " \
64+ "\t \t (docs)(DOCUMENT-<digits>)\n " \
65+ "\t \t (packaging)\n "
66+ "\t \t (maint)\n " \
67+ "\n \t This test for the commit summary is case-insensitive.\n \n \n "
68+ else
69+ puts "#{ commit_summary } "
70+ end
71+ puts "...passed"
72+ end
73+ end
You can’t perform that action at this time.
0 commit comments