Class: Gitlab::Dangerfiles::CommitLinter

Inherits:
BaseLinter
  • Object
show all
Defined in:
lib/gitlab/dangerfiles/commit_linter.rb

Constant Summary collapse

MAX_CHANGED_FILES_IN_COMMIT =
3
MAX_CHANGED_LINES_IN_COMMIT =
30
SHORT_REFERENCE_REGEX =

Issue, MR, Epic

%r{(\S*([\w\-\/]+)?(?<!`)(#|!|&)\d+(?<!`))}.freeze
MS_SHORT_REFERENCE_REGEX =

Milestone

%r{(\S*([\w\-\/]+)?(?<!`)%"?\d{1,3}\.\d{1,3}"?(?<!`))}.freeze
SUGGESTIONS_APPLIED_COMMIT_REGEX =
/Apply \d+ suggestion\(s\) to \d+ file\(s\)/.freeze

Constants inherited from BaseLinter

BaseLinter::MAX_LINE_LENGTH, BaseLinter::MIN_SUBJECT_WORDS_COUNT

Instance Attribute Summary

Attributes inherited from BaseLinter

#commit, #problems

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseLinter

#add_problem, #failed?, #inspect, #lint_subject, subject_description

Constructor Details

#initialize(commit) ⇒ CommitLinter

Returns a new instance of CommitLinter.



34
35
36
37
38
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 34

def initialize(commit)
  super

  @linted = false
end

Class Method Details

.problems_mappingObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 17

def self.problems_mapping
  super.merge(
    {
      separator_missing: "The commit subject and body must be separated by a blank line",
      details_too_many_changes: "Commits that change #{MAX_CHANGED_LINES_IN_COMMIT} or more lines across " \
      "at least #{MAX_CHANGED_FILES_IN_COMMIT} files should describe these changes in the commit body",
      details_line_too_long: "The commit body should not contain more than #{MAX_LINE_LENGTH} characters per line",
      message_contains_text_emoji: "Avoid the use of Markdown Emoji such as `:+1:`. These add limited value " \
      "to the commit message, and are displayed as plain text outside of GitLab",
      message_contains_unicode_emoji: "Avoid the use of Unicode Emoji. These add no value to the commit " \
      "message, and may not be displayed properly everywhere",
      message_contains_short_reference: "Use full URLs instead of short references (`gitlab-org/gitlab#123` or " \
      "`!123`), as short references are displayed as plain text outside of GitLab",
    }
  )
end

Instance Method Details

#fixup?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 40

def fixup?
  commit.message.start_with?("fixup!", "squash!")
end

#lintObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 60

def lint
  return self if @linted

  @linted = true
  lint_subject
  lint_separator
  lint_details
  lint_message

  self
end

#merge?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 48

def merge?
  commit.message.start_with?("Merge branch")
end

#multi_line?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 56

def multi_line?
  !details.nil? && !details.empty?
end

#revert?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 52

def revert?
  commit.message.start_with?('Revert "')
end

#suggestion?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/gitlab/dangerfiles/commit_linter.rb', line 44

def suggestion?
  SUGGESTIONS_APPLIED_COMMIT_REGEX.match?(commit.message)
end