Class: Codebot::Formatters::Ping
Overview
This class formats ping 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
22
23
24
|
# File 'lib/codebot/formatters/ping.rb', line 22
def default_format
'[%<scope>s] %<sender>s added a webhook for %<events>s'
end
|
Formats IRC messages for a ping event.
10
11
12
|
# File 'lib/codebot/formatters/ping.rb', line 10
def format
["#{summary}: #{format_url url}"]
end
|
36
37
38
39
40
41
42
43
44
|
# File 'lib/codebot/formatters/ping.rb', line 36
def format_events
if hook_events.empty?
'no events'
elsif hook_events.include? '*'
format_event 'all events'
else
format_events_some
end
end
|
46
47
48
49
50
51
52
53
54
|
# File 'lib/codebot/formatters/ping.rb', line 46
def format_events_some
if hook_events.length > 5
"#{format_number(hook_events.length)} events"
elsif hook_events.one?
"the #{format_event hook_events.first} event"
else
"the #{formatted_hook_events} events"
end
end
|
Formats the name of the repository or organization the webhook belongs to.
68
69
70
71
72
73
74
75
76
|
# File 'lib/codebot/formatters/ping.rb', line 68
def format_scope
case (:hook, :type)
when /\Aorganization\z/i
format_user (:organization, :login)
when /\Arepository\z/i
login = (:repository, :owner, :login)
"#{format_user login}/#{format_repository repository_name}"
end
end
|
60
61
62
|
# File 'lib/codebot/formatters/ping.rb', line 60
def formatted_hook_events
ary_to_sentence(hook_events.sort.map { |event| format_event event })
end
|
#hook_events ⇒ Object
56
57
58
|
# File 'lib/codebot/formatters/ping.rb', line 56
def hook_events
(:hook, :events).to_a.uniq
end
|
#summary ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/codebot/formatters/ping.rb', line 14
def summary
default_format % {
scope: format_scope,
sender: format_user(sender_name),
events: format_events
}
end
|
#summary_url ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/codebot/formatters/ping.rb', line 26
def summary_url
case (:hook, :type)
when /\Aorganization\z/i
login = (:organization, :login).to_s
"https://github.com/#{login}"
when /\Arepository\z/i
(:repository, :html_url).to_s
end
end
|