summaryrefslogtreecommitdiff
path: root/app/helpers/commits_helper.rb
blob: 23adade9bf97c6e2252b2f272170170f1a2ac0e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module CommitsHelper
  def commit_status_alert_class(commit)
    return unless commit

    case commit.status
    when 'success'
      'alert-success'
    when 'failed', 'canceled'
      'alert-danger'
    when 'skipped'
      'alert-disabled'
    else
      'alert-warning'
    end
  end

  def commit_link(commit)
    link_to(commit.short_sha, project_ref_commit_path(commit.project, commit.ref, commit.sha))
  end

  def truncate_first_line(message, length = 50)
    truncate(message.each_line.first.chomp, length: length) if message
  end
end