veyor 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a06e1104f3842fce3aa56563fceec712abf66b87
4
- data.tar.gz: cd02f3925f0a18c0c123547117e1e0639970c405
2
+ SHA256:
3
+ metadata.gz: 70f94473d07243efdf83a52ae5819cc4e952f8d221cfe6ce408f3995f9d5c1c3
4
+ data.tar.gz: e1f2d164380bcef76f40b3fa2f3ff555204d7e72cc437136ddc398c9b77e3197
5
5
  SHA512:
6
- metadata.gz: 8b1829be8ade8096598eee422bf1526f1817f2ffb2ef8ba86718c4d64cec50f7a0e5fb384c2ea78823773a52656c94a753f86c59cf0eb04d661f5f0b20bfc65b
7
- data.tar.gz: fffc01b5a2c4351a824e400ce302543350cc1e360cea99637f40f0841dbf4ad1afad2466f54cb0e62ee356b99e4e9aac221725519f07e55f08518c4ea6139d4e
6
+ metadata.gz: ca7235facce1973f38407d749788e3f8289c714024e3b862d729d71e57098d55a9d016d8f2b8d93ca3a1f0ffe781201dd1f3f32290db23137779b5bd32709d40
7
+ data.tar.gz: 81ff2b7cc4d228d7500eb7c39112d8e6ff99163b3d4986c67d442e4656a82c692286d35e6c6d754dda8f530f1051fa72316487893cf5e6ab28248f4431ed0848
data/.gitignore CHANGED
@@ -46,3 +46,5 @@ cache/
46
46
  /spec/reports/
47
47
  /tmp/
48
48
  *.gem
49
+
50
+ vendor/
@@ -0,0 +1,8 @@
1
+ SimpleCov.start do
2
+ add_filter "lib/veyor/faraday.rb"
3
+
4
+ if ENV['CI']=='true'
5
+ require 'codecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
7
+ end
8
+ end
@@ -1,10 +1,13 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.1.7
5
- - 2.2.3
6
- - 2.2.4
7
- - 2.3.1
4
+ - 2.4.1
5
+ - 2.5.0
6
+ - 2.6.0
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler
10
+ - gem --version
8
11
  script:
9
12
  bundle exec rake test TESTOPTS="-v"
10
13
 
@@ -1,3 +1,10 @@
1
+ ## 0.2.0 (2019-07-22)
2
+
3
+ * add remainder of veyor lib methods to the cli tool (#3)
4
+ * require latest Faraday (#7)
5
+ * don't require Appveyor API token for GET requests (#8) thanks @kou
6
+ * `buid_artifacts` method added (#9) thanks @kou
7
+
1
8
  ## 0.1.2 (2016-06-24)
2
9
 
3
10
  * Command line client now with all methods available
data/CONDUCT.md CHANGED
@@ -21,5 +21,5 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be repor
21
21
  opening an issue or contacting one or more of the project maintainers.
22
22
 
23
23
  This Code of Conduct is adapted from the Contributor Covenant
24
- (http:contributor-covenant.org), version 1.0.0, available at
25
- http://contributor-covenant.org/version/1/0/0/
24
+ (https://contributor-covenant.org), version 1.0.0, available at
25
+ https://contributor-covenant.org/version/1/0/0/
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2016 Scott Chamberlain
1
+ Copyright (C) 2019 Scott Chamberlain
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -28,11 +28,18 @@ rake install
28
28
 
29
29
  * `Veyor.project` - get project by name, branch, or build version
30
30
  * `Veyor.projects` - get all projects
31
+ * `Veyor.project_add` - add a project
32
+ * `Veyor.project_delete` - delete a project
31
33
  * `Veyor.project_history` - get project history
32
34
  * `Veyor.project_deployments` - get project deployments
33
35
  * `Veyor.project_settings` - get project settings
34
36
  * `Veyor.build_start` - start a build
37
+ * `Veyor.build_delete` - delete a build
35
38
  * `Veyor.build_cancel` - cancel a build
39
+ * `Veyor.build_artifacts` - get build artifacts
40
+ * `Veyor.build_log` - get build logs
41
+ * `Veyor.environments` - get environments
42
+ * `Veyor.environment_settings` - get environment settings
36
43
 
37
44
  More to come in future `veyor` versions
38
45
 
@@ -49,11 +56,13 @@ Veyor.configuration do |config|
49
56
  end
50
57
  ```
51
58
 
52
- Ideally, store those in env var keys like
59
+ Store those in env var keys like
53
60
 
54
61
  * `ENV['APPVEYOR_ACCOUNT_NAME']`
55
62
  * `ENV['APPVEYOR_API_TOKEN']`
56
63
 
64
+ An API key is not used if not provided - we don't error when it's missing as we did before. Use `verbose=true` to see request headers sent.
65
+
57
66
  ## In Ruby
58
67
 
59
68
  ### get projects
@@ -86,6 +95,26 @@ Veyor.build_start(project: 'cowsay')
86
95
  Veyor.build_cancel(project: 'cowsay', version: '1.0.697')
87
96
  ```
88
97
 
98
+ ### Kill all queued builds
99
+
100
+ Sometimes all your builds are queued and you need to kill all of them
101
+
102
+ ```ruby
103
+ x = Veyor.projects();
104
+ x.each do |z|
105
+ nm = z['name']
106
+ puts "working on " + nm
107
+ if z["builds"].length > 0
108
+ # each build
109
+ z["builds"].each do |w|
110
+ if w['status'] == "queued"
111
+ Veyor.build_cancel(project: nm, version: w['version'])
112
+ end
113
+ end
114
+ end
115
+ end
116
+ ```
117
+
89
118
  ## On the CLI
90
119
 
91
120
  List commands
@@ -175,8 +204,6 @@ veyor project cowsay --json | jq .project
175
204
  ...cutoff
176
205
  ```
177
206
 
178
-
179
-
180
207
  ## Contributing
181
208
 
182
209
  Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Code of Conduct](https://github.com/sckott/veyor/blob/master/CONDUCT.md).
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ Rake::TestTask.new do |t|
5
5
  t.libs << "test"
6
6
  t.test_files = FileList['test/test-*.rb']
7
7
  t.verbose = true
8
+ t.warning = false
8
9
  end
9
10
 
10
11
  desc "Run tests"
@@ -4,9 +4,11 @@ require 'veyor/utils'
4
4
  require 'rexml/document'
5
5
  require 'rexml/xpath'
6
6
 
7
- # @!macro veyor_params
7
+ # @!macro veyor_acct_proj
8
8
  # @param account [String] An Appveyor account name
9
9
  # @param project [String] An Appveyor project name
10
+
11
+ # @!macro veyor_verbose
10
12
  # @param verbose [Boolean] Print request headers to stdout. Default: false
11
13
 
12
14
  # @!macro history_params
@@ -34,44 +36,62 @@ require 'rexml/xpath'
34
36
  # The following methods are provided:
35
37
  # * `Veyor.project` - get project by name, branch, or build version
36
38
  # * `Veyor.projects` - get all projects
39
+ # * `Veyor.project_add` - add a project
40
+ # * `Veyor.project_delete` - delete a project
37
41
  # * `Veyor.project_history` - get project history
38
42
  # * `Veyor.project_deployments` - get project deployments
39
43
  # * `Veyor.project_settings` - get project settings
40
44
  # * `Veyor.build_start` - start a build
45
+ # * `Veyor.build_delete` - delete a build
41
46
  # * `Veyor.build_cancel` - cancel a build
47
+ # * `Veyor.build_artifacts` - get build artifacts
48
+ # * `Veyor.build_log` - get build logs
49
+ # * `Veyor.environments` - get environments
50
+ # * `Veyor.environment_settings` - get environment settings
42
51
  #
43
52
  # More will be added in future `veyor` versions
44
53
  #
45
- # @see https://www.appVeyor.com/docs/api/ for
54
+ # @see https://www.appveyor.com/docs/api/ for
46
55
  # detailed description of the Appveyor API
56
+ #
57
+ # @see https://www.appveyor.com/docs/api/environments-deployments
58
+ # for documentation on the Environments API
59
+ #
60
+ # You no longer are required to have an API key for all
61
+ # requests. If you're only doing GET requests against public projects
62
+ # you won't need a key, but if you're doing GET requests against
63
+ # non-public projects, or non-GET requests against any projects then
64
+ # you'll need a key.
65
+
47
66
 
48
67
  module Veyor
49
68
  extend Configuration
50
69
 
51
70
  define_setting :account_name, ENV['APPVEYOR_ACCOUNT_NAME']
52
71
  define_setting :account_token, ENV['APPVEYOR_API_TOKEN']
53
- define_setting :base_url, "https://ci.appVeyor.com"
72
+ define_setting :base_url, "https://ci.appveyor.com"
54
73
 
55
74
  ##
56
75
  # Fetch projects
57
76
  #
58
77
  # @!macro veyor_options
59
- # @param verbose [Boolean] Print request headers to stdout. Default: false
78
+ # @!macro veyor_verbose
60
79
  # @return [Array] An array of hashes
61
80
  #
62
81
  # @example
63
82
  # require 'veyor'
64
- # Veyor.projects()
83
+ # Veyor.projects
65
84
  def self.projects(options: nil, verbose: false)
66
85
  route = prep_route('projects', nil, nil, nil, nil)
67
- Request.new(route, nil, nil, options, verbose).get
86
+ Request.new(route, {}, nil, options, verbose).get
68
87
  end
69
88
 
70
89
  ##
71
90
  # Get a single project - gets the latest build
72
91
  #
92
+ # @!macro veyor_acct_proj
73
93
  # @!macro veyor_options
74
- # @!macro veyor_params
94
+ # @!macro veyor_verbose
75
95
  # @param branch [String] Branch name
76
96
  # @param version [String] Project version
77
97
  # @return [Array] An array of hashes
@@ -93,21 +113,58 @@ module Veyor
93
113
  version: nil, options: nil, verbose: false)
94
114
 
95
115
  route = prep_route('projects', get_account(account), project, branch, version)
96
- Request.new(route, nil, nil, options, verbose).get
116
+ Request.new(route, {}, nil, options, verbose).get
117
+ end
118
+
119
+ ##
120
+ # Add a project
121
+ #
122
+ # @param provider [String] provider name, one of gitHub, bitBucket, vso,
123
+ # gitLab, kiln, stash, git, mercurial, subversion
124
+ # @param slug [String] a project slug like e.g., foo/bar
125
+ # @!macro veyor_options
126
+ # @!macro veyor_verbose
127
+ # @return [Hash] A hash
128
+ #
129
+ # @example
130
+ # require 'veyor'
131
+ # Veyor.project_add(provider: 'gitHub', slug: 'sckott/httpcode')
132
+ def self.project_add(provider:, slug:, options: nil, verbose: false)
133
+ route = prep_route('projects', nil, nil, nil, nil)
134
+ body = { :repositoryProvider => check_provider(provider),
135
+ :repositoryName => slug }
136
+ Request.new(route, {}, body, options, verbose).post
137
+ end
138
+
139
+ ##
140
+ # Delete a project
141
+ #
142
+ # @!macro veyor_acct_proj
143
+ # @!macro veyor_options
144
+ # @!macro veyor_verbose
145
+ # @return [Int] 204 on success
146
+ #
147
+ # @example
148
+ # require 'veyor'
149
+ # Veyor.project_delete(account: 'sckott', project: 'httpcode')
150
+ def self.project_delete(account:, project:, options: nil, verbose: false)
151
+ route = prep_route('projects', account, project, nil, nil)
152
+ Request.new(route, {}, nil, options, verbose).delete
97
153
  end
98
154
 
99
155
  ##
100
156
  # Get project history
101
157
  #
158
+ # @!macro veyor_acct_proj
102
159
  # @!macro veyor_options
103
- # @!macro veyor_params
104
160
  # @!macro history_params
161
+ # @!macro veyor_verbose
105
162
  # @return [Array] An array of hashes
106
163
  #
107
164
  # @example
108
165
  # require 'veyor'
109
166
  # # get project history
110
- # x = Veyor.project_history(project: 'cowsay')
167
+ # x = Veyor.project_history(project: 'cowsay');
111
168
  # x['builds'].collect { |x| x['status'] }
112
169
  #
113
170
  # # limit results
@@ -129,26 +186,28 @@ module Veyor
129
186
  ##
130
187
  # Get project deployments
131
188
  #
189
+ # @!macro veyor_acct_proj
132
190
  # @!macro veyor_options
133
- # @!macro veyor_params
191
+ # @!macro veyor_verbose
134
192
  # @return [Array] An array of hashes
135
193
  #
136
194
  # @example
137
195
  # require 'veyor'
138
- # # get project history
139
- # x = Veyor.project_deployments(project: 'cowsay')
196
+ # # get project deployments
197
+ # x = Veyor.project_deployments(project: 'cowsay');
140
198
  # x['deployments']
141
199
  def self.project_deployments(account: nil, project: nil, options: nil, verbose: false)
142
200
  route = sprintf('/projects/%s/%s/deployments', get_account(account), project)
143
- Request.new(route, nil, nil, options, verbose).get
201
+ Request.new(route, {}, nil, options, verbose).get
144
202
  end
145
203
 
146
204
  ##
147
205
  # Get project settings
148
206
  #
149
- # @!macro veyor_options
150
- # @!macro veyor_params
207
+ # @!macro veyor_acct_proj
151
208
  # @param yaml [Boolean] Return yaml version of project settings. Default: false
209
+ # @!macro veyor_options
210
+ # @!macro veyor_verbose
152
211
  # @return [Array] An array of hashes
153
212
  #
154
213
  # @example
@@ -164,14 +223,15 @@ module Veyor
164
223
  if yaml
165
224
  route = route + '/yaml'
166
225
  end
167
- Request.new(route, nil, nil, options, verbose).get
226
+ Request.new(route, {}, nil, options, verbose).get
168
227
  end
169
228
 
170
229
  ##
171
230
  # Start build of branch of most recent commit
172
231
  #
232
+ # @!macro veyor_acct_proj
173
233
  # @!macro veyor_options
174
- # @!macro veyor_params
234
+ # @!macro veyor_verbose
175
235
  # @param branch [String] Branch name
176
236
  # @return [Array] An array of hashes
177
237
  #
@@ -182,25 +242,106 @@ module Veyor
182
242
  def self.build_start(account: nil, project:, branch: 'master', options: nil, verbose: false)
183
243
  body = { :accountName => get_account(account),
184
244
  :projectSlug => project, :branch => branch }
185
- Request.new('builds', nil, body, options, verbose).post
245
+ Request.new('builds', {}, body, options, verbose).post
186
246
  end
187
247
 
188
248
  ##
189
249
  # Cancel a build
190
250
  #
191
- # @!macro veyor_options
192
- # @!macro veyor_params
251
+ # @!macro veyor_acct_proj
193
252
  # @param version [String] Project version
194
- # @return [Array] An array of hashes
253
+ # @!macro veyor_options
254
+ # @!macro veyor_verbose
255
+ # @return [Int] 204 on success
195
256
  #
196
257
  # @example
197
258
  # require 'veyor'
198
259
  # # start a build
199
260
  # x = Veyor.build_start(project: 'cowsay')
200
- # x = Veyor.build_cancel(project: 'cowsay', version: '1.0.697')
261
+ # x = Veyor.build_cancel(project: 'cowsay', version: '1.0.6088')
201
262
  def self.build_cancel(account: nil, project:, version:, options: nil, verbose: false)
202
263
  route = sprintf('/builds/%s/%s/%s', get_account(account), project, version)
203
- Request.new(route, nil, nil, options, verbose).delete
264
+ Request.new(route, {}, nil, options, verbose).delete
204
265
  end
205
266
 
267
+ ##
268
+ # Delete a build
269
+ #
270
+ # @param build_id [String] Build ID
271
+ # @!macro veyor_options
272
+ # @!macro veyor_verbose
273
+ # @return [Int] 204 on success
274
+ #
275
+ # @example
276
+ # require 'veyor'
277
+ # # start a build
278
+ # x = Veyor.build_start(project: 'cowsay')
279
+ # x = Veyor.build_delete(build_id: '17962865')
280
+ def self.build_delete(build_id:, options: nil, verbose: false)
281
+ route = sprintf('/builds/%s', build_id)
282
+ Request.new(route, {}, nil, options, verbose).delete
283
+ end
284
+
285
+ ##
286
+ # Download a build log
287
+ #
288
+ # @param job_id [String] Job ID
289
+ # @!macro veyor_options
290
+ # @!macro veyor_verbose
291
+ # @return [Array] An array of hashes
292
+ #
293
+ # @example
294
+ # require 'veyor'
295
+ # x = Veyor.build_log(job_id: '4b9u720e2sjulln9')
296
+ def self.build_log(job_id:, options: nil, verbose: false)
297
+ route = sprintf('/buildjobs/%s/log', job_id)
298
+ Request.new(route, {}, nil, options, verbose).get
299
+ end
300
+
301
+ ##
302
+ # List artifacts of a job
303
+ #
304
+ # @param job_id [String] Job ID
305
+ # @!macro veyor_options
306
+ # @!macro veyor_verbose
307
+ # @return [Array] An array of hashes
308
+ #
309
+ # @example
310
+ # require 'veyor'
311
+ # x = Veyor.build_artifacts(job_id: '4b9u720e2sjulln9')
312
+ def self.build_artifacts(job_id:, options: nil, verbose: false)
313
+ route = sprintf('/buildjobs/%s/artifacts', job_id)
314
+ Request.new(route, {}, nil, options, verbose).get
315
+ end
316
+
317
+ # environments
318
+ ##
319
+ # Get environments
320
+ #
321
+ # @!macro veyor_options
322
+ # @!macro veyor_verbose
323
+ # @return [Array] An array of hashes
324
+ #
325
+ # @example
326
+ # require 'veyor'
327
+ # x = Veyor.environments
328
+ def self.environments(options: nil, verbose: false)
329
+ Request.new('environments', {}, nil, options, verbose).get
330
+ end
331
+
332
+ # Get environment settings
333
+ #
334
+ # @param id [String] A deployment environment ID
335
+ # @!macro veyor_options
336
+ # @!macro veyor_verbose
337
+ # @return [Array] An array of hashes
338
+ #
339
+ # @example
340
+ # require 'veyor'
341
+ # Veyor.environment_settings(id: 123456)
342
+ def self.environment_settings(id:, options: nil, verbose: false)
343
+ route = sprintf('/environments/%s/settings', id)
344
+ Request.new(route, {}, nil, options, verbose).get
345
+ end
346
+
206
347
  end
@@ -1,18 +1,70 @@
1
1
  require "faraday"
2
- require 'faraday_middleware'
3
2
  require "multi_json"
4
3
 
5
- require 'veyor/faraday'
6
- require "veyor/error"
7
4
  require 'veyor/utils'
8
5
  require 'veyor/helpers/configuration'
9
6
 
7
+ class CustomErrors < Faraday::Response::Middleware
8
+ def on_complete(env)
9
+ case env[:status]
10
+ when 400
11
+ raise Veyor::BadRequest, error_message_400(env)
12
+ when 404
13
+ raise Veyor::NotFound, error_message_400(env)
14
+ when 500
15
+ raise Veyor::InternalServerError, error_message_500(env, "Something is technically wrong.")
16
+ when 502
17
+ raise Veyor::BadGateway, error_message_500(env, "The server returned an invalid or incomplete response.")
18
+ when 503
19
+ raise Veyor::ServiceUnavailable, error_message_500(env, "Appveyor is rate limiting your requests.")
20
+ when 504
21
+ raise Veyor::GatewayTimeout, error_message_500(env, "504 Gateway Time-out")
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def error_message_400(x)
28
+ "\n #{x.method.to_s.upcase} #{x.url.to_s}\n Status #{x.status}#{error_body(x.body)}"
29
+ end
30
+
31
+ def error_body(body)
32
+ if not body.nil? and not body.empty? and body.kind_of?(String)
33
+ if is_json?(body)
34
+ body = ::MultiJson.load(body)
35
+ if body['message'].nil?
36
+ body = nil
37
+ else
38
+ body = body['message']
39
+ end
40
+ end
41
+ end
42
+
43
+ if body.nil?
44
+ nil
45
+ else
46
+ ": #{body}"
47
+ end
48
+ end
49
+
50
+ def error_message_500(x, body=nil)
51
+ "\n #{x.method.to_s.upcase} #{x.url.to_s}\n Status #{[x.status.to_s + ':', body].compact.join(' ')}"
52
+ end
53
+
54
+ def is_json?(string)
55
+ MultiJson.load(string)
56
+ return true
57
+ rescue MultiJson::ParseError => e
58
+ return false
59
+ end
60
+ end
61
+
10
62
  ##
11
63
  # veyor::Request
12
64
  #
13
65
  # Class to perform HTTP requests to the Appveyor API
14
66
  module Veyor
15
- class Request #:nodoc:
67
+ class Request
16
68
 
17
69
  attr_accessor :route
18
70
  attr_accessor :args
@@ -26,70 +78,67 @@ module Veyor
26
78
  self.body = body
27
79
  self.options = options
28
80
  self.verbose = verbose
29
-
30
- self.perform
31
81
  end
32
82
 
33
- def get
34
- res = _veyor_get(self.route, self.args)
35
- return parse_result(res)
36
- end
83
+ def get_conn
84
+ # if args.nil?
85
+ # args = {}
86
+ # end
37
87
 
38
- def post
39
- res = _veyor_post(self.route, self.body)
40
- return parse_result(res)
41
- end
42
-
43
- def delete
44
- return _veyor_delete(self.route).status
45
- end
46
-
47
- def perform
48
- if self.args.nil?
49
- self.args = {}
50
- end
51
-
52
- if verbose
53
- $conn = Faraday.new(:url => Veyor.base_url, :request => options) do |f|
88
+ if self.verbose
89
+ conn = Faraday.new(:url => Veyor.base_url, :request => self.options) do |f|
54
90
  f.request :url_encoded
55
91
  f.response :logger
92
+ f.use CustomErrors
56
93
  f.adapter Faraday.default_adapter
57
- # f.use FaradayMiddleware::RaiseHttpException
58
94
  end
59
95
  else
60
- $conn = Faraday.new(:url => Veyor.base_url, :request => options) do |f|
96
+ conn = Faraday.new(:url => Veyor.base_url, :request => self.options) do |f|
61
97
  f.request :url_encoded
98
+ f.use CustomErrors
62
99
  f.adapter Faraday.default_adapter
63
- # f.use FaradayMiddleware::RaiseHttpException
64
100
  end
65
101
  end
66
102
 
67
- $conn.headers[:user_agent] = make_ua
68
- $conn.headers["X-USER-AGENT"] = make_ua
103
+ conn.headers[:user_agent] = make_ua
104
+ conn.headers["X-USER-AGENT"] = make_ua
105
+ return conn
69
106
  end
70
107
 
71
108
  def _veyor_get(route, opts)
72
- $conn.get do |req|
109
+ tok = Veyor.account_token
110
+ conn = get_conn
111
+ conn.get do |req|
73
112
  req.url '/api/' + route
74
113
  req.params = opts
75
114
  req.headers["Content-Type"] = "application/json"
76
- req.headers["Authorization"] = "Bearer " + Veyor.account_token
115
+ req.headers["Authorization"] = "Bearer " + tok if tok
77
116
  end
78
117
  end
79
118
 
80
119
  def _veyor_post(route, body)
81
- $conn.post do |req|
120
+ tok = Veyor.account_token
121
+ if tok.nil?
122
+ raise 'could not find env var APPVEYOR_API_TOKEN; please set it'
123
+ end
124
+ conn = get_conn
125
+ conn.post do |req|
82
126
  req.url '/api/' + route
83
127
  req.body = MultiJson.dump(body)
84
128
  req.headers["Content-Type"] = "application/json"
85
- req.headers["Authorization"] = "Bearer " + Veyor.account_token
129
+ req.headers["Authorization"] = "Bearer " + tok
86
130
  end
87
131
  end
88
132
 
89
133
  def _veyor_delete(route)
90
- $conn.delete do |req|
134
+ tok = Veyor.account_token
135
+ if tok.nil?
136
+ raise 'could not find env var APPVEYOR_API_TOKEN; please set it'
137
+ end
138
+ conn = get_conn
139
+ conn.delete do |req|
91
140
  req.url '/api/' + route
92
- req.headers["Authorization"] = "Bearer " + Veyor.account_token
141
+ req.headers["Authorization"] = "Bearer " + tok
93
142
  end
94
143
  end
95
144
 
@@ -101,5 +150,19 @@ module Veyor
101
150
  end
102
151
  end
103
152
 
153
+ def get
154
+ res = _veyor_get(self.route, self.args)
155
+ return parse_result(res)
156
+ end
157
+
158
+ def post
159
+ res = _veyor_post(self.route, self.body)
160
+ return parse_result(res)
161
+ end
162
+
163
+ def delete
164
+ return _veyor_delete(self.route).status
165
+ end
166
+
104
167
  end
105
168
  end
@@ -1,26 +1,26 @@
1
- def make_ua
1
+ def make_ua #:nodoc:
2
2
  requa = 'Faraday/v' + Faraday::VERSION
3
3
  habua = 'Veyor/v' + Veyor::VERSION
4
4
  return requa + ' ' + habua
5
5
  end
6
6
 
7
- def prep_args(limit, start_build, branch)
7
+ def prep_args(limit, start_build, branch) #:nodoc:
8
8
  args = { recordsNumber: limit, startBuildId: start_build, branch: branch }
9
9
  opts = args.delete_if { |k, v| v.nil? }
10
10
  return opts
11
11
  end
12
12
 
13
- def get_account(x)
13
+ def get_account(x) #:nodoc:
14
14
  if x.nil?
15
15
  x = Veyor.account_name
16
16
  if x.nil?
17
- raise 'no account name found - one must be supplied'
17
+ raise 'could not find env var APPVEYOR_ACCOUNT_NAME; please set it'
18
18
  end
19
19
  end
20
20
  return x
21
21
  end
22
22
 
23
- def prep_route(route, account, project, branch, version)
23
+ def prep_route(route, account, project, branch, version) #:nodoc:
24
24
  if branch.nil? && version.nil?
25
25
  route = sprintf('%s/%s/%s', route, account, project)
26
26
  elsif !branch.nil? && version.nil?
@@ -30,3 +30,22 @@ def prep_route(route, account, project, branch, version)
30
30
  end
31
31
  return route
32
32
  end
33
+
34
+
35
+ def check_provider(x) #:nodoc:
36
+ appveyor_providers = ["gitHub",
37
+ "bitBucket",
38
+ "vso",
39
+ "gitLab",
40
+ "kiln",
41
+ "stash",
42
+ "git",
43
+ "mercurial",
44
+ "subversion"]
45
+
46
+ if appveyor_providers.include? x
47
+ return x
48
+ else
49
+ raise 'provider must be one of: %s' % appveyor_providers.join(', ')
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module Veyor
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = Veyor::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.required_ruby_version = '>= 2.0'
11
- s.date = '2016-06-24'
11
+ s.date = '2019-07-22'
12
12
  s.summary = "Appveyor Ruby Client"
13
13
  s.description = "Low Level Ruby Client for the Appveyor API"
14
14
  s.authors = "Scott Chamberlain"
@@ -22,14 +22,14 @@ Gem::Specification.new do |s|
22
22
  s.bindir = 'bin'
23
23
  s.executables = ['veyor']
24
24
 
25
- s.add_development_dependency "bundler", '~> 1.12', '>= 1.12.5'
26
- s.add_development_dependency "rake", '~> 11.1', '>= 11.1.2'
27
- s.add_development_dependency "test-unit", '~> 3.1', '>= 3.1.9'
28
- s.add_development_dependency "simplecov", '~> 0.11.2'
29
- s.add_development_dependency "codecov", '~> 0.1.5'
25
+ s.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
26
+ s.add_development_dependency 'rake', '~> 12.3', '>= 12.3.2'
27
+ s.add_development_dependency 'test-unit', '~> 3.3', '>= 3.3.3'
28
+ s.add_development_dependency 'simplecov', '~> 0.16.1'
29
+ s.add_development_dependency 'codecov', '~> 0.1.14'
30
30
 
31
- s.add_runtime_dependency 'faraday', '~> 0.9.2'
32
- s.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
33
- s.add_runtime_dependency 'thor', '~> 0.19.1'
34
- s.add_runtime_dependency 'multi_json', '~> 1.12', '>= 1.12.1'
31
+ s.add_runtime_dependency 'faraday', '~> 0.15.4'
32
+ s.add_runtime_dependency 'faraday_middleware', '~> 0.13.1'
33
+ s.add_runtime_dependency 'thor', '~> 0.20.3'
34
+ s.add_runtime_dependency 'multi_json', '~> 1.13', '>= 1.13.1'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veyor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chamberlain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,150 +16,150 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
19
+ version: '2.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.12.5
22
+ version: 2.0.1
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.12'
29
+ version: '2.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.12.5
32
+ version: 2.0.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '11.1'
39
+ version: '12.3'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 11.1.2
42
+ version: 12.3.2
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '11.1'
49
+ version: '12.3'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 11.1.2
52
+ version: 12.3.2
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: test-unit
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '3.1'
59
+ version: '3.3'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 3.1.9
62
+ version: 3.3.3
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.1'
69
+ version: '3.3'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 3.1.9
72
+ version: 3.3.3
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: simplecov
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: 0.11.2
79
+ version: 0.16.1
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: 0.11.2
86
+ version: 0.16.1
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: codecov
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: 0.1.5
93
+ version: 0.1.14
94
94
  type: :development
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: 0.1.5
100
+ version: 0.1.14
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: faraday
103
103
  requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - "~>"
106
106
  - !ruby/object:Gem::Version
107
- version: 0.9.2
107
+ version: 0.15.4
108
108
  type: :runtime
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - "~>"
113
113
  - !ruby/object:Gem::Version
114
- version: 0.9.2
114
+ version: 0.15.4
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: faraday_middleware
117
117
  requirement: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
- version: 0.10.0
121
+ version: 0.13.1
122
122
  type: :runtime
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - "~>"
127
127
  - !ruby/object:Gem::Version
128
- version: 0.10.0
128
+ version: 0.13.1
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: thor
131
131
  requirement: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: 0.19.1
135
+ version: 0.20.3
136
136
  type: :runtime
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: 0.19.1
142
+ version: 0.20.3
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: multi_json
145
145
  requirement: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - "~>"
148
148
  - !ruby/object:Gem::Version
149
- version: '1.12'
149
+ version: '1.13'
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: 1.12.1
152
+ version: 1.13.1
153
153
  type: :runtime
154
154
  prerelease: false
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.12'
159
+ version: '1.13'
160
160
  - - ">="
161
161
  - !ruby/object:Gem::Version
162
- version: 1.12.1
162
+ version: 1.13.1
163
163
  description: Low Level Ruby Client for the Appveyor API
164
164
  email: myrmecocystus@gmail.com
165
165
  executables:
@@ -168,6 +168,7 @@ extensions: []
168
168
  extra_rdoc_files: []
169
169
  files:
170
170
  - ".gitignore"
171
+ - ".simplecov"
171
172
  - ".travis.yml"
172
173
  - CHANGELOG.md
173
174
  - CONDUCT.md
@@ -178,8 +179,6 @@ files:
178
179
  - Rakefile
179
180
  - bin/veyor
180
181
  - lib/veyor.rb
181
- - lib/veyor/error.rb
182
- - lib/veyor/faraday.rb
183
182
  - lib/veyor/helpers/configuration.rb
184
183
  - lib/veyor/request.rb
185
184
  - lib/veyor/utils.rb
@@ -204,10 +203,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
203
  - !ruby/object:Gem::Version
205
204
  version: '0'
206
205
  requirements: []
207
- rubyforge_project:
208
- rubygems_version: 2.6.4
206
+ rubygems_version: 3.0.3
209
207
  signing_key:
210
208
  specification_version: 4
211
209
  summary: Appveyor Ruby Client
212
210
  test_files: []
213
- has_rdoc:
@@ -1,22 +0,0 @@
1
- module Veyor
2
- # Custom error class for rescuing from all Veyor errors
3
- class Error < StandardError; end
4
-
5
- # Raised when Crossref returns the HTTP status code 400
6
- class BadRequest < Error; end
7
-
8
- # Raised when Crossref returns the HTTP status code 404
9
- class NotFound < Error; end
10
-
11
- # Raised when Crossref returns the HTTP status code 500
12
- class InternalServerError < Error; end
13
-
14
- # Raised when Crossref returns the HTTP status code 502
15
- class BadGateway < Error; end
16
-
17
- # Raised when Crossref returns the HTTP status code 503
18
- class ServiceUnavailable < Error; end
19
-
20
- # Raised when Crossref returns the HTTP status code 504
21
- class GatewayTimeout < Error; end
22
- end
@@ -1,71 +0,0 @@
1
- require 'faraday'
2
- require 'multi_json'
3
-
4
- # @private
5
- module FaradayMiddleware
6
- # @private
7
- class RaiseHttpException < Faraday::Middleware
8
- def call(env)
9
- @app.call(env).on_complete do |response|
10
- case response[:status].to_i
11
- when 400
12
- raise Veyor::BadRequest, error_message_400(response)
13
- when 404
14
- raise Veyor::NotFound, error_message_400(response)
15
- when 500
16
- raise Veyor::InternalServerError, error_message_500(response, "Something is technically wrong.")
17
- when 502
18
- raise Veyor::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
19
- when 503
20
- raise Veyor::ServiceUnavailable, error_message_500(response, "Crossref is rate limiting your requests.")
21
- when 504
22
- raise Veyor::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
23
- end
24
- end
25
- end
26
-
27
- def initialize(app)
28
- super app
29
- @parser = nil
30
- end
31
-
32
- private
33
-
34
- def error_message_400(response)
35
- "\n #{response[:method].to_s.upcase} #{response[:url].to_s}\n Status #{response[:status]}#{error_body(response[:body])}"
36
- end
37
-
38
- def error_body(body)
39
- if not body.nil? and not body.empty? and body.kind_of?(String)
40
- if is_json?(body)
41
- body = ::MultiJson.load(body)
42
- if body['message'].nil?
43
- body = nil
44
- elseif body['message'].length == 1
45
- body = body['message']
46
- else
47
- body = body['message'].collect { |x| x['message'] }.join('; ')
48
- end
49
- end
50
- end
51
-
52
- if body.nil?
53
- nil
54
- else
55
- ": #{body}"
56
- end
57
- end
58
-
59
- def error_message_500(response, body=nil)
60
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
61
- end
62
-
63
- def is_json?(string)
64
- MultiJson.load(string)
65
- return true
66
- rescue MultiJson::ParseError => e
67
- return false
68
- end
69
-
70
- end
71
- end