From f0cc3bfad1bdecf383a3485377e3e89f321a8b4b Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Thu, 10 Dec 2020 20:44:22 +0400
Subject: [PATCH] fix(github): Fix `v3` stripping for graphql in GHE (#7944)

---
 lib/util/http/github.spec.ts | 4 ++--
 lib/util/http/github.ts      | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/util/http/github.spec.ts b/lib/util/http/github.spec.ts
index 9ce3ae1422..dc9c5b6ddf 100644
--- a/lib/util/http/github.spec.ts
+++ b/lib/util/http/github.spec.ts
@@ -218,12 +218,12 @@ describe(getName(__filename), () => {
       const repository = { foo: 'foo', bar: 'bar' };
       httpMock
         .scope('https://ghe.mycompany.com')
-        .post('/graphql')
+        .post('/api/graphql')
         .reply(200, { data: { repository } });
       await githubApi.queryRepo(query);
       const [req] = httpMock.getTrace();
       expect(req).toBeDefined();
-      expect(req.url).toEqual('https://ghe.mycompany.com/graphql');
+      expect(req.url).toEqual('https://ghe.mycompany.com/api/graphql');
     });
     it('supports app mode', async () => {
       hostRules.add({ hostType: 'github', token: 'x-access-token:abc123' });
diff --git a/lib/util/http/github.ts b/lib/util/http/github.ts
index cd4a663849..5c53567c39 100644
--- a/lib/util/http/github.ts
+++ b/lib/util/http/github.ts
@@ -220,10 +220,8 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {
 
     const path = 'graphql';
 
-    const { origin } = new URL(baseUrl);
-
     const opts: HttpPostOptions = {
-      baseUrl: origin,
+      baseUrl: baseUrl.replace('/v3/', '/'), // GHE uses unversioned graphql path
       body: { query },
       headers: { accept: options?.acceptHeader },
     };
-- 
GitLab