BigW Consortium Gitlab

ci_status_helper.rb 2.5 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
    end
  end

28 29 30 31 32
  def ci_status_for_statuseable(subject)
    status = subject.try(:status) || 'not found'
    status.humanize
  end

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

54
    custom_icon(icon_name)
55
  end
56

57
  def render_commit_status(commit, tooltip_placement: 'auto left')
58
    project = commit.project
59
    path = pipelines_namespace_project_commit_path(project.namespace, project, commit)
60
    render_status_with_link('commit', commit.status, path, tooltip_placement: tooltip_placement)
61 62 63 64 65
  end

  def render_pipeline_status(pipeline, tooltip_placement: 'auto left')
    project = pipeline.project
    path = namespace_project_pipeline_path(project.namespace, project, pipeline)
66
    render_status_with_link('pipeline', pipeline.status, path, tooltip_placement: tooltip_placement)
67 68
  end

69 70 71 72 73
  def no_runners_for_project?(project)
    project.runners.blank? &&
      Ci::Runner.shared.blank?
  end

74
  def render_status_with_link(type, status, path = nil, tooltip_placement: 'auto left', cssclass: '', container: 'body')
75 76
    klass = "ci-status-link ci-status-icon-#{status.dasherize} #{cssclass}"
    title = "#{type.titleize}: #{ci_label_for_status(status)}"
77
    data = { toggle: 'tooltip', placement: tooltip_placement, container: container }
78

79 80 81 82 83 84 85
    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
86
  end
87
end