Skip to content

Commit 54ca513

Browse files
committed
Add CapitalizedSubject commit message hook
It is considered good form to start your commit messages with a capitalized subject. This commit adds a commit message hook that enforces this practice. Change-Id: I447ba091978b3c62f480967a1c5df36b8ffa50eb Reviewed-on: http://gerrit.causes.com/47631 Tested-by: jenkins <jenkins@brigade.com> Reviewed-by: Henric Trotzig <henric.trotzig@brigade.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
1 parent 3246db1 commit 54ca513

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
[ruby-lint](https://github.com/YorickPeterse/ruby-lint)
2424
* Add `Jsl` pre-commit hook that checks the style of JavaScript files with
2525
[JavaScript Lint](http://www.javascriptlint.com/)
26+
* Add `CapitalizedSubject` commit message hook
2627

2728
## 0.23.0
2829

config/default.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ CommitMsg:
2222
requires_files: false
2323
quiet: false
2424

25+
CapitalizedSubject:
26+
description: 'Checking subject capitalization'
27+
2528
GerritChangeId:
2629
enabled: false
2730
description: 'Ensuring Gerrit Change-Id is present'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Overcommit::Hook::CommitMsg
2+
# Ensures commit message subject lines are followed by a blank line.
3+
class CapitalizedSubject < Base
4+
def run
5+
first_letter = commit_message_lines[0].to_s.match(/^[[:punct:]]*(.)/)[1]
6+
unless first_letter.match(/[[:upper:]]/)
7+
return :warn, 'Subject should start with a capital letter'
8+
end
9+
10+
:pass
11+
end
12+
end
13+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::CommitMsg::CapitalizedSubject do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
before do
9+
subject.stub(:commit_message_lines).and_return(commit_msg.split("\n"))
10+
end
11+
12+
context 'when subject starts with a capital letter' do
13+
let(:commit_msg) { <<-MSG }
14+
Initial commit
15+
16+
Mostly cats so far.
17+
MSG
18+
19+
it { should pass }
20+
end
21+
22+
context 'when subject starts with a utf-8 capital letter' do
23+
let(:commit_msg) { <<-MSG }
24+
Årsgång
25+
26+
Mostly cats so far.
27+
MSG
28+
29+
it { should pass }
30+
end
31+
32+
context 'when subject starts with punctuation and a capital letter' do
33+
let(:commit_msg) { <<-MSG }
34+
"Initial" commit
35+
36+
Mostly cats so far.
37+
MSG
38+
39+
it { should pass }
40+
end
41+
42+
context 'when subject starts with a lowercase letter' do
43+
let(:commit_msg) { <<-MSG }
44+
initial commit
45+
46+
I forget about commit message standards and decide to not capitalize my
47+
subject. Still mostly cats so far.
48+
MSG
49+
50+
it { should warn }
51+
end
52+
53+
context 'when subject starts with a utf-8 lowercase letter' do
54+
let(:commit_msg) { <<-MSG }
55+
årsgång
56+
57+
I forget about commit message standards and decide to not capitalize my
58+
subject. Still mostly cats so far.
59+
MSG
60+
61+
it { should warn }
62+
end
63+
64+
context 'when subject starts with punctuation and a lowercase letter' do
65+
let(:commit_msg) { <<-MSG }
66+
"initial" commit
67+
68+
I forget about commit message standards and decide to not capitalize my
69+
subject. Still mostly cats so far.
70+
MSG
71+
72+
it { should warn }
73+
end
74+
end

0 commit comments

Comments
 (0)