travis 1.8.5.travis.784.4 → 1.8.5.travis.791.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/travis/tools/github.rb +25 -11
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e0cd4124b23b23d4f6745f3fbca42cf87b581d9
4
- data.tar.gz: 90196f99281e2db71b08f9679db5e3030693c6fd
3
+ metadata.gz: 6b9c5f9724e3878c47bb8c7a1a9084f3a64292cb
4
+ data.tar.gz: d3c611ac306c10e4e4ffc2c7f0a179495168f85c
5
5
  SHA512:
6
- metadata.gz: a0d63c1b8e3666c6144027451e46bb23efc40589e094d060bfa4c5eaa72c8697c9696dbeed558bdd2559cd6835d47708a742d2d7a530f88ba2d04deb804095fc
7
- data.tar.gz: 63e75595947637a3edcbda73cc5f38348069e36c3217592d2fbbb4362981f1f26d5e4bc96d7f82b2317bebf2d2087953639678304e4d541a6d9657c0cd9943e0
6
+ metadata.gz: 25e4775422e0dfba4381e7e480cb81a90cd30f62c45b4bdbbe26fe0901f1ba0f76730d0e45fdaef590e8f2da0d9d5ae0d49eeca900343dad4485326126f8401f
7
+ data.tar.gz: 3da725f5e470a49f8a13ccb01ea8f7c0dde74631d861b64f07f6e69bb7bf864915eb436031dbbaaeb9eb2f7a5f3f13fc2df2510c30fc2ee9b4dd19489b6e3f87
@@ -205,26 +205,40 @@ module Travis
205
205
  end
206
206
 
207
207
  def basic_auth(user, password, die = true, otp = nil, &block)
208
- opt = { :username => user, :password => password }
209
- opt[:headers] = { "X-GitHub-OTP" => otp } if otp
210
- yield GH.with(opt)
208
+ gh = GH.with(:username => user, :password => password)
209
+ with_otp(gh, user, otp, &block)
211
210
  rescue GH::Error => error
212
- if error.info[:response_status] == 401 and error.info[:response_headers]['x-github-otp'].to_s =~ /required/
213
- otp = ask_otp.arity == 0 ? ask_otp.call : ask_otp.call(user)
214
- basic_auth(user, password, die, otp, &block)
215
- elsif die
216
- raise gh_error(error)
217
- end
211
+ raise gh_error(error) if die
218
212
  end
219
213
 
220
214
  def login(user, password, die = true, otp = nil)
221
215
  basic_auth(user, password, die, otp) do |gh|
222
- reply = gh.post('/authorizations', :scopes => scopes, :note => note)
223
- self.callback = proc { gh.delete reply['_links']['self']['href'] } if drop_token
216
+ reply = create_token(gh)
217
+ auth_href = reply['_links']['self']['href']
218
+ self.callback = proc { with_otp(gh, user, otp) { |g| g.delete(auth_href) } } if drop_token
224
219
  reply['token']
225
220
  end
226
221
  end
227
222
 
223
+ def create_token(gh)
224
+ gh.post('/authorizations', :scopes => scopes, :note => note)
225
+ rescue GH::Error => error
226
+ # token might already exist due to bug in earlier CLI version, we'll have to delete it first
227
+ raise error unless error.info[:response_status] == 422 and error.info[:response_body].to_s =~ /already_exists/
228
+ raise error unless reply = gh['/authorizations'].detect { |a| a['note'] == note }
229
+ gh.delete(reply['_links']['self']['href'])
230
+ retry
231
+ end
232
+
233
+ def with_otp(gh, user, otp, &block)
234
+ gh = GH.with(gh.options.merge(:headers => { "X-GitHub-OTP" => otp })) if otp
235
+ block.call(gh)
236
+ rescue GH::Error => error
237
+ raise error unless error.info[:response_status] == 401 and error.info[:response_headers]['x-github-otp'].to_s =~ /required/
238
+ otp = ask_otp.arity == 0 ? ask_otp.call : ask_otp.call(user)
239
+ retry
240
+ end
241
+
228
242
  def acceptable?(token)
229
243
  return true unless check_token
230
244
  gh = GH.with(:token => token)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.5.travis.784.4
4
+ version: 1.8.5.travis.791.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
@@ -58,7 +58,7 @@ authors:
58
58
  autorequire:
59
59
  bindir: bin
60
60
  cert_chain: []
61
- date: 2016-11-18 00:00:00.000000000 Z
61
+ date: 2016-11-22 00:00:00.000000000 Z
62
62
  dependencies:
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: faraday