34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/keepclean.rb', line 34
def self.run(args)
at_exit do
logs = @log_output.string
unless logs.empty?
puts ""
puts "===== DEBUG ====="
puts ""
puts logs
end
end
Keepclean.logger.debug "Running with args: #{args.inspect}"
puts "*** Keepclean v#{Keepclean::VERSION} ***"
token = ENV['KEEPCLEAN_TOKEN']
unless token
puts "Token no set, use KEEPCLEAN_TOKEN"
exit -1
end
unless project_name
puts "Project no set, use KEEPCLEAN_PROJECT"
exit -1
end
uri = URI("#{server}/manifest")
res = Net::HTTP.post_form(uri, {
version: Keepclean::VERSION,
token: token,
project: project_name
})
unless res['content-type'].start_with?('application/json')
puts res.body
exit -1
end
manifest = JSON.parse(res.body)
logger.debug "Manifest: #{manifest}"
puts "Configure at: #{manifest['configuration_url']}"
success = true
manifest.each do |key, metadata|
next unless metadata['enabled']
klass = case key
when 'custom'
class_name = metadata.dig('config', 'class_name')
unless class_name
puts "#{key} check skipped because the class_name is not configured"
next
end
class_name.gsub('Integration::', '')
else
key.camelize
end
logger.tagged(klass) do
begin
puts ""
puts "*** #{klass} ***"
puts ""
require "integrations/#{klass.underscore}"
success &= "Integration::#{klass}".constantize.new(pronto: metadata['on_branch']).run_with_config_handling_exit(metadata['config']) || metadata['allowed_to_fail']
logger.debug "Success: #{success}"
rescue LoadError => e
puts "#{klass} check skipped because of error: #{e.message}"
ensure
if klass
puts ""
puts "*** /#{klass}/ ***"
puts ""
end
end
end
end
exit success
rescue Errno::ECONNREFUSED => e
puts "We couldn't reach the keepclean server: #{e.message}"
end
|