xcskarel 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/xcskarel +31 -1
- data/lib/xcskarel/application.rb +56 -0
- data/lib/xcskarel/server.rb +67 -7
- data/lib/xcskarel/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a547dddbe32f8f28af3767137ebfc4b47dd0b871
|
4
|
+
data.tar.gz: a2a28673151ff2563b383738ffd8f3d4dbe42345
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93a7d7b5afd1a0478643c0ad70effc2fa01aafcf3c9d4ffcdbf4037d7e09deafef97738550c2c2eea7cd2f8d73717e4fbc9c6cc15aa44044ac580a9fa2a43b70
|
7
|
+
data.tar.gz: 21502e25cffc850bd1010daadc200b70ababb16480db04953d6cc98fc5b05e96c138f3ba985b15015f423788426b12ef6a93f56ce200ff176da7a306bd12acc1
|
data/bin/xcskarel
CHANGED
@@ -17,6 +17,10 @@ class XCSKarelApplication
|
|
17
17
|
c.option '--pass Password', 'Xcode Server password'
|
18
18
|
end
|
19
19
|
|
20
|
+
def add_bot_options(c)
|
21
|
+
c.option '--bot BOT_ID', '(required) Bot identifier'
|
22
|
+
end
|
23
|
+
|
20
24
|
def create_server_from_options(options)
|
21
25
|
host = options.host || "localhost"
|
22
26
|
XCSKarel::Server.new(host, options.user, options.pass)
|
@@ -104,7 +108,7 @@ class XCSKarelApplication
|
|
104
108
|
c.description = 'Fetches all Integrations for a specified Bot identifier'
|
105
109
|
c.example 'get all integration identifiers, numbers & results', 'xcskarel integrations --bot BOT_ID --hostname 127.0.0.1'
|
106
110
|
add_xcs_options(c)
|
107
|
-
c
|
111
|
+
add_bot_options(c)
|
108
112
|
c.action do |args, options|
|
109
113
|
raise "No Bot id was specified, please see `xcskarel integrations --help`" unless options.bot
|
110
114
|
server = create_server_from_options(options)
|
@@ -117,6 +121,21 @@ class XCSKarelApplication
|
|
117
121
|
end
|
118
122
|
end
|
119
123
|
|
124
|
+
command :integrate do |c|
|
125
|
+
c.syntax = 'xcskarel integrate [options]'
|
126
|
+
c.description = 'Kicks of an integration for the specified Bot id or name'
|
127
|
+
c.example 'starts an integration on localhost for bot name', 'xcskarel integrate --bot bot_archiver'
|
128
|
+
c.example 'starts an integration on a remote server for bot id', 'xcskarel integrate --bot 448946985304230369392c2e6b05a821 --host 192.168.1.64'
|
129
|
+
add_xcs_options(c)
|
130
|
+
add_bot_options(c)
|
131
|
+
c.action do |args, options|
|
132
|
+
bot = options.bot
|
133
|
+
raise "No Bot id or name was specified, please see `xcskarel integrations --help`" unless bot
|
134
|
+
server = create_server_from_options(options)
|
135
|
+
XCSKarel::Application.integrate(server, bot)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
120
139
|
command :health do |c|
|
121
140
|
c.syntax = 'xcskarel health [options]'
|
122
141
|
c.description = 'Fetches health information of the specified server'
|
@@ -133,6 +152,17 @@ class XCSKarelApplication
|
|
133
152
|
end
|
134
153
|
end
|
135
154
|
|
155
|
+
command :status do |c|
|
156
|
+
c.syntax = 'xcskarel status [options]'
|
157
|
+
c.description = 'Fetches status information of the specified server'
|
158
|
+
c.example 'get status', 'xcskarel status --hostname 127.0.0.1'
|
159
|
+
add_xcs_options(c)
|
160
|
+
c.action do |args, options|
|
161
|
+
server = create_server_from_options(options)
|
162
|
+
XCSKarel::Application.print_status(server)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
136
166
|
# Managing a local Xcode Server
|
137
167
|
|
138
168
|
command :'server start' do |c|
|
data/lib/xcskarel/application.rb
CHANGED
@@ -48,5 +48,61 @@ module XCSKarel
|
|
48
48
|
XCSKarel.log.info "Editing config \"#{config.name}\""
|
49
49
|
system "open \"#{config.path}\""
|
50
50
|
end
|
51
|
+
|
52
|
+
def self.colorize(key, value)
|
53
|
+
value ||= ""
|
54
|
+
case key
|
55
|
+
when "integration_step"
|
56
|
+
case value
|
57
|
+
when "completed"
|
58
|
+
value = value.white
|
59
|
+
when "pending"
|
60
|
+
value = value.blue
|
61
|
+
else
|
62
|
+
value = value.yellow
|
63
|
+
end
|
64
|
+
when "integration_result"
|
65
|
+
case value
|
66
|
+
when "succeeded"
|
67
|
+
value = value.green
|
68
|
+
when "canceled"
|
69
|
+
value = value.yellow
|
70
|
+
else
|
71
|
+
value = value.red
|
72
|
+
end
|
73
|
+
end
|
74
|
+
return value
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.print_status(server)
|
78
|
+
statuses = server.fetch_status
|
79
|
+
require 'terminal-table'
|
80
|
+
|
81
|
+
head = statuses.first.keys
|
82
|
+
table = Terminal::Table.new do |t|
|
83
|
+
statuses.each do |status|
|
84
|
+
r = head.map { |h| self.colorize(h, status[h]) }
|
85
|
+
t.add_row r
|
86
|
+
end
|
87
|
+
end
|
88
|
+
table.title = server.host
|
89
|
+
table.headings = head
|
90
|
+
# table.style = {:width => 160}
|
91
|
+
puts table.to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.integrate(server, bot_id_or_name)
|
95
|
+
|
96
|
+
# find bot by id or name
|
97
|
+
bot = server.find_bot_by_id_or_name(bot_id_or_name)
|
98
|
+
XCSKarel.log.debug "Found Bot #{bot['name']} with id #{bot['_id']}".yellow
|
99
|
+
|
100
|
+
# kick off an integration
|
101
|
+
server.integrate(bot)
|
102
|
+
|
103
|
+
# print the new status (TODO: highlight the bot's row)
|
104
|
+
self.print_status(server)
|
105
|
+
end
|
106
|
+
|
51
107
|
end
|
52
108
|
end
|
data/lib/xcskarel/server.rb
CHANGED
@@ -40,6 +40,44 @@ module XCSKarel
|
|
40
40
|
JSON.parse(response.body)
|
41
41
|
end
|
42
42
|
|
43
|
+
def fetch_status
|
44
|
+
# all bots and their integration's statuses
|
45
|
+
bot_statuses = []
|
46
|
+
bots = self.get_bots
|
47
|
+
bots.map do |bot|
|
48
|
+
status = {}
|
49
|
+
status['bot_name'] = bot['name']
|
50
|
+
status['bot_id'] = bot['_id']
|
51
|
+
last_integration = self.get_integrations(bot['_id']).first # sorted from newest to oldest
|
52
|
+
status['integration_step'] = last_integration['currentStep']
|
53
|
+
status['integration_result'] = last_integration['result']
|
54
|
+
status['integration_number'] = last_integration['number']
|
55
|
+
bot_statuses << status
|
56
|
+
end
|
57
|
+
return bot_statuses
|
58
|
+
end
|
59
|
+
|
60
|
+
def integrate(bot)
|
61
|
+
response = post_endpoint("/bots/#{bot['_id']}/integrations", nil)
|
62
|
+
integration = response.body
|
63
|
+
if response.status == 201
|
64
|
+
require 'json'
|
65
|
+
integration = JSON.parse(integration)
|
66
|
+
XCSKarel.log.info "Successfully started integration #{integration['number']} on Bot \"#{bot['name']}\"".green
|
67
|
+
else
|
68
|
+
raise "Failed to integrate Bot #{bot_id}".red
|
69
|
+
end
|
70
|
+
return integration
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_bot_by_id_or_name(id_or_name)
|
74
|
+
bots = self.get_bots
|
75
|
+
found_bots = bots.select { |bot| [bot['name'], bot['_id']].index(id_or_name) != nil }
|
76
|
+
raise "No Bot found for \"#{id_or_name}\"".red if found_bots.count == 0
|
77
|
+
XCSKarel.log.warn "More than one Bot found for \"#{id_or_name}\", taking the first one (you shouldn't have more Bots with the same name!)".red if found_bots.count > 1
|
78
|
+
return found_bots.first
|
79
|
+
end
|
80
|
+
|
43
81
|
def headers
|
44
82
|
headers = {
|
45
83
|
'user-agent' => 'xcskarel', # XCS wants user agent. for some API calls. not for others. sigh.
|
@@ -55,15 +93,37 @@ module XCSKarel
|
|
55
93
|
end
|
56
94
|
|
57
95
|
def get_endpoint(endpoint)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
96
|
+
call_endpoint("get", endpoint, nil)
|
97
|
+
end
|
98
|
+
|
99
|
+
def post_endpoint(endpoint, body)
|
100
|
+
call_endpoint("post", endpoint, body)
|
63
101
|
end
|
64
102
|
|
65
103
|
private
|
66
104
|
|
105
|
+
def call_endpoint(method, endpoint, body)
|
106
|
+
method.downcase!
|
107
|
+
url = url_for_endpoint(endpoint)
|
108
|
+
case method
|
109
|
+
when "get"
|
110
|
+
response = Excon.get(url, headers: headers)
|
111
|
+
when "post"
|
112
|
+
response = Excon.post(url, headers: headers, body: body)
|
113
|
+
else
|
114
|
+
raise "Unrecognized method #{method}"
|
115
|
+
end
|
116
|
+
msg = "#{method.upcase} endpoint #{endpoint} => #{url} => Response #{response.data[:status_line].gsub("\n", "")}"
|
117
|
+
|
118
|
+
case response.status
|
119
|
+
when 200..300
|
120
|
+
XCSKarel.log.debug msg.green
|
121
|
+
else
|
122
|
+
XCSKarel.log.warn msg.red
|
123
|
+
end
|
124
|
+
return response
|
125
|
+
end
|
126
|
+
|
67
127
|
def url_for_endpoint(endpoint)
|
68
128
|
"#{@host}:#{@port}/api#{endpoint}"
|
69
129
|
end
|
@@ -86,9 +146,9 @@ module XCSKarel
|
|
86
146
|
begin
|
87
147
|
response = get_endpoint("/ping")
|
88
148
|
rescue Exception => e
|
89
|
-
raise "Failed to validate - #{e}.\nPlease make sure your Xcode Server is up and running at #{host}. Run `xcskarel server start` to start a new local Xcode Server instance.".red
|
149
|
+
raise "Failed to validate - #{e}.\nPlease make sure your Xcode Server is up and running at #{@host}. Run `xcskarel server start` to start a new local Xcode Server instance.".red
|
90
150
|
else
|
91
|
-
raise "Failed to validate - Endpoint
|
151
|
+
raise "Failed to validate - Endpoint responded with #{response.data[:status_line]}".red if response.status != 204
|
92
152
|
@api_version = response.headers['X-XCSAPIVersion'].to_s
|
93
153
|
XCSKarel.log.debug "Validation of host #{@host} (API version #{@api_version}) succeeded.".green
|
94
154
|
end
|
data/lib/xcskarel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcskarel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Honza Dvorsky
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 4.3.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: terminal-table
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.4.5
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.4.5
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: pry
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|