From ca7dab4559ecdbd9746f75b657a3084cf8de0008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 3 Oct 2019 01:49:26 +0200 Subject: [PATCH] [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 --- features/api.feature | 16 ++++++++++++++++ github/http.go | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/features/api.feature b/features/api.feature index 5a82cfc2..f44a491d 100644 --- a/features/api.feature +++ b/features/api.feature @@ -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: diff --git a/github/http.go b/github/http.go index 017ff31e..8df7b32c 100644 --- a/github/http.go +++ b/github/http.go @@ -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) -- GitLab