Class: Codebot::Formatters::Gitlab::PipelineHook

Inherits:
Codebot::Formatter show all
Defined in:
lib/codebot/formatters/gitlab_pipeline_hook.rb

Overview

Triggered on status change of pipeline

Instance Attribute Summary

Attributes inherited from Codebot::Formatter

#payload

Instance Method Summary collapse

Methods inherited from Codebot::Formatter

#abbreviate, #action, #ary_to_sentence, #closed?, #extract, #format_branch, #format_dangerous, #format_event, #format_hash, #format_number, #format_repository, #format_url, #format_user, #gitlab_action, #gitlab_closed?, #gitlab_opened?, #gitlab_repository_url, #gitlab_url, #initialize, #opened?, #prettify, #repository_name, #repository_url, #sanitize, #sender_name, #shorten_url, #url

Constructor Details

This class inherits a constructor from Codebot::Formatter

Instance Method Details

#formatObject

rubocop:disable Metrics/MethodLength



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/codebot/formatters/gitlab_pipeline_hook.rb', line 31

def format # rubocop:disable Metrics/MethodLength
  repo_url = extract(:project, :web_url)
  repo_name = extract(:project, :path_with_namespace)

  pipeline_url = shorten_url "#{repo_url}/pipelines/#{pipeline_id}"
  reply = '[%<repository>s] pipeline %<status>s (%<url>s)' % {
    repository: format_repository(repo_name),
    status: format_job_status,
    url: pipeline_url
  }

  if pipeline_status == 'created'
    [reply + ':'] + [format_commit(extract(:commit))]
  else
    [reply]
  end
end

#format_job_statusObject

rubocop:disable Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/codebot/formatters/gitlab_pipeline_hook.rb', line 12

def format_job_status # rubocop:disable Metrics/MethodLength
  case pipeline_status
  when 'created'
    'was created from commit'
  when 'success'
    'succeeded'
  when 'skipped'
    'was skipped'
  when /^fail/, /^err/
    "failed: #{extract(:object_attributes, :detailed_status)}"
  else
    "did something: #{pipeline_status}"
  end
end

#pipeline_idObject



27
28
29
# File 'lib/codebot/formatters/gitlab_pipeline_hook.rb', line 27

def pipeline_id
  extract(:object_attributes, :id)
end

#pipeline_statusObject



8
9
10
# File 'lib/codebot/formatters/gitlab_pipeline_hook.rb', line 8

def pipeline_status
  extract(:object_attributes, :status)
end