From 0d989bbcff6a63e9f24784c3c0215263666245b0 Mon Sep 17 00:00:00 2001 From: Asher Goldberg Date: Tue, 18 Jan 2022 21:13:18 -0500 Subject: [PATCH 1/2] Fix prepend on Enteprrise for V4 --- lib/Github/Client.php | 9 ++++++++- test/Github/Tests/ClientTest.php | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 4a61af84bae..ecd4aec7904 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -346,7 +346,14 @@ private function setEnterpriseUrl($enterpriseUrl): void $builder->removePlugin(PathPrepend::class); $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri($enterpriseUrl))); - $builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion()))); + + // For GHE, v4 API endpoint is at `api/graphql` so we don't want to add the version number + // For earlier versions add the version number after /api + if ($this->getApiVersion() === 'v4') { + $builder->addPlugin(new PathPrepend('/api')); + } else { + $builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion()))); + } } /** diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index c4980b8edc5..c03ec0f53ff 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -223,4 +223,25 @@ public function testEnterpriseUrl() $client = new Client($httpClientBuilder, null, 'https://foobar.com'); $client->enterprise()->stats()->show('all'); } + + /** + * Make sure that the prepend is correct when using the v4 endpoint on Enterprise + */ + public function testEnterprisePrependGraphQLV4() + { + $httpClientMock = $this->getMockBuilder(ClientInterface::class) + ->setMethods(['sendRequest']) + ->getMock(); + + $httpClientMock->expects($this->once()) + ->method('sendRequest') + ->with($this->callback(function (RequestInterface $request) { + return (string) $request->getUri() === 'https://foobar.com/api/graphql'; + })) + ->willReturn(new Response(200, [], '[]')); + + $httpClientBuilder = new Builder($httpClientMock); + $client = new Client($httpClientBuilder, 'v4', 'https://foobar.com'); + $client->graphql()->execute('query'); + } } From a44fa2b8d067f68518796bbbc76fc5ba3d828d04 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 23 Jan 2022 12:30:09 +0100 Subject: [PATCH 2/2] Allow codestyle fix --- test/Github/Tests/ClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index c03ec0f53ff..74255c9a9f3 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -225,7 +225,7 @@ public function testEnterpriseUrl() } /** - * Make sure that the prepend is correct when using the v4 endpoint on Enterprise + * Make sure that the prepend is correct when using the v4 endpoint on Enterprise. */ public function testEnterprisePrependGraphQLV4() {