Skip to content

Commit 286bf7b

Browse files
committed
(maint) Add task to check commit messages
1 parent 18ade0a commit 286bf7b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ before_install:
1818
matrix:
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

Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,33 @@ task :gen_nodeset do
4141
end
4242
puts nodeset
4343
end
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\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \
60+
"\n\t\t#{commit_summary}\n" \
61+
"\tThe 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\tThis 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

0 commit comments

Comments
 (0)