Class: Gitlab::Suggestions::CommitMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/suggestions/commit_message.rb

Constant Summary collapse

DEFAULT_SUGGESTION_COMMIT_MESSAGE =
'Apply %{suggestions_count} suggestion(s) to %{files_count} file(s)'

Instance Method Summary collapse

Constructor Details

#initialize(user, suggestion_set, custom_message = nil) ⇒ CommitMessage

Returns a new instance of CommitMessage.


9
10
11
12
13
# File 'lib/gitlab/suggestions/commit_message.rb', line 9

def initialize(user, suggestion_set, custom_message = nil)
  @user = user
  @suggestion_set = suggestion_set
  @custom_message = custom_message
end

Instance Method Details

#messageObject


15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/suggestions/commit_message.rb', line 15

def message
  project = suggestion_set.target_project
  user_defined_message = @custom_message.presence || project.suggestion_commit_message.presence
  message = user_defined_message || DEFAULT_SUGGESTION_COMMIT_MESSAGE

  Gitlab::StringPlaceholderReplacer
    .replace_string_placeholders(message, PLACEHOLDERS_REGEX) do |key|
    PLACEHOLDERS[key].call(user, suggestion_set)
  end
end