Class: Lolcommits::Plugin::LolHipchat
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::LolHipchat
show all
- Defined in:
- lib/lolcommits/plugin/lol_hipchat.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #options, #runner
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#configuration, #configured_and_enabled?, #debug, #enabled?, #execute_capture_ready, #execute_post_capture, #execute_pre_capture, #initialize, #log_error, #parse_user_input, #print, #puts, #run_post_capture, #run_pre_capture, #valid_configuration?
Class Method Details
.name ⇒ Object
115
116
117
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 115
def self.name
'hipchat'
end
|
.runner_order ⇒ Object
119
120
121
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 119
def self.runner_order
:capture_ready
end
|
Instance Method Details
#api_url ⇒ Object
76
77
78
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 76
def api_url
URI(format('http://%<api_team>s.hipchat.com/v2/room/%<api_room>s/share/file?auth_token=%<api_token>s', symbolized_configuration))
end
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 10
def configure_auth_options
puts '-' * 50
puts ' Lolcommits HipChat Plugin Configuration'
puts '-' * 50
puts '1.) I need your Team Name '
puts 'teamname as in teamname.hipchat.com, without .hipchat.com'
print 'Your Teamname: '
teamname = gets.to_s.strip
puts "2.) We need a Authentication Token, get yours at https://#{teamname}.hipchat.com/account/api"
puts 'make sure to select scope "Send Message"'
print 'Your auth_token: '
token = gets.to_s.strip
puts '3.) Which Room should be we post to?'
puts 'can be a id or name'
print 'Your Room: '
room = gets.to_s.strip
{
'api_token' => token,
'api_team' => teamname,
'api_room' => room
}
end
|
4
5
6
7
8
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 4
def configure_options!
options = super
options.merge! configure_auth_options if options['enabled']
options
end
|
108
109
110
111
112
113
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 108
def configured?
super &&
configuration['api_token'] &&
configuration['api_team'] &&
configuration['api_room']
end
|
#message ⇒ Object
84
85
86
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 84
def message
"commited some #{random_adjective} #{random_object} to #{runner.vcs_info.repo}@#{runner.sha} (#{runner.vcs_info.branch}) "
end
|
#message_json ⇒ Object
57
58
59
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 57
def message_json
{ message: message }.to_json.force_encoding('utf-8')
end
|
#message_part ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 47
def message_part
[
'Content-Type: application/json; charset=UTF-8',
'Content-Disposition: attachment; name="metadata"',
'',
message_json,
''
].join "\r\n"
end
|
#picture ⇒ Object
72
73
74
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 72
def picture
@picture ||= File.new(runner.main_image)
end
|
#picture_part ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 61
def picture_part
mime_type = MIME::Types.type_for(picture.path)[0] || MIME::Types['application/octet-stream'][0]
[
format('Content-Type: %s', mime_type.simplified),
format('Content-Disposition: attachment; name="file"; filename="%s"', picture.path),
'',
"#{picture.read} ",
''
].join "\r\n"
end
|
#random_adjective ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 94
def random_adjective
adjectives = %w(adaptable adventurous affable affectionate agreeable ambitious amiable amicable amusing brave \
bright broad-minded calm careful charming communicative compassionate conscientious considerate \
convivial courageous courteous creative decisive determined diligent diplomatic discreet dynamic \
easygoing emotional energetic enthusiastic exuberant fair-minded faithful fearless forceful \
frank friendly funny generous gentle good gregarious hard-working helpful honest humorous \
imaginative impartial independent intellectual intelligent intuitive inventive kind loving loyal \
modest neat nice optimistic passionate patient persistent pioneering philosophical placid plucky \
polite powerful practical pro-active quick-witted quiet rational reliable reserved resourceful \
romantic self-confident self-disciplined sensible sensitive shy sincere sociable straightforward \
sympathetic thoughtful tidy tough unassuming understanding versatile warmhearted willing witty)
adjectives.sample
end
|
#random_object ⇒ Object
88
89
90
91
92
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 88
def random_object
objects = %w(screws bolts exceptions errors cookies)
objects.sample
end
|
#run_capture_ready ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 35
def run_capture_ready
http = Net::HTTP.new(api_url.host, api_url.port)
http.start do |connection|
= { 'Content-Type' => 'multipart/related; boundary=0123456789ABLEWASIEREISAWELBA9876543210' }
data = [message_part, picture_part].map do |part|
"--0123456789ABLEWASIEREISAWELBA9876543210\r\n#{part}"
end.join('') << '--0123456789ABLEWASIEREISAWELBA9876543210--'
connection.post("#{api_url.path}?#{api_url.query}", data, )
end
end
|
#symbolized_configuration ⇒ Object
80
81
82
|
# File 'lib/lolcommits/plugin/lol_hipchat.rb', line 80
def symbolized_configuration
@symbolized_configuration ||= configuration.each_with_object({}) { |(k, v), obj| obj[k.to_sym] = v }
end
|