зеркало из https://github.com/mislav/hub.git
Enable API debug output by setting HUB_VERBOSE
This will print information about every HTTP request and response to stderr. Authentication info is redacted. Example: $ HUB_VERBOSE=1 hub ci-status > GET https://api.github.com/... > ...
This commit is contained in:
Родитель
1e4477b566
Коммит
c54a78953f
|
@ -129,3 +129,28 @@ Feature: hub create
|
|||
"""
|
||||
When I successfully run `hub create`
|
||||
Then the url for "origin" should be "git@github.com:mislav/my-dot-files.git"
|
||||
|
||||
Scenario: Verbose API output
|
||||
Given the GitHub API server:
|
||||
"""
|
||||
get('/repos/mislav/dotfiles') { status 404 }
|
||||
post('/user/repos') {
|
||||
response['location'] = 'http://disney.com'
|
||||
json :full_name => 'mislav/dotfiles'
|
||||
}
|
||||
"""
|
||||
And $HUB_VERBOSE is "on"
|
||||
When I successfully run `hub create`
|
||||
Then the stderr should contain exactly:
|
||||
"""
|
||||
> GET https://api.github.com/repos/mislav/dotfiles
|
||||
> Authorization: token [REDACTED]
|
||||
< HTTP 404
|
||||
|
||||
> POST https://api.github.com/user/repos
|
||||
> Authorization: token [REDACTED]
|
||||
{"name": "dotfiles", "private": false}
|
||||
< HTTP 200
|
||||
< Location: http://disney.com
|
||||
{"full_name":"mislav/dotfiles"}\n
|
||||
"""
|
||||
|
|
|
@ -838,7 +838,9 @@ module Hub
|
|||
config_file = ENV['HUB_CONFIG'] || '~/.config/hub'
|
||||
file_store = GitHubAPI::FileStore.new File.expand_path(config_file)
|
||||
file_config = GitHubAPI::Configuration.new file_store
|
||||
GitHubAPI.new file_config, :app_url => 'http://hub.github.com/'
|
||||
GitHubAPI.new file_config,
|
||||
:app_url => 'http://hub.github.com/',
|
||||
:verbose => !ENV['HUB_VERBOSE'].to_s.empty?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,8 +27,11 @@ module Hub
|
|||
def initialize config, options
|
||||
@config = config
|
||||
@oauth_app_url = options.fetch(:app_url)
|
||||
@verbose = options.fetch(:verbose, false)
|
||||
end
|
||||
|
||||
def verbose?() @verbose end
|
||||
|
||||
# Fake exception type for net/http exception handling.
|
||||
# Necessary because net/http may or may not be loaded at the time.
|
||||
module Exceptions
|
||||
|
@ -346,9 +349,63 @@ module Hub
|
|||
end
|
||||
end
|
||||
|
||||
module Verbose
|
||||
def finalize_request(req, url)
|
||||
super
|
||||
dump_request_info(req, url) if verbose?
|
||||
end
|
||||
|
||||
def perform_request(*)
|
||||
res = super
|
||||
dump_response_info(res) if verbose?
|
||||
res
|
||||
end
|
||||
|
||||
def verbose_puts(msg)
|
||||
msg = "\e[36m%s\e[m" % msg if $stderr.tty?
|
||||
$stderr.puts msg
|
||||
end
|
||||
|
||||
def dump_request_info(req, url)
|
||||
verbose_puts "> %s %s://%s%s" % [
|
||||
req.method.to_s.upcase,
|
||||
url.scheme,
|
||||
url.host,
|
||||
req.path,
|
||||
]
|
||||
dump_headers(req, '> ')
|
||||
dump_body(req)
|
||||
end
|
||||
|
||||
def dump_response_info(res)
|
||||
verbose_puts "< HTTP %s" % res.status
|
||||
dump_headers(res, '< ')
|
||||
dump_body(res)
|
||||
end
|
||||
|
||||
def dump_body(obj)
|
||||
verbose_puts obj.body if obj.body
|
||||
end
|
||||
|
||||
DUMP_HEADERS = %w[ Authorization X-GitHub-OTP Location ]
|
||||
|
||||
def dump_headers(obj, indent)
|
||||
DUMP_HEADERS.each do |header|
|
||||
if value = obj[header]
|
||||
verbose_puts '%s%s: %s' % [
|
||||
indent,
|
||||
header,
|
||||
value.sub(/^(basic|token) (.+)/i, '\1 [REDACTED]'),
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include HttpMethods
|
||||
include OAuth
|
||||
include GistAuth
|
||||
include Verbose
|
||||
|
||||
# Filesystem store suitable for Configuration
|
||||
class FileStore
|
||||
|
|
Загрузка…
Ссылка в новой задаче