Commit 9916230f authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch...

Merge branch '208555-fix-comit-message-linter-when-message-starts-with-non-letter-char' into 'master'

Fix the commit linter to check that the first actual letter is capitalized

Closes #208555

See merge request gitlab-org/gitlab!26778
parents 737f1c4a dfd4c112
...@@ -200,7 +200,9 @@ module Gitlab ...@@ -200,7 +200,9 @@ module Gitlab
end end
def subject_starts_with_lowercase? def subject_starts_with_lowercase?
first_char = subject[0] first_char = subject.sub(/\A\[.+\]\s/, '')[0]
first_char_downcased = first_char.downcase
return true unless ('a'..'z').cover?(first_char_downcased)
first_char.downcase == first_char first_char.downcase == first_char
end end
......
...@@ -195,6 +195,39 @@ describe Gitlab::Danger::CommitLinter do ...@@ -195,6 +195,39 @@ describe Gitlab::Danger::CommitLinter do
end end
end end
[
'[ci skip] A commit message',
'[Ci skip] A commit message',
'[API] A commit message'
].each do |message|
context "when subject is '#{message}'" do
let(:commit_message) { message }
it 'does not add a problem' do
expect(commit_linter).not_to receive(:add_problem)
commit_linter.lint
end
end
end
[
'[ci skip]A commit message',
'[Ci skip] A commit message',
'[ci skip] a commit message',
'! A commit message'
].each do |message|
context "when subject is '#{message}'" do
let(:commit_message) { message }
it 'adds a problem' do
expect(commit_linter).to receive(:add_problem).with(:subject_starts_with_lowercase, described_class::DEFAULT_SUBJECT_DESCRIPTION)
commit_linter.lint
end
end
end
context 'when subject ends with a period' do context 'when subject ends with a period' do
let(:commit_message) { 'A B C.' } let(:commit_message) { 'A B C.' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment