BigW Consortium Gitlab

ci_status_helper.rb 2.35 KB
Newer Older
1
module CiStatusHelper
2 3 4
  def ci_status_path(pipeline)
    project = pipeline.project
    builds_namespace_project_commit_path(project.namespace, project, pipeline.sha)
Kamil Trzcinski committed
5 6
  end

7 8
  def ci_status_with_icon(status, target = nil)
    content = ci_icon_for_status(status) + ' '.html_safe + ci_label_for_status(status)
9
    klass = "ci-status ci-#{status}"
10
    if target
11
      link_to content, target, class: klass
12
    else
13
      content_tag :span, content, class: klass
14 15 16 17
    end
  end

  def ci_label_for_status(status)
18 19
    case status
    when 'success'
20
      'passed'
21
    when 'success_with_warnings'
22
      'passed with warnings'
23 24
    else
      status
25 26 27 28 29 30 31
    end
  end

  def ci_icon_for_status(status)
    icon_name =
      case status
      when 'success'
32
        'icon_status_success'
33
      when 'success_with_warnings'
34
        'icon_status_warning'
35
      when 'failed'
36
        'icon_status_failed'
37
      when 'pending'
38
        'icon_status_pending'
39
      when 'running'
40
        'icon_status_running'
41
      when 'play'
Annabel Dunstone committed
42
        'icon_play'
43 44
      when 'created'
        'icon_status_pending'
45
      else
46
        'icon_status_cancel'
47 48
      end

49
    custom_icon(icon_name)
50
  end
51

52
  def render_commit_status(commit, tooltip_placement: 'auto left')
53 54
    project = commit.project
    path = builds_namespace_project_commit_path(project.namespace, project, commit)
55
    render_status_with_link('commit', commit.status, path, tooltip_placement: tooltip_placement)
56 57 58 59 60
  end

  def render_pipeline_status(pipeline, tooltip_placement: 'auto left')
    project = pipeline.project
    path = namespace_project_pipeline_path(project.namespace, project, pipeline)
61
    render_status_with_link('pipeline', pipeline.status, path, tooltip_placement: tooltip_placement)
62 63
  end

64 65 66 67 68
  def no_runners_for_project?(project)
    project.runners.blank? &&
      Ci::Runner.shared.blank?
  end

69 70 71 72
  def render_status_with_link(type, status, path = nil, tooltip_placement: 'auto left', cssclass: '')
    klass = "ci-status-link ci-status-icon-#{status.dasherize} #{cssclass}"
    title = "#{type.titleize}: #{ci_label_for_status(status)}"
    data = { toggle: 'tooltip', placement: tooltip_placement }
73

74 75 76 77 78 79 80
    if path
      link_to ci_icon_for_status(status), path,
              class: klass, title: title, data: data
    else
      content_tag :span, ci_icon_for_status(status),
              class: klass, title: title, data: data
    end
81
  end
82
end