Class: Lolcommits::Plugin::Lolsrv
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Lolsrv
show all
- Defined in:
- lib/lolcommits/plugin/lolsrv.rb
Instance Attribute Summary
Attributes inherited from Base
#options, #runner
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#configuration, #configure_options!, #debug, #enabled?, #execute_postcapture, #execute_precapture, #log_error, #parse_user_input, #puts, #run_precapture, #valid_configuration?
Constructor Details
#initialize(runner) ⇒ Lolsrv
Returns a new instance of Lolsrv.
8
9
10
11
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 8
def initialize(runner)
super
options << 'server'
end
|
Class Method Details
.name ⇒ Object
49
50
51
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 49
def self.name
'lolsrv'
end
|
.runner_order ⇒ Object
53
54
55
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 53
def self.runner_order
:postcapture
end
|
Instance Method Details
17
18
19
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 17
def configured?
!configuration['enabled'].nil? && configuration['server']
end
|
#existing_lols ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 30
def existing_lols
lols = JSON.parse(RestClient.get(configuration['server'] + '/lols'))
lols.map { |lol| lol['sha'] }
rescue => e
log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}")
return nil
end
|
#run_postcapture ⇒ Object
13
14
15
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 13
def run_postcapture
fork { sync }
end
|
#sync ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 21
def sync
existing = existing_lols
return unless existing.nil?
Dir[runner.config.loldir + '/*.{jpg,gif}'].each do |item|
sha = File.basename(item, '.*')
upload(item, sha) unless existing.include?(sha) || sha == 'tmp_snapshot'
end
end
|
#upload(file, sha) ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/lolcommits/plugin/lolsrv.rb', line 38
def upload(file, sha)
RestClient.post(configuration['server'] + '/uplol',
lol: File.new(file),
url: runner.vcs_info.url + sha,
repo: runner.vcs_info.repo,
date: File.ctime(file),
sha: sha)
rescue => e
log_error(e, "ERROR: Upload of lol #{sha} FAILED #{e.class} - #{e.message}")
end
|