Skip to content

Commit 7fce659

Browse files
committed
(maint) Add commit summary check
This commit adds the `commits` rake task and runs it in the Static Code Analysis workflow as a step.
1 parent 8683821 commit 7fce659

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.github/workflows/static_code_analysis.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
steps:
2020
- name: Checkout current PR code
2121
uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 0
2224

2325
- name: Install ruby version ${{ env.ruby_version }}
2426
uses: ruby/setup-ruby@v1
@@ -28,6 +30,9 @@ jobs:
2830
- name: Prepare testing environment with bundler
2931
run: bundle update --jobs 4 --retry 3
3032

33+
- name: Run commits check
34+
run: bundle exec rake commits
35+
3136
- name: Run rubocop check
3237
run: bundle exec rake ${{ env.extra_checks }} rubocop
3338

Rakefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,28 @@ EOM
8585
end
8686
end
8787

88+
desc "verify that commit messages match CONTRIBUTING.md requirements"
89+
task(:commits) do
90+
# This rake task looks at the summary from every commit from this branch not
91+
# in the branch targeted for a PR.
92+
commit_range = 'HEAD^..HEAD'
93+
puts "Checking commits #{commit_range}"
94+
%x{git log --no-merges --pretty=%s #{commit_range}}.each_line do |commit_summary|
95+
# This regex tests for the currently supported commit summary tokens.
96+
# The exception tries to explain it in more full.
97+
if /^\((maint|packaging|doc|docs|modules-\d+)\)|revert/i.match(commit_summary).nil?
98+
raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \
99+
"\n\t\t#{commit_summary}\n" \
100+
"\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \
101+
"\t\t(MODULES-<digits>) # this is most common and should be a ticket at tickets.puppet.com\n" \
102+
"\t\t(docs)\n" \
103+
"\t\t(docs)(DOCUMENT-<digits>)\n" \
104+
"\t\t(packaging)\n"
105+
"\t\t(maint)\n" \
106+
"\n\tThis test for the commit summary is case-insensitive.\n\n\n"
107+
else
108+
puts "#{commit_summary}"
109+
end
110+
puts "...passed"
111+
end
112+
end

0 commit comments

Comments
 (0)