summaryrefslogtreecommitdiff
path: root/app/helpers/ci/commits_helper.rb
blob: 2c86bbffa365bcea77a14d6a1ea6dc2ff5146788 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Ci
  module CommitsHelper
    def commit_status_css_class(commit)
      return 'build-info' unless commit

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

    def ci_commit_path(commit)
      ci_project_ref_commits_path(commit.project, commit.ref, commit.sha)
    end

    def commit_link(commit)
      link_to(commit.short_sha, ci_commit_path(commit))
    end

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

    def ci_commit_title(commit)
      content_tag :span do
        link_to(
          simple_sanitize(commit.project.name), ci_project_path(commit.project)
        ) + ' @ ' +
          gitlab_commit_link(@project, @commit.sha)
      end
    end
  end
end