Module: CommitHelper

Included in:
ProblemPresenter
Defined in:
app/helpers/commit_helper.rb

Instance Method Summary collapse

Instance Method Details

#format_commit(commit) ⇒ Object



3
4
5
6
7
8
# File 'app/helpers/commit_helper.rb', line 3

def format_commit(commit)
  message = commit.summary
  message = format_with_tickets_linked(commit.project, message)
  message = mdown(message)
  message
end

#format_sha(sha) ⇒ Object



37
38
39
40
# File 'app/helpers/commit_helper.rb', line 37

def format_sha(sha)
  return "_"*8 if sha.blank?
  sha[0...7]
end

#format_with_tickets_linked(project, message) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/commit_helper.rb', line 42

def format_with_tickets_linked(project, message)
  message = h(message)

  message.gsub! Commit::TICKET_PATTERN do |match|
    ticket_number = Commit::TICKET_PATTERN.match(match)[1]
    link_to match, project.ticket_tracker_ticket_url(ticket_number), "target" => "_blank", "rel" => "ticket", "data-number" => ticket_number
  end

  message.gsub! Commit::EXTRA_ATTRIBUTE_PATTERN do |match|
    key, value = match.scan(Commit::EXTRA_ATTRIBUTE_PATTERN).first
    link_to_err(project, value) if key == "err"
  end

  message.html_safe
end


10
11
12
13
14
15
16
17
18
# File 'app/helpers/commit_helper.rb', line 10

def link_to_commit(commit, options={})
  return nil if commit.nil?

  project = commit.project
  content = block_given? ? yield : "<span class=\"commit-sha\">#{commit.sha[0...7]}</span>".html_safe

  return content unless github_url?(project)
  link_to content, github_commit_url(project, commit.sha), options.reverse_merge(target: "_blank")
end


29
30
31
32
33
34
35
# File 'app/helpers/commit_helper.rb', line 29

def link_to_commit_range(project, commit0, commit1)
  range = "#{format_sha(commit0)}<span class=\"ellipsis\">...</span>#{format_sha(commit1)}".html_safe
  return range unless github_url?(project)
  return range if commit0.blank? or commit1.blank?

  link_to range, github_commit_range_url(project, commit0, commit1), target: "_blank", title: "Compare"
end


25
26
27
# File 'app/helpers/commit_helper.rb', line 25

def link_to_commit_range_for_deploy(deploy)
  link_to_commit_range deploy.project, deploy.previous_deploy.try(:sha), deploy.sha
end


58
59
60
61
62
# File 'app/helpers/commit_helper.rb', line 58

def link_to_err(project, err)
  link_to project.error_tracker_error_url(err), "target" => "_blank" do
    (image_tag(image_url("bug-fixed-32.png"), "data-tooltip-placement" => "right", rel: "tooltip", title: "View Exception in Errbit", width: 16, height: 16) + err).html_safe
  end
end


20
21
22
23
# File 'app/helpers/commit_helper.rb', line 20

def link_to_release_commit_range(release)
  return "" if release.commit0.blank? && release.commit1.blank?
  link_to_commit_range(release.project, release.commit0, release.commit1)
end