Class: Codebot::Formatters::Gitlab::NoteHook

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

Overview

Triggers on a Note Hook event

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_url, #sanitize, #shorten_url, #url

Constructor Details

This class inherits a constructor from Codebot::Formatter

Instance Method Details

#comment_bodyObject



97
98
99
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 97

def comment_body
  extract(:object_attributes, :note)
end

#commit_default_formatObject



76
77
78
79
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 76

def commit_default_format
  '[%<repository>s] %<sender>s commented on commit' \
  ' %<hash>s: %<summary>s'
end

#commit_idObject



113
114
115
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 113

def commit_id
  extract(:commit, :id)
end

#commit_summaryObject



52
53
54
55
56
57
58
59
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 52

def commit_summary
  commit_default_format % {
    repository: format_repository(repository_name),
    sender: format_user(sender_name),
    hash: format_hash(commit_id),
    summary: prettify(comment_body)
  }
end

#formatObject



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

def format
  ["#{summary}: #{format_url url}"]
end

#issue_default_formatObject



61
62
63
64
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 61

def issue_default_format
  '[%<repository>s] %<sender>s commented on issue' \
  ' #%<number>s: %<summary>s'
end

#issue_numberObject



109
110
111
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 109

def issue_number
  extract(:issue, :iid)
end

#issue_summaryObject



25
26
27
28
29
30
31
32
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 25

def issue_summary
  issue_default_format % {
    repository: format_repository(repository_name),
    sender: format_user(sender_name),
    number: issue_number,
    summary: prettify(comment_body)
  }
end

#merge_request_default_formatObject



71
72
73
74
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 71

def merge_request_default_format
  '[%<repository>s] %<sender>s commented on merge request' \
  ' \'%<mr>s\': %<summary>s'
end

#merge_request_summaryObject



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

def merge_request_summary
  merge_request_default_format % {
    repository: format_repository(repository_name),
    sender: format_user(sender_name),
    mr: merge_request_title,
    summary: prettify(comment_body)
  }
end

#merge_request_titleObject



105
106
107
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 105

def merge_request_title
  extract(:merge_request, :title)
end

#note_typeObject



81
82
83
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 81

def note_type
  extract(:object_attributes, :noteable_type)
end

#repository_nameObject



85
86
87
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 85

def repository_name
  extract(:project, :path_with_namespace)
end

#sender_nameObject



89
90
91
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 89

def sender_name
  extract(:user, :name)
end

#snippet_default_formatObject



66
67
68
69
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 66

def snippet_default_format
  '[%<repository>s] %<sender>s commented on code snippet' \
  ' \'%<snippet>s\': %<summary>s'
end

#snippet_summaryObject



34
35
36
37
38
39
40
41
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 34

def snippet_summary
  snippet_default_format % {
    repository: format_repository(repository_name),
    sender: format_user(sender_name),
    snippet: snippet_title,
    summary: prettify(comment_body)
  }
end

#snippet_titleObject



101
102
103
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 101

def snippet_title
  extract(:snippet, :title)
end

#summaryObject



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

def summary
  case note_type
  when 'Issue'
    issue_summary
  when 'Snippet'
    snippet_summary
  when 'MergeRequest'
    merge_request_summary
  when 'Commit'
    commit_summary
  end
end

#summary_urlObject



93
94
95
# File 'lib/codebot/formatters/gitlab_note_hook.rb', line 93

def summary_url
  extract(:object_attributes, :url)
end