Class: Codebot::Formatters::Gitlab::IssueHook

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

Overview

This class formats issues events.

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

#default_formatObject



38
39
40
41
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 38

def default_format
  '[%<repository>s] %<sender>s %<action>s issue #%<number>s:' \
    ' %<title>s: %<url>s'
end

#formatObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 43

def format
  [default_format % {
    repository: format_repository(repo_name),
    sender: format_user(user_name),
    action: format_issue_action,
    number: extract(:object_attributes, :iid),
    title: extract(:object_attributes, :title),
    url: issue_url
  }]
end

#format_issue_actionObject



12
13
14
15
16
17
18
19
20
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 12

def format_issue_action
  case issue_action
  when 'open' then 'opened'
  when 'close' then 'closed'
  when 'reopen' then 'reopened'
  when 'update', nil then 'updated'
  else issue_action
  end
end

#issue_actionObject



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

def issue_action
  extract(:object_attributes, :action)
end

#issue_urlObject



30
31
32
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 30

def issue_url
  shorten_url extract(:object_attributes, :url)
end

#repo_nameObject



26
27
28
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 26

def repo_name
  extract(:project, :path_with_namespace)
end

#repo_urlObject



22
23
24
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 22

def repo_url
  extract(:project, :web_url)
end

#user_nameObject



34
35
36
# File 'lib/codebot/formatters/gitlab_issue_hook.rb', line 34

def user_name
  extract(:user, :name)
end