Class: Codebot::Formatters::Gollum
Overview
This class formats gollum events.
Instance Attribute Summary
#payload
Instance Method Summary
collapse
#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
Instance Method Details
#action_counts ⇒ Object
48
49
50
51
52
|
# File 'lib/codebot/formatters/gollum.rb', line 48
def action_counts
Hash.new(0).tap do |hash|
pages.each { |page| hash[page['action']] += 1 }
end.sort
end
|
25
26
27
|
# File 'lib/codebot/formatters/gollum.rb', line 25
def default_format
'[%<repository>s] %<sender>s %<summary>s'
end
|
Formats IRC messages for a gollum event.
13
14
15
|
# File 'lib/codebot/formatters/gollum.rb', line 13
def format
["#{summary}: #{format_url url}"]
end
|
#multi_page_summary ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/codebot/formatters/gollum.rb', line 36
def multi_page_summary
actions = []
counts = action_counts
counts.each { |verb, num| actions << "#{verb} #{format_number num}" }
changes = ary_to_sentence(
actions,
'pushed an empty commit that did not affect any'
)
singular_noun = counts.last.to_a.last.to_i.eql?(1)
"#{changes} wiki #{singular_noun ? 'page' : 'pages'}"
end
|
#pages ⇒ Object
62
63
64
|
# File 'lib/codebot/formatters/gollum.rb', line 62
def pages
(:pages).to_a
end
|
#single_page_summary ⇒ Object
29
30
31
32
33
34
|
# File 'lib/codebot/formatters/gollum.rb', line 29
def single_page_summary
page = pages.first.to_h
short = prettify page['summary']
suffix = ": #{short}" unless short.empty?
"#{page['action']} wiki page #{page['title']}#{suffix}"
end
|
#summary ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/codebot/formatters/gollum.rb', line 17
def summary
default_format % {
repository: format_repository(repository_name),
sender: format_user(sender_name),
summary: (pages.one? ? single_page_summary : multi_page_summary)
}
end
|
#summary_url ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/codebot/formatters/gollum.rb', line 54
def summary_url
if pages.one?
pages.first['html_url'].to_s
else
"#{repository_url}/wiki"
end
end
|