提交 ca7dab45 编写于 作者: M Mislav Marohnić

[api] Fix GraphQL requests made to Enterprise hosts

This invocation would fail:

    GITHUB_HOST=example.com hub api graphql ...

This is because hub would erroneously try to POST to
`example.com/api/v3/graphql` instead of `example.com/api/graphql`.

This applies a workaround that gets rid of the "v3" portion for requests
to "graphql" endpoint.

Fixes #2287
上级 b73f5f18
......@@ -280,6 +280,22 @@ Feature: hub api
{"name":"Jet","size":2}
"""
Scenario: Enterprise GraphQL
Given I am "octokitten" on git.my.org with OAuth token "FITOKEN"
Given the GitHub API server:
"""
post('/api/graphql', :host_name => 'git.my.org') {
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
json :name => "Ed"
}
"""
And $GITHUB_HOST is "git.my.org"
When I successfully run `hub api graphql -f query=QUERY`
Then the output should contain exactly:
"""
{"name":"Ed"}
"""
Scenario: Repo context
Given I am in "git://github.com/octocat/Hello-World.git" git repo
Given the GitHub API server:
......
......@@ -229,6 +229,11 @@ type simpleClient struct {
}
func (c *simpleClient) performRequest(method, path string, body io.Reader, configure func(*http.Request)) (*simpleResponse, error) {
if path == "graphql" {
// FIXME: This dirty workaround cancels out the "v3" portion of the
// "/api/v3" prefix used for Enterprise. Find a better place for this.
path = "../graphql"
}
url, err := url.Parse(path)
if err == nil {
url = c.rootUrl.ResolveReference(url)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册