зеркало из https://github.com/mislav/hub.git
Lock down to GitHub API v3 for future compatibility
Every API request will now declare that it wants v3 by setting "Accept: application/vnd.github.v3+json". http://developer.github.com/v3/media/
This commit is contained in:
Родитель
431bb031c2
Коммит
0c86e6acef
|
@ -11,6 +11,7 @@ Feature: hub checkout <PULLREQ-URL>
|
|||
Given the GitHub API server:
|
||||
"""
|
||||
get('/repos/mojombo/jekyll/pulls/77') {
|
||||
halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json'
|
||||
json :head => {
|
||||
:label => 'mislav:fixes',
|
||||
:repo => { :private => false }
|
||||
|
|
|
@ -42,6 +42,7 @@ Feature: hub fork
|
|||
Given the GitHub API server:
|
||||
"""
|
||||
get('/repos/mislav/dotfiles') {
|
||||
halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json'
|
||||
json :parent => { :html_url => 'https://github.com/unrelated/dotfiles' }
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -123,7 +123,7 @@ module Hub
|
|||
res.error! unless res.success?
|
||||
raw_url = res.data['files'].values.first['raw_url']
|
||||
res = get(raw_url) do |req|
|
||||
req['Accept'] = '*/*'
|
||||
req['Accept'] = 'text/plain'
|
||||
end
|
||||
res.error! unless res.success?
|
||||
res.body
|
||||
|
@ -228,6 +228,7 @@ module Hub
|
|||
req['User-Agent'] = "Hub #{Hub::VERSION}"
|
||||
apply_authentication(req, url)
|
||||
yield req if block_given?
|
||||
finalize_request(req, url)
|
||||
|
||||
begin
|
||||
res = http.start { http.request(req) }
|
||||
|
@ -261,6 +262,12 @@ module Hub
|
|||
req.basic_auth user, pass
|
||||
end
|
||||
|
||||
def finalize_request(req, url)
|
||||
if !req['Accept'] || req['Accept'] == '*/*'
|
||||
req['Accept'] = 'application/vnd.github.v3+json'
|
||||
end
|
||||
end
|
||||
|
||||
def create_connection url
|
||||
use_ssl = 'https' == url.scheme
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ class HubTest < Minitest::Test
|
|||
}))
|
||||
|
||||
stub_request(:get, "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff").
|
||||
with(:headers => {'Accept'=>'*/*'}).
|
||||
with(:headers => {'Accept'=>'text/plain'}).
|
||||
to_return(:status => 200)
|
||||
|
||||
with_tmpdir('/tmp/') do
|
||||
|
|
Загрузка…
Ссылка в новой задаче