From 40893eb95c0a9842714e857eb5b6b3c5c6afe689 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 1 Nov 2019 14:30:25 +0800 Subject: [PATCH 1/4] Add support for Pages API --- lib/Github/Api/Repo.php | 6 + lib/Github/Api/Repository/Pages.php | 63 ++++++++ .../Github/Tests/Api/Repository/PagesTest.php | 151 ++++++++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 lib/Github/Api/Repository/Pages.php create mode 100644 test/Github/Tests/Api/Repository/PagesTest.php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 37cb8aac794..03160a2e367 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -12,6 +12,7 @@ use Github\Api\Repository\Forks; use Github\Api\Repository\Hooks; use Github\Api\Repository\Labels; +use Github\Api\Repository\Pages; use Github\Api\Repository\Projects; use Github\Api\Repository\Protection; use Github\Api\Repository\Releases; @@ -595,6 +596,11 @@ public function traffic() return new Traffic($this->client); } + public function pages() + { + return new Pages($this->client); + } + /** * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Pages.php b/lib/Github/Api/Repository/Pages.php new file mode 100644 index 00000000000..ed216084949 --- /dev/null +++ b/lib/Github/Api/Repository/Pages.php @@ -0,0 +1,63 @@ + + */ +class Pages extends AbstractApi +{ + use AcceptHeaderTrait; + + public function configure() + { + $this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; + + return $this; + } + + public function show($username, $repository) + { + return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages'); + } + + public function enable($username, $repository, array $params = []) + { + return $this->post('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages', $params); + } + + public function disable($username, $repository) + { + return $this->delete('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages'); + } + + public function update($username, $repository, array $params = []) + { + return $this->put('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages', $params); + } + + public function requestBuild($username, $repository) + { + return $this->post('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds'); + } + + public function builds($username, $repository) + { + return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds'); + } + + public function showLatestBuild($username, $repository) + { + return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds/latest'); + } + + public function showBuild($username, $repository, $id) + { + return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds/' . rawurlencode($id)); + } +} diff --git a/test/Github/Tests/Api/Repository/PagesTest.php b/test/Github/Tests/Api/Repository/PagesTest.php new file mode 100644 index 00000000000..83a732a778f --- /dev/null +++ b/test/Github/Tests/Api/Repository/PagesTest.php @@ -0,0 +1,151 @@ + "built"]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/pages') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldEnablePages() + { + $params = [ + 'source' => [ + 'branch' => 'master', + 'path' => '/path', + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/pages', $params); + + $api->enable('KnpLabs', 'php-github-api', $params); + } + + /** + * @test + */ + public function shouldDisablePages() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/pages'); + + $api->disable('KnpLabs', 'php-github-api'); + } + + /** + * @test + */ + public function shouldUpdatePages() + { + $params = [ + 'source' => "master /docs", + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/pages', $params); + + $api->update('KnpLabs', 'php-github-api', $params); + } + + /** + * @test + */ + public function shouldRequestPagesBuild() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/pages/builds'); + + $api->requestBuild('KnpLabs', 'php-github-api'); + } + + /** + * @test + */ + public function shouldGetAllPagesBuilds() + { + $expectedValue = [["status" => "built"]]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/pages/builds') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->builds('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetLatestPagesBuild() + { + $expectedValue = ["status" => "built"]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/pages/builds/latest') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showLatestBuild('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function showGetOnePagesBuild() + { + $expectedValue = ["status" => "built"]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/pages/builds/some') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showBuild('KnpLabs', 'php-github-api', 'some')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Repository\Pages::class; + } +} From 3fbf4d05ce88feb6a4ff4b3c0848afd7d286eda3 Mon Sep 17 00:00:00 2001 From: yunwuxin Date: Fri, 1 Nov 2019 06:38:33 +0000 Subject: [PATCH 2/4] Apply fixes from StyleCI --- lib/Github/Api/Repository/Pages.php | 16 ++++++++-------- test/Github/Tests/Api/Repository/PagesTest.php | 15 +++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/Repository/Pages.php b/lib/Github/Api/Repository/Pages.php index ed216084949..9d53f5f0970 100644 --- a/lib/Github/Api/Repository/Pages.php +++ b/lib/Github/Api/Repository/Pages.php @@ -23,41 +23,41 @@ public function configure() public function show($username, $repository) { - return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); } public function enable($username, $repository, array $params = []) { - return $this->post('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params); } public function disable($username, $repository) { - return $this->delete('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages'); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); } public function update($username, $repository, array $params = []) { - return $this->put('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages', $params); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params); } public function requestBuild($username, $repository) { - return $this->post('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds'); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds'); } public function builds($username, $repository) { - return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds'); } public function showLatestBuild($username, $repository) { - return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds/latest'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/latest'); } public function showBuild($username, $repository, $id) { - return $this->get('/repos/' . rawurlencode($username) . '/' . rawurlencode($repository) . '/pages/builds/' . rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/'.rawurlencode($id)); } } diff --git a/test/Github/Tests/Api/Repository/PagesTest.php b/test/Github/Tests/Api/Repository/PagesTest.php index 83a732a778f..c6b34cbc8b3 100644 --- a/test/Github/Tests/Api/Repository/PagesTest.php +++ b/test/Github/Tests/Api/Repository/PagesTest.php @@ -7,19 +7,18 @@ use PHPUnit\Framework\MockObject\MockObject; /** - * Class PagesTest - * @package Github\Tests\Api\Repository + * Class PagesTest. + * * @method Pages|MockObject getApiMock() */ class PagesTest extends TestCase { - /** * @test */ public function shouldGetPagesInfo() { - $expectedValue = ["status" => "built"]; + $expectedValue = ['status' => 'built']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -69,7 +68,7 @@ public function shouldDisablePages() public function shouldUpdatePages() { $params = [ - 'source' => "master /docs", + 'source' => 'master /docs', ]; $api = $this->getApiMock(); @@ -98,7 +97,7 @@ public function shouldRequestPagesBuild() */ public function shouldGetAllPagesBuilds() { - $expectedValue = [["status" => "built"]]; + $expectedValue = [['status' => 'built']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -114,7 +113,7 @@ public function shouldGetAllPagesBuilds() */ public function shouldGetLatestPagesBuild() { - $expectedValue = ["status" => "built"]; + $expectedValue = ['status' => 'built']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -130,7 +129,7 @@ public function shouldGetLatestPagesBuild() */ public function showGetOnePagesBuild() { - $expectedValue = ["status" => "built"]; + $expectedValue = ['status' => 'built']; $api = $this->getApiMock(); $api->expects($this->once()) From 45c0048ee02aa9c7edaec94a3c8d4137e24194a3 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 1 Nov 2019 14:59:41 +0800 Subject: [PATCH 3/4] fixed --- lib/Github/Api/Repository/Pages.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/Repository/Pages.php b/lib/Github/Api/Repository/Pages.php index 9d53f5f0970..cd0b8484c4c 100644 --- a/lib/Github/Api/Repository/Pages.php +++ b/lib/Github/Api/Repository/Pages.php @@ -14,13 +14,6 @@ class Pages extends AbstractApi { use AcceptHeaderTrait; - public function configure() - { - $this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; - - return $this; - } - public function show($username, $repository) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); @@ -28,11 +21,13 @@ public function show($username, $repository) public function enable($username, $repository, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params); } public function disable($username, $repository) { + $this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); } From 91c60a291232bc94e28f81f94283cf883665f641 Mon Sep 17 00:00:00 2001 From: yunwuxin Date: Fri, 1 Nov 2019 07:00:14 +0000 Subject: [PATCH 4/4] Apply fixes from StyleCI --- lib/Github/Api/Repository/Pages.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Api/Repository/Pages.php b/lib/Github/Api/Repository/Pages.php index cd0b8484c4c..b641cb957c0 100644 --- a/lib/Github/Api/Repository/Pages.php +++ b/lib/Github/Api/Repository/Pages.php @@ -22,12 +22,14 @@ public function show($username, $repository) public function enable($username, $repository, array $params = []) { $this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params); } public function disable($username, $repository) { $this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); }