Class: SystemNotes::CommitService

Inherits:
BaseService show all
Defined in:
app/services/system_notes/commit_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#author, #noteable, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from SystemNotes::BaseService

Instance Method Details

#add_commits(new_commits, existing_commits = [], oldrev = nil) ⇒ Object

Called when commits are added to a Merge Request

new_commits - Array of Commits added since last push existing_commits - Array of Commits added in a previous push oldrev - Optional String SHA of a previous Commit

See new_commit_summary and existing_commit_summary.

Returns the created Note object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/system_notes/commit_service.rb', line 14

def add_commits(new_commits, existing_commits = [], oldrev = nil)
  total_count  = new_commits.length + existing_commits.length
  commits_text = "#{total_count} commit".pluralize(total_count)

  text_parts = ["added #{commits_text}"]
  text_parts << commits_list(noteable, new_commits, existing_commits, oldrev)
  text_parts << "[Compare with previous version](#{diff_comparison_path(noteable, project, oldrev)})"

  body = text_parts.join("\n\n")

  create_note(NoteSummary.new(noteable, project, author, body, action: 'commit', commit_count: total_count))
end

#new_commit_summary(new_commits) ⇒ Object

Build an Array of lines detailing each commit added in a merge request

new_commits - Array of new Commit objects

Returns an Array of Strings


44
45
46
47
48
# File 'app/services/system_notes/commit_service.rb', line 44

def new_commit_summary(new_commits)
  new_commits.collect do |commit|
    ('li', "#{commit.short_id} - #{commit.title}")
  end
end

#tag_commit(tag_name) ⇒ Object

Called when a commit was tagged

tag_name - The created tag name

Returns the created Note object


32
33
34
35
36
37
# File 'app/services/system_notes/commit_service.rb', line 32

def tag_commit(tag_name)
  link = url_helpers.project_tag_path(project, id: tag_name)
  body = "tagged commit #{noteable.sha} to [`#{tag_name}`](#{link})"

  create_note(NoteSummary.new(noteable, project, author, body, action: 'tag'))
end