From dc00db714761a6b3a3dfc91cebee12e5261070d9 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 11 Dec 2020 20:25:39 +0100 Subject: [PATCH] Prepare 3.0 release and remove remaining deprecated code --- UPGRADE-3.0.md | 21 +++ lib/Github/Api/Repo.php | 16 --- lib/Github/Api/Repository/Checks.php | 107 ---------------- .../HttpClient/Message/ResponseMediator.php | 5 +- .../HttpClient/Plugin/Authentication.php | 3 +- .../Plugin/GithubExceptionThrower.php | 3 +- lib/Github/HttpClient/Plugin/History.php | 3 +- lib/Github/HttpClient/Plugin/PathPrepend.php | 3 +- test/Github/Tests/Api/RepoTest.php | 10 -- .../Tests/Api/Repository/ChecksTest.php | 120 ------------------ 10 files changed, 26 insertions(+), 265 deletions(-) create mode 100644 UPGRADE-3.0.md delete mode 100644 lib/Github/Api/Repository/Checks.php delete mode 100644 test/Github/Tests/Api/Repository/ChecksTest.php diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md new file mode 100644 index 00000000000..8e0e3f5fa59 --- /dev/null +++ b/UPGRADE-3.0.md @@ -0,0 +1,21 @@ +## UPGRADE from 2.x to 3.0 + +### General + +* The `php-http/httplug` dependency requires is bumped to minimum ^2.1. +* A client implementing `psr/http-client-implementation` is required. + To upgrade your application (default install) switch from guzzle 6 to guzzle 7 (or replace `php-http/guzzle6-adapter` with any `psr/http-client-implementation`), see the install instructions in the [README file](README.md) +* All previous deprecated code in version 2 is removed. +* The following classes are now final + * `Github\HttpClient\Message\ResponseMediator` + * `Github\HttpClient\Plugin\Authentication` + * `Github\HttpClient\Plugin\GithubExceptionThrower` + * `Github\HttpClient\Plugin\History` + * `Github\HttpClient\Plugin\PathPrepend` + +### Authetication methods + +* `Github\Client::AUTH_URL_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead. +* `Github\Client::AUTH_URL_CLIENT_ID` use `Github\Client::AUTH_CLIENT_ID` instead. +* `Github\Client::AUTH_HTTP_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead. +* `Github\Client::AUTH_HTTP_PASSWORD` use `Github\Client::AUTH_ACCESS_TOKEN` instead. diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index c99ec7b80c9..4698ebbc031 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -8,7 +8,6 @@ use Github\Api\Repository\Actions\WorkflowJobs; use Github\Api\Repository\Actions\WorkflowRuns; use Github\Api\Repository\Actions\Workflows; -use Github\Api\Repository\Checks; use Github\Api\Repository\Checks\CheckRuns; use Github\Api\Repository\Checks\CheckSuites; use Github\Api\Repository\Collaborators; @@ -323,21 +322,6 @@ public function commits() return new Commits($this->getClient()); } - /** - * Manage checks on a repository. - * - * @link https://developer.github.com/v3/checks/ - * @deprecated since 2.17 and will be removed in 3.0. Use the "checkRuns" or "checkSuites" api's instead. - * - * @return Checks - */ - public function checks() - { - @trigger_error(sprintf('The "%s" is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "checkRuns" or "checkSuites" api\'s instead.', __METHOD__), E_USER_DEPRECATED); - - return new Checks($this->getClient()); - } - /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-runs */ diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php deleted file mode 100644 index b4be88668cb..00000000000 --- a/lib/Github/Api/Repository/Checks.php +++ /dev/null @@ -1,107 +0,0 @@ - - */ -class Checks extends AbstractApi -{ - // NEXT_MAJOR: remove trait use. - use AcceptHeaderTrait; - - /** - * @link https://developer.github.com/v3/checks/runs/#create-a-check-run - * - * @param string $username - * @param string $repository - * @param array $params - * - * @throws MissingArgumentException - * - * @return array - */ - public function create($username, $repository, array $params = []) - { - @trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::create" method instead.', __METHOD__), E_USER_DEPRECATED); - - if (!isset($params['name'], $params['head_sha'])) { - throw new MissingArgumentException(['name', 'head_sha']); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs', $params); - } - - /** - * @link https://developer.github.com/v3/checks/runs/#update-a-check-run - * - * @param string $username - * @param string $repository - * @param string $checkRunId - * @param array $params - * - * @return array - */ - public function update($username, $repository, $checkRunId, array $params = []) - { - @trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::update" method instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId), $params); - } - - /** - * @link https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-git-reference - * - * @param string $username - * @param string $repository - * @param string $ref - * @param array $params - * - * @return array - */ - public function all($username, $repository, $ref, $params = []) - { - @trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::allForReference" method instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); - } - - /** - * @link https://developer.github.com/v3/checks/runs/#get-a-check-run - * - * @param string $username - * @param string $repository - * @param string $checkRunId - * - * @return array - */ - public function show($username, $repository, $checkRunId) - { - @trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::show" method instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId)); - } - - /** - * @link https://developer.github.com/v3/checks/runs/#list-check-run-annotations - * - * @param string $username - * @param string $repository - * @param string $checkRunId - * - * @return array - */ - public function annotations($username, $repository, $checkRunId) - { - @trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::annotations" method instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); - } -} diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index d4974aa75bc..a72ccef7ed4 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -5,10 +5,7 @@ use Github\Exception\ApiLimitExceedException; use Psr\Http\Message\ResponseInterface; -/** - * @final since 2.19 - */ -class ResponseMediator +final class ResponseMediator { /** * @param ResponseInterface $response diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 8204bacf183..2b533436617 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -12,9 +12,8 @@ * Add authentication to the request. * * @author Tobias Nyholm - * @final since 2.19 */ -class Authentication implements Plugin +final class Authentication implements Plugin { /** * @var string diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 6a8c1330e6b..e4adb6a5f5c 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -17,9 +17,8 @@ /** * @author Joseph Bielawski * @author Tobias Nyholm - * @final since 2.19 */ -class GithubExceptionThrower implements Plugin +final class GithubExceptionThrower implements Plugin { /** * @return Promise diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 1df5c605f91..341c288a6ea 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -11,9 +11,8 @@ * A plugin to remember the last response. * * @author Tobias Nyholm - * @final since 2.19 */ -class History implements Journal +final class History implements Journal { /** * @var ResponseInterface|null diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index b82b93aa880..c1077299607 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -10,9 +10,8 @@ * Prepend the URI with a string. * * @author Tobias Nyholm - * @final since 2.19 */ -class PathPrepend implements Plugin +final class PathPrepend implements Plugin { /** * @var string diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 00cabcc2854..083d7201aa8 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -626,16 +626,6 @@ public function shouldTransferRepository() $this->assertEquals($expectedArray, $api->transfer('KnpLabs', 'php-github-api', 'github', [1234, 1235])); } - /** - * @test - */ - public function shouldGetChecksApiObject() - { - $api = $this->getApiMock(); - - $this->assertInstanceOf(\Github\Api\Repository\Checks::class, $api->checks()); - } - /** * @return string */ diff --git a/test/Github/Tests/Api/Repository/ChecksTest.php b/test/Github/Tests/Api/Repository/ChecksTest.php deleted file mode 100644 index 6db5695842c..00000000000 --- a/test/Github/Tests/Api/Repository/ChecksTest.php +++ /dev/null @@ -1,120 +0,0 @@ -expectException(MissingArgumentException::class); - $data = ['name' => 'my check']; - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('post'); - - $api->create('KnpLabs', 'php-github-api', $data); - } - - /** - * @test - */ - public function shouldNotCreateWithoutName() - { - $this->expectException(MissingArgumentException::class); - $data = ['head_sha' => 'commitSHA123456']; - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('post'); - - $api->create('KnpLabs', 'php-github-api', $data); - } - - /** - * @test - */ - public function shouldCreateCheck() - { - $expectedValue = ['state' => 'success']; - $data = ['head_sha' => 'commitSHA123456', 'name' => 'my check']; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/repos/KnpLabs/php-github-api/check-runs', $data) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); - } - - /** - * @test - */ - public function shouldUpdateCheck() - { - $expectedValue = ['state' => 'success']; - $data = ['head_sha' => 'commitSHA123456', 'name' => 'my check']; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/repos/KnpLabs/php-github-api/check-runs/123', $data) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', '123', $data)); - } - - /** - * @test - */ - public function shouldGetAllChecksForRef() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/commits/cb4abc15424c0015b4468d73df55efb8b60a4a3d/check-runs'); - - $api->all('KnpLabs', 'php-github-api', 'cb4abc15424c0015b4468d73df55efb8b60a4a3d'); - } - - /** - * @test - */ - public function shouldShowSingleCheckRun() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/check-runs/14'); - - $api->show('KnpLabs', 'php-github-api', 14); - } - - /** - * @test - */ - public function shouldListCheckRunAnnotations() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/check-runs/14/annotations'); - - $api->annotations('KnpLabs', 'php-github-api', 14); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \Github\Api\Repository\Checks::class; - } -}