Refactor commit_messages#lint_commit
This introduces additional method for linting, to reduce the complexity of `lint_commits`.
This commit is contained in:
parent
9d842c704a
commit
d8145aa693
1 changed files with 124 additions and 114 deletions
|
@ -64,11 +64,12 @@ def too_many_changed_lines?(commit)
|
|||
lines_changed_in_commit(commit) >= 30
|
||||
end
|
||||
|
||||
def lint_commits(commits)
|
||||
failures = false
|
||||
emoji_checker = EmojiChecker.new
|
||||
def emoji_checker
|
||||
@emoji_checker ||= EmojiChecker.new
|
||||
end
|
||||
|
||||
unicode_emoji_regex = %r((
|
||||
def unicode_emoji_regex
|
||||
@unicode_emoji_regex ||= %r((
|
||||
[\u{1F300}-\u{1F5FF}] |
|
||||
[\u{1F1E6}-\u{1F1FF}] |
|
||||
[\u{2700}-\u{27BF}] |
|
||||
|
@ -77,15 +78,17 @@ def lint_commits(commits)
|
|||
[\u{1F680}-\u{1F6FF}] |
|
||||
[\u{2600}-\u{26FF}]
|
||||
))x
|
||||
end
|
||||
|
||||
commits.each do |commit|
|
||||
def lint_commit(commit)
|
||||
# For now we'll ignore merge commits, as getting rid of those is a problem
|
||||
# separate from enforcing good commit messages.
|
||||
next if commit.message.start_with?('Merge branch')
|
||||
return false if commit.message.start_with?('Merge branch')
|
||||
|
||||
# We ignore revert commits as they are well structured by Git already
|
||||
next if commit.message.start_with?('Revert "')
|
||||
return false if commit.message.start_with?('Revert "')
|
||||
|
||||
failures = false
|
||||
subject, separator, details = commit.message.split("\n", 3)
|
||||
|
||||
if subject.split.length < 3
|
||||
|
@ -191,9 +194,16 @@ def lint_commits(commits)
|
|||
|
||||
failures = true
|
||||
end
|
||||
|
||||
failures
|
||||
end
|
||||
|
||||
def lint_commits(commits)
|
||||
failed = commits.reject do |commit|
|
||||
lint_commit(commit)
|
||||
end
|
||||
|
||||
if failures
|
||||
if failed.any?
|
||||
markdown(<<~MARKDOWN)
|
||||
## Commit message standards
|
||||
|
||||
|
|
Loading…
Reference in a new issue