Class: Lolcommits::LolSlack
- Inherits:
-
Plugin
- Object
- Plugin
- Lolcommits::LolSlack
show all
- Defined in:
- lib/lolcommits/plugins/lol_slack.rb
Constant Summary
collapse
- ENDPOINT_URL =
'https://slack.com/api/files.upload'.freeze
- RETRY_COUNT =
2
Instance Attribute Summary
Attributes inherited from Plugin
#options, #runner
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Plugin
#configuration, #debug, #enabled?, #execute_postcapture, #execute_precapture, #initialize, #log_error, #parse_user_input, #puts, #run_precapture, #valid_configuration?
Class Method Details
.name ⇒ Object
9
10
11
|
# File 'lib/lolcommits/plugins/lol_slack.rb', line 9
def self.name
'slack'
end
|
.runner_order ⇒ Object
13
14
15
|
# File 'lib/lolcommits/plugins/lol_slack.rb', line 13
def self.runner_order
:postcapture
end
|
Instance Method Details
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/lolcommits/plugins/lol_slack.rb', line 21
def configure
print "Open the URL below and issue a token for your user:\n"
print "https://api.slack.com/web\n"
print "Enter the generated token below, then press enter: (e.g. xxxx-xxxxxxxxx-xxxx) \n"
code = STDIN.gets.to_s.strip
print "Enter a comma-seperated list of channel IDs to post images in, then press enter: (e.g. C1234567890,C1234567890)\n"
print "NOTE: you must use channel IDs (not channel names). Grab them from here; https://api.slack.com/methods/channels.list/test\n"
channels = STDIN.gets.to_s.strip
{ 'access_token' => code,
'channels' => channels }
end
|
34
35
36
37
38
39
40
41
|
# File 'lib/lolcommits/plugins/lol_slack.rb', line 34
def configure_options!
options = super
if options['enabled']
config = configure
options.merge!(config)
end
options
end
|
17
18
19
|
# File 'lib/lolcommits/plugins/lol_slack.rb', line 17
def configured?
!configuration['access_token'].nil?
end
|
#run_postcapture ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/lolcommits/plugins/lol_slack.rb', line 43
def run_postcapture
return unless valid_configuration?
retries = RETRY_COUNT
begin
response = RestClient.post(
ENDPOINT_URL,
:file => File.new(runner.main_image),
:token => configuration['access_token'],
:filetype => 'jpg',
:filename => runner.sha,
:title => runner.message + "[#{runner.git_info.repo}]",
:channels => configuration['channels'])
debug response
rescue => e
retries -= 1
retry if retries > 0
puts "Posting to slack failed - #{e.message}"
puts 'Try running config again:'
puts "\tlolcommits --config --plugin slack"
end
end
|