From d3f4b848cf12f5ed8bf63d6a4aa5634f68884af1 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sat, 2 Mar 2013 09:49:05 +0100 Subject: [PATCH 001/951] [BUGFIX] Empty JSON-Content will be added to request If you create an POST-Request (e.g. with an forking action) the HTTPClient will be created with a post content "[]". This can create some problems on requesting path. Solution: Check if the content is empty. --- lib/Github/HttpClient/HttpClient.php | 4 +++- test/Github/Tests/HttpClient/HttpClientTest.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index bd402e17087..8b84fc3ec47 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -167,7 +167,9 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); - $request->setContent(json_encode($parameters)); + if (count($parameters) > 0) { + $request->setContent(json_encode($parameters)); + } $hasListeners = 0 < count($this->listeners); if ($hasListeners) { diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index 164a33506ca..4fc44717537 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -84,6 +84,23 @@ public function shouldDoPOSTRequest() $httpClient = new HttpClient(array(), $client); $httpClient->post($path, $parameters, $headers); + + $this->assertEquals('{"a":"b"}', $httpClient->getLastRequest()->getContent()); + } + + /** + * @test + */ + public function shouldDoPOSTRequestWithoutContent() + { + $path = '/some/path'; + + $client = $this->getBrowserMock(); + + $httpClient = new HttpClient(array(), $client); + $httpClient->post($path); + + $this->assertEmpty($httpClient->getLastRequest()->getContent()); } /** From 8313981992394ded52199e6e847b1aa5a4e9acfd Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 6 Mar 2013 18:22:13 +0100 Subject: [PATCH 002/951] Fix HttpClient instance in authenticate after last refactor. --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 4fc0dc7b741..cafe5554186 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -161,7 +161,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null $password = null; } - $this->httpClient->authenticate($tokenOrLogin, $password, $authMethod); + $this->getHttpClient()->authenticate($tokenOrLogin, $password, $authMethod); } /** From 941b00e98677219287e6a7d990de65bb49a719fd Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Sun, 10 Mar 2013 03:01:13 +0100 Subject: [PATCH 003/951] [BUGFIX] Github -> Repos -> Statuses -> Show gives 404 If you request a github repo status via api $githubClient->api('repository')->statuses()->show(... the HTTP client throws a 404, because the request URL build "//repos/...". --- lib/Github/Api/Repository/Statuses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index 6a30ee81173..9872acd06d7 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -22,7 +22,7 @@ class Statuses extends AbstractApi */ public function show($username, $repository, $sha) { - return $this->get('/repos/'.urlencode($username).'/'.urlencode($repository).'/statuses/'.urlencode($sha)); + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/statuses/'.urlencode($sha)); } /** From fefe329c28e5d81feabd928538613af952fc6642 Mon Sep 17 00:00:00 2001 From: Alexandre Bacco Date: Sun, 10 Mar 2013 20:33:22 +0100 Subject: [PATCH 004/951] Add a showContents() method to Contents API --- lib/Github/Api/Repository/Contents.php | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 23ffed4bbc8..c700cf77f74 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -72,4 +72,33 @@ public function archive($username, $repository, $format, $reference = null) 'ref' => $reference )); } + + /** + * Get the contents of a file in a repository + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param string $reference reference to a branch or commit + * + * @return string content of file + */ + public function showContents($username, $repository, $path, $reference = null) + { + $file = $this->show($username, $repository, $path, $reference); + + if (!isset($file['type']) || 'file' !== $file['type']) { + throw new \Exception(sprintf('Path "%s" is not a file.', $path)); + } + + if (!isset($file['content'])) { + throw new \Exception(sprintf('Unable to access "content" for file "%s" (possible keys: "%s").', $path, implode(', ', array_keys($file)))); + } + + if (!isset($file['encoding']) || 'base64' !== $file['encoding']) { + throw new \Exception(sprintf('Encoding of file "%s" is not supported.', $path)); + } + + return base64_decode($file['content']); + } } From b02176f74ba0738a3aa2c2a77e386461a7391c04 Mon Sep 17 00:00:00 2001 From: Alexandre Bacco Date: Tue, 12 Mar 2013 10:51:55 +0100 Subject: [PATCH 005/951] Rename showContents() to download() --- lib/Github/Api/Repository/Contents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index c700cf77f74..b3c8ad9d213 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -83,7 +83,7 @@ public function archive($username, $repository, $format, $reference = null) * * @return string content of file */ - public function showContents($username, $repository, $path, $reference = null) + public function download($username, $repository, $path, $reference = null) { $file = $this->show($username, $repository, $path, $reference); From bae4bed77f4249d27d12bd49e6ef61d02f537550 Mon Sep 17 00:00:00 2001 From: Alexandre Bacco Date: Tue, 12 Mar 2013 10:53:10 +0100 Subject: [PATCH 006/951] Add test for Api\Respository\Contents:download --- .../Tests/Api/Repository/ContentsTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 5639a4e6ede..a37cf3f7a09 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -85,6 +85,29 @@ public function shouldFetchZipballArchive() $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball')); } + + /** + * @test + */ + public function shouldDownloadForGivenPath() + { + // The show() method return + $getValue = json_decode( + '{"sha":"5639a4e6ede372d7ea25b1064be4e2045c2a053d","size":2648,"name":"ContentsTest.php","path":"test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","type":"file","url":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/contents\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","git_url":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/git\/blobs\/5639a4e6ede372d7ea25b1064be4e2045c2a053d","html_url":"https:\/\/github.com\/KnpLabs\/php-github-api\/blob\/master\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","_links":{"self":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/contents\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","git":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/git\/blobs\/5639a4e6ede372d7ea25b1064be4e2045c2a053d","html":"https:\/\/github.com\/KnpLabs\/php-github-api\/blob\/master\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php"},"content":"PD9waHAKCm5hbWVzcGFjZSBHaXRodWJcVGVzdHNcQXBpXFJlcG9zaXRvcnk7\nCgp1c2UgR2l0aHViXFRlc3RzXEFwaVxUZXN0Q2FzZTsKCmNsYXNzIENvbnRl\nbnRzVGVzdCBleHRlbmRzIFRlc3RDYXNlCnsKICAgIC8qKgogICAgICogQHRl\nc3QKICAgICAqLwogICAgcHVibGljIGZ1bmN0aW9uIHNob3VsZFNob3dDb250\nZW50Rm9yR2l2ZW5QYXRoKCkKICAgIHsKICAgICAgICAkZXhwZWN0ZWRWYWx1\nZSA9ICc8P3BocCAvLy4uJzsKCiAgICAgICAgJGFwaSA9ICR0aGlzLT5nZXRB\ncGlNb2NrKCk7CiAgICAgICAgJGFwaS0+ZXhwZWN0cygkdGhpcy0+b25jZSgp\nKQogICAgICAgICAgICAtPm1ldGhvZCgnZ2V0JykKICAgICAgICAgICAgLT53\naXRoKCdyZXBvcy9LbnBMYWJzL3BocC1naXRodWItYXBpL2NvbnRlbnRzL3Rl\nc3QlMkZHaXRodWIlMkZUZXN0cyUyRkFwaSUyRlJlcG9zaXRvcnklMkZDb250\nZW50c1Rlc3QucGhwJywgYXJyYXkoJ3JlZicgPT4gbnVsbCkpCiAgICAgICAg\nICAgIC0+d2lsbCgkdGhpcy0+cmV0dXJuVmFsdWUoJGV4cGVjdGVkVmFsdWUp\nKTsKCiAgICAgICAgJHRoaXMtPmFzc2VydEVxdWFscygkZXhwZWN0ZWRWYWx1\nZSwgJGFwaS0+c2hvdygnS25wTGFicycsICdwaHAtZ2l0aHViLWFwaScsICd0\nZXN0L0dpdGh1Yi9UZXN0cy9BcGkvUmVwb3NpdG9yeS9Db250ZW50c1Rlc3Qu\ncGhwJykpOwogICAgfQoKICAgIC8qKgogICAgICogQHRlc3QKICAgICAqLwog\nICAgcHVibGljIGZ1bmN0aW9uIHNob3VsZFNob3dSZWFkbWUoKQogICAgewog\nICAgICAgICRleHBlY3RlZFZhbHVlID0gJ1JFQURNRS4uLic7CgogICAgICAg\nICRhcGkgPSAkdGhpcy0+Z2V0QXBpTW9jaygpOwogICAgICAgICRhcGktPmV4\ncGVjdHMoJHRoaXMtPm9uY2UoKSkKICAgICAgICAgICAgLT5tZXRob2QoJ2dl\ndCcpCiAgICAgICAgICAgIC0+d2l0aCgncmVwb3MvS25wTGFicy9waHAtZ2l0\naHViLWFwaS9yZWFkbWUnLCBhcnJheSgncmVmJyA9PiBudWxsKSkKICAgICAg\nICAgICAgLT53aWxsKCR0aGlzLT5yZXR1cm5WYWx1ZSgkZXhwZWN0ZWRWYWx1\nZSkpOwoKICAgICAgICAkdGhpcy0+YXNzZXJ0RXF1YWxzKCRleHBlY3RlZFZh\nbHVlLCAkYXBpLT5yZWFkbWUoJ0tucExhYnMnLCAncGhwLWdpdGh1Yi1hcGkn\nKSk7CiAgICB9CgogICAgLyoqCiAgICAgKiBAdGVzdAogICAgICovCiAgICBw\ndWJsaWMgZnVuY3Rpb24gc2hvdWxkRmV0Y2hUYXJiYWxsQXJjaGl2ZVdoZW5G\nb3JtYXROb3RSZWNvZ25pemVkKCkKICAgIHsKICAgICAgICAkZXhwZWN0ZWRW\nYWx1ZSA9ICd0YXInOwoKICAgICAgICAkYXBpID0gJHRoaXMtPmdldEFwaU1v\nY2soKTsKICAgICAgICAkYXBpLT5leHBlY3RzKCR0aGlzLT5vbmNlKCkpCiAg\nICAgICAgICAgIC0+bWV0aG9kKCdnZXQnKQogICAgICAgICAgICAtPndpdGgo\nJ3JlcG9zL0tucExhYnMvcGhwLWdpdGh1Yi1hcGkvdGFyYmFsbCcsIGFycmF5\nKCdyZWYnID0+IG51bGwpKQogICAgICAgICAgICAtPndpbGwoJHRoaXMtPnJl\ndHVyblZhbHVlKCRleHBlY3RlZFZhbHVlKSk7CgogICAgICAgICR0aGlzLT5h\nc3NlcnRFcXVhbHMoJGV4cGVjdGVkVmFsdWUsICRhcGktPmFyY2hpdmUoJ0tu\ncExhYnMnLCAncGhwLWdpdGh1Yi1hcGknLCAnc29tZUZvcm1hdCcpKTsKICAg\nIH0KCiAgICAvKioKICAgICAqIEB0ZXN0CiAgICAgKi8KICAgIHB1YmxpYyBm\ndW5jdGlvbiBzaG91bGRGZXRjaFRhcmJhbGxBcmNoaXZlKCkKICAgIHsKICAg\nICAgICAkZXhwZWN0ZWRWYWx1ZSA9ICd0YXInOwoKICAgICAgICAkYXBpID0g\nJHRoaXMtPmdldEFwaU1vY2soKTsKICAgICAgICAkYXBpLT5leHBlY3RzKCR0\naGlzLT5vbmNlKCkpCiAgICAgICAgICAgIC0+bWV0aG9kKCdnZXQnKQogICAg\nICAgICAgICAtPndpdGgoJ3JlcG9zL0tucExhYnMvcGhwLWdpdGh1Yi1hcGkv\ndGFyYmFsbCcsIGFycmF5KCdyZWYnID0+IG51bGwpKQogICAgICAgICAgICAt\nPndpbGwoJHRoaXMtPnJldHVyblZhbHVlKCRleHBlY3RlZFZhbHVlKSk7Cgog\nICAgICAgICR0aGlzLT5hc3NlcnRFcXVhbHMoJGV4cGVjdGVkVmFsdWUsICRh\ncGktPmFyY2hpdmUoJ0tucExhYnMnLCAncGhwLWdpdGh1Yi1hcGknLCAndGFy\nYmFsbCcpKTsKICAgIH0KCiAgICAvKioKICAgICAqIEB0ZXN0CiAgICAgKi8K\nICAgIHB1YmxpYyBmdW5jdGlvbiBzaG91bGRGZXRjaFppcGJhbGxBcmNoaXZl\nKCkKICAgIHsKICAgICAgICAkZXhwZWN0ZWRWYWx1ZSA9ICd6aXAnOwoKICAg\nICAgICAkYXBpID0gJHRoaXMtPmdldEFwaU1vY2soKTsKICAgICAgICAkYXBp\nLT5leHBlY3RzKCR0aGlzLT5vbmNlKCkpCiAgICAgICAgICAgIC0+bWV0aG9k\nKCdnZXQnKQogICAgICAgICAgICAtPndpdGgoJ3JlcG9zL0tucExhYnMvcGhw\nLWdpdGh1Yi1hcGkvemlwYmFsbCcsIGFycmF5KCdyZWYnID0+IG51bGwpKQog\nICAgICAgICAgICAtPndpbGwoJHRoaXMtPnJldHVyblZhbHVlKCRleHBlY3Rl\nZFZhbHVlKSk7CgogICAgICAgICR0aGlzLT5hc3NlcnRFcXVhbHMoJGV4cGVj\ndGVkVmFsdWUsICRhcGktPmFyY2hpdmUoJ0tucExhYnMnLCAncGhwLWdpdGh1\nYi1hcGknLCAnemlwYmFsbCcpKTsKICAgIH0KCiAgICBwcm90ZWN0ZWQgZnVu\nY3Rpb24gZ2V0QXBpQ2xhc3MoKQogICAgewogICAgICAgIHJldHVybiAnR2l0\naHViXEFwaVxSZXBvc2l0b3J5XENvbnRlbnRzJzsKICAgIH0KfQo=\n","encoding":"base64"}', + true + ); + + // The download() method return + $expectedValue = base64_decode($getValue['content']); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) + ->will($this->returnValue($getValue)); + + $this->assertEquals($expectedValue, $api->download('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); + } protected function getApiClass() { From bb961f0d259f445a30fc4dc8eaf28a285a427757 Mon Sep 17 00:00:00 2001 From: winzou Date: Thu, 14 Mar 2013 11:58:19 +0100 Subject: [PATCH 007/951] Improve after feedbacks --- lib/Github/Api/Repository/Contents.php | 19 +++++++++++++------ .../Repository/ContentsDownloadFixture.php | 6 ++++++ .../Tests/Api/Repository/ContentsTest.php | 5 +---- 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 test/Github/Tests/Api/Repository/ContentsDownloadFixture.php diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index b3c8ad9d213..95d99469949 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -4,6 +4,8 @@ use Github\Api\AbstractApi; use Github\Exception\MissingArgumentException; +use Github\Exception\InvalidArgumentException; +use Github\Exception\ErrorException; /** * @link http://developer.github.com/v3/repos/contents/ @@ -81,24 +83,29 @@ public function archive($username, $repository, $format, $reference = null) * @param string $path path to file * @param string $reference reference to a branch or commit * - * @return string content of file + * @return string|null content of file, or null in case of base64_decode failure + * + * @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64 + * @throws ErrorException If $path doesn't include a 'content' index */ public function download($username, $repository, $path, $reference = null) { $file = $this->show($username, $repository, $path, $reference); if (!isset($file['type']) || 'file' !== $file['type']) { - throw new \Exception(sprintf('Path "%s" is not a file.', $path)); + throw new InvalidArgumentException(sprintf('Path "%s" is not a file.', $path)); } if (!isset($file['content'])) { - throw new \Exception(sprintf('Unable to access "content" for file "%s" (possible keys: "%s").', $path, implode(', ', array_keys($file)))); + throw new ErrorException(sprintf('Unable to access "content" for file "%s" (possible keys: "%s").', $path, implode(', ', array_keys($file)))); } - if (!isset($file['encoding']) || 'base64' !== $file['encoding']) { - throw new \Exception(sprintf('Encoding of file "%s" is not supported.', $path)); + if (!isset($file['encoding'])) { + throw new InvalidArgumentException(sprintf('Can\t decode contents of file "%s" as no encoding is defined.', $path)); + } elseif ('base64' !== $file['encoding']) { + throw new InvalidArgumentException(sprintf('Encoding "%s" of file "%s" is not supported.', $file['encoding'], $path)); } - return base64_decode($file['content']); + return base64_decode($file['content']) ?: null; } } diff --git a/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php b/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php new file mode 100644 index 00000000000..07dece20576 --- /dev/null +++ b/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php @@ -0,0 +1,6 @@ + Date: Sun, 17 Mar 2013 09:10:06 +0100 Subject: [PATCH 008/951] Fix CS from previous merge --- lib/Github/Api/Repository/Contents.php | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 95d99469949..9ee90f713a7 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -17,9 +17,9 @@ class Contents extends AbstractApi * Get content of README file in a repository * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param null|string $reference reference to a branch or commit * * @return array information for README file */ @@ -34,10 +34,10 @@ public function readme($username, $repository, $reference = null) * Get contents of any file or directory in a repository * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $path path to file or directory - * @param string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param null|string $path path to file or directory + * @param null|string $reference reference to a branch or commit * * @return array information for file | information for each item in directory */ @@ -57,10 +57,10 @@ public function show($username, $repository, $path = null, $reference = null) * Get content of archives in a repository * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $format format of archive: tarball or zipball - * @param string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $format format of archive: tarball or zipball + * @param null|string $reference reference to a branch or commit * * @return array information for archives */ @@ -78,12 +78,12 @@ public function archive($username, $repository, $format, $reference = null) /** * Get the contents of a file in a repository * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $path path to file - * @param string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param null|string $reference reference to a branch or commit * - * @return string|null content of file, or null in case of base64_decode failure + * @return null|string content of file, or null in case of base64_decode failure * * @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64 * @throws ErrorException If $path doesn't include a 'content' index @@ -91,7 +91,7 @@ public function archive($username, $repository, $format, $reference = null) public function download($username, $repository, $path, $reference = null) { $file = $this->show($username, $repository, $path, $reference); - + if (!isset($file['type']) || 'file' !== $file['type']) { throw new InvalidArgumentException(sprintf('Path "%s" is not a file.', $path)); } @@ -101,8 +101,10 @@ public function download($username, $repository, $path, $reference = null) } if (!isset($file['encoding'])) { - throw new InvalidArgumentException(sprintf('Can\t decode contents of file "%s" as no encoding is defined.', $path)); - } elseif ('base64' !== $file['encoding']) { + throw new InvalidArgumentException(sprintf('Can\'t decode content of file "%s", as no encoding is defined.', $path)); + } + + if ('base64' !== $file['encoding']) { throw new InvalidArgumentException(sprintf('Encoding "%s" of file "%s" is not supported.', $file['encoding'], $path)); } From d4a5cdee646377ae9024bf776a6feebfa23be4b8 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 19 Mar 2013 19:03:59 +0100 Subject: [PATCH 009/951] Fix ApiLimitExceedException details, fix for cache saving date --- lib/Github/Exception/ApiLimitExceedException.php | 2 +- lib/Github/HttpClient/CachedHttpClient.php | 10 ++++++++-- lib/Github/HttpClient/Message/Response.php | 15 ++------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index a9b5454f714..851631cccf8 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -9,7 +9,7 @@ */ class ApiLimitExceedException extends RuntimeException { - public function __construct($limit, $code = 0, $previous = null) + public function __construct($limit = 5000, $code = 0, $previous = null) { parent::__construct('You have reached GitHub hour limit! Actual limit is: '. $limit, $code, $previous); } diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 16457bd0683..8f6a141a82b 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -47,7 +47,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $response = parent::request($path, $parameters, $httpMethod, $headers); $key = trim($this->options['base_url'].$path, '/'); - if ($response->isNotModified()) { + if (304 == $response->getStatusCode()) { return $this->getCache()->get($key); } @@ -64,7 +64,13 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', protected function createRequest($httpMethod, $url) { $request = parent::createRequest($httpMethod, $url); - $request->addHeader(sprintf('If-Modified-Since: %s', date('r', $this->getCache()->getModifiedSince($url)))); + + if ($modifiedAt = $this->getCache()->getModifiedSince($url)) { + $modifiedAt = new \DateTime('@'.$modifiedAt); + $modifiedAt->setTimezone(new \DateTimeZone('GMT')); + + $request->addHeader(sprintf('If-Modified-Since: %s', $modifiedAt->format(DATE_RFC2822))); + } return $request; } diff --git a/lib/Github/HttpClient/Message/Response.php b/lib/Github/HttpClient/Message/Response.php index 35f2ada5264..c039ac4bae6 100644 --- a/lib/Github/HttpClient/Message/Response.php +++ b/lib/Github/HttpClient/Message/Response.php @@ -3,7 +3,6 @@ namespace Github\HttpClient\Message; use Buzz\Message\Response as BaseResponse; - use Github\Exception\ApiLimitExceedException; class Response extends BaseResponse @@ -55,23 +54,13 @@ public function getPagination() */ public function getApiLimit() { - $header = $this->getHeaderAttributes('X-RateLimit-Remaining'); + $header = $this->getHeader('X-RateLimit-Remaining'); if (!empty($header)) { $this->remainingCalls = $header; } if (null !== $this->remainingCalls && 1 > $this->remainingCalls) { - throw new ApiLimitExceedException($this->options['api_limit']); + throw new ApiLimitExceedException($this->getHeader('X-RateLimit-Limit')); } } - - /** - * Is not modified - * - * @return Boolean - */ - public function isNotModified() - { - return 304 === $this->getStatusCode(); - } } From fcee7e2e65523019a67e173d63763b5a566e7b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gildas=20Qu=C3=A9m=C3=A9ner?= Date: Wed, 20 Mar 2013 10:57:05 +0100 Subject: [PATCH 010/951] Hard-code sent timezone in If-Modified-Since header If-Modified-Since format must be RFC850 compliant and in GMT timezone BUT PHP DATE_RFC850 format keep returning UTC timezone. So, we set the GMT timezone and force its rendering in the header. --- lib/Github/HttpClient/CachedHttpClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 8f6a141a82b..f28f54bd9e2 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -67,9 +67,9 @@ protected function createRequest($httpMethod, $url) if ($modifiedAt = $this->getCache()->getModifiedSince($url)) { $modifiedAt = new \DateTime('@'.$modifiedAt); - $modifiedAt->setTimezone(new \DateTimeZone('GMT')); + $modifiedAt->setTimezone(new \DateTimeZone('GMT')); - $request->addHeader(sprintf('If-Modified-Since: %s', $modifiedAt->format(DATE_RFC2822))); + $request->addHeader(sprintf('If-Modified-Since: %s GMT', $modifiedAt->format('l, d-M-y H:i:s'))); } return $request; From 85c2994e70428f4957858d0c934496e40f3bbc09 Mon Sep 17 00:00:00 2001 From: Reto Kaiser Date: Sun, 31 Mar 2013 21:29:41 +0200 Subject: [PATCH 011/951] Force object-form when encoding json for sending as POST body --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 8b84fc3ec47..ef82a2a0044 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -168,7 +168,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); if (count($parameters) > 0) { - $request->setContent(json_encode($parameters)); + $request->setContent(json_encode($parameters, JSON_FORCE_OBJECT)); } $hasListeners = 0 < count($this->listeners); From 7898663172d54d06a6a1b3f785db6916569d28a2 Mon Sep 17 00:00:00 2001 From: GordonSchmidt Date: Mon, 8 Apr 2013 13:55:18 +0300 Subject: [PATCH 012/951] Missing autheticate method in HttpClientInterface --- lib/Github/HttpClient/HttpClientInterface.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php index 7c327d625e3..f84472ee7d6 100644 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ b/lib/Github/HttpClient/HttpClientInterface.php @@ -95,4 +95,15 @@ public function setOption($name, $value); * @param array $headers */ public function setHeaders(array $headers); + + /** + * Authenticate a user for all next requests + * + * @param string $tokenOrLogin GitHub private token/username/client ID + * @param null|string $password GitHub password/secret (optionally can contain $authMethod) + * @param null|string $authMethod One of the AUTH_* class constants + * + * @throws InvalidArgumentException If no authentication method was given + */ + public function authenticate($tokenOrLogin, $password, $authMethod); } From f491c28e8b4fc9719354010ee54c9496113343af Mon Sep 17 00:00:00 2001 From: GordonSchmidt Date: Mon, 8 Apr 2013 14:09:14 +0300 Subject: [PATCH 013/951] Update TestHttpClient for changes in interface --- test/Github/Tests/Mock/TestHttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Mock/TestHttpClient.php b/test/Github/Tests/Mock/TestHttpClient.php index 0423d8ab11d..7bef80defb7 100644 --- a/test/Github/Tests/Mock/TestHttpClient.php +++ b/test/Github/Tests/Mock/TestHttpClient.php @@ -18,7 +18,7 @@ class TestHttpClient implements HttpClientInterface public $options = array(); public $headers = array(); - public function authenticate() + public function authenticate($tokenOrLogin, $password, $authMethod) { $this->authenticated = true; } From a5948012744ece6020abf2cdb90289309f0ac49e Mon Sep 17 00:00:00 2001 From: GordonSchmidt Date: Mon, 8 Apr 2013 14:18:54 +0300 Subject: [PATCH 014/951] Update ClientTest for changes in interface --- 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 0469b887697..08984fa882b 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -171,7 +171,7 @@ public function getApiClassesProvider() public function getHttpClientMock(array $methods = array()) { $methods = array_merge( - array('get', 'post', 'patch', 'put', 'delete', 'request', 'setOption', 'setHeaders'), + array('get', 'post', 'patch', 'put', 'delete', 'request', 'setOption', 'setHeaders', 'authenticate'), $methods ); From f0cc9b758ac336d25fb8f531184ce45d94e39f19 Mon Sep 17 00:00:00 2001 From: GordonSchmidt Date: Mon, 8 Apr 2013 14:24:00 +0300 Subject: [PATCH 015/951] Update ClientTest for changes in interface --- test/Github/Tests/ClientTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 08984fa882b..d425f8d60fd 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -33,7 +33,7 @@ public function shouldPassHttpClientInterfaceToConstructor() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $httpClient = $this->getHttpClientMock(array('authenticate')); + $httpClient = $this->getHttpClientMock(); $httpClient->expects($this->once()) ->method('authenticate') ->with($login, $password, $method); @@ -58,7 +58,7 @@ public function getAuthenticationFullData() */ public function shouldAuthenticateUsingGivenParameters($token, $method) { - $httpClient = $this->getHttpClientMock(array('authenticate')); + $httpClient = $this->getHttpClientMock(); $httpClient->expects($this->once()) ->method('authenticate') ->with($token, null, $method); From d314d8fafa3511c6b9f300a71f67cded4cf0cd40 Mon Sep 17 00:00:00 2001 From: InventisPMTest Date: Thu, 25 Apr 2013 11:25:28 +0100 Subject: [PATCH 016/951] - Only use JSON_FORCE_OBJECT when parameters are empty (fixes issue where adding labels to issues fails). --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index ef82a2a0044..fe5fe1cd75e 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -168,7 +168,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); if (count($parameters) > 0) { - $request->setContent(json_encode($parameters, JSON_FORCE_OBJECT)); + $request->setContent(json_encode($parameters, empty($parameters)? JSON_FORCE_OBJECT : 0)); } $hasListeners = 0 < count($this->listeners); From 300c7904c4feef0a855d99ec13233d6586d28c31 Mon Sep 17 00:00:00 2001 From: Christof Damian Date: Wed, 15 May 2013 00:21:54 +0200 Subject: [PATCH 017/951] add authorization api --- doc/authorizations.md | 52 +++++++++ lib/Github/Api/Authorizations.php | 43 +++++++ lib/Github/Client.php | 5 + test/Github/Tests/Api/AuthorizationsTest.php | 111 +++++++++++++++++++ test/Github/Tests/ClientTest.php | 3 + 5 files changed, 214 insertions(+) create mode 100644 doc/authorizations.md create mode 100644 lib/Github/Api/Authorizations.php create mode 100644 test/Github/Tests/Api/AuthorizationsTest.php diff --git a/doc/authorizations.md b/doc/authorizations.md new file mode 100644 index 00000000000..638a15dae5d --- /dev/null +++ b/doc/authorizations.md @@ -0,0 +1,52 @@ +## Authorizations API +[Back to the navigation](index.md) + +Creating, deleting and listing authorizations. Wraps [GitHub Authorizations API](http://developer.github.com/v3/oauth/). + +#### List all authorizations. + +```php +$authorizations = $github->api('authorizations')->all(); +``` + +#### Get a single authorization + +```php +$authorization = $github->api('authorizations')->show(1); +``` + +#### Create a authorization + +```php +$data = array( + 'note' => 'This is an optional description' +); + +$authorization = $github->api('authorizations')->create($data); +``` + +Creates and returns a authorization. + +#### Update a authorization + +You can update ``note``. + +```php +$data = array( + 'note' => 'This is new note' +); + +$authorization = $github->api('authorizations')->update(1234, $data); +``` + +#### Delete a authorization + +```php +$authorization = $github->api('authorizations')->remove(1234); +``` + +#### Check a authorization + +```php +$authorization = $github->api('authorizations')->check(1234, 'token'); +``` diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php new file mode 100644 index 00000000000..6d45c23f14d --- /dev/null +++ b/lib/Github/Api/Authorizations.php @@ -0,0 +1,43 @@ +get('authorizations'); + } + + public function show($number) + { + return $this->get('authorizations/'.urlencode($number)); + } + + public function create(array $params) + { + return $this->post('authorizations', $params); + } + + public function update($id, array $params) + { + return $this->patch('authorizations/'.urlencode($id), $params); + } + + public function remove($id) + { + return $this->delete('authorizations/'.urlencode($id)); + } + + public function check($id, $token) + { + return $this->get('authorizations/'.urlencode($id).'/tokens/'.urlencode($token)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index cafe5554186..0ae764b49e0 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -134,6 +134,11 @@ public function api($name) $api = new Api\User($this); break; + case 'authorization': + case 'authorizations': + $api = new Api\Authorizations($this); + break; + default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); } diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php new file mode 100644 index 00000000000..901c5095244 --- /dev/null +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -0,0 +1,111 @@ + '123')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('authorizations') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldShowAuthorization() + { + $id = 123; + $expectedArray = array('id' => $id); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('authorizations/'.$id) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show($id)); + } + + /** + * @test + */ + public function shouldCheckAuthorization() + { + $id = 123; + $token = 'abc'; + $expectedArray = array('id' => $id); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('authorizations/'.$id.'/tokens/'.$token) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->check($id, $token)); + } + + /** + * @test + */ + public function shouldAuthorization() + { + $input = array( + 'note' => '', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('authorizations', $input); + + $api->create($input); + } + + /** + * @test + */ + public function shouldUpdateAuthorization() + { + $id = 123; + $input = array( + 'note' => '', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('authorizations/'.$id, $input); + + $api->update($id, $input); + } + + /** + * @test + */ + public function shouldDeleteAuthorization() + { + $id = 123; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('authorizations/'.$id); + + $api->remove($id); + } + + protected function getApiClass() + { + return 'Github\Api\Authorizations'; + } +} diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 0469b887697..6d443957dad 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -165,6 +165,9 @@ public function getApiClassesProvider() array('pr', 'Github\Api\PullRequest'), array('pull_request', 'Github\Api\PullRequest'), array('pull_requests', 'Github\Api\PullRequest'), + + array('authorization', 'Github\Api\Authorizations'), + array('authorizations', 'Github\Api\Authorizations'), ); } From 536d3dde0ff889e5117b929c88b83ae27ae8254d Mon Sep 17 00:00:00 2001 From: Christof Damian Date: Wed, 15 May 2013 00:57:14 +0200 Subject: [PATCH 018/951] add authorizations.md to index --- doc/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/index.md b/doc/index.md index 45d6622d1c1..648d2cb870c 100644 --- a/doc/index.md +++ b/doc/index.md @@ -2,6 +2,7 @@ Navigation ========== APIs: +* [Authorizations](authorizations.md) * [Commits](commits.md) * [Gists](gists.md) * [Issues](issues.md) From 32b6ff31dae9a08412fb7ccbacf326fee21d4f90 Mon Sep 17 00:00:00 2001 From: Christof Damian Date: Wed, 15 May 2013 01:00:17 +0200 Subject: [PATCH 019/951] spelling --- doc/authorizations.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/authorizations.md b/doc/authorizations.md index 638a15dae5d..5386c6acab5 100644 --- a/doc/authorizations.md +++ b/doc/authorizations.md @@ -15,7 +15,7 @@ $authorizations = $github->api('authorizations')->all(); $authorization = $github->api('authorizations')->show(1); ``` -#### Create a authorization +#### Create an authorization ```php $data = array( @@ -25,9 +25,9 @@ $data = array( $authorization = $github->api('authorizations')->create($data); ``` -Creates and returns a authorization. +Creates and returns an authorization. -#### Update a authorization +#### Update an authorization You can update ``note``. @@ -39,13 +39,13 @@ $data = array( $authorization = $github->api('authorizations')->update(1234, $data); ``` -#### Delete a authorization +#### Delete an authorization ```php $authorization = $github->api('authorizations')->remove(1234); ``` -#### Check a authorization +#### Check an authorization ```php $authorization = $github->api('authorizations')->check(1234, 'token'); From 4fe5c5fb223cb225c2ceba1b7de699bb73c8abaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 17 May 2013 14:02:59 +0200 Subject: [PATCH 020/951] Added pagination support for PullRequest --- lib/Github/Api/PullRequest.php | 12 ++++++++++-- test/Github/Tests/Api/PullRequestTest.php | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 5cb9b6d96ec..aed711a6c34 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -21,12 +21,20 @@ class PullRequest extends AbstractApi * @param string $repository the repository * @param string $state the state of the fetched pull requests. * The API seems to automatically default to 'open' + * @param integer $page the page + * @param integer $perPage the per page * * @return array array of pull requests for the project */ - public function all($username, $repository, $state = null) + public function all($username, $repository, $state = null, $page = 1, $perPage = 30) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', array('state' => $state)); + $parameters = array( + 'page' => $page, + 'per_page' => $perPage, + 'state' => $state, + ); + + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $parameters); } /** diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index a25943d395f..99449ec16d3 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -30,7 +30,7 @@ public function shouldGetOpenPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open')) + ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'open')); @@ -46,7 +46,7 @@ public function shouldGetClosedPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed')) + ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'closed')); From 383346b9996ffa0dfda593506fa18154bfc3c4d0 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 27 May 2013 15:37:04 +0200 Subject: [PATCH 021/951] Allow complete URL in get method The get method always prepends the baseurl before the requests path. A check was added to allow for full URLS (starting with baseurl), for following pagination links. --- lib/Github/HttpClient/HttpClient.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index ef82a2a0044..6e9e0d913b4 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -163,7 +163,9 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - $path = trim($this->options['base_url'].$path, '/'); + if (0 !== strpos( $path, $this->options['base_url'] )) { + $path = trim($this->options['base_url'].$path, '/'); + } $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); From 07138eb97d367c9ac49325e7063e4e21e16ba7b8 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 27 May 2013 15:39:56 +0200 Subject: [PATCH 022/951] Added the perPage property for Github pagination The api client supports the per_page github parameter for api calls. Default is NULL and lets github decide the default (currently 30). $client->setPerPage() --- lib/Github/Api/AbstractApi.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index be6063d3cfb..c355001947a 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -18,6 +18,13 @@ abstract class AbstractApi implements ApiInterface */ protected $client; + /** + * number of items per page (GitHub pagination) + * + * @var int + */ + protected $perPage = null; + /** * @param Client $client */ @@ -30,11 +37,31 @@ public function configure() { } + /** + * @return int|null + */ + public function getPerPage() + { + return $this->perPage; + } + + /** + * @param Client $client + */ + public function setPerPage($perPage) + { + $this->perPage = (int) $perPage; + return $this; + } + /** * {@inheritDoc} */ protected function get($path, array $parameters = array(), $requestHeaders = array()) { + if (null !== $this->perPage && !isset($parameters['per_page'])) { + $parameters['per_page'] = $this->perPage; + } $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); return $response->getContent(); From 3683986823ed7995d0ff6f20074f821eba1dd050 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 27 May 2013 15:42:09 +0200 Subject: [PATCH 023/951] Added the ResultPaginator (incomplete) This is the first pass at adding a paginator class for github API requests. It only works with fetchAll() at the moment, to demonstrate the usage. Currently: $paginator = new \Github\ResultPaginator( \Github\Client [client] ); $paginator->fetchAll( [api], [method], [parameters] ); Todo's include: Paginator is not complete for all possible headers Next, Last, Previous, First apiClient should be able to return a paginator (i.e. $client->getPaginator() ) CacheHttpClient does not work (does not return Link headers) --- lib/Github/ResultPaginator.php | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/Github/ResultPaginator.php diff --git a/lib/Github/ResultPaginator.php b/lib/Github/ResultPaginator.php new file mode 100644 index 00000000000..180ee864a14 --- /dev/null +++ b/lib/Github/ResultPaginator.php @@ -0,0 +1,57 @@ +client = $client; + } + + public function fetchAll( ApiInterface $api, $method, $parameters ) { + $result = array(); + $result = call_user_func_array( array($api,$method), $parameters); + $this->postFetch(); + + while ($this->hasNext()) { + $result = array_merge($result, $this->fetchNext()); + } + return $result; + } + + protected function postFetch() { + $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); + var_dump($this->pagination); + } + + public function fetchNext() { + $result = $this->client->getHttpClient()->get($this->pagination['next']); + $this->postFetch(); + return $result->getContent(); + } + + public function hasNext() { + if (!empty($this->pagination) and isset($this->pagination['next'])) { + return true; + } + return false; + } + + public function hasPrevious() { + if (!empty($this->pagination) and isset($this->pagination['previous'])) { + return true; + } + return false; + } + +} From bf811019a29891668cacd481c99a4bf69c7f6ea9 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Mon, 27 May 2013 16:28:11 +0200 Subject: [PATCH 024/951] removed debug --- lib/Github/ResultPaginator.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/Github/ResultPaginator.php b/lib/Github/ResultPaginator.php index 180ee864a14..1fb37378848 100644 --- a/lib/Github/ResultPaginator.php +++ b/lib/Github/ResultPaginator.php @@ -14,43 +14,54 @@ class ResultPaginator protected $pagination = null; - public function __construct( Client $client ) { + public function __construct( Client $client ) + { $this->client = $client; } - public function fetchAll( ApiInterface $api, $method, $parameters ) { + public function fetchAll( ApiInterface $api, $method, $parameters ) + { $result = array(); - $result = call_user_func_array( array($api,$method), $parameters); + $result = call_user_func_array(array($api, $method), $parameters); + $this->postFetch(); while ($this->hasNext()) { $result = array_merge($result, $this->fetchNext()); } + return $result; } - protected function postFetch() { + protected function postFetch() + { $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); - var_dump($this->pagination); } - public function fetchNext() { + public function fetchNext() + { $result = $this->client->getHttpClient()->get($this->pagination['next']); + $this->postFetch(); + return $result->getContent(); } - public function hasNext() { + public function hasNext() + { if (!empty($this->pagination) and isset($this->pagination['next'])) { return true; } + return false; } - public function hasPrevious() { + public function hasPrevious() + { if (!empty($this->pagination) and isset($this->pagination['previous'])) { return true; } + return false; } From 80eaaef748033ae652a092e4cac4aa8fcab972ae Mon Sep 17 00:00:00 2001 From: Chris Chaudruc Date: Sun, 2 Jun 2013 08:24:54 -0500 Subject: [PATCH 025/951] Update repos.md changed starting_page to start_page - that seems to work --- doc/repos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index 287a8420a35..fd8601a3b9e 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -25,7 +25,7 @@ $repos = $client->api('repo')->find('chess', array('language' => 'php')); You can specify the page number: ```php -$repos = $client->api('repo')->find('chess', array('language' => 'php', 'starting_page' => 2)); +$repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_page' => 2)); ``` ### Get extended information about a repository From 0fe721df4f97b9ef246531827a98ed3ba51ffd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeffrey=20Bo=CC=88hm?= Date: Sat, 8 Jun 2013 22:49:49 +0200 Subject: [PATCH 026/951] Get user's public events --- lib/Github/Api/User.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index af11fdf2b92..2241f79eb8c 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -107,4 +107,18 @@ public function keys($username) { return $this->get('users/'.urlencode($username).'/keys'); } + + /** + * List events performed by a user + * + * @link http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user + * + * @param string $username + * + * @return array + */ + public function publicEvents($username) + { + return $this->get('users/' . urlencode($username) . '/events/public'); + } } From 09e76f333034267cb3e6800b5bd77c6e8ccb8aa8 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 27 May 2013 15:37:04 +0200 Subject: [PATCH 027/951] Allow complete URL in get method The get method always prepends the baseurl before the requests path. A check was added to allow for full URLS (starting with baseurl), for following pagination links. --- lib/Github/HttpClient/HttpClient.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index ef82a2a0044..6e9e0d913b4 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -163,7 +163,9 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - $path = trim($this->options['base_url'].$path, '/'); + if (0 !== strpos( $path, $this->options['base_url'] )) { + $path = trim($this->options['base_url'].$path, '/'); + } $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); From 52ac68b43047da94ea331549e03b3e3964426788 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 27 May 2013 15:39:56 +0200 Subject: [PATCH 028/951] Added the perPage property for Github pagination The api client supports the per_page github parameter for api calls. Default is NULL and lets github decide the default (currently 30). $client->setPerPage() --- lib/Github/Api/AbstractApi.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index be6063d3cfb..c355001947a 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -18,6 +18,13 @@ abstract class AbstractApi implements ApiInterface */ protected $client; + /** + * number of items per page (GitHub pagination) + * + * @var int + */ + protected $perPage = null; + /** * @param Client $client */ @@ -30,11 +37,31 @@ public function configure() { } + /** + * @return int|null + */ + public function getPerPage() + { + return $this->perPage; + } + + /** + * @param Client $client + */ + public function setPerPage($perPage) + { + $this->perPage = (int) $perPage; + return $this; + } + /** * {@inheritDoc} */ protected function get($path, array $parameters = array(), $requestHeaders = array()) { + if (null !== $this->perPage && !isset($parameters['per_page'])) { + $parameters['per_page'] = $this->perPage; + } $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); return $response->getContent(); From 578332585150495df11f24e18124af2a97833081 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 27 May 2013 15:42:09 +0200 Subject: [PATCH 029/951] Added the ResultPaginator (incomplete) This is the first pass at adding a paginator class for github API requests. It only works with fetchAll() at the moment, to demonstrate the usage. Currently: $paginator = new \Github\ResultPaginator( \Github\Client [client] ); $paginator->fetchAll( [api], [method], [parameters] ); Todo's include: Paginator is not complete for all possible headers Next, Last, Previous, First apiClient should be able to return a paginator (i.e. $client->getPaginator() ) CacheHttpClient does not work (does not return Link headers) --- lib/Github/ResultPaginator.php | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/Github/ResultPaginator.php diff --git a/lib/Github/ResultPaginator.php b/lib/Github/ResultPaginator.php new file mode 100644 index 00000000000..180ee864a14 --- /dev/null +++ b/lib/Github/ResultPaginator.php @@ -0,0 +1,57 @@ +client = $client; + } + + public function fetchAll( ApiInterface $api, $method, $parameters ) { + $result = array(); + $result = call_user_func_array( array($api,$method), $parameters); + $this->postFetch(); + + while ($this->hasNext()) { + $result = array_merge($result, $this->fetchNext()); + } + return $result; + } + + protected function postFetch() { + $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); + var_dump($this->pagination); + } + + public function fetchNext() { + $result = $this->client->getHttpClient()->get($this->pagination['next']); + $this->postFetch(); + return $result->getContent(); + } + + public function hasNext() { + if (!empty($this->pagination) and isset($this->pagination['next'])) { + return true; + } + return false; + } + + public function hasPrevious() { + if (!empty($this->pagination) and isset($this->pagination['previous'])) { + return true; + } + return false; + } + +} From 76c1b46be387bd1dedbbc6e5de3a3142a1843107 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Mon, 27 May 2013 16:28:11 +0200 Subject: [PATCH 030/951] removed debug --- lib/Github/ResultPaginator.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/Github/ResultPaginator.php b/lib/Github/ResultPaginator.php index 180ee864a14..1fb37378848 100644 --- a/lib/Github/ResultPaginator.php +++ b/lib/Github/ResultPaginator.php @@ -14,43 +14,54 @@ class ResultPaginator protected $pagination = null; - public function __construct( Client $client ) { + public function __construct( Client $client ) + { $this->client = $client; } - public function fetchAll( ApiInterface $api, $method, $parameters ) { + public function fetchAll( ApiInterface $api, $method, $parameters ) + { $result = array(); - $result = call_user_func_array( array($api,$method), $parameters); + $result = call_user_func_array(array($api, $method), $parameters); + $this->postFetch(); while ($this->hasNext()) { $result = array_merge($result, $this->fetchNext()); } + return $result; } - protected function postFetch() { + protected function postFetch() + { $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); - var_dump($this->pagination); } - public function fetchNext() { + public function fetchNext() + { $result = $this->client->getHttpClient()->get($this->pagination['next']); + $this->postFetch(); + return $result->getContent(); } - public function hasNext() { + public function hasNext() + { if (!empty($this->pagination) and isset($this->pagination['next'])) { return true; } + return false; } - public function hasPrevious() { + public function hasPrevious() + { if (!empty($this->pagination) and isset($this->pagination['previous'])) { return true; } + return false; } From 09b147db62bf329d10f48228b036b001be14797f Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Mon, 8 Jul 2013 15:38:45 +0200 Subject: [PATCH 031/951] Bug Fix path is empty in some test cases but strpos can't handle an empty needle so added check if path is not empty --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 6e9e0d913b4..93c69cd3a0f 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -163,7 +163,7 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - if (0 !== strpos( $path, $this->options['base_url'] )) { + if ( !empty($this->options['base_url']) AND 0 !== strpos( $path, $this->options['base_url'] )) { $path = trim($this->options['base_url'].$path, '/'); } From 336f50aa9b281506a9d93d5e576abec0a890cf05 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 8 Jul 2013 16:52:30 +0200 Subject: [PATCH 032/951] Renamed paginator to ResultPager, added resultPagerInterface --- lib/Github/ResultPager.php | 150 ++++++++++++++++++++++++++++ lib/Github/ResultPagerInterface.php | 66 ++++++++++++ lib/Github/ResultPaginator.php | 68 ------------- 3 files changed, 216 insertions(+), 68 deletions(-) create mode 100644 lib/Github/ResultPager.php create mode 100644 lib/Github/ResultPagerInterface.php delete mode 100644 lib/Github/ResultPaginator.php diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php new file mode 100644 index 00000000000..19457d6fa72 --- /dev/null +++ b/lib/Github/ResultPager.php @@ -0,0 +1,150 @@ + + * @author Mitchel Verschoof + */ +class ResultPager implements ResultPagerInterface +{ + /** + * @var Github\Client client + */ + protected $client; + + /** + * @var array pagination + * Comes from pagination headers in Github API results + */ + protected $pagination = null; + + public function __construct( Client $client ) + { + $this->client = $client; + } + + /** + * {@inheritdoc} + */ + public function fetch( ApiInterface $api, $method ) + { + $parameters = array_slice(func_get_args(),2); + + $result = call_user_func_array(array($api, $method), $parameters); + $this->postFetch(); + + return $result; + } + + /** + * {@inheritdoc} + */ + public function fetchAll( ApiInterface $api, $method ) + { + $parameters = array_slice(func_get_args(),2); + + // Set parameters per_page to GitHub max to minimize number of requests + $api->setPerPage(100); + + $result = array(); + $result = call_user_func_array(array($api, $method), $parameters); + $this->postFetch(); + + while ($this->hasNext()) { + $result = array_merge($result, $this->fetchNext()); + } + + return $result; + } + + /** + * {@inheritdoc} + */ + public function postFetch() + { + $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); + var_dump( $this->pagination ); + } + + /** + * {@inheritdoc} + */ + public function hasNext() + { + return $this->has('next'); + } + + /** + * {@inheritdoc} + */ + public function fetchNext() + { + return $this->get('next'); + } + + /** + * {@inheritdoc} + */ + public function hasPrevious() + { + return $this->has('prev'); + } + + /** + * {@inheritdoc} + */ + public function fetchPrevious() + { + return $this->get('prev'); + } + + /** + * {@inheritdoc} + */ + public function fetchFirst() + { + return $this->get('first'); + } + + /** + * {@inheritdoc} + */ + public function fetchLast() + { + return $this->get('last'); + } + + /** + * {@inheritdoc} + */ + protected function has($key) + { + if (!empty($this->pagination) and isset($this->pagination[$key])) { + return true; + } + + return false; + } + + /** + * {@inheritdoc} + */ + protected function get($key) + { + if ( $this->has($key) ) { + $result = $this->client->getHttpClient()->get($this->pagination[$key]); + $this->postFetch(); + + return $result->getContent(); + } + } + +} diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php new file mode 100644 index 00000000000..4c8fcbd4370 --- /dev/null +++ b/lib/Github/ResultPagerInterface.php @@ -0,0 +1,66 @@ + + * @author Mitchel Verschoof + */ +interface ResultPagerInterface +{ + /** + * Fetch a single result (page) from an api call + */ + public function fetch( ApiInterface $api, $method ); + + /** + * Fetch all results (pages) from an api call + * Use with care - there is no maximum + */ + public function fetchAll( ApiInterface $api, $method ); + + /** + * Method that performs the actual work to refresh the pagination property + */ + public function postFetch(); + + /** + * Check to determine the availability of a next page + * @return bool + */ + public function hasNext(); + + /** + * Check to determine the availability of a previous page + * @return bool + */ + public function hasPrevious(); + + /** + * Fetch the next page + * @return array + */ + public function fetchNext(); + + /** + * Fetch the previous page + * @return array + */ + public function fetchPrevious(); + + /** + * Fetch the first page + * @return array + */ + public function fetchFirst(); + + /** + * Fetch the last page + * @return array + */ + public function fetchLast(); +} diff --git a/lib/Github/ResultPaginator.php b/lib/Github/ResultPaginator.php deleted file mode 100644 index 1fb37378848..00000000000 --- a/lib/Github/ResultPaginator.php +++ /dev/null @@ -1,68 +0,0 @@ -client = $client; - } - - public function fetchAll( ApiInterface $api, $method, $parameters ) - { - $result = array(); - $result = call_user_func_array(array($api, $method), $parameters); - - $this->postFetch(); - - while ($this->hasNext()) { - $result = array_merge($result, $this->fetchNext()); - } - - return $result; - } - - protected function postFetch() - { - $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); - } - - public function fetchNext() - { - $result = $this->client->getHttpClient()->get($this->pagination['next']); - - $this->postFetch(); - - return $result->getContent(); - } - - public function hasNext() - { - if (!empty($this->pagination) and isset($this->pagination['next'])) { - return true; - } - - return false; - } - - public function hasPrevious() - { - if (!empty($this->pagination) and isset($this->pagination['previous'])) { - return true; - } - - return false; - } - -} From c94daa8775dd2a54a70f9d82187a4bf1a3c371b0 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Mon, 8 Jul 2013 17:25:08 +0200 Subject: [PATCH 033/951] code cleanup --- lib/Github/ResultPager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 19457d6fa72..045b03c49ac 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -71,7 +71,6 @@ public function fetchAll( ApiInterface $api, $method ) public function postFetch() { $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); - var_dump( $this->pagination ); } /** From 496bd03fc96ec4e580603d5f21710460194e3b08 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Tue, 9 Jul 2013 16:45:24 +0200 Subject: [PATCH 034/951] tmp commit --- test/Github/Tests/Mock/TestResponse.php | 38 +++++++ test/Github/Tests/ResultPagerTest.php | 141 ++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 test/Github/Tests/Mock/TestResponse.php create mode 100644 test/Github/Tests/ResultPagerTest.php diff --git a/test/Github/Tests/Mock/TestResponse.php b/test/Github/Tests/Mock/TestResponse.php new file mode 100644 index 00000000000..aded078657d --- /dev/null +++ b/test/Github/Tests/Mock/TestResponse.php @@ -0,0 +1,38 @@ + + * @author Mitchel Verschoof + */ +class ResultPagerTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * description fetchAll + */ + public function shouldGetAllResults() + { + $organizationMockApi = $this->getApiMock( 'Github\Api\Organization' ); + $method = 'all'; + $parameters = array('netwerven'); + + // $paginator = new Github\ResultPaginator( $client ); + // $result = $paginator->fetchAll( $organizationMockApi, 'repositories', $parameters ); + } + + /** + * @test + * + * description postFetch + */ + public function postFetch() + { + + } + + /** + * @test + * + * description fetchNext + */ + public function fetchNext() + { + + } + + /** + * @test + * + * description hasNext + */ + public function shouldHasNext() + { + + } + + /** + * @test + * + * description hasPrevious + */ + public function shouldHasPrevious() + { + + } + + /** + * @test + * + * description first + */ + public function shouldHasFirst() + { + + } + + /** + * @test + * + * description last + */ + public function shouldHasLast() + { + + } + + protected function getApiMock( $apiClass ) + { + $responseStub = $this->getMock('Github\HttpClient\Message\Response', array('getPagination')); + $responseStub + ->expects($this->any()) + ->method('getPagination') + ->with(array('test' => 'test')); + + var_dump( "\n" ); + var_dump( $responseStub ); + exit; + + $httpClient = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send', 'getLastResponse')); + $httpClient + ->expects($this->any()) + ->method('setTimeout') + ->with(10); + $httpClient + ->expects($this->any()) + ->method('setVerifyPeer') + ->with(false); + $httpClient + ->expects($this->any()) + ->method('send'); + $httpClient + ->expects($this->any()) + ->method('getLastResponse') + ->with(array( + 'first' => 'test', + 'next' => 'test', + 'previous' => 'test', + 'last' => 'test', + )); + + $mock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $httpClient)); + + var_dump( $mock->getLastResponse(), $mock ); + + $client = new \Github\Client($mock); + $client->setHttpClient($mock); + + var_dump( $client->getHttpClient()->getLastResponse() ); + + return $this->getMockBuilder( $apiClass ) + ->setMethods(array('get', 'post', 'patch', 'delete', 'put')) + ->setConstructorArgs(array($client)) + ->getMock(); + } + +} \ No newline at end of file From 84b76eb0dc351339a93386e25a82ac1dd328bf86 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Thu, 11 Jul 2013 15:17:40 +0200 Subject: [PATCH 035/951] Added function getPagination so you have access to the pagination array --- lib/Github/ResultPager.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 045b03c49ac..7530f1c4a17 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -31,6 +31,14 @@ public function __construct( Client $client ) $this->client = $client; } + /** + * @return null|array pagination result of last request + */ + public function getPagination() + { + return $this->pagination; + } + /** * {@inheritdoc} */ From 5541dec015e4bae8ca7a60a29a617554b92fdb30 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Thu, 11 Jul 2013 15:32:04 +0200 Subject: [PATCH 036/951] Added TestResponse Mock to test the FetchAll Added UnitTest --- test/Github/Tests/Mock/TestResponse.php | 40 +++-- test/Github/Tests/ResultPagerTest.php | 210 ++++++++++++++++++------ 2 files changed, 183 insertions(+), 67 deletions(-) diff --git a/test/Github/Tests/Mock/TestResponse.php b/test/Github/Tests/Mock/TestResponse.php index aded078657d..0c8f04b320e 100644 --- a/test/Github/Tests/Mock/TestResponse.php +++ b/test/Github/Tests/Mock/TestResponse.php @@ -2,22 +2,24 @@ namespace Github\Tests\Mock; -use Buzz\Message\Response as BaseResponse; -use Github\Exception\ApiLimitExceedException; - -class TestResponse extends BaseResponse +class TestResponse { - /** - * @var integer - */ - public $remainingCalls; + protected $loopCount; + + protected $content; + + public function __construct( $loopCount, array $content = array() ) + { + $this->loopCount = $loopCount; + $this->content = $content; + } /** * {@inheritDoc} */ public function getContent() { - return null; + return $this->content; } /** @@ -25,14 +27,18 @@ public function getContent() */ public function getPagination() { - return null; - } + if($this->loopCount){ + $returnArray = array( + 'next' => 'http://github.com/' . $this->loopCount + ); + } else { + $returnArray = array( + 'prev' => 'http://github.com/prev' + ); + } - /** - * {@inheritDoc} - */ - public function getApiLimit() - { - return null; + $this->loopCount--; + + return $returnArray; } } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 095989e65d6..d1551767f56 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -5,6 +5,8 @@ use Github; use Github\Client; use Github\ResultPager; +use Github\HttpClient\HttpClientInterface; +use Github\Tests\Mock\TestResponse; /** * ResultPagerTest @@ -21,12 +23,63 @@ class ResultPagerTest extends \PHPUnit_Framework_TestCase */ public function shouldGetAllResults() { - $organizationMockApi = $this->getApiMock( 'Github\Api\Organization' ); - $method = 'all'; - $parameters = array('netwerven'); + $amountLoops = 3; + $content = array(1,2,3,4,5,6,7,8,9,10); + $responseMock = new TestResponse( $amountLoops, $content ); + + // httpClient mock + $httpClientMock = $this->getHttpClientMock($responseMock); + $httpClientMock + ->expects($this->exactly($amountLoops)) + ->method('get') + ->will($this->returnValue($responseMock)); + + $clientMock = $this->getClientMock($httpClientMock); + + // memberApi Mock + $memberApiMock = $this->getApiMock( 'Github\Api\Organization\Members' ); + $memberApiMock + ->expects($this->once()) + ->method('all') + ->will($this->returnValue(array())); + + $method = 'all'; + $parameters = array('netwerven'); + + // Run fetchAll on result paginator + $paginator = new Github\ResultPager( $clientMock ); + $result = $paginator->fetchAll( $memberApiMock, $method, $parameters ); + + $this->assertEquals($amountLoops * count($content), count($result)); + } + + /** + * @test + * + * description fetch + */ + public function shouldGetSomeResults() + { + $pagination = array('next' => 'http://github.com/next'); + $resultContent = 'organization test'; - // $paginator = new Github\ResultPaginator( $client ); - // $result = $paginator->fetchAll( $organizationMockApi, 'repositories', $parameters ); + $responseMock = $this->getResponseMock($pagination); + $httpClient = $this->getHttpClientMock( $responseMock ); + $client = $this->getClientMock($httpClient); + + $organizationApiMock = $this->getApiMock( 'Github\Api\Organization' ); + + $organizationApiMock + ->expects($this->once()) + ->method('show') + ->with('github') + ->will($this->returnValue($resultContent)); + + $paginator = new Github\ResultPager( $client ); + $result = $paginator->fetch($organizationApiMock, 'show', 'github'); + + $this->assertEquals($resultContent, $result); + $this->assertEquals($pagination, $paginator->getPagination()); } /** @@ -36,7 +89,27 @@ public function shouldGetAllResults() */ public function postFetch() { + $pagination = array( + 'first' => 'http://github.com', + 'next' => 'http://github.com', + 'prev' => 'http://github.com', + 'last' => 'http://github.com' + ); + + // response mock + $responseMock = $this->getMock('Github\HttpClient\Message\Response'); + $responseMock + ->expects($this->any()) + ->method('getPagination') + ->will($this->returnValue($pagination)); + $httpClient = $this->getHttpClientMock( $responseMock ); + $client = $this->getClientMock($httpClient); + + $paginator = new Github\ResultPager( $client ); + $paginator->postFetch(); + + $this->assertEquals($paginator->getPagination(), $pagination); } /** @@ -46,7 +119,33 @@ public function postFetch() */ public function fetchNext() { + $pagination = array('next' => 'http://github.com/next'); + $resultContent = 'fetch test'; + + $responseMock = $this->getResponseMock( $pagination ); + $responseMock + ->expects($this->once()) + ->method('getContent') + ->will($this->returnValue($resultContent)); + // Expected 2 times, 1 for setup and 1 for the actual test + $responseMock + ->expects($this->exactly(2)) + ->method('getPagination'); + + $httpClient = $this->getHttpClientMock( $responseMock ); + + $httpClient + ->expects($this->once()) + ->method('get') + ->with( $pagination['next'] ) + ->will($this->returnValue($responseMock)); + $client = $this->getClientMock($httpClient); + + $paginator = new Github\ResultPager( $client ); + $paginator->postFetch(); + + $this->assertEquals($paginator->fetchNext(), $resultContent); } /** @@ -54,9 +153,17 @@ public function fetchNext() * * description hasNext */ - public function shouldHasNext() + public function shouldHaveNext() { + $responseMock = $this->getResponseMock(array('next' => 'http://github.com/next')); + $httpClient = $this->getHttpClientMock( $responseMock ); + $client = $this->getClientMock($httpClient); + + $paginator = new Github\ResultPager( $client ); + $paginator->postFetch(); + $this->assertEquals($paginator->hasNext(), true); + $this->assertEquals($paginator->hasPrevious(), false); } /** @@ -64,78 +171,81 @@ public function shouldHasNext() * * description hasPrevious */ - public function shouldHasPrevious() + public function shouldHavePrevious() { + $responseMock = $this->getResponseMock(array('prev' => 'http://github.com/previous')); + $httpClient = $this->getHttpClientMock( $responseMock ); + $client = $this->getClientMock($httpClient); + $paginator = new Github\ResultPager( $client ); + $paginator->postFetch(); + + $this->assertEquals($paginator->hasPrevious(), true); + $this->assertEquals($paginator->hasNext(), false); } - /** - * @test - * - * description first - */ - public function shouldHasFirst() + protected function getResponseMock( array $pagination ) { + // response mock + $responseMock = $this->getMock('Github\HttpClient\Message\Response'); + $responseMock + ->expects($this->any()) + ->method('getPagination') + ->will($this->returnValue( + $pagination + )); + return $responseMock; } - /** - * @test - * - * description last - */ - public function shouldHasLast() + protected function getClientMock( HttpClientInterface $httpClient = null ) { + // if no httpClient isset use the default HttpClient mock + if( !$httpClient ){ + $httpClient = $this->getHttpClientMock(); + } + + $client = new \Github\Client($httpClient); + $client->setHttpClient($httpClient); + return $client; } - protected function getApiMock( $apiClass ) + protected function getHttpClientMock( $responseMock = null ) { - $responseStub = $this->getMock('Github\HttpClient\Message\Response', array('getPagination')); - $responseStub - ->expects($this->any()) - ->method('getPagination') - ->with(array('test' => 'test')); - - var_dump( "\n" ); - var_dump( $responseStub ); - exit; - - $httpClient = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send', 'getLastResponse')); - $httpClient + // mock the client interface + $clientInterfaceMock = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); + $clientInterfaceMock ->expects($this->any()) ->method('setTimeout') ->with(10); - $httpClient + $clientInterfaceMock ->expects($this->any()) ->method('setVerifyPeer') ->with(false); - $httpClient + $clientInterfaceMock ->expects($this->any()) ->method('send'); - $httpClient - ->expects($this->any()) - ->method('getLastResponse') - ->with(array( - 'first' => 'test', - 'next' => 'test', - 'previous' => 'test', - 'last' => 'test', - )); - $mock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $httpClient)); + // create the httpClient mock + $httpClientMock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $clientInterfaceMock)); - var_dump( $mock->getLastResponse(), $mock ); + if( $responseMock ){ + $httpClientMock + ->expects($this->any()) + ->method('getLastResponse') + ->will($this->returnValue($responseMock)); + } - $client = new \Github\Client($mock); - $client->setHttpClient($mock); + return $httpClientMock; + } - var_dump( $client->getHttpClient()->getLastResponse() ); + protected function getApiMock( $apiClass ) + { + $client = $this->getClientMock(); return $this->getMockBuilder( $apiClass ) - ->setMethods(array('get', 'post', 'patch', 'delete', 'put')) ->setConstructorArgs(array($client)) ->getMock(); } - } \ No newline at end of file From 3e0ffa291a8bda3a078876faeeb8172b4a80bb4e Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Tue, 9 Jul 2013 08:54:47 +0200 Subject: [PATCH 037/951] Added documentation file --- doc/index.md | 2 ++ doc/result_pager.md | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 doc/result_pager.md diff --git a/doc/index.md b/doc/index.md index 648d2cb870c..c013e13aa54 100644 --- a/doc/index.md +++ b/doc/index.md @@ -16,6 +16,8 @@ APIs: * [Repositories](repos.md) * [Users](users.md) +* [Result Pager](result_pager.md) + Additional features: * [Authentication & Security](security.md) diff --git a/doc/result_pager.md b/doc/result_pager.md new file mode 100644 index 00000000000..16ebd9db6f5 --- /dev/null +++ b/doc/result_pager.md @@ -0,0 +1,4 @@ +## Resultpager +[Back to the navigation](../index.md) + +To be written... From 74210a4c30e954ac28db2ef694d296cfb65fee83 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Tue, 9 Jul 2013 16:46:41 +0200 Subject: [PATCH 038/951] Updated result_pager.md --- doc/result_pager.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/result_pager.md b/doc/result_pager.md index 16ebd9db6f5..0e7eeb43336 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -1,4 +1,15 @@ -## Resultpager -[Back to the navigation](../index.md) +## Result Pager +[Back to the navigation](index.md) -To be written... +### Usage examples + +Get all results of a organization + +```php +$client = new Github\Client(); + +$organizationApi = $client->api('organization'); + +$paginator = new Github\ResultPager( $client ); +$result = $paginator->fetchAll( $organizationApi, 'repositories', 'future500' ); +``` From 7fd1cb1e2eae7ecad4d2258820dba6f604a8c57d Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Thu, 11 Jul 2013 15:41:14 +0200 Subject: [PATCH 039/951] Added documentation for the pagination support --- doc/index.md | 3 +-- doc/result_pager.md | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/doc/index.md b/doc/index.md index c013e13aa54..5a98737f912 100644 --- a/doc/index.md +++ b/doc/index.md @@ -16,10 +16,9 @@ APIs: * [Repositories](repos.md) * [Users](users.md) -* [Result Pager](result_pager.md) - Additional features: +* [Pagination support](result_pager.md) * [Authentication & Security](security.md) * [Request any Route](request_any_route.md) * [Customize `php-github-api` and testing](customize.md) diff --git a/doc/result_pager.md b/doc/result_pager.md index 0e7eeb43336..c18a9f2923b 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -3,7 +3,7 @@ ### Usage examples -Get all results of a organization +Get all repositories of a organization ```php $client = new Github\Client(); @@ -11,5 +11,34 @@ $client = new Github\Client(); $organizationApi = $client->api('organization'); $paginator = new Github\ResultPager( $client ); -$result = $paginator->fetchAll( $organizationApi, 'repositories', 'future500' ); +$result = $paginator->fetchAll( $organizationApi, 'repositories', 'github ); ``` + +Get the first page +```php +$client = new Github\Client(); + +$organizationApi = $client->api('organization'); + +$paginator = new Github\ResultPager( $client ); +$result = $paginator->fetch( $organizationApi, 'repositories', 'github ); +``` +Check for a next page: +```php +$paginator->hasNext(); +``` + +Get next page: +```php +$paginator->fetchNext(); +``` + +Check for pervious page: +```php +$paginator->getPrevious(); +``` + +Get prevrious page: +```php +$paginator->fetchPrevious(); +``` \ No newline at end of file From 99ed0c73ea1f18ee3c03ad525b4aa59dbe8a0bac Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Fri, 12 Jul 2013 08:56:29 +0200 Subject: [PATCH 040/951] Fixed documentation --- doc/result_pager.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/result_pager.md b/doc/result_pager.md index c18a9f2923b..3c9e24493b5 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -11,7 +11,7 @@ $client = new Github\Client(); $organizationApi = $client->api('organization'); $paginator = new Github\ResultPager( $client ); -$result = $paginator->fetchAll( $organizationApi, 'repositories', 'github ); +$result = $paginator->fetchAll( $organizationApi, 'repositories', 'github' ); ``` Get the first page @@ -21,7 +21,7 @@ $client = new Github\Client(); $organizationApi = $client->api('organization'); $paginator = new Github\ResultPager( $client ); -$result = $paginator->fetch( $organizationApi, 'repositories', 'github ); +$result = $paginator->fetch( $organizationApi, 'repositories', 'github' ); ``` Check for a next page: ```php @@ -35,7 +35,7 @@ $paginator->fetchNext(); Check for pervious page: ```php -$paginator->getPrevious(); +$paginator->hasPrevious(); ``` Get prevrious page: From c8f5738541f3fd67c7225f31c0b139b6abec3d01 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Fri, 12 Jul 2013 10:49:01 +0200 Subject: [PATCH 041/951] fixed CS Updated coding standard to PSR-2 fixed CS issues and typos updated docs changed fetch() and fetchAll() signature to an array of parameters for flexibility in the future --- doc/result_pager.md | 18 ++++++--- lib/Github/Api/AbstractApi.php | 10 ++--- lib/Github/HttpClient/HttpClient.php | 2 +- lib/Github/ResultPager.php | 39 ++++++++++++------- lib/Github/ResultPagerInterface.php | 22 ++++++++++- test/Github/Tests/ResultPagerTest.php | 56 +++++++++++++-------------- 6 files changed, 90 insertions(+), 57 deletions(-) diff --git a/doc/result_pager.md b/doc/result_pager.md index 3c9e24493b5..a802be1caa9 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -10,8 +10,9 @@ $client = new Github\Client(); $organizationApi = $client->api('organization'); -$paginator = new Github\ResultPager( $client ); -$result = $paginator->fetchAll( $organizationApi, 'repositories', 'github' ); +$paginator = new Github\ResultPager($client); +$parameters = array('github'); +$result = $paginator->fetchAll($organizationApi, 'repositories', $parameters); ``` Get the first page @@ -20,9 +21,11 @@ $client = new Github\Client(); $organizationApi = $client->api('organization'); -$paginator = new Github\ResultPager( $client ); -$result = $paginator->fetch( $organizationApi, 'repositories', 'github' ); +$paginator = new Github\ResultPager( $client ); +$parameters = array('github'); +$result = $paginator->fetch($organizationApi, 'repositories', $parameters); ``` + Check for a next page: ```php $paginator->hasNext(); @@ -41,4 +44,9 @@ $paginator->hasPrevious(); Get prevrious page: ```php $paginator->fetchPrevious(); -``` \ No newline at end of file +``` + +If you want to retrieve the pagination links (available after the call to fetch): +```php +$paginator->getPagination(); +``` diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index c355001947a..378b3414d71 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -21,9 +21,9 @@ abstract class AbstractApi implements ApiInterface /** * number of items per page (GitHub pagination) * - * @var int + * @var null|int */ - protected $perPage = null; + protected $perPage; /** * @param Client $client @@ -38,7 +38,7 @@ public function configure() } /** - * @return int|null + * @return null|int */ public function getPerPage() { @@ -46,11 +46,11 @@ public function getPerPage() } /** - * @param Client $client + * @param null|int $perPage */ public function setPerPage($perPage) { - $this->perPage = (int) $perPage; + $this->perPage = (null === $perPage ? $perPage : (int) $perPage); return $this; } diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 93c69cd3a0f..92467bb1e91 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -163,7 +163,7 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - if ( !empty($this->options['base_url']) AND 0 !== strpos( $path, $this->options['base_url'] )) { + if (!empty($this->options['base_url']) && 0 !== strpos($path, $this->options['base_url'])) { $path = trim($this->options['base_url'].$path, '/'); } diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 7530f1c4a17..0ce7d11f595 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -24,15 +24,27 @@ class ResultPager implements ResultPagerInterface * @var array pagination * Comes from pagination headers in Github API results */ - protected $pagination = null; + protected $pagination; - public function __construct( Client $client ) + + /** + * The Github client to use for pagination. This must be the same + * instance that you got the Api instance from, i.e.: + * + * $client = new \Github\Client(); + * $api = $client->api('someApi'); + * $pager = new \Github\ResultPager($client); + * + * @param \Github\Client $client + * + */ + public function __construct(Client $client) { $this->client = $client; } /** - * @return null|array pagination result of last request + * {@inheritdoc} */ public function getPagination() { @@ -42,10 +54,8 @@ public function getPagination() /** * {@inheritdoc} */ - public function fetch( ApiInterface $api, $method ) + public function fetch(ApiInterface $api, $method, array $parameters = array()) { - $parameters = array_slice(func_get_args(),2); - $result = call_user_func_array(array($api, $method), $parameters); $this->postFetch(); @@ -55,9 +65,10 @@ public function fetch( ApiInterface $api, $method ) /** * {@inheritdoc} */ - public function fetchAll( ApiInterface $api, $method ) + public function fetchAll(ApiInterface $api, $method, array $parameters = array()) { - $parameters = array_slice(func_get_args(),2); + // get the perPage from the api + $perPage = $api->getPerPage(); // Set parameters per_page to GitHub max to minimize number of requests $api->setPerPage(100); @@ -70,6 +81,9 @@ public function fetchAll( ApiInterface $api, $method ) $result = array_merge($result, $this->fetchNext()); } + // restore the perPage + $api->setPerPage($perPage); + return $result; } @@ -134,11 +148,7 @@ public function fetchLast() */ protected function has($key) { - if (!empty($this->pagination) and isset($this->pagination[$key])) { - return true; - } - - return false; + return !empty($this->pagination) && isset($this->pagination[$key]); } /** @@ -146,12 +156,11 @@ protected function has($key) */ protected function get($key) { - if ( $this->has($key) ) { + if ($this->has($key)) { $result = $this->client->getHttpClient()->get($this->pagination[$key]); $this->postFetch(); return $result->getContent(); } } - } diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 4c8fcbd4370..6faab5efda2 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -12,16 +12,34 @@ */ interface ResultPagerInterface { + + /** + * @return null|array pagination result of last request + */ + public function getPagination(); + /** * Fetch a single result (page) from an api call + * + * @param ApiInterface $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array + * + * @return array returns the result of the Api::$method() call */ - public function fetch( ApiInterface $api, $method ); + public function fetch(ApiInterface $api, $method, array $parameters = array()); /** * Fetch all results (pages) from an api call * Use with care - there is no maximum + * + * @param ApiInterface $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array + * + * @return array returns a merge of the results of the Api::$method() call */ - public function fetchAll( ApiInterface $api, $method ); + public function fetchAll(ApiInterface $api, $method, array $parameters = array()); /** * Method that performs the actual work to refresh the pagination property diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index d1551767f56..df862c1d50a 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -25,7 +25,7 @@ public function shouldGetAllResults() { $amountLoops = 3; $content = array(1,2,3,4,5,6,7,8,9,10); - $responseMock = new TestResponse( $amountLoops, $content ); + $responseMock = new TestResponse($amountLoops, $content); // httpClient mock $httpClientMock = $this->getHttpClientMock($responseMock); @@ -37,7 +37,7 @@ public function shouldGetAllResults() $clientMock = $this->getClientMock($httpClientMock); // memberApi Mock - $memberApiMock = $this->getApiMock( 'Github\Api\Organization\Members' ); + $memberApiMock = $this->getApiMock('Github\Api\Organization\Members'); $memberApiMock ->expects($this->once()) ->method('all') @@ -47,8 +47,8 @@ public function shouldGetAllResults() $parameters = array('netwerven'); // Run fetchAll on result paginator - $paginator = new Github\ResultPager( $clientMock ); - $result = $paginator->fetchAll( $memberApiMock, $method, $parameters ); + $paginator = new Github\ResultPager($clientMock); + $result = $paginator->fetchAll($memberApiMock, $method, $parameters); $this->assertEquals($amountLoops * count($content), count($result)); } @@ -64,10 +64,10 @@ public function shouldGetSomeResults() $resultContent = 'organization test'; $responseMock = $this->getResponseMock($pagination); - $httpClient = $this->getHttpClientMock( $responseMock ); + $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); - $organizationApiMock = $this->getApiMock( 'Github\Api\Organization' ); + $organizationApiMock = $this->getApiMock('Github\Api\Organization'); $organizationApiMock ->expects($this->once()) @@ -75,8 +75,8 @@ public function shouldGetSomeResults() ->with('github') ->will($this->returnValue($resultContent)); - $paginator = new Github\ResultPager( $client ); - $result = $paginator->fetch($organizationApiMock, 'show', 'github'); + $paginator = new Github\ResultPager($client); + $result = $paginator->fetch($organizationApiMock, 'show', array('github')); $this->assertEquals($resultContent, $result); $this->assertEquals($pagination, $paginator->getPagination()); @@ -103,10 +103,10 @@ public function postFetch() ->method('getPagination') ->will($this->returnValue($pagination)); - $httpClient = $this->getHttpClientMock( $responseMock ); + $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); - $paginator = new Github\ResultPager( $client ); + $paginator = new Github\ResultPager($client); $paginator->postFetch(); $this->assertEquals($paginator->getPagination(), $pagination); @@ -122,7 +122,7 @@ public function fetchNext() $pagination = array('next' => 'http://github.com/next'); $resultContent = 'fetch test'; - $responseMock = $this->getResponseMock( $pagination ); + $responseMock = $this->getResponseMock($pagination); $responseMock ->expects($this->once()) ->method('getContent') @@ -132,17 +132,17 @@ public function fetchNext() ->expects($this->exactly(2)) ->method('getPagination'); - $httpClient = $this->getHttpClientMock( $responseMock ); + $httpClient = $this->getHttpClientMock($responseMock); $httpClient ->expects($this->once()) ->method('get') - ->with( $pagination['next'] ) + ->with($pagination['next']) ->will($this->returnValue($responseMock)); $client = $this->getClientMock($httpClient); - $paginator = new Github\ResultPager( $client ); + $paginator = new Github\ResultPager($client); $paginator->postFetch(); $this->assertEquals($paginator->fetchNext(), $resultContent); @@ -156,10 +156,10 @@ public function fetchNext() public function shouldHaveNext() { $responseMock = $this->getResponseMock(array('next' => 'http://github.com/next')); - $httpClient = $this->getHttpClientMock( $responseMock ); + $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); - $paginator = new Github\ResultPager( $client ); + $paginator = new Github\ResultPager($client); $paginator->postFetch(); $this->assertEquals($paginator->hasNext(), true); @@ -174,34 +174,32 @@ public function shouldHaveNext() public function shouldHavePrevious() { $responseMock = $this->getResponseMock(array('prev' => 'http://github.com/previous')); - $httpClient = $this->getHttpClientMock( $responseMock ); + $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); - $paginator = new Github\ResultPager( $client ); + $paginator = new Github\ResultPager($client); $paginator->postFetch(); $this->assertEquals($paginator->hasPrevious(), true); $this->assertEquals($paginator->hasNext(), false); } - protected function getResponseMock( array $pagination ) + protected function getResponseMock(array $pagination) { // response mock $responseMock = $this->getMock('Github\HttpClient\Message\Response'); $responseMock ->expects($this->any()) ->method('getPagination') - ->will($this->returnValue( - $pagination - )); + ->will($this->returnValue($pagination)); return $responseMock; } - protected function getClientMock( HttpClientInterface $httpClient = null ) + protected function getClientMock(HttpClientInterface $httpClient = null) { // if no httpClient isset use the default HttpClient mock - if( !$httpClient ){ + if (!$httpClient) { $httpClient = $this->getHttpClientMock(); } @@ -211,7 +209,7 @@ protected function getClientMock( HttpClientInterface $httpClient = null ) return $client; } - protected function getHttpClientMock( $responseMock = null ) + protected function getHttpClientMock($responseMock = null) { // mock the client interface $clientInterfaceMock = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); @@ -230,7 +228,7 @@ protected function getHttpClientMock( $responseMock = null ) // create the httpClient mock $httpClientMock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $clientInterfaceMock)); - if( $responseMock ){ + if ($responseMock) { $httpClientMock ->expects($this->any()) ->method('getLastResponse') @@ -240,12 +238,12 @@ protected function getHttpClientMock( $responseMock = null ) return $httpClientMock; } - protected function getApiMock( $apiClass ) + protected function getApiMock($apiClass) { $client = $this->getClientMock(); - return $this->getMockBuilder( $apiClass ) + return $this->getMockBuilder($apiClass) ->setConstructorArgs(array($client)) ->getMock(); } -} \ No newline at end of file +} From 4f62c8103d39c24b990b3dcb0034a91fb20b2e1a Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Tue, 30 Jul 2013 12:02:06 +0200 Subject: [PATCH 042/951] Added new parameters for creating a repository --- lib/Github/Api/Repo.php | 51 ++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index be6bd0db8e9..0b7deab20ef 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -55,24 +55,49 @@ public function show($username, $repository) * Create repository * @link http://developer.github.com/v3/repos/ * - * @param string $name name of the repository - * @param string $description repository description - * @param string $homepage homepage url - * @param boolean $public `true` for public, `false` for private - * @param null|string $organization username of organization if applicable + * @param string $name name of the repository + * @param string $description repository description + * @param string $homepage homepage url + * @param boolean $public `true` for public, `false` for private + * @param null|string $organization username of organization if applicable + * @param boolean $hasIssues `true` to enable issues for this repository, `false` to disable them + * @param boolean $hasWiki `true` to enable the wiki for this repository, `false` to disable it + * @param boolean $hadDownloads `true` to enable downloads for this repository, `false` to disable them + * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. + * @param boolean $autoInit `true` to create an initial commit with empty README, `false` for no initial commit * * @return array returns repository data */ - public function create($name, $description = '', $homepage = '', $public = true, $organization = null) - { + public function create( + $name, + $description = '', + $homepage = '', + $public = true, + $organization = null, + $hasIssues = false, + $hasWiki = false, + $hasDownloads = false, + $teamId = null, + $autoInit = false + ) { $path = null !== $organization ? 'orgs/'.$organization.'/repos' : 'user/repos'; - return $this->post($path, array( - 'name' => $name, - 'description' => $description, - 'homepage' => $homepage, - 'private' => !$public - )); + $parameters = array( + 'name' => $name, + 'description' => $description, + 'homepage' => $homepage, + 'private' => !$public, + 'has_issues' => $hasIssues, + 'has_wiki' => $hasWiki, + 'has_downloads' => $hasDownloads, + 'auto_init' => $autoInit + ); + + if ($organization && $teamId) { + $parameters['team_id'] = $teamId; + } + + return $this->post($path, $parameters); } /** From 470b8ac122597aec0ef993ed0ce18d33c02b6e26 Mon Sep 17 00:00:00 2001 From: Mitchel Verschoof Date: Tue, 30 Jul 2013 13:28:49 +0200 Subject: [PATCH 043/951] Added newline after return Added spaces after comma in an array --- lib/Github/Api/AbstractApi.php | 1 + test/Github/Tests/ResultPagerTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 378b3414d71..727f4e51824 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -51,6 +51,7 @@ public function getPerPage() public function setPerPage($perPage) { $this->perPage = (null === $perPage ? $perPage : (int) $perPage); + return $this; } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index df862c1d50a..7d37bb4a957 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -24,7 +24,7 @@ class ResultPagerTest extends \PHPUnit_Framework_TestCase public function shouldGetAllResults() { $amountLoops = 3; - $content = array(1,2,3,4,5,6,7,8,9,10); + $content = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $responseMock = new TestResponse($amountLoops, $content); // httpClient mock From 32ec61d5fb97835f346984bd3ca8f20d94d5fc78 Mon Sep 17 00:00:00 2001 From: Corey Ballou Date: Wed, 31 Jul 2013 06:53:23 -0400 Subject: [PATCH 044/951] Update CurrentUser.php Adding method to retrieve a current user's starred repositories. --- lib/Github/Api/CurrentUser.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 6237eb44393..dba5325e5e6 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -100,4 +100,14 @@ public function watched($page = 1) 'page' => $page )); } + + /** + * @link http://developer.github.com/changes/2012-9-5-watcher-api/ + */ + public function starred($page = 1) + { + return $this->get('user/starred', array( + 'page' => $page + )); + } } From 5c3bb6967562509d974f26838cd9a516113d8033 Mon Sep 17 00:00:00 2001 From: leonardaustin Date: Fri, 2 Aug 2013 16:29:09 +0100 Subject: [PATCH 045/951] Add stargazers methods --- lib/Github/Api/Repo.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 0b7deab20ef..c6f2381c672 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -331,4 +331,19 @@ public function watchers($username, $repository, $page = 1) 'page' => $page )); } + + + /** + * @param string $username + * @param string $repository + * @param integer $page + * + * @return array + */ + public function stargazers($username, $repository, $page = 1) + { + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/stargazers', array( + 'page' => $page + )); + } } From ac2846e05c18a34099370550bc00f55e00f61248 Mon Sep 17 00:00:00 2001 From: Tim Massey Date: Mon, 5 Aug 2013 11:50:06 +1000 Subject: [PATCH 046/951] Fixes bug where supplied option for timeout were ignored in constructor. --- lib/Github/HttpClient/HttpClient.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index ef82a2a0044..d118a2d73cb 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -55,7 +55,8 @@ class HttpClient implements HttpClientInterface public function __construct(array $options = array(), ClientInterface $client = null) { $client = $client ?: new Curl(); - $client->setTimeout($this->options['timeout']); + $timeout = isset($options['timeout']) ? $options['timeout'] : $this->options['timeout']; + $client->setTimeout($timeout); $client->setVerifyPeer(false); $this->options = array_merge($this->options, $options); From 58b983584fce2425b73fecf49f5c5f2b7eed3883 Mon Sep 17 00:00:00 2001 From: leonardaustin Date: Mon, 12 Aug 2013 22:36:38 +0100 Subject: [PATCH 047/951] If calling rate_limit resource does not throw an exception if there is less than 0 requests remaining (rate_limit is exempt from any api request limits) --- lib/Github/HttpClient/Listener/ErrorListener.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 1d537240900..3f20c05093b 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -43,7 +43,8 @@ public function postSend(RequestInterface $request, MessageInterface $response) /** @var $response \Github\HttpClient\Message\Response */ if ($response->isClientError() || $response->isServerError()) { $remaining = $response->getHeader('X-RateLimit-Remaining'); - if (null !== $remaining && 1 > $remaining) { + + if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getResource(), 1, 10)) { throw new ApiLimitExceedException($this->options['api_limit']); } From 57722a27dbc9d9bdd3754b4ed11cb806592cd9f6 Mon Sep 17 00:00:00 2001 From: Sebastian Grodzicki Date: Fri, 16 Aug 2013 12:16:32 +0200 Subject: [PATCH 048/951] Fixed updating a pull request --- lib/Github/Api/PullRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index aed711a6c34..c322c00f003 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -102,13 +102,13 @@ public function create($username, $repository, array $params) return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $params); } - public function update($username, $repository, array $params) + public function update($username, $repository, $id, array $params) { if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { $params['state'] = 'open'; } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $params); + return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id), $params); } public function merged($username, $repository, $id) From 22a09e848738d29fb5bbf7b3f26f7e2bbb046987 Mon Sep 17 00:00:00 2001 From: Sebastian Grodzicki Date: Wed, 21 Aug 2013 08:52:29 +0200 Subject: [PATCH 049/951] Support for merging branches in a repository --- lib/Github/Api/Repo.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 0b7deab20ef..2b2d29475b9 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -331,4 +331,25 @@ public function watchers($username, $repository, $page = 1) 'page' => $page )); } + + /** + * Perform a merge + * @link http://developer.github.com/v3/repos/merging/ + * + * @param string $username + * @param string $repository + * @param string $base The name of the base branch that the head will be merged into. + * @param string $head The head to merge. This can be a branch name or a commit SHA1. + * @param string $message Commit message to use for the merge commit. If omitted, a default message will be used. + * + * @return array|null + */ + public function merge($username, $repository, $base, $head, $message = null) + { + return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/merges', array( + 'base' => $base, + 'head' => $head, + 'commit_message' => $message + )); + } } From 930abe61893b21fa5aa3f060f1e793f6712adbed Mon Sep 17 00:00:00 2001 From: Kristopher Wilson Date: Thu, 22 Aug 2013 14:05:57 -0400 Subject: [PATCH 050/951] Implementing handling organization issues --- lib/Github/Api/Issue.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 56aa327ed47..c1afaf45ec5 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -51,6 +51,24 @@ public function find($username, $repository, $state, $keyword) return $this->get('legacy/issues/search/'.urlencode($username).'/'.urlencode($repository).'/'.urlencode($state).'/'.urlencode($keyword)); } + /** + * List issues by organization + * @link http://developer.github.com/v3/issues/ + * + * @param string $organization the organization + * @param string $state the issue state, can be open or closed + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * @return array list of issues found + */ + public function org($organization, $state, array $params = array()) + { + if (!in_array($state, array('open', 'closed'))) { + $state = 'open'; + } + + return $this->get('orgs/'.urlencode($organization).'/issues', array_merge(array('page' => 1, 'state' => $state), $params)); + } + /** * Get extended information about an issue by its username, repo and number * @link http://developer.github.com/v3/issues/ From 18460e31534f2dc30243093d8622b337265918d1 Mon Sep 17 00:00:00 2001 From: Kristopher Wilson Date: Thu, 22 Aug 2013 15:51:07 -0400 Subject: [PATCH 051/951] Implementing retrieving organization repos --- lib/Github/Api/Repo.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 0b7deab20ef..a7fc5ba0e8c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -37,6 +37,20 @@ public function find($keyword, array $params) return $this->get('legacy/repos/search/'.urlencode($keyword), array_merge(array('start_page' => 1), $params)); } + /** + * List all repositories for an organization + * @link http://developer.github.com/v3/repos/#list-organization-repositories + * + * @param string $organization the name of the organization + * @param array $params + * + * @return array list of organization repositories + */ + public function org($organization, array $params = array()) + { + return $this->get('orgs/'.$organization.'/repos', array_merge(array('start_page' => 1), $params)); + } + /** * Get extended information about a repository by its username and repository name * @link http://developer.github.com/v3/repos/ From 0005d74ae5b9f07b8af02d429cd1170380974606 Mon Sep 17 00:00:00 2001 From: Matthew Simo Date: Fri, 23 Aug 2013 17:43:33 -0500 Subject: [PATCH 052/951] Add Class for releases. --- lib/Github/Api/Repo.php | 12 ++++++ lib/Github/Api/Repository/Releases.php | 52 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 lib/Github/Api/Repository/Releases.php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index e61c9c6c02b..71cd726f380 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -8,6 +8,7 @@ use Github\Api\Repository\Contents; use Github\Api\Repository\DeployKeys; use Github\Api\Repository\Downloads; +use Github\Api\Repository\Releases; use Github\Api\Repository\Forks; use Github\Api\Repository\Hooks; use Github\Api\Repository\Labels; @@ -156,6 +157,17 @@ public function downloads() return new Downloads($this->client); } + /** + * Manage the releases of a repository (Currently Undocumented) + * @link http://developer.github.com/v3/repos/ + * + * @return Releases + */ + public function releases() + { + return new Releases($this->client); + } + /** * Manage the deploy keys of a repository * @link http://developer.github.com/v3/repos/keys/ diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php new file mode 100644 index 00000000000..f027d3194e0 --- /dev/null +++ b/lib/Github/Api/Repository/Releases.php @@ -0,0 +1,52 @@ + + */ +class Releases extends AbstractApi +{ + /** + * List releases in selected repository + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * + * @return array + */ + public function all($username, $repository) + { + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/releases'); + } + + /** + * Get a release in selected repository + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the release + * + * @return array + */ + public function show($username, $repository, $id) + { + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/releases/'.urlencode($id)); + } + + /** + * Delete a download in selected repository + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the release + * + * @return array + */ + public function remove($username, $repository, $id) + { + return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/releases/'.urlencode($id)); + } +} From 08e7c7c9e86014526340c031f96bd361ac11caaa Mon Sep 17 00:00:00 2001 From: Matthew Simo Date: Fri, 23 Aug 2013 18:23:29 -0500 Subject: [PATCH 053/951] Docs & a comment --- doc/index.md | 1 + doc/repo/releases.md | 25 +++++++++++++++++++++++++ lib/Github/Api/Repository/Releases.php | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 doc/repo/releases.md diff --git a/doc/index.md b/doc/index.md index 45d6622d1c1..68d1540707e 100644 --- a/doc/index.md +++ b/doc/index.md @@ -13,6 +13,7 @@ APIs: * [Pull Requests](pull_requests.md) * [Comments](pull_request/comments.md) * [Repositories](repos.md) + * [Releases](repo/releases.md) * [Users](users.md) Additional features: diff --git a/doc/repo/releases.md b/doc/repo/releases.md new file mode 100644 index 00000000000..63a4241a0b4 --- /dev/null +++ b/doc/repo/releases.md @@ -0,0 +1,25 @@ +## Repo / Releases API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) + +This Github API Endpoint is currently undocumented because it's new, but works just fine. + + +### List all releases + +```php +$releases = $client->api('repo')->releases()->all('twbs', 'bootstrap'); +``` + +### List one release + +```php +$release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id); +``` + +### Remove a release + +This works, but isn't thoroughly tested, use at your own risk. + +```php +$response = $client->api('repo')->releases()->remove('twbs', 'bootstrap', $id); +``` diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index f027d3194e0..3def47b154f 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -37,7 +37,7 @@ public function show($username, $repository, $id) } /** - * Delete a download in selected repository + * Delete a download in selected repository (Not thoroughly tested!) * * @param string $username the user who owns the repo * @param string $repository the name of the repo From 6df2deb6f70b7c44e8b091b5c71aa4b9ddcf3829 Mon Sep 17 00:00:00 2001 From: Sebastian Grodzicki Date: Fri, 30 Aug 2013 11:16:00 +0200 Subject: [PATCH 054/951] Fixed formatting in PHPDoc --- lib/Github/Api/Repo.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 2b2d29475b9..1bac1ed8687 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -336,11 +336,11 @@ public function watchers($username, $repository, $page = 1) * Perform a merge * @link http://developer.github.com/v3/repos/merging/ * - * @param string $username - * @param string $repository - * @param string $base The name of the base branch that the head will be merged into. - * @param string $head The head to merge. This can be a branch name or a commit SHA1. - * @param string $message Commit message to use for the merge commit. If omitted, a default message will be used. + * @param string $username + * @param string $repository + * @param string $base The name of the base branch that the head will be merged into. + * @param string $head The head to merge. This can be a branch name or a commit SHA1. + * @param string $message Commit message to use for the merge commit. If omitted, a default message will be used. * * @return array|null */ From 7f44a117797a849e55e78b095de0be1440b98615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 17 May 2013 14:52:29 +0200 Subject: [PATCH 055/951] Removed useless condition --- lib/Github/Client.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 0ae764b49e0..a69a9c762a1 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -72,9 +72,7 @@ class Client */ public function __construct(HttpClientInterface $httpClient = null) { - if (null !== $httpClient) { - $this->httpClient = $httpClient; - } + $this->httpClient = $httpClient; } /** From 67c72b49c1742cc8c8bb74639cff89dea1684584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 17 May 2013 14:57:00 +0200 Subject: [PATCH 056/951] Fixed CS --- lib/Github/Api/CurrentUser.php | 2 +- lib/Github/Api/CurrentUser/Followers.php | 8 +- lib/Github/Api/CurrentUser/Notifications.php | 30 ++--- lib/Github/Api/CurrentUser/Watchers.php | 14 +-- lib/Github/Api/Issue.php | 54 ++++----- lib/Github/Api/Organization.php | 10 +- lib/Github/Api/PullRequest.php | 36 +++--- lib/Github/Api/Repo.php | 108 +++++++++--------- lib/Github/Api/Repository/Contents.php | 45 ++++---- lib/Github/Api/Repository/Downloads.php | 16 +-- lib/Github/Api/Repository/Statuses.php | 2 +- lib/Github/Api/User.php | 32 +++--- lib/Github/Client.php | 12 +- .../HttpClient/Cache/CacheInterface.php | 7 +- .../HttpClient/Cache/FilesystemCache.php | 1 - lib/Github/HttpClient/HttpClient.php | 2 - lib/Github/HttpClient/HttpClientInterface.php | 62 +++++----- lib/Github/ResultPager.php | 3 - lib/Github/ResultPagerInterface.php | 16 +-- test/Github/Tests/Api/Issue/CommentsTest.php | 1 - .../Repository/ContentsDownloadFixture.php | 2 +- .../Tests/Api/Repository/ContentsTest.php | 6 +- .../Tests/Api/Repository/DeployKeysTest.php | 1 - .../Github/Tests/Api/Repository/HooksTest.php | 1 - .../Tests/Api/Repository/LabelsTest.php | 1 - .../HttpClient/Cache/FilesystemCacheTest.php | 1 - test/Github/Tests/Mock/TestResponse.php | 2 +- test/bootstrap.php | 3 +- 28 files changed, 231 insertions(+), 247 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index dba5325e5e6..688282cb65b 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -100,7 +100,7 @@ public function watched($page = 1) 'page' => $page )); } - + /** * @link http://developer.github.com/changes/2012-9-5-watcher-api/ */ diff --git a/lib/Github/Api/CurrentUser/Followers.php b/lib/Github/Api/CurrentUser/Followers.php index d513e5ff251..022df3374f8 100644 --- a/lib/Github/Api/CurrentUser/Followers.php +++ b/lib/Github/Api/CurrentUser/Followers.php @@ -14,7 +14,7 @@ class Followers extends AbstractApi * List followed users by the authenticated user * @link http://developer.github.com/v3/repos/followers/ * - * @param integer $page + * @param integer $page * @return array */ public function all($page = 1) @@ -28,7 +28,7 @@ public function all($page = 1) * Check that the authenticated user follows a user * @link http://developer.github.com/v3/repos/followers/ * - * @param string $username the username to follow + * @param string $username the username to follow * @return array */ public function check($username) @@ -40,7 +40,7 @@ public function check($username) * Make the authenticated user follow a user * @link http://developer.github.com/v3/repos/followers/ * - * @param string $username the username to follow + * @param string $username the username to follow * @return array */ public function follow($username) @@ -52,7 +52,7 @@ public function follow($username) * Make the authenticated user un-follow a user * @link http://developer.github.com/v3/repos/followers/ * - * @param string $username the username to un-follow + * @param string $username the username to un-follow * @return array */ public function unfollow($username) diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index 1f9a377110f..40d37a50bf8 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -14,7 +14,7 @@ class Notifications extends AbstractApi * List all notifications for the authenticated user * @link http://developer.github.com/v3/activity/notifications/#list-your-notifications * - * @param array $params + * @param array $params * @return array */ public function all(array $params = array()) @@ -26,9 +26,9 @@ public function all(array $params = array()) * List all notifications for the authenticated user in selected repository * @link http://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param array $params + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param array $params * @return array */ public function allInRepository($username, $repository, array $params = array()) @@ -39,7 +39,7 @@ public function allInRepository($username, $repository, array $params = array()) /** * @link http://developer.github.com/v3/activity/notifications/#mark-as-read * - * @param array $params + * @param array $params * @return array */ public function markAsReadAll(array $params = array()) @@ -50,9 +50,9 @@ public function markAsReadAll(array $params = array()) /** * @link http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param array $params + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param array $params * @return array */ public function markAsReadInRepository($username, $repository, array $params = array()) @@ -63,8 +63,8 @@ public function markAsReadInRepository($username, $repository, array $params = a /** * @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read * - * @param string $id the notification number - * @param array $params + * @param string $id the notification number + * @param array $params * @return array */ public function markAsRead($id, array $params) @@ -75,7 +75,7 @@ public function markAsRead($id, array $params) /** * @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread * - * @param string $id the notification number + * @param string $id the notification number * @return array */ public function show($id) @@ -86,7 +86,7 @@ public function show($id) /** * @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription * - * @param string $id the notification number + * @param string $id the notification number * @return array */ public function showSubscription($id) @@ -97,8 +97,8 @@ public function showSubscription($id) /** * @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription * - * @param string $id the notification number - * @param array $params + * @param string $id the notification number + * @param array $params * @return array */ public function createSubscription($id, array $params) @@ -109,7 +109,7 @@ public function createSubscription($id, array $params) /** * @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription * - * @param string $id the notification number + * @param string $id the notification number * @return array */ public function removeSubscription($id) diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 1277ff34f9c..7a752c0b90d 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -14,7 +14,7 @@ class Watchers extends AbstractApi * List repositories watched by the authenticated user * @link http://developer.github.com/v3/repos/watching/ * - * @param integer $page + * @param integer $page * @return array */ public function all($page = 1) @@ -28,8 +28,8 @@ public function all($page = 1) * Check that the authenticated user watches a repository * @link http://developer.github.com/v3/repos/watching/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo * @return array */ public function check($username, $repository) @@ -41,8 +41,8 @@ public function check($username, $repository) * Make the authenticated user watch a repository * @link http://developer.github.com/v3/repos/watching/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo * @return array */ public function watch($username, $repository) @@ -54,8 +54,8 @@ public function watch($username, $repository) * Make the authenticated user unwatch a repository * @link http://developer.github.com/v3/repos/watching/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo * @return array */ public function unwatch($username, $repository) diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index c1afaf45ec5..918eb478138 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -21,10 +21,10 @@ class Issue extends AbstractApi * List issues by username, repo and state * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction - * @return array list of issues found + * @param string $username the username + * @param string $repository the repository + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * @return array list of issues found */ public function all($username, $repository, array $params = array()) { @@ -35,12 +35,12 @@ public function all($username, $repository, array $params = array()) * Search issues by username, repo, state and keyword * @link http://developer.github.com/v3/search/#search-issues * - * @param string $username the username - * @param string $repository the repository - * @param string $state the issue state, can be open or closed - * @param string $keyword the keyword to filter issues by + * @param string $username the username + * @param string $repository the repository + * @param string $state the issue state, can be open or closed + * @param string $keyword the keyword to filter issues by * - * @return array list of issues found + * @return array list of issues found */ public function find($username, $repository, $state, $keyword) { @@ -55,10 +55,10 @@ public function find($username, $repository, $state, $keyword) * List issues by organization * @link http://developer.github.com/v3/issues/ * - * @param string $organization the organization - * @param string $state the issue state, can be open or closed - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction - * @return array list of issues found + * @param string $organization the organization + * @param string $state the issue state, can be open or closed + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * @return array list of issues found */ public function org($organization, $state, array $params = array()) { @@ -73,10 +73,10 @@ public function org($organization, $state, array $params = array()) * Get extended information about an issue by its username, repo and number * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param string $id the issue number - * @return array information about the issue + * @param string $username the username + * @param string $repository the repository + * @param string $id the issue number + * @return array information about the issue */ public function show($username, $repository, $id) { @@ -88,10 +88,10 @@ public function show($username, $repository, $id) * The issue is assigned to the authenticated user. Requires authentication. * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param array $params the new issue data - * @return array information about the issue + * @param string $username the username + * @param string $repository the repository + * @param array $params the new issue data + * @return array information about the issue * * @throws MissingArgumentException */ @@ -108,12 +108,12 @@ public function create($username, $repository, array $params) * Update issue information's by username, repo and issue number. Requires authentication. * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param string $id the issue number - * @param array $params key=>value user attributes to update. - * key can be title or body - * @return array information about the issue + * @param string $username the username + * @param string $repository the repository + * @param string $id the issue number + * @param array $params key=>value user attributes to update. + * key can be title or body + * @return array information about the issue */ public function update($username, $repository, $id, array $params) { diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 29f23ccf2d7..0a1af06b8d4 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -18,9 +18,9 @@ class Organization extends AbstractApi * Get extended information about an organization by its name * @link http://developer.github.com/v3/orgs/#get * - * @param string $organization the organization to show + * @param string $organization the organization to show * - * @return array informations about the organization + * @return array informations about the organization */ public function show($organization) { @@ -36,10 +36,10 @@ public function update($organization, array $params) * List all repositories across all the organizations that you can access * @link http://developer.github.com/v3/repos/#list-organization-repositories * - * @param string $organization the user name - * @param string $type the type of repositories + * @param string $organization the user name + * @param string $type the type of repositories * - * @return array the repositories + * @return array the repositories */ public function repositories($organization, $type = 'all') { diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index c322c00f003..4f2170fe09d 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -17,14 +17,14 @@ class PullRequest extends AbstractApi * Get a listing of a project's pull requests by the username, repository and (optionally) state. * @link http://developer.github.com/v3/pulls/ * - * @param string $username the username - * @param string $repository the repository - * @param string $state the state of the fetched pull requests. - * The API seems to automatically default to 'open' - * @param integer $page the page - * @param integer $perPage the per page + * @param string $username the username + * @param string $repository the repository + * @param string $state the state of the fetched pull requests. + * The API seems to automatically default to 'open' + * @param integer $page the page + * @param integer $perPage the per page * - * @return array array of pull requests for the project + * @return array array of pull requests for the project */ public function all($username, $repository, $state = null, $page = 1, $perPage = 30) { @@ -41,11 +41,11 @@ public function all($username, $repository, $state = null, $page = 1, $perPage = * Show all details of a pull request, including the discussions. * @link http://developer.github.com/v3/pulls/ * - * @param string $username the username - * @param string $repository the repository - * @param string $id the ID of the pull request for which details are retrieved + * @param string $username the username + * @param string $repository the repository + * @param string $id the ID of the pull request for which details are retrieved * - * @return array array of pull requests for the project + * @return array array of pull requests for the project */ public function show($username, $repository, $id) { @@ -71,13 +71,13 @@ public function comments() * Create a pull request * @link http://developer.github.com/v3/pulls/ * - * @param string $username the username - * @param string $repository the repository - * @param array $params A String of the branch or commit SHA that you want your changes to be pulled to. - * A String of the branch or commit SHA of your changes. Typically this will be a branch. - * If the branch is in a fork of the original repository, specify the username first: - * "my-user:some-branch". The String title of the Pull Request. The String body of - * the Pull Request. The issue number. Used when title and body is not set. + * @param string $username the username + * @param string $repository the repository + * @param array $params A String of the branch or commit SHA that you want your changes to be pulled to. + * A String of the branch or commit SHA of your changes. Typically this will be a branch. + * If the branch is in a fork of the original repository, specify the username first: + * "my-user:some-branch". The String title of the Pull Request. The String body of + * the Pull Request. The issue number. Used when title and body is not set. * * @return array * diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 5f39087804e..711af9e5cd2 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -27,10 +27,10 @@ class Repo extends AbstractApi * Search repositories by keyword: * @link http://developer.github.com/v3/search/#search-repositories * - * @param string $keyword the search query - * @param array $params + * @param string $keyword the search query + * @param array $params * - * @return array list of founded repositories + * @return array list of founded repositories */ public function find($keyword, array $params) { @@ -41,10 +41,10 @@ public function find($keyword, array $params) * List all repositories for an organization * @link http://developer.github.com/v3/repos/#list-organization-repositories * - * @param string $organization the name of the organization - * @param array $params + * @param string $organization the name of the organization + * @param array $params * - * @return array list of organization repositories + * @return array list of organization repositories */ public function org($organization, array $params = array()) { @@ -55,10 +55,10 @@ public function org($organization, array $params = array()) * Get extended information about a repository by its username and repository name * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository + * @param string $username the user who owns the repository + * @param string $repository the name of the repository * - * @return array informations about the repository + * @return array informations about the repository */ public function show($username, $repository) { @@ -69,18 +69,18 @@ public function show($username, $repository) * Create repository * @link http://developer.github.com/v3/repos/ * - * @param string $name name of the repository - * @param string $description repository description - * @param string $homepage homepage url - * @param boolean $public `true` for public, `false` for private - * @param null|string $organization username of organization if applicable - * @param boolean $hasIssues `true` to enable issues for this repository, `false` to disable them - * @param boolean $hasWiki `true` to enable the wiki for this repository, `false` to disable it - * @param boolean $hadDownloads `true` to enable downloads for this repository, `false` to disable them - * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. - * @param boolean $autoInit `true` to create an initial commit with empty README, `false` for no initial commit - * - * @return array returns repository data + * @param string $name name of the repository + * @param string $description repository description + * @param string $homepage homepage url + * @param boolean $public `true` for public, `false` for private + * @param null|string $organization username of organization if applicable + * @param boolean $hasIssues `true` to enable issues for this repository, `false` to disable them + * @param boolean $hasWiki `true` to enable the wiki for this repository, `false` to disable it + * @param boolean $hadDownloads `true` to enable downloads for this repository, `false` to disable them + * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. + * @param boolean $autoInit `true` to create an initial commit with empty README, `false` for no initial commit + * + * @return array returns repository data */ public function create( $name, @@ -118,11 +118,11 @@ public function create( * Set information of a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param array $values the key => value pairs to post + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param array $values the key => value pairs to post * - * @return array informations about the repository + * @return array informations about the repository */ public function update($username, $repository, array $values) { @@ -133,10 +133,10 @@ public function update($username, $repository, array $values) * Delete a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository + * @param string $username the user who owns the repository + * @param string $repository the name of the repository * - * @return mixed null on success, array on error with 'message' + * @return mixed null on success, array on error with 'message' */ public function remove($username, $repository) { @@ -257,11 +257,11 @@ public function statuses() * Get the branch(es) of a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the username - * @param string $repository the name of the repository - * @param string $branch the name of the branch + * @param string $username the username + * @param string $repository the name of the repository + * @param string $branch the name of the branch * - * @return array list of the repository branches + * @return array list of the repository branches */ public function branches($username, $repository, $branch = null) { @@ -277,11 +277,11 @@ public function branches($username, $repository, $branch = null) * Get the contributors of a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param boolean $includingAnonymous by default, the list only shows GitHub users. - * You can include non-users too by setting this to true - * @return array list of the repo contributors + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param boolean $includingAnonymous by default, the list only shows GitHub users. + * You can include non-users too by setting this to true + * @return array list of the repo contributors */ public function contributors($username, $repository, $includingAnonymous = false) { @@ -294,10 +294,10 @@ public function contributors($username, $repository, $includingAnonymous = false * Get the language breakdown of a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository + * @param string $username the user who owns the repository + * @param string $repository the name of the repository * - * @return array list of the languages + * @return array list of the languages */ public function languages($username, $repository) { @@ -308,10 +308,10 @@ public function languages($username, $repository) * Get the tags of a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository + * @param string $username the user who owns the repository + * @param string $repository the name of the repository * - * @return array list of the repository tags + * @return array list of the repository tags */ public function tags($username, $repository) { @@ -322,10 +322,10 @@ public function tags($username, $repository) * Get the teams of a repository * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo * - * @return array list of the languages + * @return array list of the languages */ public function teams($username, $repository) { @@ -333,9 +333,9 @@ public function teams($username, $repository) } /** - * @param string $username - * @param string $repository - * @param integer $page + * @param string $username + * @param string $repository + * @param integer $page * * @return array */ @@ -350,11 +350,11 @@ public function watchers($username, $repository, $page = 1) * Perform a merge * @link http://developer.github.com/v3/repos/merging/ * - * @param string $username - * @param string $repository - * @param string $base The name of the base branch that the head will be merged into. - * @param string $head The head to merge. This can be a branch name or a commit SHA1. - * @param string $message Commit message to use for the merge commit. If omitted, a default message will be used. + * @param string $username + * @param string $repository + * @param string $base The name of the base branch that the head will be merged into. + * @param string $head The head to merge. This can be a branch name or a commit SHA1. + * @param string $message Commit message to use for the merge commit. If omitted, a default message will be used. * * @return array|null */ diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 9ee90f713a7..6a79377654f 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -3,7 +3,6 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; -use Github\Exception\MissingArgumentException; use Github\Exception\InvalidArgumentException; use Github\Exception\ErrorException; @@ -17,11 +16,11 @@ class Contents extends AbstractApi * Get content of README file in a repository * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param null|string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param null|string $reference reference to a branch or commit * - * @return array information for README file + * @return array information for README file */ public function readme($username, $repository, $reference = null) { @@ -34,12 +33,12 @@ public function readme($username, $repository, $reference = null) * Get contents of any file or directory in a repository * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param null|string $path path to file or directory - * @param null|string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param null|string $path path to file or directory + * @param null|string $reference reference to a branch or commit * - * @return array information for file | information for each item in directory + * @return array information for file | information for each item in directory */ public function show($username, $repository, $path = null, $reference = null) { @@ -57,12 +56,12 @@ public function show($username, $repository, $path = null, $reference = null) * Get content of archives in a repository * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $format format of archive: tarball or zipball - * @param null|string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $format format of archive: tarball or zipball + * @param null|string $reference reference to a branch or commit * - * @return array information for archives + * @return array information for archives */ public function archive($username, $repository, $format, $reference = null) { @@ -74,19 +73,19 @@ public function archive($username, $repository, $format, $reference = null) 'ref' => $reference )); } - + /** * Get the contents of a file in a repository * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $path path to file - * @param null|string $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param null|string $reference reference to a branch or commit * - * @return null|string content of file, or null in case of base64_decode failure + * @return null|string content of file, or null in case of base64_decode failure * - * @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64 - * @throws ErrorException If $path doesn't include a 'content' index + * @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64 + * @throws ErrorException If $path doesn't include a 'content' index */ public function download($username, $repository, $path, $reference = null) { diff --git a/lib/Github/Api/Repository/Downloads.php b/lib/Github/Api/Repository/Downloads.php index c289e1a8ef9..e402c317c1d 100644 --- a/lib/Github/Api/Repository/Downloads.php +++ b/lib/Github/Api/Repository/Downloads.php @@ -14,8 +14,8 @@ class Downloads extends AbstractApi * List downloads in selected repository * @link http://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo * * @return array */ @@ -28,9 +28,9 @@ public function all($username, $repository) * Get a download in selected repository * @link http://developer.github.com/v3/repos/downloads/#get-a-single-download * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the download file + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the download file * * @return array */ @@ -43,9 +43,9 @@ public function show($username, $repository, $id) * Delete a download in selected repository * @link http://developer.github.com/v3/repos/downloads/#delete-a-download * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the download file + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the download file * * @return array */ diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index 9872acd06d7..9b3e7630ecc 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -31,7 +31,7 @@ public function show($username, $repository, $sha) * @param string $username * @param string $repository * @param string $sha - * @param array $params + * @param array $params * * @return array * diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 2241f79eb8c..6ecb28ca597 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -15,9 +15,9 @@ class User extends AbstractApi * Search users by username: * @link http://developer.github.com/v3/search/#search-users * - * @param string $keyword the keyword to search + * @param string $keyword the keyword to search * - * @return array list of users found + * @return array list of users found */ public function find($keyword) { @@ -28,8 +28,8 @@ public function find($keyword) * Get extended information about a user by its username * @link http://developer.github.com/v3/users/ * - * @param string $username the username to show - * @return array informations about the user + * @param string $username the username to show + * @return array informations about the user */ public function show($username) { @@ -40,8 +40,8 @@ public function show($username) * Request the users that a specific user is following * @link http://developer.github.com/v3/users/followers/ * - * @param string $username the username - * @return array list of followed users + * @param string $username the username + * @return array list of followed users */ public function following($username) { @@ -52,8 +52,8 @@ public function following($username) * Request the users following a specific user * @link http://developer.github.com/v3/users/followers/ * - * @param string $username the username - * @return array list of following users + * @param string $username the username + * @return array list of following users */ public function followers($username) { @@ -64,8 +64,8 @@ public function followers($username) * Request the repository that a specific user is watching * @link http://developer.github.com/v3/repos/watching/ * - * @param string $username the username - * @return array list of watched repositories + * @param string $username the username + * @return array list of watched repositories */ public function watched($username) { @@ -76,8 +76,8 @@ public function watched($username) * Get the repositories of a user * @link http://developer.github.com/v3/repos/ * - * @param string $username the username - * @return array list of the user repositories + * @param string $username the username + * @return array list of the user repositories */ public function repositories($username) { @@ -88,8 +88,8 @@ public function repositories($username) * Get the public gists for a user * @link http://developer.github.com/v3/gists/ * - * @param string $username the username - * @return array list of the user gists + * @param string $username the username + * @return array list of the user gists */ public function gists($username) { @@ -100,8 +100,8 @@ public function gists($username) * Get the public keys for a user * @link http://developer.github.com/v3/users/keys/#list-public-keys-for-a-user * - * @param string $username the username - * @return array list of the user public keys + * @param string $username the username + * @return array list of the user public keys */ public function keys($username) { diff --git a/lib/Github/Client.php b/lib/Github/Client.php index a69a9c762a1..e50d5e94638 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -2,9 +2,6 @@ namespace Github; -use Buzz\Client\Curl; -use Buzz\Client\ClientInterface; - use Github\Api\ApiInterface; use Github\Exception\InvalidArgumentException; use Github\HttpClient\HttpClient; @@ -147,11 +144,11 @@ public function api($name) /** * Authenticate a user for all next requests * - * @param string $tokenOrLogin GitHub private token/username/client ID - * @param null|string $password GitHub password/secret (optionally can contain $authMethod) - * @param null|string $authMethod One of the AUTH_* class constants + * @param string $tokenOrLogin GitHub private token/username/client ID + * @param null|string $password GitHub password/secret (optionally can contain $authMethod) + * @param null|string $authMethod One of the AUTH_* class constants * - * @throws InvalidArgumentException If no authentication method was given + * @throws InvalidArgumentException If no authentication method was given */ public function authenticate($tokenOrLogin, $password = null, $authMethod = null) { @@ -219,7 +216,6 @@ public function getOption($name) return $this->options[$name]; } - /** * @param string $name * @param mixed $value diff --git a/lib/Github/HttpClient/Cache/CacheInterface.php b/lib/Github/HttpClient/Cache/CacheInterface.php index b2889d1e4db..b1ada0e53d9 100644 --- a/lib/Github/HttpClient/Cache/CacheInterface.php +++ b/lib/Github/HttpClient/Cache/CacheInterface.php @@ -12,16 +12,16 @@ interface CacheInterface { /** - * @param string $id The id of the cached resource + * @param string $id The id of the cached resource * * @return null|integer The modified since timestamp */ public function getModifiedSince($id); /** - * @param string $id The id of the cached resource + * @param string $id The id of the cached resource * - * @return Response The cached response object + * @return Response The cached response object * * @throws \InvalidArgumentException If cache data don't exists */ @@ -35,4 +35,3 @@ public function get($id); */ public function set($id, Response $response); } - diff --git a/lib/Github/HttpClient/Cache/FilesystemCache.php b/lib/Github/HttpClient/Cache/FilesystemCache.php index c700d31cb2e..ad1f90821cf 100644 --- a/lib/Github/HttpClient/Cache/FilesystemCache.php +++ b/lib/Github/HttpClient/Cache/FilesystemCache.php @@ -67,4 +67,3 @@ protected function getPath($id) return sprintf('%s%s%s', rtrim($this->path, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, md5($id)); } } - diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 7d13ca6a129..8e5bafcab16 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -3,8 +3,6 @@ namespace Github\HttpClient; use Buzz\Client\ClientInterface; -use Buzz\Message\MessageInterface; -use Buzz\Message\RequestInterface; use Buzz\Listener\ListenerInterface; use Github\Exception\ErrorException; diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php index f84472ee7d6..09ee8d11708 100644 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ b/lib/Github/HttpClient/HttpClientInterface.php @@ -14,55 +14,55 @@ interface HttpClientInterface /** * Send a GET request * - * @param string $path Request path - * @param array $parameters GET Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param array $parameters GET Parameters + * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return array Data */ public function get($path, array $parameters = array(), array $headers = array()); /** * Send a POST request * - * @param string $path Request path - * @param array $parameters POST Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param array $parameters POST Parameters + * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return array Data */ public function post($path, array $parameters = array(), array $headers = array()); /** * Send a PATCH request * - * @param string $path Request path - * @param array $parameters PATCH Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param array $parameters PATCH Parameters + * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return array Data */ public function patch($path, array $parameters = array(), array $headers = array()); /** * Send a PUT request * - * @param string $path Request path - * @param array $parameters PUT Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param array $parameters PUT Parameters + * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return array Data */ public function put($path, array $parameters = array(), array $headers = array()); /** * Send a DELETE request * - * @param string $path Request path - * @param array $parameters DELETE Parameters - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param array $parameters DELETE Parameters + * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return array Data */ public function delete($path, array $parameters = array(), array $headers = array()); @@ -70,20 +70,20 @@ public function delete($path, array $parameters = array(), array $headers = arra * Send a request to the server, receive a response, * decode the response and returns an associative array * - * @param string $path Request API path - * @param array $parameters Parameters - * @param string $httpMethod HTTP method to use - * @param array $headers Request headers + * @param string $path Request API path + * @param array $parameters Parameters + * @param string $httpMethod HTTP method to use + * @param array $headers Request headers * - * @return array Data + * @return array Data */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()); /** * Change an option value. * - * @param string $name The option name - * @param mixed $value The value + * @param string $name The option name + * @param mixed $value The value * * @throws InvalidArgumentException */ @@ -95,13 +95,13 @@ public function setOption($name, $value); * @param array $headers */ public function setHeaders(array $headers); - + /** * Authenticate a user for all next requests * - * @param string $tokenOrLogin GitHub private token/username/client ID - * @param null|string $password GitHub password/secret (optionally can contain $authMethod) - * @param null|string $authMethod One of the AUTH_* class constants + * @param string $tokenOrLogin GitHub private token/username/client ID + * @param null|string $password GitHub password/secret (optionally can contain $authMethod) + * @param null|string $authMethod One of the AUTH_* class constants * * @throws InvalidArgumentException If no authentication method was given */ diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 0ce7d11f595..83f2692a29a 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -3,9 +3,7 @@ namespace Github; use Github\Api\ApiInterface; -use Github\Exception\InvalidArgumentException; use Github\HttpClient\HttpClient; -use Github\HttpClient\HttpClientInterface; /** * Pager class for supporting pagination in github classes @@ -26,7 +24,6 @@ class ResultPager implements ResultPagerInterface */ protected $pagination; - /** * The Github client to use for pagination. This must be the same * instance that you got the Api instance from, i.e.: diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 6faab5efda2..7604fd0ecea 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -21,11 +21,11 @@ public function getPagination(); /** * Fetch a single result (page) from an api call * - * @param ApiInterface $api the Api instance - * @param string $method the method name to call on the Api instance - * @param array $parameters the method parameters in an array + * @param ApiInterface $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array * - * @return array returns the result of the Api::$method() call + * @return array returns the result of the Api::$method() call */ public function fetch(ApiInterface $api, $method, array $parameters = array()); @@ -33,11 +33,11 @@ public function fetch(ApiInterface $api, $method, array $parameters = array()); * Fetch all results (pages) from an api call * Use with care - there is no maximum * - * @param ApiInterface $api the Api instance - * @param string $method the method name to call on the Api instance - * @param array $parameters the method parameters in an array + * @param ApiInterface $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array * - * @return array returns a merge of the results of the Api::$method() call + * @return array returns a merge of the results of the Api::$method() call */ public function fetchAll(ApiInterface $api, $method, array $parameters = array()); diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 6e8cd9e1981..687dc3a35f7 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -53,7 +53,6 @@ public function shouldNotCreateWithoutBody() $api->create('KnpLabs', 'php-github-api', '123', $data); } - /** * @test */ diff --git a/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php b/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php index 07dece20576..a403c2feb23 100644 --- a/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php +++ b/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php @@ -3,4 +3,4 @@ return json_decode( '{"sha":"5639a4e6ede372d7ea25b1064be4e2045c2a053d","size":2648,"name":"ContentsTest.php","path":"test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","type":"file","url":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/contents\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","git_url":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/git\/blobs\/5639a4e6ede372d7ea25b1064be4e2045c2a053d","html_url":"https:\/\/github.com\/KnpLabs\/php-github-api\/blob\/master\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","_links":{"self":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/contents\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php","git":"https:\/\/api.github.com\/repos\/KnpLabs\/php-github-api\/git\/blobs\/5639a4e6ede372d7ea25b1064be4e2045c2a053d","html":"https:\/\/github.com\/KnpLabs\/php-github-api\/blob\/master\/test\/Github\/Tests\/Api\/Repository\/ContentsTest.php"},"content":"PD9waHAKCm5hbWVzcGFjZSBHaXRodWJcVGVzdHNcQXBpXFJlcG9zaXRvcnk7\nCgp1c2UgR2l0aHViXFRlc3RzXEFwaVxUZXN0Q2FzZTsKCmNsYXNzIENvbnRl\nbnRzVGVzdCBleHRlbmRzIFRlc3RDYXNlCnsKICAgIC8qKgogICAgICogQHRl\nc3QKICAgICAqLwogICAgcHVibGljIGZ1bmN0aW9uIHNob3VsZFNob3dDb250\nZW50Rm9yR2l2ZW5QYXRoKCkKICAgIHsKICAgICAgICAkZXhwZWN0ZWRWYWx1\nZSA9ICc8P3BocCAvLy4uJzsKCiAgICAgICAgJGFwaSA9ICR0aGlzLT5nZXRB\ncGlNb2NrKCk7CiAgICAgICAgJGFwaS0+ZXhwZWN0cygkdGhpcy0+b25jZSgp\nKQogICAgICAgICAgICAtPm1ldGhvZCgnZ2V0JykKICAgICAgICAgICAgLT53\naXRoKCdyZXBvcy9LbnBMYWJzL3BocC1naXRodWItYXBpL2NvbnRlbnRzL3Rl\nc3QlMkZHaXRodWIlMkZUZXN0cyUyRkFwaSUyRlJlcG9zaXRvcnklMkZDb250\nZW50c1Rlc3QucGhwJywgYXJyYXkoJ3JlZicgPT4gbnVsbCkpCiAgICAgICAg\nICAgIC0+d2lsbCgkdGhpcy0+cmV0dXJuVmFsdWUoJGV4cGVjdGVkVmFsdWUp\nKTsKCiAgICAgICAgJHRoaXMtPmFzc2VydEVxdWFscygkZXhwZWN0ZWRWYWx1\nZSwgJGFwaS0+c2hvdygnS25wTGFicycsICdwaHAtZ2l0aHViLWFwaScsICd0\nZXN0L0dpdGh1Yi9UZXN0cy9BcGkvUmVwb3NpdG9yeS9Db250ZW50c1Rlc3Qu\ncGhwJykpOwogICAgfQoKICAgIC8qKgogICAgICogQHRlc3QKICAgICAqLwog\nICAgcHVibGljIGZ1bmN0aW9uIHNob3VsZFNob3dSZWFkbWUoKQogICAgewog\nICAgICAgICRleHBlY3RlZFZhbHVlID0gJ1JFQURNRS4uLic7CgogICAgICAg\nICRhcGkgPSAkdGhpcy0+Z2V0QXBpTW9jaygpOwogICAgICAgICRhcGktPmV4\ncGVjdHMoJHRoaXMtPm9uY2UoKSkKICAgICAgICAgICAgLT5tZXRob2QoJ2dl\ndCcpCiAgICAgICAgICAgIC0+d2l0aCgncmVwb3MvS25wTGFicy9waHAtZ2l0\naHViLWFwaS9yZWFkbWUnLCBhcnJheSgncmVmJyA9PiBudWxsKSkKICAgICAg\nICAgICAgLT53aWxsKCR0aGlzLT5yZXR1cm5WYWx1ZSgkZXhwZWN0ZWRWYWx1\nZSkpOwoKICAgICAgICAkdGhpcy0+YXNzZXJ0RXF1YWxzKCRleHBlY3RlZFZh\nbHVlLCAkYXBpLT5yZWFkbWUoJ0tucExhYnMnLCAncGhwLWdpdGh1Yi1hcGkn\nKSk7CiAgICB9CgogICAgLyoqCiAgICAgKiBAdGVzdAogICAgICovCiAgICBw\ndWJsaWMgZnVuY3Rpb24gc2hvdWxkRmV0Y2hUYXJiYWxsQXJjaGl2ZVdoZW5G\nb3JtYXROb3RSZWNvZ25pemVkKCkKICAgIHsKICAgICAgICAkZXhwZWN0ZWRW\nYWx1ZSA9ICd0YXInOwoKICAgICAgICAkYXBpID0gJHRoaXMtPmdldEFwaU1v\nY2soKTsKICAgICAgICAkYXBpLT5leHBlY3RzKCR0aGlzLT5vbmNlKCkpCiAg\nICAgICAgICAgIC0+bWV0aG9kKCdnZXQnKQogICAgICAgICAgICAtPndpdGgo\nJ3JlcG9zL0tucExhYnMvcGhwLWdpdGh1Yi1hcGkvdGFyYmFsbCcsIGFycmF5\nKCdyZWYnID0+IG51bGwpKQogICAgICAgICAgICAtPndpbGwoJHRoaXMtPnJl\ndHVyblZhbHVlKCRleHBlY3RlZFZhbHVlKSk7CgogICAgICAgICR0aGlzLT5h\nc3NlcnRFcXVhbHMoJGV4cGVjdGVkVmFsdWUsICRhcGktPmFyY2hpdmUoJ0tu\ncExhYnMnLCAncGhwLWdpdGh1Yi1hcGknLCAnc29tZUZvcm1hdCcpKTsKICAg\nIH0KCiAgICAvKioKICAgICAqIEB0ZXN0CiAgICAgKi8KICAgIHB1YmxpYyBm\ndW5jdGlvbiBzaG91bGRGZXRjaFRhcmJhbGxBcmNoaXZlKCkKICAgIHsKICAg\nICAgICAkZXhwZWN0ZWRWYWx1ZSA9ICd0YXInOwoKICAgICAgICAkYXBpID0g\nJHRoaXMtPmdldEFwaU1vY2soKTsKICAgICAgICAkYXBpLT5leHBlY3RzKCR0\naGlzLT5vbmNlKCkpCiAgICAgICAgICAgIC0+bWV0aG9kKCdnZXQnKQogICAg\nICAgICAgICAtPndpdGgoJ3JlcG9zL0tucExhYnMvcGhwLWdpdGh1Yi1hcGkv\ndGFyYmFsbCcsIGFycmF5KCdyZWYnID0+IG51bGwpKQogICAgICAgICAgICAt\nPndpbGwoJHRoaXMtPnJldHVyblZhbHVlKCRleHBlY3RlZFZhbHVlKSk7Cgog\nICAgICAgICR0aGlzLT5hc3NlcnRFcXVhbHMoJGV4cGVjdGVkVmFsdWUsICRh\ncGktPmFyY2hpdmUoJ0tucExhYnMnLCAncGhwLWdpdGh1Yi1hcGknLCAndGFy\nYmFsbCcpKTsKICAgIH0KCiAgICAvKioKICAgICAqIEB0ZXN0CiAgICAgKi8K\nICAgIHB1YmxpYyBmdW5jdGlvbiBzaG91bGRGZXRjaFppcGJhbGxBcmNoaXZl\nKCkKICAgIHsKICAgICAgICAkZXhwZWN0ZWRWYWx1ZSA9ICd6aXAnOwoKICAg\nICAgICAkYXBpID0gJHRoaXMtPmdldEFwaU1vY2soKTsKICAgICAgICAkYXBp\nLT5leHBlY3RzKCR0aGlzLT5vbmNlKCkpCiAgICAgICAgICAgIC0+bWV0aG9k\nKCdnZXQnKQogICAgICAgICAgICAtPndpdGgoJ3JlcG9zL0tucExhYnMvcGhw\nLWdpdGh1Yi1hcGkvemlwYmFsbCcsIGFycmF5KCdyZWYnID0+IG51bGwpKQog\nICAgICAgICAgICAtPndpbGwoJHRoaXMtPnJldHVyblZhbHVlKCRleHBlY3Rl\nZFZhbHVlKSk7CgogICAgICAgICR0aGlzLT5hc3NlcnRFcXVhbHMoJGV4cGVj\ndGVkVmFsdWUsICRhcGktPmFyY2hpdmUoJ0tucExhYnMnLCAncGhwLWdpdGh1\nYi1hcGknLCAnemlwYmFsbCcpKTsKICAgIH0KCiAgICBwcm90ZWN0ZWQgZnVu\nY3Rpb24gZ2V0QXBpQ2xhc3MoKQogICAgewogICAgICAgIHJldHVybiAnR2l0\naHViXEFwaVxSZXBvc2l0b3J5XENvbnRlbnRzJzsKICAgIH0KfQo=\n","encoding":"base64"}', true -); \ No newline at end of file +); diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 3b15118cf34..e3191af4da2 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -85,7 +85,7 @@ public function shouldFetchZipballArchive() $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball')); } - + /** * @test */ @@ -93,10 +93,10 @@ public function shouldDownloadForGivenPath() { // The show() method return $getValue = include 'ContentsDownloadFixture.php'; - + // The download() method return $expectedValue = base64_decode($getValue['content']); - + $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index 77fbbc2f662..a235bad8f0b 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -101,7 +101,6 @@ public function shouldCreateDeployKey() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** * @test * @expectedException Github\Exception\MissingArgumentException diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index 444d5cc633e..6744d8c9158 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -101,7 +101,6 @@ public function shouldCreateHook() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** * @test * @expectedException Github\Exception\MissingArgumentException diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index 75e5676a2da..6526ec4b3bb 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -101,7 +101,6 @@ public function shouldCreateLabel() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** * @test * @expectedException Github\Exception\MissingArgumentException diff --git a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php index f3655705d15..841f38f690b 100644 --- a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php +++ b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php @@ -41,4 +41,3 @@ public function shouldNotGetATimestampForInexistingFile() $this->assertNull($cache->getModifiedSince('test2')); } } - diff --git a/test/Github/Tests/Mock/TestResponse.php b/test/Github/Tests/Mock/TestResponse.php index 0c8f04b320e..3cac1212d70 100644 --- a/test/Github/Tests/Mock/TestResponse.php +++ b/test/Github/Tests/Mock/TestResponse.php @@ -27,7 +27,7 @@ public function getContent() */ public function getPagination() { - if($this->loopCount){ + if ($this->loopCount) { $returnArray = array( 'next' => 'http://github.com/' . $this->loopCount ); diff --git a/test/bootstrap.php b/test/bootstrap.php index 69436c1fb1d..416d08990eb 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,6 +1,7 @@ Date: Sun, 1 Sep 2013 23:20:08 +0300 Subject: [PATCH 057/951] Fix tests --- test/Github/Tests/Api/PullRequestTest.php | 6 ++--- test/Github/Tests/Api/RepoTest.php | 33 ++++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 99449ec16d3..ac38dc4513d 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -106,15 +106,15 @@ public function shouldShowFilesFromPullRequest() */ public function shouldUpdatePullRequests() { - $expectedArray = array('id' => 'id', 'sha' => '123123'); + $expectedArray = array('id' => 15, 'sha' => '123123'); $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'some' => 'param')) + ->with('repos/ezsystems/ezpublish/pulls/15', array('state' => 'open', 'some' => 'param')) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', array('state' => 'aa', 'some' => 'param'))); + $this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', 15, array('state' => 'aa', 'some' => 'param'))); } /** diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 2f74d5e27b2..44b1a25f2d5 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -68,7 +68,16 @@ public function shouldCreateRepositoryUsingNameOnly() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/repos', array('name' => 'l3l0Repo', 'description' => '', 'homepage' => '', 'private' => false)) + ->with('user/repos', array( + 'name' => 'l3l0Repo', + 'description' => '', + 'homepage' => '', + 'private' => false, + 'has_issues' => false, + 'has_wiki' => false, + 'has_downloads' => false, + 'auto_init' => false + )) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('l3l0Repo')); @@ -84,7 +93,16 @@ public function shouldCreateRepositoryForOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/repos', array('name' => 'KnpLabsRepo', 'description' => '', 'homepage' => '', 'private' => false)) + ->with('orgs/KnpLabs/repos', array( + 'name' => 'KnpLabsRepo', + 'description' => '', + 'homepage' => '', + 'private' => false, + 'has_issues' => false, + 'has_wiki' => false, + 'has_downloads' => false, + 'auto_init' => false + )) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('KnpLabsRepo', '', '', true, 'KnpLabs')); @@ -228,7 +246,16 @@ public function shouldCreateUsingAllParams() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/repos', array('name' => 'l3l0Repo', 'description' => 'test', 'homepage' => 'http://l3l0.eu', 'private' => true)) + ->with('user/repos', array( + 'name' => 'l3l0Repo', + 'description' => 'test', + 'homepage' => 'http://l3l0.eu', + 'private' => true, + 'has_issues' => false, + 'has_wiki' => false, + 'has_downloads' => false, + 'auto_init' => false + )) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('l3l0Repo', 'test', 'http://l3l0.eu', false)); From d68723acf68d8ea249f739449b35ada68f04eaba Mon Sep 17 00:00:00 2001 From: Alex Demchenko Date: Fri, 13 Sep 2013 17:48:43 +0300 Subject: [PATCH 058/951] Update CS --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 67bbf8c0fac..3538f102589 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -169,7 +169,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); if (count($parameters) > 0) { - $request->setContent(json_encode($parameters, empty($parameters)? JSON_FORCE_OBJECT : 0)); + $request->setContent(json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0)); } $hasListeners = 0 < count($this->listeners); From 19d794c9d1ff793cc694a7057d4447f35cb6da61 Mon Sep 17 00:00:00 2001 From: AD7six Date: Tue, 24 Sep 2013 09:16:36 +0000 Subject: [PATCH 059/951] make it possible to list all labels and create them Allow the following syntax to work, from doc/issue/labels.md ```php $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api'); ``` Also add an interface for creating labels. --- lib/Github/Api/Issue/Labels.php | 18 +++++++- test/Github/Tests/Api/Issue/LabelsTest.php | 54 ++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 55e68273d3a..ccb81b768cb 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -11,11 +11,27 @@ */ class Labels extends AbstractApi { - public function all($username, $repository, $issue) + public function all($username, $repository, $issue = null) { + if ($issue === null) { + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/labels'); + } + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/labels'); } + public function create($username, $repository, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException('name'); + } + if (!isset($params['color'])) { + $params['color'] = 'FFFFFF'; + } + + return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/labels', $params); + } + public function add($username, $repository, $issue, $labels) { if (is_string($labels)) { diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index 484f9be2a80..1bfa73c69ca 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -6,6 +6,26 @@ class LabelsTest extends TestCase { + + /** + * @test + */ + public function shouldGetProjectLabels() + { + $expectedValue = array( + array('name' => 'l3l0repo'), + array('name' => 'other'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/labels', array()) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + /** * @test */ @@ -22,6 +42,40 @@ public function shouldGetAllIssueLabels() $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', '123')); } + /** + * @test + */ + public function shouldCreateLabel() + { + $expectedValue = array(array('name' => 'label', 'color' => 'FFFFFF')); + $data = array('name' => 'label'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('repos/KnpLabs/php-github-api/labels', $data + array('color' => 'FFFFFF')) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + */ + public function shouldCreateLabelWithColor() + { + $expectedValue = array(array('name' => 'label', 'color' => '111111')); + $data = array('name' => 'label', 'color' => '111111'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('repos/KnpLabs/php-github-api/labels', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + /** * @test */ From 05a33190f57f8618b45d03fd3947389b29486e43 Mon Sep 17 00:00:00 2001 From: AD7six Date: Wed, 25 Sep 2013 09:20:11 +0000 Subject: [PATCH 060/951] provide a better missing error message When github say's missing, it's not talking about the resource - it means something referenced in the data. For example, specifying a milestone that doesn't exist will return: ``` { "message": "Validation Failed" "documentation_url": "http"://developer.github.com/v3" "errors": [ { "value": 42, "resource": "Issue", "field": "milestone", "code": "missing" } ] } ``` Previously this would be reported as: > Validation Failed: Resource "Issue" not exists anymore Now it's reported as > The milestone 42 doesa not exist, for resource "Issue" --- lib/Github/HttpClient/Listener/ErrorListener.php | 2 +- test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 3f20c05093b..3f2963fc995 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -57,7 +57,7 @@ public function postSend(RequestInterface $request, MessageInterface $response) foreach ($content['errors'] as $error) { switch ($error['code']) { case 'missing': - $errors[] = sprintf('Resource "%s" not exists anymore', $error['resource']); + $errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']); break; case 'missing_field': diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index fb05761e891..3a539343370 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -124,6 +124,7 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) array( 'code' => $errorCode, 'field' => 'test', + 'value' => 'wrong', 'resource' => 'fake' ) ) From 9234e8e8f5aa9fe6216ee381854da4fd6ac6bc1a Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Wed, 16 Oct 2013 12:09:12 +0300 Subject: [PATCH 061/951] Red test --- .../Tests/Api/Repository/ContentsTest.php | 22 ++++++++++++++++++- .../ContentsDownloadFixture.php | 0 .../ContentsDownloadSpacedFixture.php | 6 +++++ 3 files changed, 27 insertions(+), 1 deletion(-) rename test/Github/Tests/Api/Repository/{ => fixtures}/ContentsDownloadFixture.php (100%) create mode 100644 test/Github/Tests/Api/Repository/fixtures/ContentsDownloadSpacedFixture.php diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index e3191af4da2..56a7e1088b0 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -92,7 +92,7 @@ public function shouldFetchZipballArchive() public function shouldDownloadForGivenPath() { // The show() method return - $getValue = include 'ContentsDownloadFixture.php'; + $getValue = include __DIR__.'/fixtures/ContentsDownloadFixture.php'; // The download() method return $expectedValue = base64_decode($getValue['content']); @@ -106,6 +106,26 @@ public function shouldDownloadForGivenPath() $this->assertEquals($expectedValue, $api->download('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); } + /** + * @test + */ + public function shouldDownloadForSpacedPath() + { + // The show() method return + $getValue = include __DIR__.'/fixtures/ContentsDownloadSpacedFixture.php'; + + // The download() method return + $expectedValue = base64_decode($getValue['content']); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/mads379/scala.tmbundle/contents/Syntaxes/Simple%20Build%20Tool.tmLanguage', array('ref' => null)) + ->will($this->returnValue($getValue)); + + $this->assertEquals($expectedValue, $api->download('mads379', 'scala.tmbundle', 'Syntaxes/Simple Build Tool.tmLanguage')); + } + protected function getApiClass() { return 'Github\Api\Repository\Contents'; diff --git a/test/Github/Tests/Api/Repository/ContentsDownloadFixture.php b/test/Github/Tests/Api/Repository/fixtures/ContentsDownloadFixture.php similarity index 100% rename from test/Github/Tests/Api/Repository/ContentsDownloadFixture.php rename to test/Github/Tests/Api/Repository/fixtures/ContentsDownloadFixture.php diff --git a/test/Github/Tests/Api/Repository/fixtures/ContentsDownloadSpacedFixture.php b/test/Github/Tests/Api/Repository/fixtures/ContentsDownloadSpacedFixture.php new file mode 100644 index 00000000000..5178659574f --- /dev/null +++ b/test/Github/Tests/Api/Repository/fixtures/ContentsDownloadSpacedFixture.php @@ -0,0 +1,6 @@ + Date: Wed, 16 Oct 2013 12:14:33 +0300 Subject: [PATCH 062/951] Green test --- lib/Github/Api/Repository/Contents.php | 2 +- test/Github/Tests/Api/Repository/ContentsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 6a79377654f..25c9a5247ab 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -44,7 +44,7 @@ public function show($username, $repository, $path = null, $reference = null) { $url = 'repos/'.urlencode($username).'/'.urlencode($repository).'/contents'; if (null !== $path) { - $url .= '/'.urlencode($path); + $url .= '/'.rawurlencode($path); } return $this->get($url, array( diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 56a7e1088b0..0eb91a4cd15 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -120,7 +120,7 @@ public function shouldDownloadForSpacedPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/mads379/scala.tmbundle/contents/Syntaxes/Simple%20Build%20Tool.tmLanguage', array('ref' => null)) + ->with('repos/mads379/scala.tmbundle/contents/Syntaxes%2FSimple%20Build%20Tool.tmLanguage', array('ref' => null)) ->will($this->returnValue($getValue)); $this->assertEquals($expectedValue, $api->download('mads379', 'scala.tmbundle', 'Syntaxes/Simple Build Tool.tmLanguage')); From 9f53cedf8589fec9adb0b92eef38002b842359ee Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Wed, 16 Oct 2013 12:19:37 +0300 Subject: [PATCH 063/951] Replace other urlencode with rawurlencode --- lib/Github/Api/Authorizations.php | 8 +++--- lib/Github/Api/CurrentUser/DeployKeys.php | 6 ++--- lib/Github/Api/CurrentUser/Followers.php | 6 ++--- lib/Github/Api/CurrentUser/Notifications.php | 14 +++++------ lib/Github/Api/CurrentUser/Watchers.php | 6 ++--- lib/Github/Api/Gists.php | 16 ++++++------ lib/Github/Api/GitData/Blobs.php | 4 +-- lib/Github/Api/GitData/Commits.php | 4 +-- lib/Github/Api/GitData/References.php | 14 +++++------ lib/Github/Api/GitData/Tags.php | 6 ++--- lib/Github/Api/GitData/Trees.php | 4 +-- lib/Github/Api/Issue.php | 12 ++++----- lib/Github/Api/Issue/Comments.php | 10 ++++---- lib/Github/Api/Issue/Events.php | 6 ++--- lib/Github/Api/Issue/Labels.php | 14 +++++------ lib/Github/Api/Issue/Milestones.php | 12 ++++----- lib/Github/Api/Organization.php | 6 ++--- lib/Github/Api/Organization/Members.php | 14 +++++------ lib/Github/Api/Organization/Teams.php | 26 ++++++++++---------- lib/Github/Api/PullRequest.php | 16 ++++++------ lib/Github/Api/PullRequest/Comments.php | 10 ++++---- lib/Github/Api/Repo.php | 24 +++++++++--------- lib/Github/Api/Repository/Collaborators.php | 8 +++--- lib/Github/Api/Repository/Comments.php | 12 ++++----- lib/Github/Api/Repository/Commits.php | 6 ++--- lib/Github/Api/Repository/Contents.php | 6 ++--- lib/Github/Api/Repository/DeployKeys.php | 10 ++++---- lib/Github/Api/Repository/Downloads.php | 6 ++--- lib/Github/Api/Repository/Forks.php | 4 +-- lib/Github/Api/Repository/Hooks.php | 12 ++++----- lib/Github/Api/Repository/Labels.php | 10 ++++---- lib/Github/Api/Repository/Statuses.php | 4 +-- lib/Github/Api/User.php | 18 +++++++------- test/Github/Tests/Api/IssueTest.php | 6 ++--- 34 files changed, 170 insertions(+), 170 deletions(-) diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index 6d45c23f14d..0066a1f0f3f 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -18,7 +18,7 @@ public function all() public function show($number) { - return $this->get('authorizations/'.urlencode($number)); + return $this->get('authorizations/'.rawurlencode($number)); } public function create(array $params) @@ -28,16 +28,16 @@ public function create(array $params) public function update($id, array $params) { - return $this->patch('authorizations/'.urlencode($id), $params); + return $this->patch('authorizations/'.rawurlencode($id), $params); } public function remove($id) { - return $this->delete('authorizations/'.urlencode($id)); + return $this->delete('authorizations/'.rawurlencode($id)); } public function check($id, $token) { - return $this->get('authorizations/'.urlencode($id).'/tokens/'.urlencode($token)); + return $this->get('authorizations/'.rawurlencode($id).'/tokens/'.rawurlencode($token)); } } diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/DeployKeys.php index 75f64e8e9f4..87a0eaed843 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/DeployKeys.php @@ -31,7 +31,7 @@ public function all() */ public function show($id) { - return $this->get('user/keys/'.urlencode($id)); + return $this->get('user/keys/'.rawurlencode($id)); } /** @@ -68,7 +68,7 @@ public function update($id, array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->patch('user/keys/'.urlencode($id), $params); + return $this->patch('user/keys/'.rawurlencode($id), $params); } /** @@ -80,6 +80,6 @@ public function update($id, array $params) */ public function remove($id) { - return $this->delete('user/keys/'.urlencode($id)); + return $this->delete('user/keys/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/CurrentUser/Followers.php b/lib/Github/Api/CurrentUser/Followers.php index 022df3374f8..ea356d85e32 100644 --- a/lib/Github/Api/CurrentUser/Followers.php +++ b/lib/Github/Api/CurrentUser/Followers.php @@ -33,7 +33,7 @@ public function all($page = 1) */ public function check($username) { - return $this->get('user/following/'.urlencode($username)); + return $this->get('user/following/'.rawurlencode($username)); } /** @@ -45,7 +45,7 @@ public function check($username) */ public function follow($username) { - return $this->put('user/following/'.urlencode($username)); + return $this->put('user/following/'.rawurlencode($username)); } /** @@ -57,6 +57,6 @@ public function follow($username) */ public function unfollow($username) { - return $this->delete('user/following/'.urlencode($username)); + return $this->delete('user/following/'.rawurlencode($username)); } } diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index 40d37a50bf8..a35519df783 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -33,7 +33,7 @@ public function all(array $params = array()) */ public function allInRepository($username, $repository, array $params = array()) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/notifications', $params); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); } /** @@ -57,7 +57,7 @@ public function markAsReadAll(array $params = array()) */ public function markAsReadInRepository($username, $repository, array $params = array()) { - return $this->put('repos/'.urlencode($username).'/'.urlencode($repository).'/notifications', $params); + return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); } /** @@ -69,7 +69,7 @@ public function markAsReadInRepository($username, $repository, array $params = a */ public function markAsRead($id, array $params) { - return $this->patch('notifications/threads/'.urlencode($id), $params); + return $this->patch('notifications/threads/'.rawurlencode($id), $params); } /** @@ -80,7 +80,7 @@ public function markAsRead($id, array $params) */ public function show($id) { - return $this->get('notifications/threads/'.urlencode($id)); + return $this->get('notifications/threads/'.rawurlencode($id)); } /** @@ -91,7 +91,7 @@ public function show($id) */ public function showSubscription($id) { - return $this->get('notifications/threads/'.urlencode($id).'/subscription'); + return $this->get('notifications/threads/'.rawurlencode($id).'/subscription'); } /** @@ -103,7 +103,7 @@ public function showSubscription($id) */ public function createSubscription($id, array $params) { - return $this->put('notifications/threads/'.urlencode($id).'/subscription', $params); + return $this->put('notifications/threads/'.rawurlencode($id).'/subscription', $params); } /** @@ -114,6 +114,6 @@ public function createSubscription($id, array $params) */ public function removeSubscription($id) { - return $this->delete('notifications/threads/'.urlencode($id).'/subscription'); + return $this->delete('notifications/threads/'.rawurlencode($id).'/subscription'); } } diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 7a752c0b90d..398ac58536a 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -34,7 +34,7 @@ public function all($page = 1) */ public function check($username, $repository) { - return $this->get('user/watched/'.urlencode($username).'/'.urlencode($repository)); + return $this->get('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -47,7 +47,7 @@ public function check($username, $repository) */ public function watch($username, $repository) { - return $this->put('user/watched/'.urlencode($username).'/'.urlencode($repository)); + return $this->put('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -60,6 +60,6 @@ public function watch($username, $repository) */ public function unwatch($username, $repository) { - return $this->delete('user/watched/'.urlencode($username).'/'.urlencode($repository)); + return $this->delete('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); } } diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index b0a59960094..7514d99e6ff 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -20,12 +20,12 @@ public function all($type = null) return $this->get('gists'); } - return $this->get('gists/'.urlencode($type)); + return $this->get('gists/'.rawurlencode($type)); } public function show($number) { - return $this->get('gists/'.urlencode($number)); + return $this->get('gists/'.rawurlencode($number)); } public function create(array $params) @@ -41,31 +41,31 @@ public function create(array $params) public function update($id, array $params) { - return $this->patch('gists/'.urlencode($id), $params); + return $this->patch('gists/'.rawurlencode($id), $params); } public function fork($id) { - return $this->post('gists/'.urlencode($id).'/fork'); + return $this->post('gists/'.rawurlencode($id).'/fork'); } public function remove($id) { - return $this->delete('gists/'.urlencode($id)); + return $this->delete('gists/'.rawurlencode($id)); } public function check($id) { - return $this->get('gists/'.urlencode($id).'/star'); + return $this->get('gists/'.rawurlencode($id).'/star'); } public function star($id) { - return $this->put('gists/'.urlencode($id).'/star'); + return $this->put('gists/'.rawurlencode($id).'/star'); } public function unstar($id) { - return $this->delete('gists/'.urlencode($id).'/star'); + return $this->delete('gists/'.rawurlencode($id).'/star'); } } diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index ee1c3df5137..ce2407b472d 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -22,7 +22,7 @@ public function configure($bodyType = null) public function show($username, $repository, $sha) { - $response = $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/blobs/'.urlencode($sha)); + $response = $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha)); return $response; } @@ -33,6 +33,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('content', 'encoding')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/git/blobs', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs', $params); } } diff --git a/lib/Github/Api/GitData/Commits.php b/lib/Github/Api/GitData/Commits.php index 8aaefe3ddf4..ab6a07ecff5 100644 --- a/lib/Github/Api/GitData/Commits.php +++ b/lib/Github/Api/GitData/Commits.php @@ -13,7 +13,7 @@ class Commits extends AbstractApi { public function show($username, $repository, $sha) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/commits/'.urlencode($sha)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha)); } public function create($username, $repository, array $params) @@ -22,6 +22,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('message', 'tree', 'parents')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/git/commits', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits', $params); } } diff --git a/lib/Github/Api/GitData/References.php b/lib/Github/Api/GitData/References.php index 89886084660..70d8fa37afa 100644 --- a/lib/Github/Api/GitData/References.php +++ b/lib/Github/Api/GitData/References.php @@ -13,22 +13,22 @@ class References extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs'); } public function branches($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs/heads'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads'); } public function tags($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs/tags'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } public function show($username, $repository, $reference) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs/'.urlencode($reference)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference)); } public function create($username, $repository, array $params) @@ -37,7 +37,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('ref', 'sha')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params); } public function update($username, $repository, $reference, array $params) @@ -46,11 +46,11 @@ public function update($username, $repository, $reference, array $params) throw new MissingArgumentException('sha'); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs/'.urlencode($reference), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference), $params); } public function remove($username, $repository, $reference) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs/'.urlencode($reference)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference)); } } diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index 376a6d6ee4f..b27dddd12f4 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -13,12 +13,12 @@ class Tags extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/refs/tags'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } public function show($username, $repository, $sha) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/tags/'.urlencode($sha)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags/'.rawurlencode($sha)); } public function create($username, $repository, array $params) @@ -35,6 +35,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('tagger.name', 'tagger.email', 'tagger.date')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/git/tags', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags', $params); } } diff --git a/lib/Github/Api/GitData/Trees.php b/lib/Github/Api/GitData/Trees.php index daf487cc1d6..92bd21ac433 100644 --- a/lib/Github/Api/GitData/Trees.php +++ b/lib/Github/Api/GitData/Trees.php @@ -13,7 +13,7 @@ class Trees extends AbstractApi { public function show($username, $repository, $sha, $recursive = false) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/git/trees/'.urlencode($sha), array('recursive' => $recursive ? 1 : null)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), array('recursive' => $recursive ? 1 : null)); } public function create($username, $repository, array $params) @@ -37,6 +37,6 @@ public function create($username, $repository, array $params) } } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/git/trees', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees', $params); } } diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 918eb478138..c4aae96e994 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -28,7 +28,7 @@ class Issue extends AbstractApi */ public function all($username, $repository, array $params = array()) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues', array_merge(array('page' => 1), $params)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(array('page' => 1), $params)); } /** @@ -48,7 +48,7 @@ public function find($username, $repository, $state, $keyword) $state = 'open'; } - return $this->get('legacy/issues/search/'.urlencode($username).'/'.urlencode($repository).'/'.urlencode($state).'/'.urlencode($keyword)); + return $this->get('legacy/issues/search/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($state).'/'.rawurlencode($keyword)); } /** @@ -66,7 +66,7 @@ public function org($organization, $state, array $params = array()) $state = 'open'; } - return $this->get('orgs/'.urlencode($organization).'/issues', array_merge(array('page' => 1, 'state' => $state), $params)); + return $this->get('orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => 1, 'state' => $state), $params)); } /** @@ -80,7 +80,7 @@ public function org($organization, $state, array $params = array()) */ public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id)); } /** @@ -101,7 +101,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('title', 'body')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/issues', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', $params); } /** @@ -117,7 +117,7 @@ public function create($username, $repository, array $params) */ public function update($username, $repository, $id, array $params) { - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($id), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params); } /** diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index f8fceb8d57e..ae6370fc660 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -35,14 +35,14 @@ public function configure($bodyType = null) public function all($username, $repository, $issue, $page = 1) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/comments', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array( 'page' => $page )); } public function show($username, $repository, $comment) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/comments/'.urlencode($comment)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); } public function create($username, $repository, $issue, array $params) @@ -51,7 +51,7 @@ public function create($username, $repository, $issue, array $params) throw new MissingArgumentException('body'); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/comments', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params); } public function update($username, $repository, $comment, array $params) @@ -60,11 +60,11 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/comments/'.urlencode($comment), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params); } public function remove($username, $repository, $comment) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/comments/'.urlencode($comment)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 726185466bb..17bcef83921 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -13,18 +13,18 @@ class Events extends AbstractApi public function all($username, $repository, $issue = null, $page = 1) { if (null !== $issue) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/events', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events', array( 'page' => $page )); } - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/events', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events', array( 'page' => $page )); } public function show($username, $repository, $event) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/events/'.urlencode($event)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event)); } } diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index ccb81b768cb..5628201f50c 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -14,10 +14,10 @@ class Labels extends AbstractApi public function all($username, $repository, $issue = null) { if ($issue === null) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/labels'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'); } - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/labels'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); } public function create($username, $repository, array $params) @@ -29,7 +29,7 @@ public function create($username, $repository, array $params) $params['color'] = 'FFFFFF'; } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/labels', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } public function add($username, $repository, $issue, $labels) @@ -40,21 +40,21 @@ public function add($username, $repository, $issue, $labels) throw new InvalidArgumentException(); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/labels', $labels); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels); } public function replace($username, $repository, $issue, array $params) { - return $this->put('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/labels', $params); + return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params); } public function remove($username, $repository, $issue, $label) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/labels/'.urlencode($label)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label)); } public function clear($username, $repository, $issue) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/issues/'.urlencode($issue).'/labels'); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); } } diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index e19cbc0d391..c13c4aebb2b 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -23,12 +23,12 @@ public function all($username, $repository, array $params = array()) $params['direction'] = 'desc'; } - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/milestones', array_merge(array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc'), $params)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc'), $params)); } public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/milestones/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } public function create($username, $repository, array $params) @@ -40,7 +40,7 @@ public function create($username, $repository, array $params) $params['state'] = 'open'; } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/milestones', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); } public function update($username, $repository, $milestone, array $params) @@ -49,16 +49,16 @@ public function update($username, $repository, $milestone, array $params) $params['state'] = 'open'; } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/milestones/'.urlencode($milestone), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($milestone), $params); } public function remove($username, $repository, $milestone) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/milestones/'.urlencode($milestone)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($milestone)); } public function labels($username, $repository, $milestone) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/milestones/'.urlencode($milestone).'/labels'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($milestone).'/labels'); } } diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 0a1af06b8d4..da46badcfcd 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -24,12 +24,12 @@ class Organization extends AbstractApi */ public function show($organization) { - return $this->get('orgs/'.urlencode($organization)); + return $this->get('orgs/'.rawurlencode($organization)); } public function update($organization, array $params) { - return $this->patch('orgs/'.urlencode($organization), $params); + return $this->patch('orgs/'.rawurlencode($organization), $params); } /** @@ -43,7 +43,7 @@ public function update($organization, array $params) */ public function repositories($organization, $type = 'all') { - return $this->get('orgs/'.urlencode($organization).'/repos', array( + return $this->get('orgs/'.rawurlencode($organization).'/repos', array( 'type' => $type )); } diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 7aa9e29bf1b..691f11c335c 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -13,34 +13,34 @@ class Members extends AbstractApi public function all($organization, $type = null) { if (null === $type) { - return $this->get('orgs/'.urlencode($organization).'/members'); + return $this->get('orgs/'.rawurlencode($organization).'/members'); } - return $this->get('orgs/'.urlencode($organization).'/public_members'); + return $this->get('orgs/'.rawurlencode($organization).'/public_members'); } public function show($organization, $username) { - return $this->get('orgs/'.urlencode($organization).'/members/'.urlencode($username)); + return $this->get('orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); } public function check($organization, $username) { - return $this->get('orgs/'.urlencode($organization).'/public_members/'.urlencode($username)); + return $this->get('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } public function publicize($organization, $username) { - return $this->put('orgs/'.urlencode($organization).'/public_members/'.urlencode($username)); + return $this->put('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } public function conceal($organization, $username) { - return $this->delete('orgs/'.urlencode($organization).'/public_members/'.urlencode($username)); + return $this->delete('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } public function remove($organization, $username) { - return $this->delete('orgs/'.urlencode($organization).'/members/'.urlencode($username)); + return $this->delete('orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); } } diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 3f231c13eaa..5cdf876db74 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -13,7 +13,7 @@ class Teams extends AbstractApi { public function all($organization) { - return $this->get('orgs/'.urlencode($organization).'/teams'); + return $this->get('orgs/'.rawurlencode($organization).'/teams'); } public function create($organization, array $params) @@ -28,12 +28,12 @@ public function create($organization, array $params) $params['permission'] = 'pull'; } - return $this->post('orgs/'.urlencode($organization).'/teams', $params); + return $this->post('orgs/'.rawurlencode($organization).'/teams', $params); } public function show($team) { - return $this->get('teams/'.urlencode($team)); + return $this->get('teams/'.rawurlencode($team)); } public function update($team, array $params) @@ -45,51 +45,51 @@ public function update($team, array $params) $params['permission'] = 'pull'; } - return $this->patch('teams/'.urlencode($team), $params); + return $this->patch('teams/'.rawurlencode($team), $params); } public function remove($team) { - return $this->delete('teams/'.urlencode($team)); + return $this->delete('teams/'.rawurlencode($team)); } public function members($team) { - return $this->get('teams/'.urlencode($team).'/members'); + return $this->get('teams/'.rawurlencode($team).'/members'); } public function check($team, $username) { - return $this->get('teams/'.urlencode($team).'/members/'.urlencode($username)); + return $this->get('teams/'.rawurlencode($team).'/members/'.rawurlencode($username)); } public function addMember($team, $username) { - return $this->put('teams/'.urlencode($team).'/members/'.urlencode($username)); + return $this->put('teams/'.rawurlencode($team).'/members/'.rawurlencode($username)); } public function removeMember($team, $username) { - return $this->delete('teams/'.urlencode($team).'/members/'.urlencode($username)); + return $this->delete('teams/'.rawurlencode($team).'/members/'.rawurlencode($username)); } public function repositories($team) { - return $this->get('teams/'.urlencode($team).'/repos'); + return $this->get('teams/'.rawurlencode($team).'/repos'); } public function repository($team, $username, $repository) { - return $this->get('teams/'.urlencode($team).'/repos/'.urlencode($username).'/'.urlencode($repository)); + return $this->get('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } public function addRepository($team, $username, $repository) { - return $this->put('teams/'.urlencode($team).'/repos/'.urlencode($username).'/'.urlencode($repository)); + return $this->put('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } public function removeRepository($team, $username, $repository) { - return $this->delete('teams/'.urlencode($team).'/repos/'.urlencode($username).'/'.urlencode($repository)); + return $this->delete('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } } diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 4f2170fe09d..e52815cf01a 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -34,7 +34,7 @@ public function all($username, $repository, $state = null, $page = 1, $perPage = 'state' => $state, ); - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $parameters); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } /** @@ -49,17 +49,17 @@ public function all($username, $repository, $state = null, $page = 1, $perPage = */ public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id)); } public function commits($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id).'/commits'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); } public function files($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id).'/files'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files'); } public function comments() @@ -99,7 +99,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('issue', 'body')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params); } public function update($username, $repository, $id, array $params) @@ -108,17 +108,17 @@ public function update($username, $repository, $id, array $params) $params['state'] = 'open'; } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id), $params); } public function merged($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id).'/merge'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); } public function merge($username, $repository, $id, $message = null) { - return $this->put('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($id).'/merge', array( + return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', array( 'commit_message' => $message )); } diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 0263e9c8943..dec30fb0566 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -13,12 +13,12 @@ class Comments extends AbstractApi { public function all($username, $repository, $pullRequest) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($pullRequest).'/comments'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); } public function show($username, $repository, $comment) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/comments/'.urlencode($comment)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); } public function create($username, $repository, $pullRequest, array $params) @@ -32,7 +32,7 @@ public function create($username, $repository, $pullRequest, array $params) throw new MissingArgumentException(array('commit_id', 'path', 'position')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/'.urlencode($pullRequest).'/comments', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params); } public function update($username, $repository, $comment, array $params) @@ -41,11 +41,11 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/comments/'.urlencode($comment), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment), $params); } public function remove($username, $repository, $comment) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls/comments/'.urlencode($comment)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 711af9e5cd2..cd5a400ea6c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -34,7 +34,7 @@ class Repo extends AbstractApi */ public function find($keyword, array $params) { - return $this->get('legacy/repos/search/'.urlencode($keyword), array_merge(array('start_page' => 1), $params)); + return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); } /** @@ -62,7 +62,7 @@ public function org($organization, array $params = array()) */ public function show($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -126,7 +126,7 @@ public function create( */ public function update($username, $repository, array $values) { - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository), $values); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository), $values); } /** @@ -140,7 +140,7 @@ public function update($username, $repository, array $values) */ public function remove($username, $repository) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -265,9 +265,9 @@ public function statuses() */ public function branches($username, $repository, $branch = null) { - $url = 'repos/'.urlencode($username).'/'.urlencode($repository).'/branches'; + $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches'; if (null !== $branch) { - $url .= '/'.urlencode($branch); + $url .= '/'.rawurlencode($branch); } return $this->get($url); @@ -285,7 +285,7 @@ public function branches($username, $repository, $branch = null) */ public function contributors($username, $repository, $includingAnonymous = false) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/contributors', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', array( 'anon' => $includingAnonymous ?: null )); } @@ -301,7 +301,7 @@ public function contributors($username, $repository, $includingAnonymous = false */ public function languages($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/languages'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/languages'); } /** @@ -315,7 +315,7 @@ public function languages($username, $repository) */ public function tags($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/tags'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags'); } /** @@ -329,7 +329,7 @@ public function tags($username, $repository) */ public function teams($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/teams'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams'); } /** @@ -341,7 +341,7 @@ public function teams($username, $repository) */ public function watchers($username, $repository, $page = 1) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/watchers', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array( 'page' => $page )); } @@ -360,7 +360,7 @@ public function watchers($username, $repository, $page = 1) */ public function merge($username, $repository, $base, $head, $message = null) { - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/merges', array( + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', array( 'base' => $base, 'head' => $head, 'commit_message' => $message diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index 987a148d167..89a95068559 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -12,21 +12,21 @@ class Collaborators extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/collaborators'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators'); } public function check($username, $repository, $collaborator) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/collaborators/'.urlencode($collaborator)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } public function add($username, $repository, $collaborator) { - return $this->put('repos/'.urlencode($username).'/'.urlencode($repository).'/collaborators/'.urlencode($collaborator)); + return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } public function remove($username, $repository, $collaborator) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/collaborators/'.urlencode($collaborator)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } } diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index 29119f389d5..cce0e5059d6 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -36,15 +36,15 @@ public function configure($bodyType = null) public function all($username, $repository, $sha = null) { if (null === $sha) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/comments'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments'); } - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/commits/'.urlencode($sha).'/comments'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments'); } public function show($username, $repository, $comment) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/comments/'.urlencode($comment)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment)); } public function create($username, $repository, $sha, array $params) @@ -53,7 +53,7 @@ public function create($username, $repository, $sha, array $params) throw new MissingArgumentException('body'); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/commits/'.urlencode($sha).'/comments', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments', $params); } public function update($username, $repository, $comment, array $params) @@ -62,11 +62,11 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/comments/'.urlencode($comment), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment), $params); } public function remove($username, $repository, $comment) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/comments/'.urlencode($comment)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 030231e0b1c..9c8726bd3b8 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -12,16 +12,16 @@ class Commits extends AbstractApi { public function all($username, $repository, array $params) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/commits', $params); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params); } public function compare($username, $repository, $base, $head) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/compare/'.urlencode($base).'...'.urlencode($head)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head)); } public function show($username, $repository, $sha) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/commits/'.urlencode($sha)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha)); } } diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 25c9a5247ab..47ce7a462e8 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -24,7 +24,7 @@ class Contents extends AbstractApi */ public function readme($username, $repository, $reference = null) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/readme', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', array( 'ref' => $reference )); } @@ -42,7 +42,7 @@ public function readme($username, $repository, $reference = null) */ public function show($username, $repository, $path = null, $reference = null) { - $url = 'repos/'.urlencode($username).'/'.urlencode($repository).'/contents'; + $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; if (null !== $path) { $url .= '/'.rawurlencode($path); } @@ -69,7 +69,7 @@ public function archive($username, $repository, $format, $reference = null) $format = 'tarball'; } - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/'.urlencode($format), array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format), array( 'ref' => $reference )); } diff --git a/lib/Github/Api/Repository/DeployKeys.php b/lib/Github/Api/Repository/DeployKeys.php index b25b1d04780..390835798ac 100644 --- a/lib/Github/Api/Repository/DeployKeys.php +++ b/lib/Github/Api/Repository/DeployKeys.php @@ -13,12 +13,12 @@ class DeployKeys extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/keys'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys'); } public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/keys/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id)); } public function create($username, $repository, array $params) @@ -27,7 +27,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/keys', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys', $params); } public function update($username, $repository, $id, array $params) @@ -36,11 +36,11 @@ public function update($username, $repository, $id, array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/keys/'.urlencode($id), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params); } public function remove($username, $repository, $id) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/keys/'.urlencode($id)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Downloads.php b/lib/Github/Api/Repository/Downloads.php index e402c317c1d..f3b96891c77 100644 --- a/lib/Github/Api/Repository/Downloads.php +++ b/lib/Github/Api/Repository/Downloads.php @@ -21,7 +21,7 @@ class Downloads extends AbstractApi */ public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/downloads'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads'); } /** @@ -36,7 +36,7 @@ public function all($username, $repository) */ public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/downloads/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); } /** @@ -51,6 +51,6 @@ public function show($username, $repository, $id) */ public function remove($username, $repository, $id) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/downloads/'.urlencode($id)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Forks.php b/lib/Github/Api/Repository/Forks.php index 2a88c330f12..c165961856e 100644 --- a/lib/Github/Api/Repository/Forks.php +++ b/lib/Github/Api/Repository/Forks.php @@ -16,11 +16,11 @@ public function all($username, $repository, array $params = array()) $params['sort'] = 'newest'; } - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/forks', array_merge(array('page' => 1), $params)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', array_merge(array('page' => 1), $params)); } public function create($username, $repository, array $params = array()) { - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/forks', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', $params); } } diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index 7c8b696b79d..ad9e8596ecd 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -13,12 +13,12 @@ class Hooks extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/hooks'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks'); } public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/hooks/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id)); } public function create($username, $repository, array $params) @@ -27,7 +27,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('name', 'config')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/hooks', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks', $params); } public function update($username, $repository, $id, array $params) @@ -36,16 +36,16 @@ public function update($username, $repository, $id, array $params) throw new MissingArgumentException(array('name', 'config')); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/hooks/'.urlencode($id), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params); } public function test($username, $repository, $id) { - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/hooks/'.urlencode($id).'/test'); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/test'); } public function remove($username, $repository, $id) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/hooks/'.urlencode($id)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Labels.php b/lib/Github/Api/Repository/Labels.php index 5ff2305ae7e..e35b4ded71d 100644 --- a/lib/Github/Api/Repository/Labels.php +++ b/lib/Github/Api/Repository/Labels.php @@ -13,12 +13,12 @@ class Labels extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/labels'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'); } public function show($username, $repository, $label) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/labels/'.urlencode($label)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } public function create($username, $repository, array $params) @@ -27,7 +27,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('name', 'color')); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/labels', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } public function update($username, $repository, $label, array $params) @@ -36,11 +36,11 @@ public function update($username, $repository, $label, array $params) throw new MissingArgumentException(array('name', 'color')); } - return $this->patch('repos/'.urlencode($username).'/'.urlencode($repository).'/labels/'.urlencode($label), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); } public function remove($username, $repository, $label) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/labels/'.urlencode($label)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } } diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index 9b3e7630ecc..918b2bd4cd6 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -22,7 +22,7 @@ class Statuses extends AbstractApi */ public function show($username, $repository, $sha) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/statuses/'.urlencode($sha)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha)); } /** @@ -43,6 +43,6 @@ public function create($username, $repository, $sha, array $params = array()) throw new MissingArgumentException('state'); } - return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/statuses/'.urlencode($sha), $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha), $params); } } diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 6ecb28ca597..97c3be0fda4 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -21,7 +21,7 @@ class User extends AbstractApi */ public function find($keyword) { - return $this->get('legacy/user/search/'.urlencode($keyword)); + return $this->get('legacy/user/search/'.rawurlencode($keyword)); } /** @@ -33,7 +33,7 @@ public function find($keyword) */ public function show($username) { - return $this->get('users/'.urlencode($username)); + return $this->get('users/'.rawurlencode($username)); } /** @@ -45,7 +45,7 @@ public function show($username) */ public function following($username) { - return $this->get('users/'.urlencode($username).'/following'); + return $this->get('users/'.rawurlencode($username).'/following'); } /** @@ -57,7 +57,7 @@ public function following($username) */ public function followers($username) { - return $this->get('users/'.urlencode($username).'/followers'); + return $this->get('users/'.rawurlencode($username).'/followers'); } /** @@ -69,7 +69,7 @@ public function followers($username) */ public function watched($username) { - return $this->get('users/'.urlencode($username).'/watched'); + return $this->get('users/'.rawurlencode($username).'/watched'); } /** @@ -81,7 +81,7 @@ public function watched($username) */ public function repositories($username) { - return $this->get('users/'.urlencode($username).'/repos'); + return $this->get('users/'.rawurlencode($username).'/repos'); } /** @@ -93,7 +93,7 @@ public function repositories($username) */ public function gists($username) { - return $this->get('users/'.urlencode($username).'/gists'); + return $this->get('users/'.rawurlencode($username).'/gists'); } /** @@ -105,7 +105,7 @@ public function gists($username) */ public function keys($username) { - return $this->get('users/'.urlencode($username).'/keys'); + return $this->get('users/'.rawurlencode($username).'/keys'); } /** @@ -119,6 +119,6 @@ public function keys($username) */ public function publicEvents($username) { - return $this->get('users/' . urlencode($username) . '/events/public'); + return $this->get('users/'.rawurlencode($username) . '/events/public'); } } diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index a2c48d57157..cdd7ba7f3b1 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -164,7 +164,7 @@ public function shouldSearchOpenIssues() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/issues/search/KnpLabs/php-github-api/open/Invalid+Commits') + ->with('legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'open', 'Invalid Commits')); @@ -180,7 +180,7 @@ public function shouldSearchClosedIssues() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/issues/search/KnpLabs/php-github-api/closed/Invalid+Commits') + ->with('legacy/issues/search/KnpLabs/php-github-api/closed/Invalid%20Commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'closed', 'Invalid Commits')); @@ -196,7 +196,7 @@ public function shouldSearchOpenIssuesWhenStateNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/issues/search/KnpLabs/php-github-api/open/Invalid+Commits') + ->with('legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'abc', 'Invalid Commits')); From 682b8cea30752ab579687c95955f88b876ac97e9 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Wed, 16 Oct 2013 13:39:40 +0300 Subject: [PATCH 064/951] Update README.markdown --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index 3f82fffeda6..86b07dfa0ae 100755 --- a/README.markdown +++ b/README.markdown @@ -102,6 +102,7 @@ See the `doc` directory for more detailed documentation. ### Contributors - Thanks to [Thibault Duplessis aka. ornicar](http://github.com/ornicar) for his first version of this library. +- Thanks to [Joseph Bielawski aka. stloyed](http://github.com/stloyd) for his contributions and support. - Thanks to [noloh](http://github.com/noloh) for his contribution on the Object API. - Thanks to [bshaffer](http://github.com/bshaffer) for his contribution on the Repo API. - Thanks to [Rolf van de Krol](http://github.com/rolfvandekrol) for his countless contributions. From 5bae94f348bed5464e308e780fb3b897d15f44d6 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 17 Oct 2013 17:18:05 +0300 Subject: [PATCH 065/951] Add tests, add more release apis, add assets api, update docs --- composer.json | 3 + doc/index.md | 1 + doc/repo/assets.md | 30 +++++ doc/repo/releases.md | 10 ++ lib/Github/Api/Repository/Assets.php | 80 ++++++++++++ lib/Github/Api/Repository/Releases.php | 56 +++++++- test/Github/Tests/Api/RepoTest.php | 10 ++ .../Tests/Api/Repository/AssetsTest.php | 98 ++++++++++++++ .../Tests/Api/Repository/ReleasesTest.php | 123 ++++++++++++++++++ 9 files changed, 406 insertions(+), 5 deletions(-) create mode 100644 doc/repo/assets.md create mode 100644 lib/Github/Api/Repository/Assets.php create mode 100644 test/Github/Tests/Api/Repository/AssetsTest.php create mode 100644 test/Github/Tests/Api/Repository/ReleasesTest.php diff --git a/composer.json b/composer.json index 1f0c1c9f266..d3471164d68 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,9 @@ "ext-curl": "*", "kriswallsmith/buzz": ">=0.7" }, + "require-dev": { + "phpunit/phpunit": ">=3.6.0" + }, "autoload": { "psr-0": { "Github\\": "lib/" } }, diff --git a/doc/index.md b/doc/index.md index cd98aaac896..1f447d6e457 100644 --- a/doc/index.md +++ b/doc/index.md @@ -15,6 +15,7 @@ APIs: * [Comments](pull_request/comments.md) * [Repositories](repos.md) * [Releases](repo/releases.md) + * [Assets](repo/assets.md) * [Users](users.md) Additional features: diff --git a/doc/repo/assets.md b/doc/repo/assets.md new file mode 100644 index 00000000000..05a6d9e04e7 --- /dev/null +++ b/doc/repo/assets.md @@ -0,0 +1,30 @@ +## Repo / Releases API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) + +### List all assets by release + +```php +$assets = $client->api('repo')->releases()->assets()->all('twbs', 'bootstrap', $releaseId); +``` + +### List one asset + +```php +$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId); +``` + +### Create an asset + +This feature is not implemented because require usage of `uploads.github.com` subdomain. + +### Edit an asset + +```php +$asset = $client->api('repo')->releases()->assets()->edit('twbs', 'bootstrap', $assetId, array('name' => 'New name')); +``` + +### Remove an asset + +```php +$asset = $client->api('repo')->releases()->assets()->remove('twbs', 'bootstrap', $assetId); +``` diff --git a/doc/repo/releases.md b/doc/repo/releases.md index 63a4241a0b4..cfbf5721338 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -16,6 +16,16 @@ $releases = $client->api('repo')->releases()->all('twbs', 'bootstrap'); $release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id); ``` +### Create a release +```php +$release = $client->api('repo')->releases()->create('twbs', 'bootstrap', array('tag_name' => 'v1.1')); +``` + +### Edit a release +```php +$release = $client->api('repo')->releases()->edit('twbs', 'bootstrap', $id, array('name' => 'New release name')); +``` + ### Remove a release This works, but isn't thoroughly tested, use at your own risk. diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php new file mode 100644 index 00000000000..5a1137b35d6 --- /dev/null +++ b/lib/Github/Api/Repository/Assets.php @@ -0,0 +1,80 @@ + + */ +class Assets extends AbstractApi +{ + /** + * Get all release's assets in selected repository + * GET /repos/:owner/:repo/releases/:id/assets + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the release + * + * @return array + */ + public function all($username, $repository, $id) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets'); + } + + /** + * Get an asset in selected repository's release + * GET /repos/:owner/:repo/releases/assets/:id + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the asset + * + * @return array + */ + public function show($username, $repository, $id) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); + } + + /** + * Edit an asset in selected repository's release + * PATCH /repos/:owner/:repo/releases/assets/:id + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the asset + * @param array $params request parameters + * + * @throws MissingArgumentException + * + * @return array + */ + public function edit($username, $repository, $id, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException('name'); + } + + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params); + } + + /** + * Delete an asset in selected repository's release + * DELETE /repos/:owner/:repo/releases/assets/:id + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the asset + * + * @return array + */ + public function remove($username, $repository, $id) + { + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); + } +} diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 3def47b154f..a2ee5201ffe 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -3,9 +3,12 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Exception\MissingArgumentException; /** + * @link http://developer.github.com/v3/repos/releases/ * @author Matthew Simo + * @author Evgeniy Guseletov */ class Releases extends AbstractApi { @@ -19,7 +22,7 @@ class Releases extends AbstractApi */ public function all($username, $repository) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/releases'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases'); } /** @@ -27,17 +30,52 @@ public function all($username, $repository) * * @param string $username the user who owns the repo * @param string $repository the name of the repo - * @param integer $id the id of the release + * @param integer $id the id of the release * * @return array */ public function show($username, $repository, $id) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/releases/'.urlencode($id)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + } + + /** + * Create new release in selected repository + * + * @param string $username + * @param string $repository + * @param array $params + * + * @throws MissingArgumentException + * + * @return array + */ + public function create($username, $repository, array $params) + { + if (!isset($params['tag_name'])) { + throw new MissingArgumentException('tag_name'); + } + + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + } + + /** + * Edit release in selected repository + * + * @param string $username + * @param string $repository + * @param integer $id + * @param array $params + * + * @return array + */ + public function edit($username, $repository, $id, array $params) + { + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); } /** - * Delete a download in selected repository (Not thoroughly tested!) + * Delete a release in selected repository (Not thoroughly tested!) * * @param string $username the user who owns the repo * @param string $repository the name of the repo @@ -47,6 +85,14 @@ public function show($username, $repository, $id) */ public function remove($username, $repository, $id) { - return $this->delete('repos/'.urlencode($username).'/'.urlencode($repository).'/releases/'.urlencode($id)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + } + + /** + * @return Assets + */ + public function assets() + { + return new Assets($this->client); } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 44b1a25f2d5..db125a72622 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -407,6 +407,16 @@ public function shouldGetStatusesApiObject() $this->assertInstanceOf('Github\Api\Repository\Statuses', $api->statuses()); } + /** + * @test + */ + public function shouldGetReleasesApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases()); + } + protected function getApiClass() { return 'Github\Api\Repo'; diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php new file mode 100644 index 00000000000..52347a4ec72 --- /dev/null +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -0,0 +1,98 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/releases/'.$id.'/assets') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldGetSingleReleaseAsset() + { + $expectedValue = array('assetData'); + $assetId = 2; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/releases/assets/'.$assetId) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $assetId)); + } + + /** + * @test + */ + public function shouldEditReleaseAsset() + { + $expectedValue = array('assetUpdatedData'); + $assetId = 5; + $data = array('name' => 'asset111_name_qweqwe'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('repos/KnpLabs/php-github-api/releases/assets/'.$assetId) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $assetId, $data)); + } + + /** + * @test + * @expectedException Github\Exception\MissingArgumentException + */ + public function shouldNotEditReleaseAssetWithoutName() + { + $assetId = 5; + $data = array('not_a_name' => 'just a value'); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('patch'); + + $api->edit('KnpLabs', 'php-github-api', $assetId, $data); + } + + /** + * @test + */ + public function shouldRemoveReleaseAsset() + { + $expectedValue = array('assetUpdatedData'); + $assetId = 5; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('repos/KnpLabs/php-github-api/releases/assets/'.$assetId) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $assetId)); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Assets'; + } +} diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php new file mode 100644 index 00000000000..c9fac0a0f80 --- /dev/null +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -0,0 +1,123 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSingleRepositoryRelease() + { + $expectedValue = array('releaseData'); + $id = 331; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldCreateRepositoryRelease() + { + $expectedValue = array('newReleaseData'); + $data = array('tag_name' => '1.1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + * @expectedException Github\Exception\MissingArgumentException + */ + public function shouldNotCreateRepositoryReleaseWithoutTagName() + { + $data = array('not_a_tag_name' => '1.1'); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', $data); + } + + /** + * @test + */ + public function shouldEditRepositoryRelease() + { + $expectedValue = array('updatedData'); + $id = 332; + $data = array('some' => 'thing'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $id, $data)); + } + + /** + * @test + */ + public function shouldRemoveRepositoryRelease() + { + $expectedValue = array('deleted'); + $id = 333; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldGetAssetsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Assets', $api->assets()); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Releases'; + } +} From 111ac7754b989c059614b70a41c2c3992e97cd19 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Tue, 22 Oct 2013 18:35:28 +0300 Subject: [PATCH 066/951] Add manifold preview media type --- lib/Github/Api/Repository/Assets.php | 10 ++++++++++ lib/Github/Api/Repository/Releases.php | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 5a1137b35d6..a39f4057c7d 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -11,6 +11,16 @@ */ class Assets extends AbstractApi { + /** + * @deprecated Will be removed as soon as gh releases api gets stable + */ + public function configure() + { + $this->client->setHeaders(array( + 'Accept: application/vnd.github.manifold-preview' + )); + } + /** * Get all release's assets in selected repository * GET /repos/:owner/:repo/releases/:id/assets diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index a2ee5201ffe..d276084d75d 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -12,6 +12,16 @@ */ class Releases extends AbstractApi { + /** + * @deprecated Will be removed as soon as gh releases api gets stable + */ + public function configure() + { + $this->client->setHeaders(array( + 'Accept: application/vnd.github.manifold-preview' + )); + } + /** * List releases in selected repository * From c90c84c95ea95c480a7f4c393cb0ae6408a61a5e Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 31 Oct 2013 12:19:10 +0200 Subject: [PATCH 067/951] Migrate from Buzz to Guzzle --- README.markdown | 2 +- composer.json | 11 +- lib/Github/Api/ApiInterface.php | 7 + lib/Github/HttpClient/CachedHttpClient.php | 5 +- lib/Github/HttpClient/HttpClient.php | 120 ++++------------- .../HttpClient/Listener/AuthListener.php | 110 +++++---------- .../HttpClient/Listener/ErrorListener.php | 32 +++-- lib/Github/HttpClient/Message/Request.php | 10 -- lib/Github/HttpClient/Message/Response.php | 34 ++++- lib/Github/ResultPager.php | 3 +- test/Github/Tests/Api/AbstractApiTest.php | 10 +- test/Github/Tests/Api/TestCase.php | 10 +- test/Github/Tests/Functional/UserTest.php | 4 +- .../HttpClient/Cache/FilesystemCacheTest.php | 4 +- .../Tests/HttpClient/CachedHttpClientTest.php | 22 ++- .../Tests/HttpClient/HttpClientTest.php | 88 ++++++------ .../HttpClient/Listener/AuthListenerTest.php | 125 ++++++------------ .../HttpClient/Listener/ErrorListenerTest.php | 41 ++++-- test/Github/Tests/ResultPagerTest.php | 14 +- 19 files changed, 258 insertions(+), 394 deletions(-) delete mode 100644 lib/Github/HttpClient/Message/Request.php diff --git a/README.markdown b/README.markdown index 3f82fffeda6..73e2f196d9c 100755 --- a/README.markdown +++ b/README.markdown @@ -15,7 +15,7 @@ Uses [GitHub API v3](http://developer.github.com/v3/). The object API is very si ## Requirements * PHP >= 5.3.2 with [cURL](http://php.net/manual/en/book.curl.php) extension, -* [Buzz](https://github.com/kriswallsmith/Buzz) library, +* [Guzzle](https://github.com/guzzle/guzzle) library, * (optional) PHPUnit to run tests. ## Autoload diff --git a/composer.json b/composer.json index 1f0c1c9f266..a9dbf2d1538 100644 --- a/composer.json +++ b/composer.json @@ -17,16 +17,19 @@ } ], "require": { - "php": ">=5.3.2", - "ext-curl": "*", - "kriswallsmith/buzz": ">=0.7" + "php": ">=5.3.2", + "ext-curl": "*", + "guzzle/guzzle": ">=3.7" + }, + "require-dev": { + "phpunit/phpunit": ">=3.7" }, "autoload": { "psr-0": { "Github\\": "lib/" } }, "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } } } diff --git a/lib/Github/Api/ApiInterface.php b/lib/Github/Api/ApiInterface.php index 06a95047f28..c5928637ac7 100644 --- a/lib/Github/Api/ApiInterface.php +++ b/lib/Github/Api/ApiInterface.php @@ -2,6 +2,8 @@ namespace Github\Api; +use Github\Client; + /** * Api interface * @@ -9,4 +11,9 @@ */ interface ApiInterface { + public function __construct(Client $client); + + public function getPerPage(); + + public function setPerPage($perPage); } diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index f28f54bd9e2..ba41d5ac3ea 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -69,7 +69,10 @@ protected function createRequest($httpMethod, $url) $modifiedAt = new \DateTime('@'.$modifiedAt); $modifiedAt->setTimezone(new \DateTimeZone('GMT')); - $request->addHeader(sprintf('If-Modified-Since: %s GMT', $modifiedAt->format('l, d-M-y H:i:s'))); + $request->addHeader( + 'If-Modified-Since', + sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) + ); } return $request; diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 3538f102589..f6fac9643ae 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -2,16 +2,15 @@ namespace Github\HttpClient; -use Buzz\Client\ClientInterface; -use Buzz\Listener\ListenerInterface; +use Github\HttpClient\Listener\AuthListener; +use Github\HttpClient\Listener\ErrorListener; +use Guzzle\Http\Client as GuzzleClient; +use Guzzle\Http\ClientInterface; +use Guzzle\Http\Message\Request; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; -use Github\HttpClient\Listener\AuthListener; -use Github\HttpClient\Listener\ErrorListener; -use Github\HttpClient\Message\Request; use Github\HttpClient\Message\Response; -use Buzz\Client\Curl; /** * Performs requests on GitHub API. API documentation should be self-explanatory. @@ -20,9 +19,6 @@ */ class HttpClient implements HttpClientInterface { - /** - * @var array - */ protected $options = array( 'base_url' => 'https://api.github.com/', @@ -30,17 +26,11 @@ class HttpClient implements HttpClientInterface 'timeout' => 10, 'api_limit' => 5000, - 'api_version' => 'beta', + 'api_version' => 'v3', 'cache_dir' => null ); - /** - * @var array - */ - protected $listeners = array(); - /** - * @var array - */ + protected $headers = array(); private $lastResponse; @@ -52,32 +42,14 @@ class HttpClient implements HttpClientInterface */ public function __construct(array $options = array(), ClientInterface $client = null) { - $client = $client ?: new Curl(); - $timeout = isset($options['timeout']) ? $options['timeout'] : $this->options['timeout']; - $client->setTimeout($timeout); - $client->setVerifyPeer(false); - $this->options = array_merge($this->options, $options); + $client = $client ?: new GuzzleClient($options['base_url'], $this->options); $this->client = $client; - $this->addListener(new ErrorListener($this->options)); - + $this->addListener('request.error', array(new ErrorListener($this->options), 'onRequestError')); $this->clearHeaders(); } - public function authenticate($tokenOrLogin, $password, $authMethod) - { - $this->addListener( - new AuthListener( - $authMethod, - array( - 'tokenOrLogin' => $tokenOrLogin, - 'password' => $password - ) - ) - ); - } - /** * {@inheritDoc} */ @@ -105,12 +77,9 @@ public function clearHeaders() ); } - /** - * @param ListenerInterface $listener - */ - public function addListener(ListenerInterface $listener) + public function addListener($eventName, $listener) { - $this->listeners[get_class($listener)] = $listener; + $this->client->getEventDispatcher()->addListener($eventName, $listener); } /** @@ -118,11 +87,7 @@ public function addListener(ListenerInterface $listener) */ public function get($path, array $parameters = array(), array $headers = array()) { - if (0 < count($parameters)) { - $path .= (false === strpos($path, '?') ? '?' : '&').http_build_query($parameters, '', '&'); - } - - return $this->request($path, array(), 'GET', $headers); + return $this->request($path, $parameters, 'GET', $headers); } /** @@ -162,27 +127,17 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - if (!empty($this->options['base_url']) && 0 !== strpos($path, $this->options['base_url'])) { - $path = trim($this->options['base_url'].$path, '/'); - } + $requestBody = count($parameters) === 0 + ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0) + ; - $request = $this->createRequest($httpMethod, $path); + $request = $this->client->createRequest($httpMethod, $path, array_merge($this->headers, $headers), $requestBody); $request->addHeaders($headers); - if (count($parameters) > 0) { - $request->setContent(json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0)); - } - - $hasListeners = 0 < count($this->listeners); - if ($hasListeners) { - foreach ($this->listeners as $listener) { - $listener->preSend($request); - } - } - - $response = $this->createResponse(); try { - $this->client->send($request, $response); + $response = Response::fromMessage( + $this->client->send($request) + ); } catch (\LogicException $e) { throw new ErrorException($e->getMessage()); } catch (\RuntimeException $e) { @@ -192,51 +147,32 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $this->lastRequest = $request; $this->lastResponse = $response; - if ($hasListeners) { - foreach ($this->listeners as $listener) { - $listener->postSend($request, $response); - } - } - return $response; } /** - * @return Request - */ - public function getLastRequest() - { - return $this->lastRequest; - } - - /** - * @return Response + * {@inheritDoc} */ - public function getLastResponse() + public function authenticate($tokenOrLogin, $password = null, $method) { - return $this->lastResponse; + $this->addListener('request.before_send', array( + new AuthListener($tokenOrLogin, $password, $method), 'onRequestBeforeSend' + )); } /** - * @param string $httpMethod - * @param string $url - * * @return Request */ - protected function createRequest($httpMethod, $url) + public function getLastRequest() { - $request = new Request($httpMethod); - $request->setHeaders($this->headers); - $request->fromUrl($url); - - return $request; + return $this->lastRequest; } /** * @return Response */ - protected function createResponse() + public function getLastResponse() { - return new Response(); + return $this->lastResponse; } } diff --git a/lib/Github/HttpClient/Listener/AuthListener.php b/lib/Github/HttpClient/Listener/AuthListener.php index 1f5e9e64b2f..41ad42e4642 100644 --- a/lib/Github/HttpClient/Listener/AuthListener.php +++ b/lib/Github/HttpClient/Listener/AuthListener.php @@ -2,44 +2,24 @@ namespace Github\HttpClient\Listener; +use Guzzle\Common\Event; use Github\Client; -use Github\Exception\InvalidArgumentException; +use Github\Exception\RuntimeException; -use Buzz\Listener\ListenerInterface; -use Buzz\Message\MessageInterface; -use Buzz\Message\RequestInterface; -use Buzz\Util\Url; - -/** - * @author Joseph Bielawski - */ -class AuthListener implements ListenerInterface +class AuthListener { - /** - * @var string - */ + private $tokenOrLogin; + private $password; private $method; - /** - * @var array - */ - private $options; - /** - * @param string $method - * @param array $options - */ - public function __construct($method, array $options) + public function __construct($tokenOrLogin, $password = null, $method) { - $this->method = $method; - $this->options = $options; + $this->tokenOrLogin = $tokenOrLogin; + $this->password = $password; + $this->method = $method; } - /** - * {@inheritDoc} - * - * @throws InvalidArgumentException - */ - public function preSend(RequestInterface $request) + public function onRequestBeforeSend(Event $event) { // Skip by default if (null === $this->method) { @@ -48,71 +28,41 @@ public function preSend(RequestInterface $request) switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: - if (!isset($this->options['tokenOrLogin'], $this->options['password'])) { - throw new InvalidArgumentException('You need to set username with password!'); - } - - $request->addHeader('Authorization: Basic '. base64_encode($this->options['tokenOrLogin'] .':'. $this->options['password'])); + $event['request']->setHeader( + 'Authorization', + sprintf('Basic %s', base64_encode($this->tokenOrLogin . ':' . $this->password)) + ); break; case Client::AUTH_HTTP_TOKEN: - if (!isset($this->options['tokenOrLogin'])) { - throw new InvalidArgumentException('You need to set OAuth token!'); - } - - $request->addHeader('Authorization: token '. $this->options['tokenOrLogin']); + $event['request']->setHeader('Authorization', sprintf('token %s', $this->tokenOrLogin)); break; case Client::AUTH_URL_CLIENT_ID: - if (!isset($this->options['tokenOrLogin'], $this->options['password'])) { - throw new InvalidArgumentException('You need to set client_id and client_secret!'); - } + $url = $event['request']->getUrl(); - $this->setRequestUrl( - $request, - array( - 'client_id' => $this->options['tokenOrLogin'], - 'client_secret' => $this->options['password'], - ) + $parameters = array( + 'client_id' => $this->tokenOrLogin, + 'client_secret' => $this->password, ); + + $url .= (false === strpos($url, '?') ? '?' : '&'); + $url .= utf8_encode(http_build_query($parameters, '', '&')); + + $event['request']->setUrl($url); break; case Client::AUTH_URL_TOKEN: - if (!isset($this->options['tokenOrLogin'])) { - throw new InvalidArgumentException('You need to set OAuth token!'); - } + $url = $event['request']->getUrl(); + $url .= (false === strpos($url, '?') ? '?' : '&'); + $url .= utf8_encode(http_build_query(array('access_token' => $this->tokenOrLogin), '', '&')); - $this->setRequestUrl( - $request, - array( - 'access_token' => $this->options['tokenOrLogin'], - ) - ); + $event['request']->setUrl($url); break; default: - throw new InvalidArgumentException(sprintf('Unknown method called "%s".', $this->method)); + throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); + break; } } - - /** - * {@inheritDoc} - */ - public function postSend(RequestInterface $request, MessageInterface $response) - { - } - - /** - * @param RequestInterface $request - * @param array $parameters - * - * @return Url - */ - private function setRequestUrl(RequestInterface $request, array $parameters = array()) - { - $url = $request->getUrl(); - $url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query($parameters, '', '&')); - - $request->fromUrl(new Url($url)); - } } diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 3f2963fc995..c89592ad92c 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -2,9 +2,10 @@ namespace Github\HttpClient\Listener; -use Buzz\Listener\ListenerInterface; -use Buzz\Message\MessageInterface; -use Buzz\Message\RequestInterface; +use Guzzle\Common\Event; +use Guzzle\Http\Message\Response as GuzzleResponse; + +use Github\HttpClient\Message\Response; use Github\Exception\ApiLimitExceedException; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; @@ -13,7 +14,7 @@ /** * @author Joseph Bielawski */ -class ErrorListener implements ListenerInterface +class ErrorListener { /** * @var array @@ -31,18 +32,14 @@ public function __construct(array $options) /** * {@inheritDoc} */ - public function preSend(RequestInterface $request) + public function onRequestError(Event $event) { - } + /** @var $request \Guzzle\Http\Message\Request */ + $request = $event['request']; + $response = $this->createResponse($request->getResponse()); - /** - * {@inheritDoc} - */ - public function postSend(RequestInterface $request, MessageInterface $response) - { - /** @var $response \Github\HttpClient\Message\Response */ if ($response->isClientError() || $response->isServerError()) { - $remaining = $response->getHeader('X-RateLimit-Remaining'); + $remaining = (string) $response->getHeader('X-RateLimit-Remaining'); if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getResource(), 1, 10)) { throw new ApiLimitExceedException($this->options['api_limit']); @@ -84,6 +81,15 @@ public function postSend(RequestInterface $request, MessageInterface $response) } throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); + }; + } + + protected function createResponse(GuzzleResponse $response) + { + if (!($response instanceof Response)) { + return Response::fromMessage($response); + } else { + return $response; } } } diff --git a/lib/Github/HttpClient/Message/Request.php b/lib/Github/HttpClient/Message/Request.php deleted file mode 100644 index cbc206809de..00000000000 --- a/lib/Github/HttpClient/Message/Request.php +++ /dev/null @@ -1,10 +0,0 @@ -getParser('message')->parseResponse($message); + if (!$data) { + return false; + } + + $response = new static($data['code'], $data['headers'], $data['body']); + $response->setProtocol($data['protocol'], $data['version']) + ->setStatus($data['code'], $data['reason_phrase']); + + // Set the appropriate Content-Length if the one set is inaccurate (e.g. setting to X) + $contentLength = (string) $response->getHeader('Content-Length'); + $actualLength = strlen($data['body']); + if (strlen($data['body']) > 0 && $contentLength != $actualLength) { + $response->setHeader('Content-Length', $actualLength); + } + + return $response; + } + /** * {@inheritDoc} */ public function getContent() { - $response = parent::getContent(); + $response = parent::getBody(true); $content = json_decode($response, true); if (JSON_ERROR_NONE !== json_last_error()) { diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 83f2692a29a..ab4664c4c8d 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -3,7 +3,6 @@ namespace Github; use Github\Api\ApiInterface; -use Github\HttpClient\HttpClient; /** * Pager class for supporting pagination in github classes @@ -14,7 +13,7 @@ class ResultPager implements ResultPagerInterface { /** - * @var Github\Client client + * @var \Github\Client client */ protected $client; diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 40d8c2c3436..a48b28775f1 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -134,15 +134,7 @@ protected function getHttpMock() protected function getHttpClientMock() { - $mock = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); - $mock - ->expects($this->any()) - ->method('setTimeout') - ->with(10); - $mock - ->expects($this->any()) - ->method('setVerifyPeer') - ->with(false); + $mock = $this->getMock('Guzzle\Http\Client', array('send')); $mock ->expects($this->any()) ->method('send'); diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 5bae9b02972..81e7635939f 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -8,15 +8,7 @@ abstract protected function getApiClass(); protected function getApiMock() { - $httpClient = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); - $httpClient - ->expects($this->any()) - ->method('setTimeout') - ->with(10); - $httpClient - ->expects($this->any()) - ->method('setVerifyPeer') - ->with(false); + $httpClient = $this->getMock('Guzzle\Http\Client', array('send')); $httpClient ->expects($this->any()) ->method('send'); diff --git a/test/Github/Tests/Functional/UserTest.php b/test/Github/Tests/Functional/UserTest.php index cdcdedde021..8cef6d7a88a 100644 --- a/test/Github/Tests/Functional/UserTest.php +++ b/test/Github/Tests/Functional/UserTest.php @@ -5,7 +5,7 @@ /** * @group functional */ -class UsetTest extends TestCase +class UserTest extends TestCase { /** * @test @@ -58,7 +58,7 @@ public function shouldGetUsersWhoUserIsFollowing() */ public function shouldGetFollowersUsers() { - $username = 'KnpLabs'; + $username = 'cursedcoder'; $users = $this->client->api('user')->followers($username); $user = array_pop($users); diff --git a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php index 841f38f690b..45a038bcc5f 100644 --- a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php +++ b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php @@ -14,7 +14,7 @@ public function shouldStoreAResponseForAGivenKey() { $cache = new FilesystemCache('/tmp/github-api-test'); - $cache->set('test', new Response); + $cache->set('test', new Response(200)); $this->assertNotNull($cache->get('test')); } @@ -26,7 +26,7 @@ public function shouldGetATimestampForExistingFile() { $cache = new FilesystemCache('/tmp/github-api-test'); - $cache->set('test', new Response); + $cache->set('test', new Response(200)); $this->assertInternalType('int', $cache->getModifiedSince('test')); } diff --git a/test/Github/Tests/HttpClient/CachedHttpClientTest.php b/test/Github/Tests/HttpClient/CachedHttpClientTest.php index 5a5e29dfde9..1d92bd2f24a 100644 --- a/test/Github/Tests/HttpClient/CachedHttpClientTest.php +++ b/test/Github/Tests/HttpClient/CachedHttpClientTest.php @@ -8,7 +8,7 @@ class CachedHttpClientTest extends HttpClientTest { /** - * @test + * test */ public function shouldCacheResponseAtFirstTime() { @@ -16,27 +16,26 @@ public function shouldCacheResponseAtFirstTime() $httpClient = new TestCachedHttpClient( array('base_url' => ''), - $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')) + $this->getMock('Guzzle\Http\ClientInterface', array('send')) ); $httpClient->setCache($cache); - $cache->expects($this->once())->method('set')->with('test', new Response); + $cache->expects($this->once())->method('set')->with('test', new Response(200)); $httpClient->get('test'); } /** - * @test + * test */ public function shouldGetCachedResponseWhileResourceNotModified() { - $client = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); + $client = $this->getMock('Guzzle\Http\ClientInterface', array('send')); $client->expects($this->once())->method('send'); $cache = $this->getCacheMock(); - $response = new Response; - $response->addHeader('HTTP/1.1 304 Not Modified'); + $response = new Response(304); $httpClient = new TestCachedHttpClient( array('base_url' => ''), @@ -51,17 +50,16 @@ public function shouldGetCachedResponseWhileResourceNotModified() } /** - * @test + * test */ public function shouldRenewCacheWhenResourceHasChanged() { - $client = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); + $client = $this->getMock('Guzzle\Http\ClientInterface', array('send')); $client->expects($this->once())->method('send'); $cache = $this->getCacheMock(); - $response = new Response; - $response->addHeader('HTTP/1.1 200 OK'); + $response = new Response(200); $httpClient = new TestCachedHttpClient( array('base_url' => ''), @@ -88,6 +86,6 @@ class TestCachedHttpClient extends CachedHttpClient protected function createResponse() { - return $this->fakeResponse ?: new Response(); + return $this->fakeResponse ?: new Response(200); } } diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index 4fc44717537..6d09cba4a82 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -4,8 +4,9 @@ use Github\Client; use Github\HttpClient\HttpClient; -use Github\HttpClient\Message\Request; use Github\HttpClient\Message\Response; +use Guzzle\Plugin\Mock\MockPlugin; +use Guzzle\Http\Client as GuzzleClient; class HttpClientTest extends \PHPUnit_Framework_TestCase { @@ -39,11 +40,16 @@ public function shouldBeAbleToSetOption() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $client = new TestHttpClient(); - $client->authenticate($login, $password, $method); + $client = new GuzzleClient(); - $this->assertCount(2, $client->listeners); - $this->assertInstanceOf('Github\HttpClient\Listener\AuthListener', $client->listeners['Github\HttpClient\Listener\AuthListener']); + $httpClient = new TestHttpClient(array(), $client); + $httpClient->authenticate($login, $password, $method); + + $this->assertCount(1, $client->getEventDispatcher()->getListeners('request.create')); + $this->assertInstanceOf( + 'Github\HttpClient\Listener\AuthListener', + current(current($client->getEventDispatcher()->getListeners('request.create'))) + ); } public function getAuthenticationFullData() @@ -81,11 +87,12 @@ public function shouldDoPOSTRequest() $headers = array('c' => 'd'); $client = $this->getBrowserMock(); + $client->expects($this->once()) + ->method('send') + ->with($this->anything(), $this->isType('array'), '{"a":"b"}'); $httpClient = new HttpClient(array(), $client); $httpClient->post($path, $parameters, $headers); - - $this->assertEquals('{"a":"b"}', $httpClient->getLastRequest()->getContent()); } /** @@ -97,10 +104,12 @@ public function shouldDoPOSTRequestWithoutContent() $client = $this->getBrowserMock(); + $client->expects($this->once()) + ->method('send') + ->with($this->anything(), $this->isType('array'), $this->isEmpty()); + $httpClient = new HttpClient(array(), $client); $httpClient->post($path); - - $this->assertEmpty($httpClient->getLastRequest()->getContent()); } /** @@ -171,8 +180,8 @@ public function shouldHandlePagination() $parameters = array('a' => 'b'); $headers = array('c' => 'd'); - $response = new Response(); - $response->addHeader("Link:; rel=\"page2\", \n; rel=\"page4\""); + $response = new Response(200); + $response->addHeader('Link', "; rel=\"page2\", \n; rel=\"page4\""); $client = $this->getBrowserMock(); @@ -191,20 +200,21 @@ public function shouldAllowToReturnRawContent() $parameters = array('a' => 'b'); $headers = array('c' => 'd'); - $message = $this->getMock('Github\HttpClient\Message\Response'); + $message = $this->getMock('Github\HttpClient\Message\Response', array(), array(200)); $message->expects($this->once()) - ->method('getContent') + ->method('getBody') ->will($this->returnValue('Just raw context')); $client = $this->getBrowserMock(); + $client->expects($this->once()) + ->method('send') + ->will($this->returnValue($message)); $httpClient = new TestHttpClient(array(), $client); - $httpClient->fakeResponse = $message; - $response = $httpClient->get($path, $parameters, $headers); - $this->assertEquals("Just raw context", $response->getContent()); - $this->assertInstanceOf('Buzz\Message\MessageInterface', $response); + $this->assertEquals("Just raw context", $response->getBody()); + $this->assertInstanceOf('Guzzle\Http\Message\MessageInterface', $response); } /** @@ -217,22 +227,25 @@ public function shouldThrowExceptionWhenApiIsExceeded() $parameters = array('a' => 'b'); $headers = array('c' => 'd'); - $response = new Response(); - $response->addHeader('HTTP/1.1 403 Forbidden'); - $response->addHeader('X-RateLimit-Remaining: 0'); + $response = new Response(403); + $response->addHeader('X-RateLimit-Remaining', 0); - $httpClient = new TestHttpClient(array(), $this->getBrowserMock()); - $httpClient->fakeResponse = $response; + $mockPlugin = new MockPlugin(); + $mockPlugin->addResponse($response); + $client = new GuzzleClient('http://123.com/'); + $client->addSubscriber($mockPlugin); + + $httpClient = new TestHttpClient(array(), $client); $httpClient->get($path, $parameters, $headers); } protected function getBrowserMock(array $methods = array()) { return $this->getMock( - 'Buzz\Client\ClientInterface', + 'Guzzle\Http\Client', array_merge( - array('setTimeout', 'setVerifyPeer', 'send'), + array('send'), $methods ) ); @@ -241,38 +254,15 @@ protected function getBrowserMock(array $methods = array()) class TestHttpClient extends HttpClient { - public $fakeResponse; - public $listeners; - public function getOption($name, $default = null) { return isset($this->options[$name]) ? $this->options[$name] : $default; } - public function clearHeaders() - { - } - public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - $request = $this->createRequest($httpMethod, $path); - $response = $this->createResponse(); - if (0 < count($this->listeners)) { - foreach ($this->listeners as $listener) { - $listener->postSend($request, $response); - } - } - - return $response; - } + $request = $this->createRequest($httpMethod, $path); - protected function createRequest($httpMethod, $url) - { - return new Request($httpMethod); - } - - protected function createResponse() - { - return $this->fakeResponse ?: new Response(); + return $this->client->send($request, $headers, $parameters); } } diff --git a/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php b/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php index cfd741c7a0c..d071687488d 100644 --- a/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php @@ -2,61 +2,21 @@ namespace Github\Tests\HttpClient; +use Guzzle\Http\Message\Request; + use Github\Client; -use Github\Exception\InvalidArgumentException; use Github\HttpClient\Listener\AuthListener; -use Github\HttpClient\Message\Request; class AuthListenerTest extends \PHPUnit_Framework_TestCase { /** * @test - * @expectedException InvalidArgumentException + * @expectedException \RuntimeException */ public function shouldHaveKnownMethodName() { - $listener = new AuthListener('unknown', array('tokenOrLogin' => 'test')); - $listener->preSend($this->getMock('Buzz\Message\RequestInterface')); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldHaveLoginAndPasswordForAuthPassMethod() - { - $listener = new AuthListener(Client::AUTH_HTTP_PASSWORD, array('tokenOrLogin' => 'test')); - $listener->preSend($this->getMock('Buzz\Message\RequestInterface')); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldHaveTokenForHttpTokenMethod() - { - $listener = new AuthListener(Client::AUTH_HTTP_TOKEN, array('password' => 'pass')); - $listener->preSend($this->getMock('Buzz\Message\RequestInterface')); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldHaveTokenForUrlTokenMethod() - { - $listener = new AuthListener(Client::AUTH_URL_TOKEN, array('password' => 'login')); - $listener->preSend($this->getMock('Buzz\Message\RequestInterface')); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldHaveClientIdAndSecretForUrlClientIdMethod() - { - $listener = new AuthListener(Client::AUTH_URL_CLIENT_ID, array('password' => 'login')); - $listener->preSend($this->getMock('Buzz\Message\RequestInterface')); + $listener = new AuthListener('test', null, 'unknown'); + $listener->onRequestBeforeSend($this->getEventMock()); } /** @@ -64,7 +24,7 @@ public function shouldHaveClientIdAndSecretForUrlClientIdMethod() */ public function shouldDoNothingForHaveNullMethod() { - $request = $this->getMock('Buzz\Message\RequestInterface'); + $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); $request->expects($this->never()) ->method('addHeader'); $request->expects($this->never()) @@ -72,8 +32,8 @@ public function shouldDoNothingForHaveNullMethod() $request->expects($this->never()) ->method('getUrl'); - $listener = new AuthListener(null, array('password' => 'pass', 'tokenOrLogin' => 'test')); - $listener->preSend($request); + $listener = new AuthListener('test', 'pass', null); + $listener->onRequestBeforeSend($this->getEventMock($request)); } /** @@ -81,7 +41,7 @@ public function shouldDoNothingForHaveNullMethod() */ public function shouldDoNothingForPostSend() { - $request = $this->getMock('Buzz\Message\RequestInterface'); + $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); $request->expects($this->never()) ->method('addHeader'); $request->expects($this->never()) @@ -89,22 +49,8 @@ public function shouldDoNothingForPostSend() $request->expects($this->never()) ->method('getUrl'); - $response = $this->getMock('Buzz\Message\MessageInterface'); - $response->expects($this->never()) - ->method('addHeader'); - $response->expects($this->never()) - ->method('setContent'); - $response->expects($this->never()) - ->method('setHeaders'); - $response->expects($this->never()) - ->method('getContent'); - $response->expects($this->never()) - ->method('__toString'); - $response->expects($this->never()) - ->method('getHeader'); - - $listener = new AuthListener(Client::AUTH_HTTP_PASSWORD, array('tokenOrLogin' => 'login', 'password' => 'mypasswd')); - $listener->postSend($request, $response); + $listener = new AuthListener('login', 'somepassphrase', Client::AUTH_HTTP_PASSWORD); + $listener->onRequestBeforeSend($this->getEventMock($request)); } /** @@ -112,19 +58,19 @@ public function shouldDoNothingForPostSend() */ public function shouldSetAuthBasicHeaderForAuthPassMethod() { - $expected = 'Basic '.base64_encode('login:mypasswd'); + $expected = 'Basic '.base64_encode('login2:pass42323'); - $request = $this->getMock('Buzz\Message\RequestInterface'); + $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); $request->expects($this->once()) - ->method('addHeader') - ->with('Authorization: '.$expected); + ->method('setHeader') + ->with('Authorization', $expected); $request->expects($this->once()) ->method('getHeader') ->with('Authorization') ->will($this->returnValue($expected)); - $listener = new AuthListener(Client::AUTH_HTTP_PASSWORD, array('tokenOrLogin' => 'login', 'password' => 'mypasswd')); - $listener->preSend($request); + $listener = new AuthListener('login2', 'pass42323', Client::AUTH_HTTP_PASSWORD); + $listener->onRequestBeforeSend($this->getEventMock($request)); $this->assertEquals($expected, $request->getHeader('Authorization')); } @@ -136,17 +82,17 @@ public function shouldSetAuthTokenHeaderForAuthPassMethod() { $expected = 'token test'; - $request = $this->getMock('Buzz\Message\RequestInterface'); + $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); $request->expects($this->once()) - ->method('addHeader') - ->with('Authorization: '.$expected); + ->method('setHeader') + ->with('Authorization', $expected); $request->expects($this->once()) ->method('getHeader') ->with('Authorization') ->will($this->returnValue($expected)); - $listener = new AuthListener(Client::AUTH_HTTP_TOKEN, array('tokenOrLogin' => 'test')); - $listener->preSend($request); + $listener = new AuthListener('test', null, Client::AUTH_HTTP_TOKEN); + $listener->onRequestBeforeSend($this->getEventMock($request)); $this->assertEquals($expected, $request->getHeader('Authorization')); } @@ -156,10 +102,10 @@ public function shouldSetAuthTokenHeaderForAuthPassMethod() */ public function shouldSetTokenInUrlForAuthUrlMethod() { - $request = new Request(Request::METHOD_GET, '/res'); + $request = new Request('GET', '/res'); - $listener = new AuthListener(Client::AUTH_URL_TOKEN, array('tokenOrLogin' => 'test')); - $listener->preSend($request); + $listener = new AuthListener('test', null, Client::AUTH_URL_TOKEN); + $listener->onRequestBeforeSend($this->getEventMock($request)); $this->assertEquals('/res?access_token=test', $request->getUrl()); } @@ -169,11 +115,24 @@ public function shouldSetTokenInUrlForAuthUrlMethod() */ public function shouldSetClientDetailsInUrlForAuthUrlMethod() { - $request = new Request(Request::METHOD_GET, '/res'); + $request = new Request('GET', '/res'); + + $listener = new AuthListener('clientId', 'clientSecret', Client::AUTH_URL_CLIENT_ID); + $listener->onRequestBeforeSend($this->getEventMock($request)); + + $this->assertEquals('/res?client_id=clientId&client_secret=clientSecret', $request->getUrl()); + } + + private function getEventMock($request = null) + { + $mock = $this->getMockBuilder('Guzzle\Common\Event')->getMock(); - $listener = new AuthListener(Client::AUTH_URL_CLIENT_ID, array('tokenOrLogin' => 'clientId', 'password' => 'clientSsecret')); - $listener->preSend($request); + if ($request) { + $mock->expects($this->any()) + ->method('offsetGet') + ->will($this->returnValue($request)); + } - $this->assertEquals('/res?client_id=clientId&client_secret=clientSsecret', $request->getUrl()); + return $mock; } } diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index 3a539343370..8277999ca6f 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -11,13 +11,13 @@ class ErrorListenerTest extends \PHPUnit_Framework_TestCase */ public function shouldPassIfResponseNotHaveErrorStatus() { - $response = $this->getMock('Github\HttpClient\Message\Response'); + $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(false)); $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->postSend($this->getMock('Buzz\Message\RequestInterface'), $response); + $listener->onRequestError($this->getEventMock($response)); } /** @@ -26,7 +26,7 @@ public function shouldPassIfResponseNotHaveErrorStatus() */ public function shouldFailWhenApiLimitWasExceed() { - $response = $this->getMock('Github\HttpClient\Message\Response'); + $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -36,7 +36,7 @@ public function shouldFailWhenApiLimitWasExceed() ->will($this->returnValue(0)); $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->postSend($this->getMock('Buzz\Message\RequestInterface'), $response); + $listener->onRequestError($this->getEventMock($response)); } /** @@ -45,7 +45,7 @@ public function shouldFailWhenApiLimitWasExceed() */ public function shouldNotPassWhenContentWasNotValidJson() { - $response = $this->getMock('Github\HttpClient\Message\Response'); + $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -58,7 +58,7 @@ public function shouldNotPassWhenContentWasNotValidJson() ->will($this->returnValue('fail')); $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->postSend($this->getMock('Buzz\Message\RequestInterface'), $response); + $listener->onRequestError($this->getEventMock($response)); } /** @@ -67,7 +67,7 @@ public function shouldNotPassWhenContentWasNotValidJson() */ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() { - $response = $this->getMock('Github\HttpClient\Message\Response'); + $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -83,7 +83,7 @@ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() ->will($this->returnValue(404)); $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->postSend($this->getMock('Buzz\Message\RequestInterface'), $response); + $listener->onRequestError($this->getEventMock($response)); } /** @@ -92,7 +92,7 @@ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() */ public function shouldNotPassWhen400IsSent() { - $response = $this->getMock('Github\HttpClient\Message\Response'); + $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -108,7 +108,7 @@ public function shouldNotPassWhen400IsSent() ->will($this->returnValue(400)); $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->postSend($this->getMock('Buzz\Message\RequestInterface'), $response); + $listener->onRequestError($this->getEventMock($response)); } /** @@ -130,7 +130,7 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) ) ); - $response = $this->getMock('Github\HttpClient\Message\Response'); + $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -146,7 +146,7 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) ->will($this->returnValue(422)); $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->postSend($this->getMock('Buzz\Message\RequestInterface'), $response); + $listener->onRequestError($this->getEventMock($response)); } public function getErrorCodesProvider() @@ -158,4 +158,21 @@ public function getErrorCodesProvider() array('already_exists'), ); } + + private function getEventMock($response) + { + $mock = $this->getMockBuilder('Guzzle\Common\Event')->getMock(); + + $request = $this->getMockBuilder('Guzzle\Http\Message\Request')->disableOriginalConstructor()->getMock(); + + $request->expects($this->any()) + ->method('getResponse') + ->will($this->returnValue($response)); + + $mock->expects($this->any()) + ->method('offsetGet') + ->will($this->returnValue($request)); + + return $mock; + } } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 7d37bb4a957..0603244758b 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -97,7 +97,7 @@ public function postFetch() ); // response mock - $responseMock = $this->getMock('Github\HttpClient\Message\Response'); + $responseMock = $this->getMock('Github\HttpClient\Message\Response', array(), array(200)); $responseMock ->expects($this->any()) ->method('getPagination') @@ -187,7 +187,7 @@ public function shouldHavePrevious() protected function getResponseMock(array $pagination) { // response mock - $responseMock = $this->getMock('Github\HttpClient\Message\Response'); + $responseMock = $this->getMock('Github\HttpClient\Message\Response', array(), array(200)); $responseMock ->expects($this->any()) ->method('getPagination') @@ -212,15 +212,7 @@ protected function getClientMock(HttpClientInterface $httpClient = null) protected function getHttpClientMock($responseMock = null) { // mock the client interface - $clientInterfaceMock = $this->getMock('Buzz\Client\ClientInterface', array('setTimeout', 'setVerifyPeer', 'send')); - $clientInterfaceMock - ->expects($this->any()) - ->method('setTimeout') - ->with(10); - $clientInterfaceMock - ->expects($this->any()) - ->method('setVerifyPeer') - ->with(false); + $clientInterfaceMock = $this->getMock('Guzzle\Http\Client', array('send')); $clientInterfaceMock ->expects($this->any()) ->method('send'); From 9b55adbdcaaf3b10385a42e55820d0d95c074513 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 31 Oct 2013 13:43:44 +0200 Subject: [PATCH 068/951] Fix CachedHttpKernel tests, fix events --- lib/Github/HttpClient/CachedHttpClient.php | 6 +-- lib/Github/HttpClient/HttpClient.php | 16 ++++-- .../Tests/HttpClient/CachedHttpClientTest.php | 52 +++++++------------ .../Tests/HttpClient/HttpClientTest.php | 33 +++++++----- 4 files changed, 55 insertions(+), 52 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index ba41d5ac3ea..cd847581762 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -61,11 +61,11 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', * * {@inheritdoc} */ - protected function createRequest($httpMethod, $url) + protected function createRequest($httpMethod, $path, $requestBody, array $headers = array()) { - $request = parent::createRequest($httpMethod, $url); + $request = parent::createRequest($httpMethod, $path, $requestBody, $headers = array()); - if ($modifiedAt = $this->getCache()->getModifiedSince($url)) { + if ($modifiedAt = $this->getCache()->getModifiedSince($path)) { $modifiedAt = new \DateTime('@'.$modifiedAt); $modifiedAt->setTimezone(new \DateTimeZone('GMT')); diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index f6fac9643ae..581b8827782 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -131,13 +131,11 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0) ; - $request = $this->client->createRequest($httpMethod, $path, array_merge($this->headers, $headers), $requestBody); + $request = $this->createRequest($httpMethod, $path, $requestBody, $headers); $request->addHeaders($headers); try { - $response = Response::fromMessage( - $this->client->send($request) - ); + $response = $this->createResponse($this->client->send($request)); } catch (\LogicException $e) { throw new ErrorException($e->getMessage()); } catch (\RuntimeException $e) { @@ -175,4 +173,14 @@ public function getLastResponse() { return $this->lastResponse; } + + protected function createRequest($httpMethod, $path, $requestBody, array $headers = array()) + { + return $this->client->createRequest($httpMethod, $path, array_merge($this->headers, $headers), $requestBody); + } + + protected function createResponse($response) + { + return Response::fromMessage($response); + } } diff --git a/test/Github/Tests/HttpClient/CachedHttpClientTest.php b/test/Github/Tests/HttpClient/CachedHttpClientTest.php index 1d92bd2f24a..3a39867b849 100644 --- a/test/Github/Tests/HttpClient/CachedHttpClientTest.php +++ b/test/Github/Tests/HttpClient/CachedHttpClientTest.php @@ -8,39 +8,30 @@ class CachedHttpClientTest extends HttpClientTest { /** - * test + * @test */ public function shouldCacheResponseAtFirstTime() { $cache = $this->getCacheMock(); + $response = new Response(200); - $httpClient = new TestCachedHttpClient( - array('base_url' => ''), - $this->getMock('Guzzle\Http\ClientInterface', array('send')) - ); + $httpClient = $this->getHttpClientMock($response); $httpClient->setCache($cache); - $cache->expects($this->once())->method('set')->with('test', new Response(200)); + $cache->expects($this->once())->method('set')->with('test', $response); $httpClient->get('test'); } /** - * test + * @test */ public function shouldGetCachedResponseWhileResourceNotModified() { - $client = $this->getMock('Guzzle\Http\ClientInterface', array('send')); - $client->expects($this->once())->method('send'); - $cache = $this->getCacheMock(); - $response = new Response(304); - $httpClient = new TestCachedHttpClient( - array('base_url' => ''), - $client - ); + $httpClient = $this->getHttpClientMock($response); $httpClient->setCache($cache); $httpClient->fakeResponse = $response; @@ -50,23 +41,15 @@ public function shouldGetCachedResponseWhileResourceNotModified() } /** - * test + * @test */ public function shouldRenewCacheWhenResourceHasChanged() { - $client = $this->getMock('Guzzle\Http\ClientInterface', array('send')); - $client->expects($this->once())->method('send'); - $cache = $this->getCacheMock(); - $response = new Response(200); - $httpClient = new TestCachedHttpClient( - array('base_url' => ''), - $client - ); + $httpClient = $this->getHttpClientMock($response); $httpClient->setCache($cache); - $httpClient->fakeResponse = $response; $cache->expects($this->once())->method('set')->with('test', $response); $cache->expects($this->once())->method('getModifiedSince')->with('test')->will($this->returnValue(1256953732)); @@ -78,14 +61,19 @@ public function getCacheMock() { return $this->getMock('Github\HttpClient\Cache\CacheInterface'); } -} - -class TestCachedHttpClient extends CachedHttpClient -{ - public $fakeResponse; - protected function createResponse() + private function getHttpClientMock($response) { - return $this->fakeResponse ?: new Response(200); + $mock = $this + ->getMockBuilder('Github\HttpClient\CachedHttpClient') + ->setConstructorArgs(array(array('base_url' => ''), $this->getBrowserMock())) + ->setMethods(array('createResponse')) + ->getMock(); + + $mock->expects($this->any()) + ->method('createResponse') + ->will($this->returnValue($response)); + + return $mock; } } diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index 6d09cba4a82..bd34dba7c04 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -41,15 +41,17 @@ public function shouldBeAbleToSetOption() public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { $client = new GuzzleClient(); + $listeners = $client->getEventDispatcher()->getListeners('request.before_send'); + $this->assertCount(1, $listeners); $httpClient = new TestHttpClient(array(), $client); $httpClient->authenticate($login, $password, $method); - $this->assertCount(1, $client->getEventDispatcher()->getListeners('request.create')); - $this->assertInstanceOf( - 'Github\HttpClient\Listener\AuthListener', - current(current($client->getEventDispatcher()->getListeners('request.create'))) - ); + $listeners = $client->getEventDispatcher()->getListeners('request.before_send'); + $this->assertCount(2, $listeners); + + $authListener = $listeners[1][0]; + $this->assertInstanceOf('Github\HttpClient\Listener\AuthListener', $authListener); } public function getAuthenticationFullData() @@ -88,8 +90,8 @@ public function shouldDoPOSTRequest() $client = $this->getBrowserMock(); $client->expects($this->once()) - ->method('send') - ->with($this->anything(), $this->isType('array'), '{"a":"b"}'); + ->method('createRequest') + ->with('POST', $path, $this->isType('array'), '{"a":"b"}'); $httpClient = new HttpClient(array(), $client); $httpClient->post($path, $parameters, $headers); @@ -103,10 +105,9 @@ public function shouldDoPOSTRequestWithoutContent() $path = '/some/path'; $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('send') - ->with($this->anything(), $this->isType('array'), $this->isEmpty()); + ->method('createRequest') + ->with('POST', $path, $this->isType('array')); $httpClient = new HttpClient(array(), $client); $httpClient->post($path); @@ -242,13 +243,19 @@ public function shouldThrowExceptionWhenApiIsExceeded() protected function getBrowserMock(array $methods = array()) { - return $this->getMock( + $mock = $this->getMock( 'Guzzle\Http\Client', array_merge( - array('send'), + array('send', 'createRequest'), $methods ) ); + + $mock->expects($this->any()) + ->method('createRequest') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\Request', array(), array('GET', 'some')))); + + return $mock; } } @@ -261,7 +268,7 @@ public function getOption($name, $default = null) public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - $request = $this->createRequest($httpMethod, $path); + $request = $this->client->createRequest($httpMethod, $path); return $this->client->send($request, $headers, $parameters); } From 390e21d9708c52927b864c180bf76f3447a9e405 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Sat, 2 Nov 2013 23:03:35 +0200 Subject: [PATCH 069/951] Replace Response with ResponseMediator --- lib/Github/Api/AbstractApi.php | 11 ++- .../HttpClient/Cache/CacheInterface.php | 2 +- .../HttpClient/Cache/FilesystemCache.php | 2 +- lib/Github/HttpClient/HttpClient.php | 13 +-- .../HttpClient/Listener/ErrorListener.php | 17 +--- lib/Github/HttpClient/Message/Response.php | 96 ------------------- .../HttpClient/Message/ResponseMediator.php | 50 ++++++++++ lib/Github/ResultPager.php | 5 +- .../HttpClient/Cache/FilesystemCacheTest.php | 2 +- .../Tests/HttpClient/CachedHttpClientTest.php | 39 ++++---- .../Tests/HttpClient/HttpClientTest.php | 7 +- .../HttpClient/Listener/ErrorListenerTest.php | 28 +++--- test/Github/Tests/Mock/TestResponse.php | 25 ++--- test/Github/Tests/ResultPagerTest.php | 41 +++++--- 14 files changed, 143 insertions(+), 195 deletions(-) delete mode 100644 lib/Github/HttpClient/Message/Response.php create mode 100644 lib/Github/HttpClient/Message/ResponseMediator.php diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 727f4e51824..7ea594e3bf5 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -3,6 +3,7 @@ namespace Github\Api; use Github\Client; +use Github\HttpClient\Message\ResponseMediator; /** * Abstract class for Api classes @@ -65,7 +66,7 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr } $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); - return $response->getContent(); + return ResponseMediator::getContent($response); } /** @@ -75,7 +76,7 @@ protected function post($path, array $parameters = array(), $requestHeaders = ar { $response = $this->client->getHttpClient()->post($path, $parameters, $requestHeaders); - return $response->getContent(); + return ResponseMediator::getContent($response); } /** @@ -85,7 +86,7 @@ protected function patch($path, array $parameters = array(), $requestHeaders = a { $response = $this->client->getHttpClient()->patch($path, $parameters, $requestHeaders); - return $response->getContent(); + return ResponseMediator::getContent($response); } /** @@ -95,7 +96,7 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr { $response = $this->client->getHttpClient()->put($path, $parameters, $requestHeaders); - return $response->getContent(); + return ResponseMediator::getContent($response); } /** @@ -105,6 +106,6 @@ protected function delete($path, array $parameters = array(), $requestHeaders = { $response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); - return $response->getContent(); + return ResponseMediator::getContent($response); } } diff --git a/lib/Github/HttpClient/Cache/CacheInterface.php b/lib/Github/HttpClient/Cache/CacheInterface.php index b1ada0e53d9..50fedd6e25b 100644 --- a/lib/Github/HttpClient/Cache/CacheInterface.php +++ b/lib/Github/HttpClient/Cache/CacheInterface.php @@ -2,7 +2,7 @@ namespace Github\HttpClient\Cache; -use Github\HttpClient\Message\Response; +use Guzzle\Http\Message\Response; /** * Caches github api responses diff --git a/lib/Github/HttpClient/Cache/FilesystemCache.php b/lib/Github/HttpClient/Cache/FilesystemCache.php index ad1f90821cf..e7c7588cd03 100644 --- a/lib/Github/HttpClient/Cache/FilesystemCache.php +++ b/lib/Github/HttpClient/Cache/FilesystemCache.php @@ -2,7 +2,7 @@ namespace Github\HttpClient\Cache; -use Github\HttpClient\Message\Response; +use Guzzle\Http\Message\Response; class FilesystemCache implements CacheInterface { diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 581b8827782..f8833b43d14 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -2,15 +2,15 @@ namespace Github\HttpClient; -use Github\HttpClient\Listener\AuthListener; -use Github\HttpClient\Listener\ErrorListener; use Guzzle\Http\Client as GuzzleClient; use Guzzle\Http\ClientInterface; use Guzzle\Http\Message\Request; +use Guzzle\Http\Message\Response; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; -use Github\HttpClient\Message\Response; +use Github\HttpClient\Listener\AuthListener; +use Github\HttpClient\Listener\ErrorListener; /** * Performs requests on GitHub API. API documentation should be self-explanatory. @@ -135,7 +135,7 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', $request->addHeaders($headers); try { - $response = $this->createResponse($this->client->send($request)); + $response = $this->client->send($request); } catch (\LogicException $e) { throw new ErrorException($e->getMessage()); } catch (\RuntimeException $e) { @@ -178,9 +178,4 @@ protected function createRequest($httpMethod, $path, $requestBody, array $header { return $this->client->createRequest($httpMethod, $path, array_merge($this->headers, $headers), $requestBody); } - - protected function createResponse($response) - { - return Response::fromMessage($response); - } } diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index c89592ad92c..2294cfbad35 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -2,10 +2,10 @@ namespace Github\HttpClient\Listener; +use Github\HttpClient\Message\ResponseMediator; use Guzzle\Common\Event; -use Guzzle\Http\Message\Response as GuzzleResponse; +use Guzzle\Http\Message\Response; -use Github\HttpClient\Message\Response; use Github\Exception\ApiLimitExceedException; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; @@ -36,7 +36,7 @@ public function onRequestError(Event $event) { /** @var $request \Guzzle\Http\Message\Request */ $request = $event['request']; - $response = $this->createResponse($request->getResponse()); + $response = $request->getResponse(); if ($response->isClientError() || $response->isServerError()) { $remaining = (string) $response->getHeader('X-RateLimit-Remaining'); @@ -45,7 +45,7 @@ public function onRequestError(Event $event) throw new ApiLimitExceedException($this->options['api_limit']); } - $content = $response->getContent(); + $content = ResponseMediator::getContent($response); if (is_array($content) && isset($content['message'])) { if (400 == $response->getStatusCode()) { throw new ErrorException($content['message'], 400); @@ -83,13 +83,4 @@ public function onRequestError(Event $event) throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); }; } - - protected function createResponse(GuzzleResponse $response) - { - if (!($response instanceof Response)) { - return Response::fromMessage($response); - } else { - return $response; - } - } } diff --git a/lib/Github/HttpClient/Message/Response.php b/lib/Github/HttpClient/Message/Response.php deleted file mode 100644 index d1359e4d658..00000000000 --- a/lib/Github/HttpClient/Message/Response.php +++ /dev/null @@ -1,96 +0,0 @@ -getParser('message')->parseResponse($message); - if (!$data) { - return false; - } - - $response = new static($data['code'], $data['headers'], $data['body']); - $response->setProtocol($data['protocol'], $data['version']) - ->setStatus($data['code'], $data['reason_phrase']); - - // Set the appropriate Content-Length if the one set is inaccurate (e.g. setting to X) - $contentLength = (string) $response->getHeader('Content-Length'); - $actualLength = strlen($data['body']); - if (strlen($data['body']) > 0 && $contentLength != $actualLength) { - $response->setHeader('Content-Length', $actualLength); - } - - return $response; - } - - /** - * {@inheritDoc} - */ - public function getContent() - { - $response = parent::getBody(true); - $content = json_decode($response, true); - - if (JSON_ERROR_NONE !== json_last_error()) { - return $response; - } - - return $content; - } - - /** - * @return array|null - */ - public function getPagination() - { - $header = $this->getHeader('Link'); - if (empty($header)) { - return null; - } - - $pagination = array(); - foreach (explode(',', $header) as $link) { - preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match); - - if (3 === count($match)) { - $pagination[$match[2]] = $match[1]; - } - } - - return $pagination; - } - - /** - * {@inheritDoc} - */ - public function getApiLimit() - { - $header = $this->getHeader('X-RateLimit-Remaining'); - if (!empty($header)) { - $this->remainingCalls = $header; - } - - if (null !== $this->remainingCalls && 1 > $this->remainingCalls) { - throw new ApiLimitExceedException($this->getHeader('X-RateLimit-Limit')); - } - } -} diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php new file mode 100644 index 00000000000..72fe7c7129e --- /dev/null +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -0,0 +1,50 @@ +getBody(true); + $content = json_decode($body, true); + + if (JSON_ERROR_NONE !== json_last_error()) { + return $body; + } + + return $content; + } + + public static function getPagination(Response $response) + { + $header = $response->getHeader('Link'); + + if (empty($header)) { + return null; + } + + $pagination = array(); + foreach (explode(',', $header) as $link) { + preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match); + + if (3 === count($match)) { + $pagination[$match[2]] = $match[1]; + } + } + + return $pagination; + } + + public static function getApiLimit(Response $response) + { + $remainingCalls = $response->getHeader('X-RateLimit-Remaining'); + + if (null !== $remainingCalls && 1 > $remainingCalls) { + throw new ApiLimitExceedException($remainingCalls); + } + } +} diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index ab4664c4c8d..7483194ba3b 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -3,6 +3,7 @@ namespace Github; use Github\Api\ApiInterface; +use Github\HttpClient\Message\ResponseMediator; /** * Pager class for supporting pagination in github classes @@ -88,7 +89,7 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = array() */ public function postFetch() { - $this->pagination = $this->client->getHttpClient()->getLastResponse()->getPagination(); + $this->pagination = ResponseMediator::getPagination($this->client->getHttpClient()->getLastResponse()); } /** @@ -156,7 +157,7 @@ protected function get($key) $result = $this->client->getHttpClient()->get($this->pagination[$key]); $this->postFetch(); - return $result->getContent(); + return ResponseMediator::getContent($result); } } } diff --git a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php index 45a038bcc5f..54efdd49ba4 100644 --- a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php +++ b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php @@ -2,7 +2,7 @@ namespace Github\Tests\HttpClient\Cache; -use Github\HttpClient\Message\Response; +use Guzzle\Http\Message\Response; use Github\HttpClient\Cache\FilesystemCache; class FilesystemCacheTest extends \PHPUnit_Framework_TestCase diff --git a/test/Github/Tests/HttpClient/CachedHttpClientTest.php b/test/Github/Tests/HttpClient/CachedHttpClientTest.php index 3a39867b849..477b3e2eab3 100644 --- a/test/Github/Tests/HttpClient/CachedHttpClientTest.php +++ b/test/Github/Tests/HttpClient/CachedHttpClientTest.php @@ -3,7 +3,7 @@ namespace Github\Tests\HttpClient; use Github\HttpClient\CachedHttpClient; -use Github\HttpClient\Message\Response; +use Guzzle\Http\Message\Response; class CachedHttpClientTest extends HttpClientTest { @@ -15,11 +15,15 @@ public function shouldCacheResponseAtFirstTime() $cache = $this->getCacheMock(); $response = new Response(200); - $httpClient = $this->getHttpClientMock($response); + $client = $this->getBrowserMock(); + $client->expects($this->once()) + ->method('send') + ->will($this->returnValue($response)); + + $httpClient = new CachedHttpClient(array('base_url' => ''), $client); $httpClient->setCache($cache); $cache->expects($this->once())->method('set')->with('test', $response); - $httpClient->get('test'); } @@ -31,7 +35,12 @@ public function shouldGetCachedResponseWhileResourceNotModified() $cache = $this->getCacheMock(); $response = new Response(304); - $httpClient = $this->getHttpClientMock($response); + $client = $this->getBrowserMock(); + $client->expects($this->once()) + ->method('send') + ->will($this->returnValue($response)); + + $httpClient = new CachedHttpClient(array('base_url' => ''), $client); $httpClient->setCache($cache); $httpClient->fakeResponse = $response; @@ -48,7 +57,12 @@ public function shouldRenewCacheWhenResourceHasChanged() $cache = $this->getCacheMock(); $response = new Response(200); - $httpClient = $this->getHttpClientMock($response); + $client = $this->getBrowserMock(); + $client->expects($this->once()) + ->method('send') + ->will($this->returnValue($response)); + + $httpClient = new CachedHttpClient(array('base_url' => ''), $client); $httpClient->setCache($cache); $cache->expects($this->once())->method('set')->with('test', $response); @@ -61,19 +75,4 @@ public function getCacheMock() { return $this->getMock('Github\HttpClient\Cache\CacheInterface'); } - - private function getHttpClientMock($response) - { - $mock = $this - ->getMockBuilder('Github\HttpClient\CachedHttpClient') - ->setConstructorArgs(array(array('base_url' => ''), $this->getBrowserMock())) - ->setMethods(array('createResponse')) - ->getMock(); - - $mock->expects($this->any()) - ->method('createResponse') - ->will($this->returnValue($response)); - - return $mock; - } } diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index bd34dba7c04..85e20a2eb98 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -4,7 +4,8 @@ use Github\Client; use Github\HttpClient\HttpClient; -use Github\HttpClient\Message\Response; +use Github\HttpClient\Message\ResponseMediator; +use Guzzle\Http\Message\Response; use Guzzle\Plugin\Mock\MockPlugin; use Guzzle\Http\Client as GuzzleClient; @@ -189,7 +190,7 @@ public function shouldHandlePagination() $httpClient = new HttpClient(array(), $client); $httpClient->request($path, $parameters, 'HEAD', $headers); - $this->assertEquals(array('page2' => 'page1', 'page4' => 'page3'), $response->getPagination()); + $this->assertEquals(array('page2' => 'page1', 'page4' => 'page3'), ResponseMediator::getPagination($response)); } /** @@ -201,7 +202,7 @@ public function shouldAllowToReturnRawContent() $parameters = array('a' => 'b'); $headers = array('c' => 'd'); - $message = $this->getMock('Github\HttpClient\Message\Response', array(), array(200)); + $message = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); $message->expects($this->once()) ->method('getBody') ->will($this->returnValue('Just raw context')); diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index 8277999ca6f..8bb0bfa177f 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -11,7 +11,7 @@ class ErrorListenerTest extends \PHPUnit_Framework_TestCase */ public function shouldPassIfResponseNotHaveErrorStatus() { - $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(false)); @@ -26,7 +26,7 @@ public function shouldPassIfResponseNotHaveErrorStatus() */ public function shouldFailWhenApiLimitWasExceed() { - $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -45,7 +45,7 @@ public function shouldFailWhenApiLimitWasExceed() */ public function shouldNotPassWhenContentWasNotValidJson() { - $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -54,7 +54,7 @@ public function shouldNotPassWhenContentWasNotValidJson() ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); $response->expects($this->once()) - ->method('getContent') + ->method('getBody') ->will($this->returnValue('fail')); $listener = new ErrorListener(array('api_limit' => 5000)); @@ -67,7 +67,7 @@ public function shouldNotPassWhenContentWasNotValidJson() */ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() { - $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -76,8 +76,8 @@ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); $response->expects($this->once()) - ->method('getContent') - ->will($this->returnValue(array('message' => 'test'))); + ->method('getBody') + ->will($this->returnValue(json_encode(array('message' => 'test')))); $response->expects($this->any()) ->method('getStatusCode') ->will($this->returnValue(404)); @@ -92,7 +92,7 @@ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() */ public function shouldNotPassWhen400IsSent() { - $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -101,8 +101,8 @@ public function shouldNotPassWhen400IsSent() ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); $response->expects($this->once()) - ->method('getContent') - ->will($this->returnValue(array('message' => 'test'))); + ->method('getBody') + ->will($this->returnValue(json_encode(array('message' => 'test')))); $response->expects($this->any()) ->method('getStatusCode') ->will($this->returnValue(400)); @@ -118,7 +118,7 @@ public function shouldNotPassWhen400IsSent() */ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) { - $content = array( + $content = json_encode(array( 'message' => 'Validation Failed', 'errors' => array( array( @@ -128,9 +128,9 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) 'resource' => 'fake' ) ) - ); + )); - $response = $this->getMockBuilder('Github\HttpClient\Message\Response')->disableOriginalConstructor()->getMock(); + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); @@ -139,7 +139,7 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); $response->expects($this->once()) - ->method('getContent') + ->method('getBody') ->will($this->returnValue($content)); $response->expects($this->any()) ->method('getStatusCode') diff --git a/test/Github/Tests/Mock/TestResponse.php b/test/Github/Tests/Mock/TestResponse.php index 3cac1212d70..9d102844138 100644 --- a/test/Github/Tests/Mock/TestResponse.php +++ b/test/Github/Tests/Mock/TestResponse.php @@ -2,13 +2,15 @@ namespace Github\Tests\Mock; -class TestResponse +use Guzzle\Http\Message\Response; + +class TestResponse extends Response { protected $loopCount; protected $content; - public function __construct( $loopCount, array $content = array() ) + public function __construct($loopCount, array $content = array()) { $this->loopCount = $loopCount; $this->content = $content; @@ -17,28 +19,21 @@ public function __construct( $loopCount, array $content = array() ) /** * {@inheritDoc} */ - public function getContent() + public function getBody($asString = false) { - return $this->content; + return json_encode($this->content); } - /** - * @return array|null - */ - public function getPagination() + public function getHeader($header = null) { if ($this->loopCount) { - $returnArray = array( - 'next' => 'http://github.com/' . $this->loopCount - ); + $header = sprintf('; rel="next"', $this->loopCount); } else { - $returnArray = array( - 'prev' => 'http://github.com/prev' - ); + $header = '; rel="prev"'; } $this->loopCount--; - return $returnArray; + return $header; } } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 0603244758b..df7f0e11c85 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -60,10 +60,10 @@ public function shouldGetAllResults() */ public function shouldGetSomeResults() { - $pagination = array('next' => 'http://github.com/next'); - $resultContent = 'organization test'; + $pagination = array('next' => 'http://github.com/next'); + $resultContent = 'organization test'; - $responseMock = $this->getResponseMock($pagination); + $responseMock = $this->getResponseMock('; rel="next"'); $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); @@ -89,6 +89,13 @@ public function shouldGetSomeResults() */ public function postFetch() { + $header = <<; rel="first", +; rel="next", +; rel="prev", +; rel="last", +TEXT; + $pagination = array( 'first' => 'http://github.com', 'next' => 'http://github.com', @@ -97,11 +104,12 @@ public function postFetch() ); // response mock - $responseMock = $this->getMock('Github\HttpClient\Message\Response', array(), array(200)); + $responseMock = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); $responseMock ->expects($this->any()) - ->method('getPagination') - ->will($this->returnValue($pagination)); + ->method('getHeader') + ->with('Link') + ->will($this->returnValue($header)); $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); @@ -119,18 +127,20 @@ public function postFetch() */ public function fetchNext() { + $header = '; rel="next"'; $pagination = array('next' => 'http://github.com/next'); $resultContent = 'fetch test'; - $responseMock = $this->getResponseMock($pagination); + $responseMock = $this->getResponseMock($header); $responseMock ->expects($this->once()) - ->method('getContent') + ->method('getBody') ->will($this->returnValue($resultContent)); // Expected 2 times, 1 for setup and 1 for the actual test $responseMock ->expects($this->exactly(2)) - ->method('getPagination'); + ->method('getHeader') + ->with('Link'); $httpClient = $this->getHttpClientMock($responseMock); @@ -155,7 +165,7 @@ public function fetchNext() */ public function shouldHaveNext() { - $responseMock = $this->getResponseMock(array('next' => 'http://github.com/next')); + $responseMock = $this->getResponseMock('; rel="next"'); $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); @@ -173,7 +183,7 @@ public function shouldHaveNext() */ public function shouldHavePrevious() { - $responseMock = $this->getResponseMock(array('prev' => 'http://github.com/previous')); + $responseMock = $this->getResponseMock('; rel="prev"'); $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); @@ -184,14 +194,15 @@ public function shouldHavePrevious() $this->assertEquals($paginator->hasNext(), false); } - protected function getResponseMock(array $pagination) + protected function getResponseMock($header) { // response mock - $responseMock = $this->getMock('Github\HttpClient\Message\Response', array(), array(200)); + $responseMock = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); $responseMock ->expects($this->any()) - ->method('getPagination') - ->will($this->returnValue($pagination)); + ->method('getHeader') + ->with('Link') + ->will($this->returnValue($header)); return $responseMock; } From 1f644eb7da1af9fe3eae5cf5459feda9c7c10a24 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Sun, 3 Nov 2013 16:50:51 +0200 Subject: [PATCH 070/951] Fix base url call, closes #82 --- lib/Github/HttpClient/HttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index f8833b43d14..bcc5ac45f35 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -43,7 +43,7 @@ class HttpClient implements HttpClientInterface public function __construct(array $options = array(), ClientInterface $client = null) { $this->options = array_merge($this->options, $options); - $client = $client ?: new GuzzleClient($options['base_url'], $this->options); + $client = $client ?: new GuzzleClient($this->options['base_url'], $this->options); $this->client = $client; $this->addListener('request.error', array(new ErrorListener($this->options), 'onRequestError')); From 694759070693bf94852a62dc40155add88d42b3b Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Tue, 5 Nov 2013 22:16:15 +0200 Subject: [PATCH 071/951] Change the way GET request is build, fix pagination parameter --- lib/Github/HttpClient/CachedHttpClient.php | 4 +-- lib/Github/HttpClient/HttpClient.php | 28 +++++++++++++----- .../Tests/Functional/ResultPagerTest.php | 29 +++++++++++++++++++ test/Github/Tests/Functional/TestCase.php | 1 + 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 test/Github/Tests/Functional/ResultPagerTest.php diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index cd847581762..699afe0ee01 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -61,9 +61,9 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', * * {@inheritdoc} */ - protected function createRequest($httpMethod, $path, $requestBody, array $headers = array()) + protected function createRequest($httpMethod, $path, array $parameters = array(), array $headers = array()) { - $request = parent::createRequest($httpMethod, $path, $requestBody, $headers = array()); + $request = parent::createRequest($httpMethod, $path, $parameters, $headers = array()); if ($modifiedAt = $this->getCache()->getModifiedSince($path)) { $modifiedAt = new \DateTime('@'.$modifiedAt); diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index bcc5ac45f35..88c2b25bf56 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -43,7 +43,7 @@ class HttpClient implements HttpClientInterface public function __construct(array $options = array(), ClientInterface $client = null) { $this->options = array_merge($this->options, $options); - $client = $client ?: new GuzzleClient($this->options['base_url'], $this->options); + $client = $client ?: new GuzzleClient($this->options['base_url'], $this->options); $this->client = $client; $this->addListener('request.error', array(new ErrorListener($this->options), 'onRequestError')); @@ -127,11 +127,7 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { - $requestBody = count($parameters) === 0 - ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0) - ; - - $request = $this->createRequest($httpMethod, $path, $requestBody, $headers); + $request = $this->createRequest($httpMethod, $path, $parameters, $headers); $request->addHeaders($headers); try { @@ -174,8 +170,24 @@ public function getLastResponse() return $this->lastResponse; } - protected function createRequest($httpMethod, $path, $requestBody, array $headers = array()) + protected function createRequest($httpMethod, $path, array $parameters = array(), array $headers = array()) { - return $this->client->createRequest($httpMethod, $path, array_merge($this->headers, $headers), $requestBody); + if ('GET' !== $httpMethod) { + $requestBody = count($parameters) === 0 + ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0) + ; + $options = array(); + } else { + $requestBody = null; + $options = array('query' => $parameters); + } + + return $this->client->createRequest( + $httpMethod, + $path, + array_merge($this->headers, $headers), + $requestBody, + $options + ); } } diff --git a/test/Github/Tests/Functional/ResultPagerTest.php b/test/Github/Tests/Functional/ResultPagerTest.php new file mode 100644 index 00000000000..9c67b39d25a --- /dev/null +++ b/test/Github/Tests/Functional/ResultPagerTest.php @@ -0,0 +1,29 @@ +client->api('user'); + $repositoriesApi->setPerPage(10); + + $pager = new ResultPager($this->client); + + $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); + $this->assertCount(10, $repositories); + + $repositoriesApi->setPerPage(20); + $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); + $this->assertCount(20, $repositories); + } +} diff --git a/test/Github/Tests/Functional/TestCase.php b/test/Github/Tests/Functional/TestCase.php index 3b80ad91e50..ef51c1a52c9 100644 --- a/test/Github/Tests/Functional/TestCase.php +++ b/test/Github/Tests/Functional/TestCase.php @@ -15,6 +15,7 @@ class TestCase extends \PHPUnit_Framework_TestCase public function setUp() { + // You have to specify authentication here to run full suite $client = new Client(); try { From 7f2249e1868368b3de49b5e7dfbbe286f5dd756b Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Wed, 6 Nov 2013 05:06:13 +0200 Subject: [PATCH 072/951] Remove manifold header as Releases api is official now --- lib/Github/Api/Repository/Assets.php | 10 ---------- lib/Github/Api/Repository/Releases.php | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index a39f4057c7d..5a1137b35d6 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -11,16 +11,6 @@ */ class Assets extends AbstractApi { - /** - * @deprecated Will be removed as soon as gh releases api gets stable - */ - public function configure() - { - $this->client->setHeaders(array( - 'Accept: application/vnd.github.manifold-preview' - )); - } - /** * Get all release's assets in selected repository * GET /repos/:owner/:repo/releases/:id/assets diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index d276084d75d..a2ee5201ffe 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -12,16 +12,6 @@ */ class Releases extends AbstractApi { - /** - * @deprecated Will be removed as soon as gh releases api gets stable - */ - public function configure() - { - $this->client->setHeaders(array( - 'Accept: application/vnd.github.manifold-preview' - )); - } - /** * List releases in selected repository * From c2751e5724dbbbbb0cdd545ab66c7b148059ac3e Mon Sep 17 00:00:00 2001 From: Gianni Moschini Date: Fri, 8 Nov 2013 12:41:10 +0000 Subject: [PATCH 073/951] Fix Git Show path call --- lib/Github/Api/GitData/Commits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GitData/Commits.php b/lib/Github/Api/GitData/Commits.php index ab6a07ecff5..1c161e1d790 100644 --- a/lib/Github/Api/GitData/Commits.php +++ b/lib/Github/Api/GitData/Commits.php @@ -13,7 +13,7 @@ class Commits extends AbstractApi { public function show($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits/'.rawurlencode($sha)); } public function create($username, $repository, array $params) From 782b02d735c60a6355e849ffdfc02da43f519449 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Sat, 9 Nov 2013 01:13:48 +0200 Subject: [PATCH 074/951] Fix last PRs failing test --- test/Github/Tests/Api/GitData/CommitsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/GitData/CommitsTest.php b/test/Github/Tests/Api/GitData/CommitsTest.php index 732debffd16..a665d90a495 100644 --- a/test/Github/Tests/Api/GitData/CommitsTest.php +++ b/test/Github/Tests/Api/GitData/CommitsTest.php @@ -16,7 +16,7 @@ public function shouldShowCommitUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/commits/123') + ->with('repos/KnpLabs/php-github-api/git/commits/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); From 9f65965e706b2718d082caf246eb1119d091d53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Garn=C3=A6s?= Date: Fri, 15 Nov 2013 16:15:45 +0100 Subject: [PATCH 075/951] Do not report validation errors as rate limits When receiving a validation error (as in #86) there is no `X-RateLimit-Remaining` header included with the response. That is quite confusing. Here `$remaining` when cast to a string is set to "" (empty string). This does not strictly equal null and thus a `ApiLimitExceedException` is thrown. This change fixes this behavior. cURL requests/responses: ``` # Request: POST /repos/kasperg/release-asset-test/releases/92217/assets?name=test2.txt HTTP/1.1 Host: uploads.github.com 0: Accept: application/vnd.github.v3+json 1: User-Agent: php-github-api (http://github.com/KnpLabs/php-github-api) Content-Type: text/plain, text/plain User-Agent: Guzzle/3.7.4 curl/7.30.0 PHP/5.3.27 Authorization: Basic a2FzcGVyZzpwaW5rbW9ucw== Content-Length: 14 {"body":"122"} # Response: HTTP/1.1 422 status code 422 Cache-Control: no-cache Content-Length: 214 Content-Type: application/json; charset=utf-8 X-Content-Type-Options: nosniff X-Github-Media-Type: github.beta; format=json X-Github-Request-Id: a6633df9-4dff-11e3-800a-0be28f962e12 Date: Fri, 15 Nov 2013 14:10:15 GMT {"message":"Validation Failed","request_id":"a6633df9-4dff-11e3-800a-0be28f962e12","documentation_url":"http://developer.github.com/v3","errors":[{"resource":"ReleaseAsset","code":"already_exists","field":"name"}]} ``` --- lib/Github/HttpClient/Listener/ErrorListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 2294cfbad35..60cbc5a80fd 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -41,7 +41,7 @@ public function onRequestError(Event $event) if ($response->isClientError() || $response->isServerError()) { $remaining = (string) $response->getHeader('X-RateLimit-Remaining'); - if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getResource(), 1, 10)) { + if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getResource(), 1, 10)) { throw new ApiLimitExceedException($this->options['api_limit']); } From 5b34368f0ca8fdc3403707db62746c5e587ae9ea Mon Sep 17 00:00:00 2001 From: Kasper Garnaes Date: Sun, 17 Nov 2013 12:59:59 +0100 Subject: [PATCH 076/951] Refactored HttpClient to send a raw request body instead of only JSON encoded parameters. This is needed to support Asset creation where the request body must be the content of the asset. This involves the following changes - Updated HttpClient methods to accept an untyped body instead of an array of parameters - Moved JSON encoding to AbstractApi and updated documentation accordingly - Updated test cases --- lib/Github/Api/AbstractApi.php | 85 +++++++++++++++++-- lib/Github/HttpClient/CachedHttpClient.php | 8 +- lib/Github/HttpClient/HttpClient.php | 36 +++----- lib/Github/HttpClient/HttpClientInterface.php | 23 ++--- test/Github/Tests/Api/AbstractApiTest.php | 8 ++ test/Github/Tests/Api/TestCase.php | 2 +- .../Tests/HttpClient/HttpClientTest.php | 30 +++---- test/Github/Tests/Mock/TestHttpClient.php | 6 +- 8 files changed, 132 insertions(+), 66 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 7ea594e3bf5..48ee8405d35 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -57,7 +57,12 @@ public function setPerPage($perPage) } /** - * {@inheritDoc} + * Send a GET request with query parameters. + * + * @param string $path Request path. + * @param array $parameters GET parameters. + * @param array $requestHeaders Request Headers. + * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ protected function get($path, array $parameters = array(), $requestHeaders = array()) { @@ -70,42 +75,104 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr } /** - * {@inheritDoc} + * Send a POST request with JSON-encoded parameters. + * + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function post($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->post($path, $parameters, $requestHeaders); + return $this->postRaw( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); + } + + /** + * Send a POST request with raw data. + * + * @param string $path Request path. + * @param $body Request body. + * @param array $requestHeaders Request headers. + * @return \Guzzle\Http\EntityBodyInterface|mixed|string + */ + protected function postRaw($path, $body, $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->post( + $path, + $body, + $requestHeaders + ); return ResponseMediator::getContent($response); } + /** - * {@inheritDoc} + * Send a PATCH request with JSON-encoded parameters. + * + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function patch($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->patch($path, $parameters, $requestHeaders); + $response = $this->client->getHttpClient()->patch( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); return ResponseMediator::getContent($response); } + /** - * {@inheritDoc} + * Send a PUT request with JSON-encoded parameters. + * + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function put($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->put($path, $parameters, $requestHeaders); + $response = $this->client->getHttpClient()->put( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); return ResponseMediator::getContent($response); } + /** - * {@inheritDoc} + * Send a DELETE request with JSON-encoded parameters. + * + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function delete($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); + $response = $this->client->getHttpClient()->delete( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); return ResponseMediator::getContent($response); } + + /** + * Create a JSON encoded version of an array of parameters. + * + * @param $parameters Request parameters + * @return null|string + */ + protected function createJsonBody(array $parameters) { + return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0); + } } diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 699afe0ee01..e3f777e4e7e 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -42,9 +42,9 @@ public function setCache(CacheInterface $cache) /** * {@inheritdoc} */ - public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) + public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { - $response = parent::request($path, $parameters, $httpMethod, $headers); + $response = parent::request($path, $body, $httpMethod, $headers, $options); $key = trim($this->options['base_url'].$path, '/'); if (304 == $response->getStatusCode()) { @@ -61,9 +61,9 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET', * * {@inheritdoc} */ - protected function createRequest($httpMethod, $path, array $parameters = array(), array $headers = array()) + protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) { - $request = parent::createRequest($httpMethod, $path, $parameters, $headers = array()); + $request = parent::createRequest($httpMethod, $path, $body, $headers = array(), $options); if ($modifiedAt = $this->getCache()->getModifiedSince($path)) { $modifiedAt = new \DateTime('@'.$modifiedAt); diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 88c2b25bf56..068f411230f 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -87,47 +87,47 @@ public function addListener($eventName, $listener) */ public function get($path, array $parameters = array(), array $headers = array()) { - return $this->request($path, $parameters, 'GET', $headers); + return $this->request($path, null, 'GET', $headers, array('query' => $parameters)); } /** * {@inheritDoc} */ - public function post($path, array $parameters = array(), array $headers = array()) + public function post($path, $body = null, array $headers = array()) { - return $this->request($path, $parameters, 'POST', $headers); + return $this->request($path, $body, 'POST', $headers); } /** * {@inheritDoc} */ - public function patch($path, array $parameters = array(), array $headers = array()) + public function patch($path, $body = null, array $headers = array()) { - return $this->request($path, $parameters, 'PATCH', $headers); + return $this->request($path, $body, 'PATCH', $headers); } /** * {@inheritDoc} */ - public function delete($path, array $parameters = array(), array $headers = array()) + public function delete($path, $body = null, array $headers = array()) { - return $this->request($path, $parameters, 'DELETE', $headers); + return $this->request($path, $body, 'DELETE', $headers); } /** * {@inheritDoc} */ - public function put($path, array $parameters = array(), array $headers = array()) + public function put($path, $body, array $headers = array()) { - return $this->request($path, $parameters, 'PUT', $headers); + return $this->request($path, $body, 'PUT', $headers); } /** * {@inheritDoc} */ - public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) + public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { - $request = $this->createRequest($httpMethod, $path, $parameters, $headers); + $request = $this->createRequest($httpMethod, $path, $body, $headers, $options); $request->addHeaders($headers); try { @@ -170,23 +170,13 @@ public function getLastResponse() return $this->lastResponse; } - protected function createRequest($httpMethod, $path, array $parameters = array(), array $headers = array()) + protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) { - if ('GET' !== $httpMethod) { - $requestBody = count($parameters) === 0 - ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0) - ; - $options = array(); - } else { - $requestBody = null; - $options = array('query' => $parameters); - } - return $this->client->createRequest( $httpMethod, $path, array_merge($this->headers, $headers), - $requestBody, + $body, $options ); } diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php index 09ee8d11708..d6fd78dd2bb 100644 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ b/lib/Github/HttpClient/HttpClientInterface.php @@ -26,58 +26,59 @@ public function get($path, array $parameters = array(), array $headers = array() * Send a POST request * * @param string $path Request path - * @param array $parameters POST Parameters + * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * * @return array Data */ - public function post($path, array $parameters = array(), array $headers = array()); + public function post($path, $body = null, array $headers = array()); /** * Send a PATCH request * * @param string $path Request path - * @param array $parameters PATCH Parameters + * @param mixed $body Reuqest body * @param array $headers Reconfigure the request headers for this call only * + * @internal param array $parameters Request body * @return array Data */ - public function patch($path, array $parameters = array(), array $headers = array()); + public function patch($path, $body = null, array $headers = array()); /** * Send a PUT request * * @param string $path Request path - * @param array $parameters PUT Parameters + * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * * @return array Data */ - public function put($path, array $parameters = array(), array $headers = array()); + public function put($path, $body, array $headers = array()); /** * Send a DELETE request * * @param string $path Request path - * @param array $parameters DELETE Parameters + * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * * @return array Data */ - public function delete($path, array $parameters = array(), array $headers = array()); + public function delete($path, $body = null, array $headers = array()); /** * Send a request to the server, receive a response, * decode the response and returns an associative array * - * @param string $path Request API path - * @param array $parameters Parameters + * @param string $path Request path + * @param mixed $body Request body * @param string $httpMethod HTTP method to use * @param array $headers Request headers * * @return array Data */ - public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()); + public function request($path, $body, $httpMethod = 'GET', array $headers = array()); /** * Change an option value. diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index a48b28775f1..7dff2e0dd53 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -161,6 +161,14 @@ public function post($path, array $parameters = array(), $requestHeaders = array return $this->client->getHttpClient()->post($path, $parameters, $requestHeaders); } + /** + * {@inheritDoc} + */ + public function postRaw($path, $body, $requestHeaders = array()) + { + return $this->client->getHttpClient()->post($path, $body, $requestHeaders); + } + /** * {@inheritDoc} */ diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 81e7635939f..b96f0e43bbb 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -19,7 +19,7 @@ protected function getApiMock() $client->setHttpClient($mock); return $this->getMockBuilder($this->getApiClass()) - ->setMethods(array('get', 'post', 'patch', 'delete', 'put')) + ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put')) ->setConstructorArgs(array($client)) ->getMock(); } diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index 85e20a2eb98..cb83e9af96d 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -86,16 +86,16 @@ public function shouldDoGETRequest() public function shouldDoPOSTRequest() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $body = 'a = b'; $headers = array('c' => 'd'); $client = $this->getBrowserMock(); $client->expects($this->once()) ->method('createRequest') - ->with('POST', $path, $this->isType('array'), '{"a":"b"}'); + ->with('POST', $path, $this->isType('array'), $body); $httpClient = new HttpClient(array(), $client); - $httpClient->post($path, $parameters, $headers); + $httpClient->post($path, $body, $headers); } /** @@ -120,13 +120,13 @@ public function shouldDoPOSTRequestWithoutContent() public function shouldDoPATCHRequest() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $body = 'a = b'; $headers = array('c' => 'd'); $client = $this->getBrowserMock(); $httpClient = new HttpClient(array(), $client); - $httpClient->patch($path, $parameters, $headers); + $httpClient->patch($path, $body, $headers); } /** @@ -135,13 +135,13 @@ public function shouldDoPATCHRequest() public function shouldDoDELETERequest() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $body = 'a = b'; $headers = array('c' => 'd'); $client = $this->getBrowserMock(); $httpClient = new HttpClient(array(), $client); - $httpClient->delete($path, $parameters, $headers); + $httpClient->delete($path, $body, $headers); } /** @@ -164,13 +164,13 @@ public function shouldDoPUTRequest() public function shouldDoCustomRequest() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $body = 'a = b'; $options = array('c' => 'd'); $client = $this->getBrowserMock(); $httpClient = new HttpClient(array(), $client); - $httpClient->request($path, $parameters, 'HEAD', $options); + $httpClient->request($path, $body, 'HEAD', $options); } /** @@ -179,7 +179,7 @@ public function shouldDoCustomRequest() public function shouldHandlePagination() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $body = 'a = b'; $headers = array('c' => 'd'); $response = new Response(200); @@ -188,7 +188,7 @@ public function shouldHandlePagination() $client = $this->getBrowserMock(); $httpClient = new HttpClient(array(), $client); - $httpClient->request($path, $parameters, 'HEAD', $headers); + $httpClient->request($path, $body, 'HEAD', $headers); $this->assertEquals(array('page2' => 'page1', 'page4' => 'page3'), ResponseMediator::getPagination($response)); } @@ -199,7 +199,7 @@ public function shouldHandlePagination() public function shouldAllowToReturnRawContent() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $parameters = array('a = b'); $headers = array('c' => 'd'); $message = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); @@ -226,7 +226,7 @@ public function shouldAllowToReturnRawContent() public function shouldThrowExceptionWhenApiIsExceeded() { $path = '/some/path'; - $parameters = array('a' => 'b'); + $parameters = array('a = b'); $headers = array('c' => 'd'); $response = new Response(403); @@ -267,10 +267,10 @@ public function getOption($name, $default = null) return isset($this->options[$name]) ? $this->options[$name] : $default; } - public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) + public function request($path, $body, $httpMethod = 'GET', array $headers = array(), array $options = array()) { $request = $this->client->createRequest($httpMethod, $path); - return $this->client->send($request, $headers, $parameters); + return $this->client->send($request); } } diff --git a/test/Github/Tests/Mock/TestHttpClient.php b/test/Github/Tests/Mock/TestHttpClient.php index 7bef80defb7..7b52d8807cc 100644 --- a/test/Github/Tests/Mock/TestHttpClient.php +++ b/test/Github/Tests/Mock/TestHttpClient.php @@ -38,12 +38,12 @@ public function get($path, array $parameters = array(), array $headers = array() $this->requests['get'][] = $path; } - public function post($path, array $parameters = array(), array $headers = array()) + public function post($path, $body = null, array $headers = array()) { $this->requests['post'][] = $path; } - public function patch($path, array $parameters = array(), array $headers = array()) + public function patch($path, $body = null, array $headers = array()) { $this->requests['patch'][] = $path; } @@ -53,7 +53,7 @@ public function put($path, array $options = array(), array $headers = array()) $this->requests['put'][] = $path; } - public function delete($path, array $parameters = array(), array $headers = array()) + public function delete($path, $body = null, array $headers = array()) { $this->requests['delete'][] = $path; } From bad663dc8ce73557bba177b3bcdedfa58e7c5868 Mon Sep 17 00:00:00 2001 From: Kasper Garnaes Date: Wed, 13 Nov 2013 11:03:36 +0100 Subject: [PATCH 077/951] Add support for asset creation Added coresponding unit test for PHP 5.3.4 or newer. SSL extensions are not fully working for 5.3.3. See https://github.com/travis-ci/travis-ci/issues/1385. Updated documentation to show that Asset creation is now supported. --- doc/repo/assets.md | 4 +- lib/Github/Api/AbstractApi.php | 5 ++- lib/Github/Api/Repository/Assets.php | 43 +++++++++++++++++++ .../Tests/Api/Repository/AssetsTest.php | 20 +++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/doc/repo/assets.md b/doc/repo/assets.md index 05a6d9e04e7..be59c6b1b8d 100644 --- a/doc/repo/assets.md +++ b/doc/repo/assets.md @@ -15,7 +15,9 @@ $asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $ ### Create an asset -This feature is not implemented because require usage of `uploads.github.com` subdomain. +```php +$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $releaseId, $name, $contentType, $content); +``` ### Edit an asset diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 48ee8405d35..b68eb771a05 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -169,10 +169,11 @@ protected function delete($path, array $parameters = array(), $requestHeaders = /** * Create a JSON encoded version of an array of parameters. * - * @param $parameters Request parameters + * @param array $parameters Request parameters * @return null|string */ - protected function createJsonBody(array $parameters) { + protected function createJsonBody(array $parameters) + { return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0); } } diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 5a1137b35d6..039b31f896b 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -3,7 +3,9 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Exception\ErrorException; use Github\Exception\MissingArgumentException; +use Github\HttpClient\HttpClient; /** * @link http://developer.github.com/v3/repos/releases/ @@ -41,6 +43,47 @@ public function show($username, $repository, $id) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); } + /** + * Create an asset for selected repository's release + * POST /repos/:owner/:repo/releases/:id/assets?name=:filename + * + * Creating an asset requires support for server name indentification (SNI) + * so this must be supported by your PHP version. + * @see http://developer.github.com/v3/repos/releases/#upload-a-release-asset + * @see http://php.net/manual/en/openssl.constsni.php + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param integer $id the id of the release + * @param string $name the filename for the asset + * @param string $contentType the content type for the asset + * @param string $content the content of the asset + * + * @throws MissingArgumentException + * @throws ErrorException + * + * @return array + */ + public function create($username, $repository, $id, $name, $contentType, $content) + { + if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) { + throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported se your PHP version. See http://php.net/manual/en/openssl.constsni.php.'); + } + + // Asset creation requires a separate endpoint, uploads.github.com. + // Change the base url for the HTTP client temporarily while we execute + // this request. + $baseUrl = $this->client->getHttpClient()->client->getBaseUrl(); + $this->client->getHttpClient()->client->setBaseUrl('https://uploads.github.com/'); + + $response = $this->postRaw('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, array('Content-Type' => $contentType)); + + // Reset the base url. + $this->client->getHttpClient()->client->setBaseUrl($baseUrl); + + return $response; + } + /** * Edit an asset in selected repository's release * PATCH /repos/:owner/:repo/releases/assets/:id diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 52347a4ec72..2e560193a6c 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -40,6 +40,26 @@ public function shouldGetSingleReleaseAsset() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $assetId)); } + /** + * @test + * @requires PHP 5.3.4 + */ + public function shouldCreateReleaseAsset() + { + $name = 'asset.gzip'; + $body = 'assetCreatedData'; + $contentType = 'application/gzip'; + $releaseId = '12345'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('postRaw') + ->with('repos/KnpLabs/php-github-api/releases/'. $releaseId .'/assets?name='.$name) + ->will($this->returnValue($body)); + + $this->assertEquals($body, $api->create('KnpLabs', 'php-github-api', $releaseId, $name, $contentType, $body)); + } + /** * @test */ From e61e9a2eee7d5107d47987dc736927de7a58f14d Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Tue, 19 Nov 2013 21:48:16 +0100 Subject: [PATCH 078/951] Fix typo --- doc/result_pager.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/result_pager.md b/doc/result_pager.md index a802be1caa9..52ac2993696 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -36,12 +36,12 @@ Get next page: $paginator->fetchNext(); ``` -Check for pervious page: +Check for previous page: ```php $paginator->hasPrevious(); ``` -Get prevrious page: +Get previous page: ```php $paginator->fetchPrevious(); ``` From 8b6d3d1965487bc913b52b1eacbfd19e0199774b Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Tue, 19 Nov 2013 23:04:19 +0100 Subject: [PATCH 079/951] Don't send an emtpy ref to the client The api will return Not Found when sending an empty ref. --- lib/Github/Api/AbstractApi.php | 3 +++ test/Github/Tests/Api/AbstractApiTest.php | 32 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index b68eb771a05..7ef6e6cf353 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -69,6 +69,9 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; } + if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { + unset($parameters['ref']); + } $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); return ResponseMediator::getContent($response); diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 7dff2e0dd53..f3982e398e6 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -3,6 +3,7 @@ namespace Github\Tests\Api; use Github\Api\AbstractApi; +use Guzzle\Http\Message\Response; class AbstractApiTest extends \PHPUnit_Framework_TestCase { @@ -111,6 +112,26 @@ public function shouldPassDELETERequestToClient() $this->assertEquals($expectedArray, $api->delete('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))); } + /** + * @test + */ + public function shouldNotPassEmptyRefToClient() + { + $expectedResponse = new Response('value'); + + $httpClient = $this->getHttpMock(); + $httpClient + ->expects($this->any()) + ->method('get') + ->with('/path', array()) + ->will($this->returnValue($expectedResponse)); + $client = $this->getClientMock(); + $client->setHttpClient($httpClient); + + $api = new ExposedAbstractApiTestInstance($client); + $api->get('/path', array('ref' => null)); + } + protected function getAbstractApiObject($client) { return new AbstractApiTestInstance($client); @@ -193,3 +214,14 @@ public function delete($path, array $parameters = array(), $requestHeaders = arr return $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); } } + +class ExposedAbstractApiTestInstance extends AbstractApi +{ + /** + * {@inheritDoc} + */ + public function get($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::get($path, $parameters, $requestHeaders); + } +} From 741e62517b3bf63b33a0ccc8a1e8a0ee2137e93d Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Sun, 24 Nov 2013 19:15:12 +0000 Subject: [PATCH 080/951] Fixed typos --- README.markdown | 2 +- lib/Github/HttpClient/HttpClientInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 616f99f83a1..33e302afc83 100755 --- a/README.markdown +++ b/README.markdown @@ -102,7 +102,7 @@ See the `doc` directory for more detailed documentation. ### Contributors - Thanks to [Thibault Duplessis aka. ornicar](http://github.com/ornicar) for his first version of this library. -- Thanks to [Joseph Bielawski aka. stloyed](http://github.com/stloyd) for his contributions and support. +- Thanks to [Joseph Bielawski aka. stloyd](http://github.com/stloyd) for his contributions and support. - Thanks to [noloh](http://github.com/noloh) for his contribution on the Object API. - Thanks to [bshaffer](http://github.com/bshaffer) for his contribution on the Repo API. - Thanks to [Rolf van de Krol](http://github.com/rolfvandekrol) for his countless contributions. diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php index d6fd78dd2bb..a56d7ff7df5 100644 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ b/lib/Github/HttpClient/HttpClientInterface.php @@ -37,7 +37,7 @@ public function post($path, $body = null, array $headers = array()); * Send a PATCH request * * @param string $path Request path - * @param mixed $body Reuqest body + * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * * @internal param array $parameters Request body From 3cc624aeefe3d5ca525af0872f470509f87d0425 Mon Sep 17 00:00:00 2001 From: Jens Segers Date: Tue, 26 Nov 2013 12:53:55 +0100 Subject: [PATCH 081/951] Add API request to get the readme content Adding a `readme` method to the repo api to get the readme for a repository. This is described by http://developer.github.com/v3/repos/contents/#get-the-readme --- lib/Github/Api/Repo.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index cdc03398294..e0b891841f0 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -143,6 +143,20 @@ public function remove($username, $repository) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } + + /** + * Get the readme content for a repository by its username and repository name + * @link http://developer.github.com/v3/repos/contents/#get-the-readme + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * + * @return array the readme content + */ + public function readme($username, $repository) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme'); + } /** * Manage the collaborators of a repository From 5911c3de439be26f0cee5916ebf280e883005b9f Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Fri, 29 Nov 2013 06:30:37 +0200 Subject: [PATCH 082/951] Fix clearHeaders to use array keys instead of plain text --- lib/Github/HttpClient/HttpClient.php | 4 ++-- test/Github/Tests/Functional/RepoTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 068f411230f..268c1396f56 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -72,8 +72,8 @@ public function setHeaders(array $headers) public function clearHeaders() { $this->headers = array( - sprintf('Accept: application/vnd.github.%s+json', $this->options['api_version']), - sprintf('User-Agent: %s', $this->options['user_agent']), + 'Accept' => sprintf('application/vnd.github.%s+json', $this->options['api_version']), + 'User-Agent' => sprintf('%s', $this->options['user_agent']), ); } diff --git a/test/Github/Tests/Functional/RepoTest.php b/test/Github/Tests/Functional/RepoTest.php index 9ad68dc6e17..5fb6d3faa50 100644 --- a/test/Github/Tests/Functional/RepoTest.php +++ b/test/Github/Tests/Functional/RepoTest.php @@ -7,6 +7,23 @@ */ class RepoTest extends TestCase { + /** + * @test + */ + public function shouldShowPRDiffIfHeaderIsPresent() + { + $this->client->setHeaders( + array('Accept' => sprintf( + 'application/vnd.github.%s.diff', + $this->client->getOption('api_version') + )) + ); + + $diff = $this->client->api('pull_request')->show('KnpLabs', 'php-github-api', '92'); + + $this->assertTrue('string' === gettype($diff)); + } + /** * @test */ From 6f033f7b9b56da4479d439d1102133d8adde5f0b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 29 Nov 2013 19:49:12 +0300 Subject: [PATCH 083/951] Fixed raw blob retrieval --- lib/Github/Api/GitData/Blobs.php | 2 +- test/Github/Tests/Functional/RepoTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index ce2407b472d..2ff844db24a 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -15,7 +15,7 @@ public function configure($bodyType = null) { if ('raw' == $bodyType) { $this->client->setHeaders(array( - sprintf('Accept: application/vnd.github.%s.raw', $this->client->getOption('api_version')) + 'Accept' => sprintf('application/vnd.github.%s.raw', $this->client->getOption('api_version')) )); } } diff --git a/test/Github/Tests/Functional/RepoTest.php b/test/Github/Tests/Functional/RepoTest.php index 5fb6d3faa50..ce25d545ee6 100644 --- a/test/Github/Tests/Functional/RepoTest.php +++ b/test/Github/Tests/Functional/RepoTest.php @@ -24,6 +24,24 @@ public function shouldShowPRDiffIfHeaderIsPresent() $this->assertTrue('string' === gettype($diff)); } + /** + * @test + */ + public function shouldRetrieveRawBlob() + { + $api = $this->client->api('git_data')->blobs(); + $api->configure('raw'); + + $contents = $api->show( + 'KnpLabs', + 'php-github-api', + 'e50d5e946385cff052636e2f09f36b03d1c368f4' + ); + + $this->assertInternalType('string', $contents); + $this->assertStringStartsWith(' Date: Sat, 30 Nov 2013 23:09:43 +0200 Subject: [PATCH 084/951] Update request_any_route.md --- doc/request_any_route.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/request_any_route.md b/doc/request_any_route.md index 648d8a79f09..1465ff7934d 100644 --- a/doc/request_any_route.md +++ b/doc/request_any_route.md @@ -5,8 +5,9 @@ The method you need does not exist yet? You can access any GitHub route by using For example: ```php -$client = new Github\Client(); -$repo = $client->getHttpClient()->get('repos/KnpLabs/php-github-api'); +$client = new Github\Client(); +$response = $client->getHttpClient()->get('repos/KnpLabs/php-github-api'); +$repo = Github\HttpClient\Message\ResponseMediator::getContent($response); ``` Returns an array describing the "php-github-api" repository. From 2f44ea621aa42849bcc2aa6ab8ce0b8193ebabfa Mon Sep 17 00:00:00 2001 From: fh Date: Sun, 1 Dec 2013 13:13:06 +0100 Subject: [PATCH 085/951] Added missing \ prefix for the github classes to deal with namespaces --- README.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.markdown b/README.markdown index 33e302afc83..ff29b648a9f 100755 --- a/README.markdown +++ b/README.markdown @@ -52,7 +52,7 @@ Now we can use autoloader from Composer by: // This file is generated by Composer require_once 'vendor/autoload.php'; -$client = new Github\Client(); +$client = new \Github\Client(); $repositories = $client->api('user')->repositories('ornicar'); ``` @@ -66,19 +66,19 @@ From `$client` object, you can access to all GitHub. // This file is generated by Composer require_once 'vendor/autoload.php'; -$client = new Github\Client( - new Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache')) +$client = new \Github\Client( + new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache')) ); // Or select directly which cache you want to use -$client = new Github\HttpClient\CachedHttpClient(); +$client = new \Github\HttpClient\CachedHttpClient(); $client->setCache( // Built in one, or any cache implementing this interface: // Github\HttpClient\Cache\CacheInterface - new Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache') + new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache') ); -$client = new Github\Client($client); +$client = new \Github\Client($client); ``` Using cache, the client will get cached responses if resources haven't changed since last time, From 64fe2a6f24bc2203a2320691e639cc43ed3a25ad Mon Sep 17 00:00:00 2001 From: fh Date: Sun, 1 Dec 2013 13:56:14 +0100 Subject: [PATCH 086/951] adding call for user/orgs --- lib/Github/Api/CurrentUser.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 688282cb65b..7b1af4381c8 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -76,6 +76,16 @@ public function notifications() return new Notifications($this->client); } + /** + * @link http://developer.github.com/v3/orgs/#list-user-organizations + * + * @return array + */ + public function organizations() + { + return $this->get('user/orgs'); + } + /** * @link http://developer.github.com/v3/repos/#list-your-repositories * From a1f59206ca448fd2689ac833131db222e04fd144 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Fri, 6 Dec 2013 16:02:20 +0100 Subject: [PATCH 087/951] add support for Gaufrette cache --- composer.json | 6 +- .../HttpClient/Cache/GaufretteCache.php | 52 ++++++++++++ .../HttpClient/Cache/GaufretteCacheTest.php | 84 +++++++++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 lib/Github/HttpClient/Cache/GaufretteCache.php create mode 100644 test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php diff --git a/composer.json b/composer.json index ec95b7e0119..09f24c3d735 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "require": { "php": ">=5.3.2", "ext-curl": "*", - "guzzle/guzzle": ">=3.7" + "guzzle/guzzle": ">=3.7", + "knplabs/gaufrette": "0.1.*" }, "require-dev": { "phpunit/phpunit": ">=3.7" @@ -27,6 +28,9 @@ "require-dev": { "phpunit/phpunit": ">=3.6.0" }, + "suggest": { + "knplabs/gaufrette": "Needed for optional Gaufrette cache" + }, "autoload": { "psr-0": { "Github\\": "lib/" } }, diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php new file mode 100644 index 00000000000..3f5dbaaee44 --- /dev/null +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -0,0 +1,52 @@ +filesystem = $filesystem; + } + + /** + * {@inheritdoc} + */ + public function get($id) + { + $content = $this->filesystem->read($id); + + return unserialize($content); + } + + /** + * {@inheritdoc} + */ + public function set($id, Response $response) + { + $this->filesystem->write($id, serialize($response)); + } + + /** + * {@inheritdoc} + */ + public function getModifiedSince($id) + { + if ($this->filesystem->has($id)) { + return $this->filesystem->mtime($id); + } + + return null; + } +} diff --git a/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php b/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php new file mode 100644 index 00000000000..2a84f14ad54 --- /dev/null +++ b/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php @@ -0,0 +1,84 @@ +markTestSkipped('Gaufrette not installed.'); + } + } + + /** + * @test + */ + public function shouldStoreAResponseForAGivenKey() + { + $response = new Response(200); + $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); + $filesystem + ->expects($this->once()) + ->method('write') + ->with('test', serialize($response)) + ; + $filesystem + ->expects($this->once()) + ->method('read') + ->with('test') + ->will($this->returnValue('a:0:{}')) + ; + + $cache = new GaufretteCache($filesystem); + $cache->set('test', $response); + $this->assertNotNull($cache->get('test')); + } + + /** + * @test + */ + public function shouldGetATimestampForExistingFile() + { + $response = new Response(200); + $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); + $filesystem + ->expects($this->once()) + ->method('has') + ->with('test') + ->will($this->returnValue(true)) + ; + $filesystem + ->expects($this->once()) + ->method('mtime') + ->with('test') + ->will($this->returnValue(100)) + ; + + $cache = new GaufretteCache($filesystem); + $cache->set('test', new Response(200)); + + $this->assertInternalType('int', $cache->getModifiedSince('test')); + } + + /** + * @test + */ + public function shouldNotGetATimestampForInexistingFile() + { + $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); + $filesystem + ->expects($this->once()) + ->method('has') + ->with('test2') + ->will($this->returnValue(false)) + ; + + $cache = new GaufretteCache($filesystem); + + $this->assertNull($cache->getModifiedSince('test2')); + } +} From a496becd8b825996a021c46d4ee04a1d6cf5b375 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Fri, 6 Dec 2013 16:04:34 +0100 Subject: [PATCH 088/951] remove wrong dependency --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 09f24c3d735..2ef7ee247d3 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ "require": { "php": ">=5.3.2", "ext-curl": "*", - "guzzle/guzzle": ">=3.7", - "knplabs/gaufrette": "0.1.*" + "guzzle/guzzle": ">=3.7" }, "require-dev": { "phpunit/phpunit": ">=3.7" From a3724c17b5d10c3915a06a8936dac3297bf4bd94 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Fri, 6 Dec 2013 16:13:40 +0100 Subject: [PATCH 089/951] add author note --- lib/Github/HttpClient/Cache/GaufretteCache.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php index 3f5dbaaee44..9e3df8c64e1 100644 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -5,6 +5,11 @@ use Guzzle\Http\Message\Response; use Gaufrette\Filesystem; +/** + * Gaufrette Cache + * + * @author Massimiliano Arione + */ class GaufretteCache implements CacheInterface { /** From d83153740c8a8e265bb35553b58adb30fd09da32 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Fri, 6 Dec 2013 16:25:13 +0100 Subject: [PATCH 090/951] fix overwrite flag --- lib/Github/HttpClient/Cache/GaufretteCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php index 9e3df8c64e1..2c6ac43fd28 100644 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -40,7 +40,7 @@ public function get($id) */ public function set($id, Response $response) { - $this->filesystem->write($id, serialize($response)); + $this->filesystem->write($id, serialize($response), true); } /** From 9acae681c2420542321f5e2a8bf850083dec7869 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Sat, 7 Dec 2013 19:10:32 +0100 Subject: [PATCH 091/951] remove redundant return --- lib/Github/HttpClient/Cache/GaufretteCache.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php index 2c6ac43fd28..d198f3d24ce 100644 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -51,7 +51,5 @@ public function getModifiedSince($id) if ($this->filesystem->has($id)) { return $this->filesystem->mtime($id); } - - return null; } } From 9e22b446e55cea8a2bfd088c8acfd01ca87776f0 Mon Sep 17 00:00:00 2001 From: Klein Florian Date: Thu, 19 Dec 2013 23:21:44 +0100 Subject: [PATCH 092/951] use ETag to decrease rate limit hits --- .../HttpClient/Cache/CacheInterface.php | 14 +++++++++++++ .../HttpClient/Cache/FilesystemCache.php | 20 +++++++++++++++++-- .../HttpClient/Cache/GaufretteCache.php | 16 +++++++++++++++ lib/Github/HttpClient/CachedHttpClient.php | 11 +++++++--- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/lib/Github/HttpClient/Cache/CacheInterface.php b/lib/Github/HttpClient/Cache/CacheInterface.php index 50fedd6e25b..e669f72fe1a 100644 --- a/lib/Github/HttpClient/Cache/CacheInterface.php +++ b/lib/Github/HttpClient/Cache/CacheInterface.php @@ -11,6 +11,13 @@ */ interface CacheInterface { + /** + * @param string $id The id of the cached resource + * + * @return bool if present + */ + public function has($id); + /** * @param string $id The id of the cached resource * @@ -18,6 +25,13 @@ interface CacheInterface */ public function getModifiedSince($id); + /** + * @param string $id The id of the cached resource + * + * @return null|string The ETag value + */ + public function getETag($id); + /** * @param string $id The id of the cached resource * diff --git a/lib/Github/HttpClient/Cache/FilesystemCache.php b/lib/Github/HttpClient/Cache/FilesystemCache.php index e7c7588cd03..ff332b57075 100644 --- a/lib/Github/HttpClient/Cache/FilesystemCache.php +++ b/lib/Github/HttpClient/Cache/FilesystemCache.php @@ -43,6 +43,17 @@ public function set($id, Response $response) if (false === @file_put_contents($this->getPath($id), serialize($response))) { throw new \InvalidArgumentException(sprintf('Cannot put content in file "%s"', $this->getPath($id))); } + if (false === @file_put_contents($this->getPath($id).'.etag', $response->getHeader('ETag'))) { + throw new \InvalidArgumentException(sprintf('Cannot put content in file "%s"', $this->getPath($id).'.etag')); + } + } + + /** + * {@inheritdoc} + */ + public function has($id) + { + return file_exists($this->getPath($id)); } /** @@ -50,11 +61,16 @@ public function set($id, Response $response) */ public function getModifiedSince($id) { - if (file_exists($this->getPath($id))) { + if ($this->has($id)) { return filemtime($this->getPath($id)); } + } - return null; + public function getETag($id) + { + if (file_exists($this->getPath($id).'.etag')) { + return file_get_contents($this->getPath($id).'.etag'); + } } /** diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php index d198f3d24ce..0797a043b91 100644 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -41,6 +41,15 @@ public function get($id) public function set($id, Response $response) { $this->filesystem->write($id, serialize($response), true); + $this->filesystem->write($id.'.etag', $response->getHeader('ETag'), true); + } + + /** + * {@inheritdoc} + */ + public function has($id) + { + $this->filesystem->has($id); } /** @@ -52,4 +61,11 @@ public function getModifiedSince($id) return $this->filesystem->mtime($id); } } + + public function getETag($id) + { + if ($this->filesystem->has($id)) { + return $this->filesystem->read($id.'.etag'); + } + } } diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index e3f777e4e7e..dfbe6630f31 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -46,12 +46,11 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers { $response = parent::request($path, $body, $httpMethod, $headers, $options); - $key = trim($this->options['base_url'].$path, '/'); if (304 == $response->getStatusCode()) { - return $this->getCache()->get($key); + return $this->getCache()->get($path); } - $this->getCache()->set($key, $response); + $this->getCache()->set($path, $response); return $response; } @@ -74,6 +73,12 @@ protected function createRequest($httpMethod, $path, $body = null, array $header sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) ); } + if ($etag = $this->getCache()->getETag($path)) { + $request->addHeader( + 'If-None-Match', + $etag + ); + } return $request; } From 874f4f9ca80cac282ebd1d5e3cbaf82904cd0d7d Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Tue, 31 Dec 2013 17:00:33 +0100 Subject: [PATCH 093/951] Fixed 39 : urls to get informations about watching --- lib/Github/Api/Repo.php | 2 +- lib/Github/Api/User.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index e0b891841f0..a1352389422 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -367,7 +367,7 @@ public function teams($username, $repository) */ public function watchers($username, $repository, $page = 1) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array( + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', array( 'page' => $page )); } diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 97c3be0fda4..5e70b26c9a0 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -69,7 +69,7 @@ public function followers($username) */ public function watched($username) { - return $this->get('users/'.rawurlencode($username).'/watched'); + return $this->get('users/'.rawurlencode($username).'/subscriptions'); } /** From ec321170015094d4eb91824222e219df525dde25 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Thu, 2 Jan 2014 15:27:44 +1100 Subject: [PATCH 094/951] Add file create, update and delete operations --- lib/Github/Api/Repository/Contents.php | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 47ce7a462e8..0f361c23f65 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -52,6 +52,96 @@ public function show($username, $repository, $path = null, $reference = null) )); } + /** + * Creates a new file in a repository + * @link http://developer.github.com/v3/repos/contents/#create-a-file + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param string $content contents of the new file + * @param string $message the commit message + * @param null|string $branch name of a branch + * + * @return array information about the new file + */ + public function create($username, $repository, $path, $content, $message, $branch = null) + { + $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); + + $parameters = array( + 'content' => base64_encode($content), + 'message' => $message, + ); + + if (null !== $branch) { + $parameters['branch'] = $branch; + } + + return $this->put($url, $parameters); + } + + /** + * Updates the contents of a file in a repository + * @link http://developer.github.com/v3/repos/contents/#update-a-file + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param string $content contents of the new file + * @param string $message the commit message + * @param string $sha blob SHA of the file being replaced + * @param null|string $branch name of a branch + * + * @return array information about the updated file + */ + public function update($username, $repository, $path, $content, $message, $sha, $branch = null) + { + $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); + + $parameters = array( + 'content' => base64_encode($content), + 'message' => $message, + 'sha' => $sha, + ); + + if (null !== $branch) { + $parameters['branch'] = $branch; + } + + return $this->put($url, $parameters); + } + + + /** + * Deletes a file from a repository + * @link http://developer.github.com/v3/repos/contents/#delete-a-file + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param string $message the commit message + * @param string $sha blob SHA of the file being deleted + * @param null|string $branch name of a branch + * + * @return array information about the updated file + */ + public function rm($username, $repository, $path, $message, $sha, $branch = null) + { + $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); + + $parameters = array( + 'message' => $message, + 'sha' => $sha, + ); + + if (null !== $branch) { + $parameters['branch'] = $branch; + } + + return $this->delete($url, $parameters); + } + /** * Get content of archives in a repository * @link http://developer.github.com/v3/repos/contents/ From 85f1be577dfa0c31828cd7a6d16b9f30f466bece Mon Sep 17 00:00:00 2001 From: Jon Pugh Date: Thu, 2 Jan 2014 13:10:01 -0500 Subject: [PATCH 095/951] Adding "teams" to the $client->api() function --- lib/Github/Client.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e50d5e94638..ac05746a1d9 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -124,6 +124,11 @@ public function api($name) $api = new Api\Repo($this); break; + case 'team': + case 'teams': + $api = new Api\Organization\Teams($this); + break; + case 'user': case 'users': $api = new Api\User($this); From d0799233f1854462f1246ed0a63e201f8d9f8c2a Mon Sep 17 00:00:00 2001 From: Luis Cordova Date: Fri, 3 Jan 2014 20:12:24 -0500 Subject: [PATCH 096/951] fix typo --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index e0b891841f0..ae43470ebe3 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -31,7 +31,7 @@ class Repo extends AbstractApi * @param string $keyword the search query * @param array $params * - * @return array list of founded repositories + * @return array list of found repositories */ public function find($keyword, array $params) { From 2aafb2cc4e0130cc0965ab0541ee979ace83f8db Mon Sep 17 00:00:00 2001 From: Dan Barrett Date: Sun, 5 Jan 2014 00:00:39 +1100 Subject: [PATCH 097/951] Added contributor commit statistics for repository Added contributor statics for commits for a specified repository as per http://developer.github.com/v3/repos/statistics/#contributors Not sure if it's in the right file, but it's a handy function to have. --- lib/Github/Api/Repo.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index ae43470ebe3..047b213c048 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -37,6 +37,20 @@ public function find($keyword, array $params) { return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); } + + /** + * Get contributor commit statistics for a repository + * @link http://developer.github.com/v3/repos/statistics/#contributors + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * + * @return array list of contributors and their commit statistics + */ + public function statistics($username, $repository) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); + } /** * List all repositories for an organization From 7fdbecb16ddf8dcfbe0fcbe67fbc9fe063845cd5 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Thu, 31 Oct 2013 03:36:26 -0500 Subject: [PATCH 098/951] Add mimetype support to compare() so diff/patches can be fetched --- lib/Github/Api/Repository/Commits.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 9c8726bd3b8..6753c8b5a2e 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -15,9 +15,13 @@ public function all($username, $repository, array $params) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params); } - public function compare($username, $repository, $base, $head) + public function compare($username, $repository, $base, $head, $mediaType = NULL) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head)); + $headers = array(); + if (NULL !== $mediaType) { + $headers['Accept'] = $mediaType; + } + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), array(), $headers); } public function show($username, $repository, $sha) From b06e01c507c9ddfb3b1c1f7bead45c538ecb5cc0 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Wed, 8 Jan 2014 20:25:22 +0200 Subject: [PATCH 099/951] Set auth type for http auth by default, fixes #110 --- lib/Github/Client.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ac05746a1d9..0ec20c21aa4 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -166,6 +166,10 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null $password = null; } + if (null === $authMethod) { + $authMethod = self::AUTH_HTTP_PASSWORD; + } + $this->getHttpClient()->authenticate($tokenOrLogin, $password, $authMethod); } From dc2b09cdfa2771f3aa2bf3103ca7d131ffb01e53 Mon Sep 17 00:00:00 2001 From: Joe Colburn Date: Tue, 14 Jan 2014 13:37:21 -0500 Subject: [PATCH 100/951] issue 42 - default find param to an empty array --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 047b213c048..91a032a1f02 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -33,7 +33,7 @@ class Repo extends AbstractApi * * @return array list of found repositories */ - public function find($keyword, array $params) + public function find($keyword, array $params = array()) { return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); } From d17d2b82643247bb21e450be66de7c4d6a0027a7 Mon Sep 17 00:00:00 2001 From: "Maxime Veber (aka Nek)" Date: Tue, 28 Jan 2014 15:41:25 +0100 Subject: [PATCH 101/951] Deprecated watch methods --- lib/Github/Api/Repo.php | 15 +++++++++++++++ lib/Github/Api/User.php | 14 +++++++++++++- test/Github/Tests/Api/RepoTest.php | 6 +++--- test/Github/Tests/Api/UserTest.php | 6 +++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a1352389422..2ba40fdee67 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -359,6 +359,7 @@ public function teams($username, $repository) } /** + * @deprecated see subscribers method * @param string $username * @param string $repository * @param integer $page @@ -366,6 +367,20 @@ public function teams($username, $repository) * @return array */ public function watchers($username, $repository, $page = 1) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array( + 'page' => $page + )); + } + + /** + * @param string $username + * @param string $repository + * @param integer $page + * + * @return array + */ + public function subscribers($username, $repository, $page = 1) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', array( 'page' => $page diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 5e70b26c9a0..1681d8e5217 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -62,12 +62,24 @@ public function followers($username) /** * Request the repository that a specific user is watching - * @link http://developer.github.com/v3/repos/watching/ + * @deprecated see subscriptions method * * @param string $username the username * @return array list of watched repositories */ public function watched($username) + { + return $this->get('users/'.rawurlencode($username).'/watched'); + } + + /** + * Request the repository that a specific user is watching + * @link http://developer.github.com/v3/activity/watching/ + * + * @param string $username the username + * @return array list of watched repositories + */ + public function subscriptions($username) { return $this->get('users/'.rawurlencode($username).'/subscriptions'); } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index db125a72622..84fba69f843 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -111,17 +111,17 @@ public function shouldCreateRepositoryForOrganization() /** * @test */ - public function shouldGetRepositoryWatchers() + public function shouldGetRepositorySubscribers() { $expectedArray = array(array('id' => 1, 'username' => 'l3l0')); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/watchers', array('page' => 2)) + ->with('repos/KnpLabs/php-github-api/subscribers', array('page' => 2)) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->watchers('KnpLabs', 'php-github-api', 2)); + $this->assertEquals($expectedArray, $api->subscribers('KnpLabs', 'php-github-api', 2)); } /** diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index dd3811dd8fb..95dcb542e5f 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -74,17 +74,17 @@ public function shouldGetUserFollowers() /** * @test */ - public function shouldGetWatchedRepositories() + public function shouldGetSubscriptionsToRepositories() { $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/watched') + ->with('users/l3l0/subscriptions') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->watched('l3l0')); + $this->assertEquals($expectedArray, $api->subscriptions('l3l0')); } /** From e9d2f292624b53a103a284e4d81644e0e68b8c43 Mon Sep 17 00:00:00 2001 From: "Maxime Veber (aka Nek)" Date: Fri, 31 Jan 2014 14:43:58 +0100 Subject: [PATCH 102/951] Updated comments documentation --- doc/issue/comments.md | 55 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/doc/issue/comments.md b/doc/issue/comments.md index f976047b885..9a5f7b1d851 100644 --- a/doc/issue/comments.md +++ b/doc/issue/comments.md @@ -9,8 +9,24 @@ Wraps [GitHub Issue Comments API](http://developer.github.com/v3/issues/comments $comments = $client->api('issue')->comments()->all('KnpLabs', 'php-github-api', 4); ``` -List an issue comments by username, repo and issue number. -Returns an array of issues. +* `KnpLabs` : the owner of the repository +* `php-github-api` : the name of the repository +* `4` : the id of the issue +* You can select another page of comments using one more parameter (default: 1) + +Returns an array of comments. + + +### Show an issue comment + +```php +$comment = $client->api('issue')->comments()->show('KnpLabs', 'php-github-api', 33793831); +``` + +* `KnpLabs` : the owner of the repository +* `php-github-api` : the name of the repository +* `33793831` : the id of the comment + ### Add a comment on an issue @@ -23,5 +39,36 @@ Returns an array of issues. $client->api('issue')->comments()->create('KnpLabs', 'php-github-api', 4, array('body' => 'My new comment')); ``` -Add a comment to the issue by username, repo and issue number and array with comment data: `body` -and optionally `title`. +* `KnpLabs` : the owner of the repository +* `php-github-api` : the name of the repository +* `4` : the id of the issue +* You can set a `body` and optionally a `title` + + +### Update a comment on an issue + +> **Note:** + +> Requires [authentication](../security.md). + +```php +$client->api('issue')->comments()->create('KnpLabs', 'php-github-api', 33793831, array('body' => 'My updated comment')); +``` + +* `KnpLabs` : the owner of the repository +* `php-github-api` : the name of the repository +* `33793831` : the id of the comment + +### Remove a comment on an issue + +> **Note:** + +> Requires [authentication](../security.md). + +```php +$client->api('issue')->comments()->remove('KnpLabs', 'php-github-api', 33793831); +``` + +* `KnpLabs` : the owner of the repository +* `php-github-api` : the name of the repository +* `33793831` : the id of the comment \ No newline at end of file From db1995bc025f1cfd24d8a09d11c011cb157e68c8 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 14:39:09 -0500 Subject: [PATCH 103/951] Add the activity() method to return a year's worth of commit activity, grouped by week. --- lib/Github/Api/Repo.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a7fd586e16d..a05d5d1559c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -39,19 +39,33 @@ public function find($keyword, array $params = array()) } /** - * Get contributor commit statistics for a repository - * @link http://developer.github.com/v3/repos/statistics/#contributors + * Get the last year of commit activity for a repository grouped by week + * @link http://developer.github.com/v3/repos/statistics/#commit-activity * * @param string $username the user who owns the repository * @param string $repository the name of the repository * - * @return array list of contributors and their commit statistics + * @return array commit activity grouped by week */ - public function statistics($username, $repository) + public function activity($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity'); } + /** + * Get contributor commit statistics for a repository + * @link http://developer.github.com/v3/repos/statistics/#contributors + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * + * @return array list of contributors and their commit statistics + */ + public function statistics($username, $repository) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); + } + /** * List all repositories for an organization * @link http://developer.github.com/v3/repos/#list-organization-repositories From f082186958c5717d333887fa47a5ad6ab4c2b3f7 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 14:46:39 -0500 Subject: [PATCH 104/951] Added documentation for the activity() method. --- doc/repos.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index fd8601a3b9e..d3c62ed203c 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -230,3 +230,11 @@ To include non GitHub users, add a third parameter to true: ```php $contributors = $client->api('repo')->contributors('ornicar', 'php-github-api', true); ``` + +### Get the commit activity of a repository + +```php +$activity = $client->api('repo')->activity('ornicar', 'php-github-api'); +``` + +Returns an array of commit activity group by week. \ No newline at end of file From 8e207cbb135f712ff52b84bdf0305249367f5c18 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 15:01:21 -0500 Subject: [PATCH 105/951] Added test for the new activity() method. --- test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 84fba69f843..082ce2fdde0 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -417,6 +417,22 @@ public function shouldGetReleasesApiObject() $this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases()); } + /** + * @test + */ + public function shouldGetCommitActivity() + { + $expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400)); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/stats/commit_activity') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); + } + protected function getApiClass() { return 'Github\Api\Repo'; From d9120252b13ae22769ec47679ebe6cb127476300 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 15:07:59 -0500 Subject: [PATCH 106/951] Fixed spacing. --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a05d5d1559c..892e807d538 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -40,7 +40,7 @@ public function find($keyword, array $params = array()) /** * Get the last year of commit activity for a repository grouped by week - * @link http://developer.github.com/v3/repos/statistics/#commit-activity + * @link http://developer.github.com/v3/repos/statistics/#commit-activity * * @param string $username the user who owns the repository * @param string $repository the name of the repository From 719258739930276602af7b86ff3be2f466b7e524 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 15:16:54 -0500 Subject: [PATCH 107/951] Fixed spacing. --- test/Github/Tests/Api/RepoTest.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 082ce2fdde0..90366110110 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -417,21 +417,21 @@ public function shouldGetReleasesApiObject() $this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases()); } - /** - * @test - */ - public function shouldGetCommitActivity() - { - $expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400)); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('repos/KnpLabs/php-github-api/stats/commit_activity') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); - } + /** + * @test + */ + public function shouldGetCommitActivity() + { + $expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400)); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/stats/commit_activity') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); + } protected function getApiClass() { From ec7da6e21b753878bb1431801da9ce243ab5e296 Mon Sep 17 00:00:00 2001 From: Justin Tallant Date: Wed, 19 Feb 2014 00:00:14 -0600 Subject: [PATCH 108/951] Use remove method for repo delete Calling delete on an instance of Repo calls delete from the parent class. The parent class delete method doesn't expect the arguments being passed in the format the old example uses. Example should use `remove` instead of `delete`. --- doc/repos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index fd8601a3b9e..d857f3c33c7 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -76,7 +76,7 @@ Updates and returns the repository named 'my-new-repo' that is owned by 'usernam > Requires [authentication](security.md). ```php -$client->api('repo')->delete('username', 'my-new-repo'); // Get the deletion token +$client->api('repo')->remove('username', 'my-new-repo'); // Get the deletion token ``` Deletes the my-new-repo repository. From 84f909398aac9b8fd0e6e17afd3abeefe51fa832 Mon Sep 17 00:00:00 2001 From: Till! Date: Fri, 21 Feb 2014 13:29:42 +0100 Subject: [PATCH 109/951] Fix: validate composer.json Removed duplicate "require-dev" key, assuming the later version of PHPUnit was wanted. --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 2ef7ee247d3..a7f89ecae82 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,6 @@ "require-dev": { "phpunit/phpunit": ">=3.7" }, - "require-dev": { - "phpunit/phpunit": ">=3.6.0" - }, "suggest": { "knplabs/gaufrette": "Needed for optional Gaufrette cache" }, From 57e674cf6bd653288c5bf0dc27b0319425866e42 Mon Sep 17 00:00:00 2001 From: Sean Hellwig Date: Fri, 21 Feb 2014 16:31:29 -0800 Subject: [PATCH 110/951] Update User API to include /users/:user/starred --- doc/users.md | 6 ++++++ lib/Github/Api/User.php | 15 +++++++++++++ test/Github/Tests/Functional/UserTest.php | 26 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/doc/users.md b/doc/users.md index b0cc072bbbf..bc3c2579b45 100644 --- a/doc/users.md +++ b/doc/users.md @@ -97,6 +97,12 @@ Returns an array of followed users. $users = $client->api('user')->watched('ornicar'); ``` +### Get repos that a specific user has starred + +```php +$users = $client->api('user')->starred('ornicar'); +``` + For authenticated user use. > Requires [authentication](security.md). diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 1681d8e5217..e832bd84710 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -72,6 +72,21 @@ public function watched($username) return $this->get('users/'.rawurlencode($username).'/watched'); } + /** + * Request starred repositories that a specific user has starred + * @link http://developer.github.com/v3/activity/starring/ + * + * @param string $username the username + * @param int $page the page number of the paginated result set + * @return array list of starred repositories + */ + public function starred($username, $page = 1) + { + return $this->get('users/'.rawurlencode($username).'/starred', array( + 'page' => $page + )); + } + /** * Request the repository that a specific user is watching * @link http://developer.github.com/v3/activity/watching/ diff --git a/test/Github/Tests/Functional/UserTest.php b/test/Github/Tests/Functional/UserTest.php index 8cef6d7a88a..3366ab96d02 100644 --- a/test/Github/Tests/Functional/UserTest.php +++ b/test/Github/Tests/Functional/UserTest.php @@ -110,4 +110,30 @@ public function shouldGetReposBeingWatched() $this->assertArrayHasKey('git_url', $repo); $this->assertArrayHasKey('svn_url', $repo); } + + /** + * @test + */ + public function shouldGetReposBeingStarred() + { + $username = 'l3l0'; + + $repos = $this->client->api('user')->starred($username); + $repo = array_pop($repos); + + $this->assertArrayHasKey('id', $repo); + $this->assertArrayHasKey('name', $repo); + $this->assertArrayHasKey('description', $repo); + $this->assertArrayHasKey('url', $repo); + $this->assertArrayHasKey('has_wiki', $repo); + $this->assertArrayHasKey('has_issues', $repo); + $this->assertArrayHasKey('forks', $repo); + $this->assertArrayHasKey('updated_at', $repo); + $this->assertArrayHasKey('created_at', $repo); + $this->assertArrayHasKey('pushed_at', $repo); + $this->assertArrayHasKey('open_issues', $repo); + $this->assertArrayHasKey('ssh_url', $repo); + $this->assertArrayHasKey('git_url', $repo); + $this->assertArrayHasKey('svn_url', $repo); + } } From 819d9cca1ac3aaca86c9c135887411670435f5a1 Mon Sep 17 00:00:00 2001 From: Luis Cordova Date: Wed, 19 Mar 2014 05:57:10 -0700 Subject: [PATCH 111/951] added addSubscriber method because guzzle plugins are subscribers and not just listeners --- lib/Github/HttpClient/HttpClient.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 268c1396f56..514b08262f9 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -82,6 +82,11 @@ public function addListener($eventName, $listener) $this->client->getEventDispatcher()->addListener($eventName, $listener); } + public function addSubscriber($subscriber) + { + $this->client->addSubscriber($subscriber); + } + /** * {@inheritDoc} */ From 1bb5ba7f1ed4846efdbeb961d83709b325a41032 Mon Sep 17 00:00:00 2001 From: Luis Cordova Date: Wed, 19 Mar 2014 07:26:52 -0700 Subject: [PATCH 112/951] add typehint as per @stof's suggestion --- lib/Github/HttpClient/HttpClient.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 514b08262f9..59b3cce759e 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -11,6 +11,7 @@ use Github\Exception\RuntimeException; use Github\HttpClient\Listener\AuthListener; use Github\HttpClient\Listener\ErrorListener; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Performs requests on GitHub API. API documentation should be self-explanatory. @@ -82,7 +83,7 @@ public function addListener($eventName, $listener) $this->client->getEventDispatcher()->addListener($eventName, $listener); } - public function addSubscriber($subscriber) + public function addSubscriber(EventSubscriberInterface $subscriber) { $this->client->addSubscriber($subscriber); } From 94e1385ff1ac6e43f964be172039bb8bacdf658e Mon Sep 17 00:00:00 2001 From: Bas Kok Date: Wed, 30 Apr 2014 15:05:32 +0200 Subject: [PATCH 113/951] typo in assets documentation --- doc/repo/assets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/assets.md b/doc/repo/assets.md index be59c6b1b8d..9e6ac8b8f20 100644 --- a/doc/repo/assets.md +++ b/doc/repo/assets.md @@ -16,7 +16,7 @@ $asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $ ### Create an asset ```php -$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $releaseId, $name, $contentType, $content); +$asset = $client->api('repo')->releases()->assets()->create('twbs', 'bootstrap', $releaseId, $name, $contentType, $content); ``` ### Edit an asset From 3b08cd9a504af76fe0fe5d4f92856cd44b69e1a6 Mon Sep 17 00:00:00 2001 From: jdohuutin Date: Mon, 5 May 2014 11:43:05 +0200 Subject: [PATCH 114/951] add committer parameter in contents api --- lib/Github/Api/Repository/Contents.php | 37 +++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 0f361c23f65..5ed185b362b 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -5,6 +5,7 @@ use Github\Api\AbstractApi; use Github\Exception\InvalidArgumentException; use Github\Exception\ErrorException; +use Github\Exception\MissingArgumentException; /** * @link http://developer.github.com/v3/repos/contents/ @@ -62,10 +63,13 @@ public function show($username, $repository, $path = null, $reference = null) * @param string $content contents of the new file * @param string $message the commit message * @param null|string $branch name of a branch + * @param null|array $committer information about the committer + * + * @throws MissingArgumentException * * @return array information about the new file */ - public function create($username, $repository, $path, $content, $message, $branch = null) + public function create($username, $repository, $path, $content, $message, $branch = null, array $committer = null) { $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); @@ -78,6 +82,13 @@ public function create($username, $repository, $path, $content, $message, $branc $parameters['branch'] = $branch; } + if (null !== $committer) { + if (!isset($committer['name'], $committer['email'])) { + throw new MissingArgumentException(array('name', 'email')); + } + $parameters['committer'] = $committer; + } + return $this->put($url, $parameters); } @@ -92,10 +103,13 @@ public function create($username, $repository, $path, $content, $message, $branc * @param string $message the commit message * @param string $sha blob SHA of the file being replaced * @param null|string $branch name of a branch + * @param null|array $committer information about the committer + * + * @throws MissingArgumentException * * @return array information about the updated file */ - public function update($username, $repository, $path, $content, $message, $sha, $branch = null) + public function update($username, $repository, $path, $content, $message, $sha, $branch = null, array $committer = null) { $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); @@ -109,6 +123,13 @@ public function update($username, $repository, $path, $content, $message, $sha, $parameters['branch'] = $branch; } + if (null !== $committer) { + if (!isset($committer['name'], $committer['email'])) { + throw new MissingArgumentException(array('name', 'email')); + } + $parameters['committer'] = $committer; + } + return $this->put($url, $parameters); } @@ -123,10 +144,13 @@ public function update($username, $repository, $path, $content, $message, $sha, * @param string $message the commit message * @param string $sha blob SHA of the file being deleted * @param null|string $branch name of a branch + * @param null|array $committer information about the committer + * + * @throws MissingArgumentException * * @return array information about the updated file */ - public function rm($username, $repository, $path, $message, $sha, $branch = null) + public function rm($username, $repository, $path, $message, $sha, $branch = null, array $committer = null) { $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); @@ -139,6 +163,13 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null $parameters['branch'] = $branch; } + if (null !== $committer) { + if (!isset($committer['name'], $committer['email'])) { + throw new MissingArgumentException(array('name', 'email')); + } + $parameters['committer'] = $committer; + } + return $this->delete($url, $parameters); } From 779e83baac911057267ef6dce479b798e3347bde Mon Sep 17 00:00:00 2001 From: jdohuutin Date: Mon, 5 May 2014 14:32:33 +0200 Subject: [PATCH 115/951] add tests for contents create, update and rm methods --- .../Tests/Api/Repository/ContentsTest.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 0eb91a4cd15..0f74f237fb8 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -38,6 +38,122 @@ public function shouldShowReadme() $this->assertEquals($expectedValue, $api->readme('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldCreateNewFile() + { + $expectedArray = array('content' => 'some data'); + $content = ' 'committer name', 'email' => 'email@example.com'); + $parameters = array( + 'content' => base64_encode($content), + 'message' => $message, + 'committer' => $committer, + 'branch' => $branch, + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $content, $message, $branch, $committer)); + } + + /** + * @test + * @expectedException Github\Exception\MissingArgumentException + * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! + */ + public function shouldThrowExceptionWhenCreateNewFileWithInvalidCommitter() + { + $committer = array('invalid_key' => 'some data'); + $api = $this->getApiMock(); + $api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, $committer); + } + + /** + * @test + */ + public function shouldUpdateFile() + { + $expectedArray = array('content' => 'some data'); + $content = ' 'committer name', 'email' => 'email@example.com'); + $parameters = array( + 'content' => base64_encode($content), + 'message' => $message, + 'committer' => $committer, + 'branch' => $branch, + 'sha' => $sha, + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $content, $message, $sha, $branch, $committer)); + } + + /** + * @test + * @expectedException Github\Exception\MissingArgumentException + * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! + */ + public function shouldThrowExceptionWhenUpdateFileWithInvalidCommitter() + { + $committer = array('invalid_key' => 'some data'); + $api = $this->getApiMock(); + $api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, null, $committer); + } + + /** + * @test + */ + public function shouldDeleteFile() + { + $expectedArray = array('content' => 'some data'); + $message = 'a commit message'; + $sha = 'a sha'; + $branch = 'master'; + $committer = array('name' => 'committer name', 'email' => 'email@example.com'); + $parameters = array( + 'message' => $message, + 'committer' => $committer, + 'branch' => $branch, + 'sha' => $sha, + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $message, $sha, $branch, $committer)); + } + + /** + * @test + * @expectedException Github\Exception\MissingArgumentException + * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! + */ + public function shouldThrowExceptionWhenDeleteFileWithInvalidCommitter() + { + $committer = array('invalid_key' => 'some data'); + $api = $this->getApiMock(); + $api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'a commit message', null, null, $committer); + } + /** * @test */ From 4e6658d7f91ef9661e2494244442c13d414642a5 Mon Sep 17 00:00:00 2001 From: Claude Dioudonnat Date: Sat, 10 May 2014 00:02:39 +0200 Subject: [PATCH 116/951] Add the /meta api part --- doc/index.md | 1 + doc/meta.md | 29 +++++++++++++++++++++++++ lib/Github/Api/Meta.php | 22 +++++++++++++++++++ lib/Github/Client.php | 4 ++++ test/Github/Tests/Api/MetaTest.php | 35 ++++++++++++++++++++++++++++++ test/Github/Tests/ClientTest.php | 2 ++ 6 files changed, 93 insertions(+) create mode 100644 doc/meta.md create mode 100644 lib/Github/Api/Meta.php create mode 100644 test/Github/Tests/Api/MetaTest.php diff --git a/doc/index.md b/doc/index.md index 1f447d6e457..7e4356427ad 100644 --- a/doc/index.md +++ b/doc/index.md @@ -17,6 +17,7 @@ APIs: * [Releases](repo/releases.md) * [Assets](repo/assets.md) * [Users](users.md) +* [Meta](meta.md) Additional features: diff --git a/doc/meta.md b/doc/meta.md new file mode 100644 index 00000000000..24ea3bfa270 --- /dev/null +++ b/doc/meta.md @@ -0,0 +1,29 @@ +## Users API +[Back to the navigation](index.md) + + +Wrap [GitHub User API](http://developer.github.com/v3/meta/). + +### Get information about GitHub services + +```php +$service = $client->api('meta')->service(); +``` + +return + +``` +array(3) { + 'verifiable_password_authentication' => bool + 'hooks' => + array(1) { + [0] => + string(15) "127.0.0.1/22" + } + 'git' => + array(1) { + [0] => + string(15) "127.0.0.1/22" + } +} +``` \ No newline at end of file diff --git a/lib/Github/Api/Meta.php b/lib/Github/Api/Meta.php new file mode 100644 index 00000000000..de504da9e72 --- /dev/null +++ b/lib/Github/Api/Meta.php @@ -0,0 +1,22 @@ + + */ +class Meta extends AbstractApi +{ + /** + * Get the ip address of the hook and git servers for the GitHub.com service + * + * @return array Informations about the service of GitHub.com + */ + public function service() + { + return $this->get('meta'); + } +} \ No newline at end of file diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 0ec20c21aa4..d99fa44e515 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -139,6 +139,10 @@ public function api($name) $api = new Api\Authorizations($this); break; + case 'meta': + $api = new Api\Meta($this); + break; + default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); } diff --git a/test/Github/Tests/Api/MetaTest.php b/test/Github/Tests/Api/MetaTest.php new file mode 100644 index 00000000000..f284613a381 --- /dev/null +++ b/test/Github/Tests/Api/MetaTest.php @@ -0,0 +1,35 @@ + array( + '127.0.0.1/32' + ), + 'git' => array( + '127.0.0.1/32' + ), + 'verifiable_password_authentication' => true + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->service()); + } + + protected function getApiClass() + { + return 'Github\Api\Meta'; + } +} diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 29e926b246a..8ebe27f785f 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -168,6 +168,8 @@ public function getApiClassesProvider() array('authorization', 'Github\Api\Authorizations'), array('authorizations', 'Github\Api\Authorizations'), + + array('meta', 'Github\Api\Meta') ); } From 8953af322689a8d7bca30c143e221352ee8ffcdb Mon Sep 17 00:00:00 2001 From: Claude Dioudonnat Date: Mon, 12 May 2014 23:54:54 +0200 Subject: [PATCH 117/951] Fix lines --- lib/Github/Api/Meta.php | 2 +- test/Github/Tests/Api/MetaTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Meta.php b/lib/Github/Api/Meta.php index de504da9e72..a10c1361b12 100644 --- a/lib/Github/Api/Meta.php +++ b/lib/Github/Api/Meta.php @@ -19,4 +19,4 @@ public function service() { return $this->get('meta'); } -} \ No newline at end of file +} diff --git a/test/Github/Tests/Api/MetaTest.php b/test/Github/Tests/Api/MetaTest.php index f284613a381..f2f8374f314 100644 --- a/test/Github/Tests/Api/MetaTest.php +++ b/test/Github/Tests/Api/MetaTest.php @@ -9,11 +9,10 @@ class MetaTest extends TestCase */ public function shouldGetInformationService() { - $expectedArray = array( 'hooks' => array( '127.0.0.1/32' - ), + ), 'git' => array( '127.0.0.1/32' ), From 76c7dc744b2f2796bdbcd9a0328123c4c5d3814c Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 16 May 2014 00:36:35 -0400 Subject: [PATCH 118/951] List all GitHub users. --- doc/users.md | 16 ++++++++++++++++ lib/Github/Api/User.php | 15 +++++++++++++++ test/Github/Tests/Api/UserTest.php | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/doc/users.md b/doc/users.md index b0cc072bbbf..57a7ff43178 100644 --- a/doc/users.md +++ b/doc/users.md @@ -12,6 +12,22 @@ $users = $client->api('user')->find('KnpLabs'); Returns an array of found users. +### Lists all users, in the order they signed up, since the last user you've seen + +```php +$users = $client->api('user')->all(135); +``` + +Returns an array of all users that registered after the user whose ID is 135. + +### Lists all users, in the order they signed up + +```php +$users = $client->api('user')->all(); +``` + +Returns an array of all users. + ### Get information about a user ```php diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 1681d8e5217..59940481ef5 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -24,6 +24,21 @@ public function find($keyword) return $this->get('legacy/user/search/'.rawurlencode($keyword)); } + /** + * Request all users: + * @link https://developer.github.com/v3/users/#get-all-users + * + * @param integer|null $id ID of the last user that you've seen + * @return array list of users found + */ + public function all($id = null) + { + if (!is_integer($id)) { + return $this->get('users'); + } + return $this->get('users?since=' . rawurldecode($id)); + } + /** * Get extended information about a user by its username * @link http://developer.github.com/v3/users/ diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 95dcb542e5f..05eb7061b0d 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -20,6 +20,25 @@ public function shouldShowUser() $this->assertEquals($expectedArray, $api->show('l3l0')); } + /** + * @test + */ + public function shouldGetAllUsers() + { + $expectedArray = array( + array('id' => 1, 'username' => 'l3l0'), + array('id' => 2, 'username' => 'l3l0test') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + /** * @test */ From 50800ab03fda62270c64d978a7b6542439f7de12 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 16 May 2014 09:06:39 -0400 Subject: [PATCH 119/951] Changed the URL so I can use my fork while they review my latest pull request --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2ef7ee247d3..821614f2aa1 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "knplabs/github-api", + "name": "guillermoandrae/php-github-api", "type": "library", "description": "GitHub API v3 client", - "homepage": "https://github.com/KnpLabs/php-github-api", + "homepage": "https://github.com/guillermoandrae/php-github-api", "keywords": ["github", "gh", "api", "gist"], "license": "MIT", "authors": [ From 4124067c5478189e2f167b901243a92f8e4a9f06 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Sun, 18 May 2014 21:10:19 -0400 Subject: [PATCH 120/951] Fixed composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 821614f2aa1..3bd0f08715a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "guillermoandrae/php-github-api", + "name": "knplabs/github-api", "type": "library", "description": "GitHub API v3 client", "homepage": "https://github.com/guillermoandrae/php-github-api", From b8072320d7b8cbef39de333d69a2a81c4b65b677 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Sun, 18 May 2014 21:14:43 -0400 Subject: [PATCH 121/951] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3bd0f08715a..2ef7ee247d3 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "knplabs/github-api", "type": "library", "description": "GitHub API v3 client", - "homepage": "https://github.com/guillermoandrae/php-github-api", + "homepage": "https://github.com/KnpLabs/php-github-api", "keywords": ["github", "gh", "api", "gist"], "license": "MIT", "authors": [ From 3e5e7d6cac150334b5e4ad91fc5c1f5af3a4c99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Thu, 12 Jun 2014 22:52:07 +0200 Subject: [PATCH 122/951] corrected Return Annotations Guzzle returns a Response Object not directly an array --- lib/Github/HttpClient/HttpClientInterface.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php index a56d7ff7df5..0961b8cc7a7 100644 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ b/lib/Github/HttpClient/HttpClientInterface.php @@ -3,6 +3,7 @@ namespace Github\HttpClient; use Github\Exception\InvalidArgumentException; +use Guzzle\Http\Message\Response; /** * Performs requests on GitHub API. API documentation should be self-explanatory. @@ -18,7 +19,7 @@ interface HttpClientInterface * @param array $parameters GET Parameters * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return Response */ public function get($path, array $parameters = array(), array $headers = array()); @@ -29,7 +30,7 @@ public function get($path, array $parameters = array(), array $headers = array() * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return Response */ public function post($path, $body = null, array $headers = array()); @@ -41,7 +42,7 @@ public function post($path, $body = null, array $headers = array()); * @param array $headers Reconfigure the request headers for this call only * * @internal param array $parameters Request body - * @return array Data + * @return Response */ public function patch($path, $body = null, array $headers = array()); @@ -52,7 +53,7 @@ public function patch($path, $body = null, array $headers = array()); * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return Response */ public function put($path, $body, array $headers = array()); @@ -63,7 +64,7 @@ public function put($path, $body, array $headers = array()); * @param mixed $body Request body * @param array $headers Reconfigure the request headers for this call only * - * @return array Data + * @return Response */ public function delete($path, $body = null, array $headers = array()); @@ -76,7 +77,7 @@ public function delete($path, $body = null, array $headers = array()); * @param string $httpMethod HTTP method to use * @param array $headers Request headers * - * @return array Data + * @return Response */ public function request($path, $body, $httpMethod = 'GET', array $headers = array()); From 1406c447f8d2542447675e41f7a1b5a62fe883de Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 13 Jun 2014 14:37:25 +0200 Subject: [PATCH 123/951] Allow to provide parameters for PullRequests list According to the [API documentation](https://developer.github.com/v3/pulls/#list-pull-requests) of the v3 API a sort can be added and some other parameters not yet supported by this library. I have changed the "all" function to allow parameters to be given. --- lib/Github/Api/PullRequest.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index e52815cf01a..70a6f52b632 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -19,22 +19,13 @@ class PullRequest extends AbstractApi * * @param string $username the username * @param string $repository the repository - * @param string $state the state of the fetched pull requests. - * The API seems to automatically default to 'open' - * @param integer $page the page - * @param integer $perPage the per page + * @param array $params a list of extra parameters. * * @return array array of pull requests for the project */ - public function all($username, $repository, $state = null, $page = 1, $perPage = 30) + public function all($username, $repository, array $params = array()) { - $parameters = array( - 'page' => $page, - 'per_page' => $perPage, - 'state' => $state, - ); - - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params ); } /** From 876cbecf71b966e021486f2c7c21e909b77880b1 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 13 Jun 2014 16:33:36 +0100 Subject: [PATCH 124/951] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a7f89ecae82..8202e6656f6 100644 --- a/composer.json +++ b/composer.json @@ -19,10 +19,10 @@ "require": { "php": ">=5.3.2", "ext-curl": "*", - "guzzle/guzzle": ">=3.7" + "guzzle/guzzle": "~3.7" }, "require-dev": { - "phpunit/phpunit": ">=3.7" + "phpunit/phpunit": "~4.0" }, "suggest": { "knplabs/gaufrette": "Needed for optional Gaufrette cache" From fa6c7852b06fd5b0f6f4a58018f53056f864628d Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Sat, 14 Jun 2014 13:17:42 +0200 Subject: [PATCH 125/951] Add support for two fatcor authentication --- lib/Github/Api/Authorizations.php | 6 ++-- ...oFactorAuthenticationRequiredException.php | 19 +++++++++++ lib/Github/HttpClient/HttpClient.php | 7 ++-- .../HttpClient/Listener/ErrorListener.php | 9 ++++++ .../Tests/HttpClient/HttpClientTest.php | 23 +++++++++++++ .../HttpClient/Listener/ErrorListenerTest.php | 32 +++++++++++++++++++ 6 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 lib/Github/Exception/TwoFactorAuthenticationRequiredException.php diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index 0066a1f0f3f..68f9414fd0c 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -21,9 +21,11 @@ public function show($number) return $this->get('authorizations/'.rawurlencode($number)); } - public function create(array $params) + public function create(array $params, $OTPCode = null) { - return $this->post('authorizations', $params); + $headers = null === $OTPCode ? array() : array('X-GitHub-OTP' => $OTPCode); + + return $this->post('authorizations', $params, $headers); } public function update($id, array $params) diff --git a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php new file mode 100644 index 00000000000..6f93fe40b14 --- /dev/null +++ b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php @@ -0,0 +1,19 @@ +type = $type; + parent::__construct('Two factor authentication is enabled on this account', $code, $previous); + } + + public function getType() + { + return $this->type; + } +} diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 59b3cce759e..2ba4d9cf873 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -2,6 +2,7 @@ namespace Github\HttpClient; +use Github\Exception\TwoFactorAuthenticationRequiredException; use Guzzle\Http\Client as GuzzleClient; use Guzzle\Http\ClientInterface; use Guzzle\Http\Message\Request; @@ -139,9 +140,11 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers try { $response = $this->client->send($request); } catch (\LogicException $e) { - throw new ErrorException($e->getMessage()); + throw new ErrorException($e->getMessage(), $e->getCode(), $e); + } catch (TwoFactorAuthenticationRequiredException $e) { + throw $e; } catch (\RuntimeException $e) { - throw new RuntimeException($e->getMessage()); + throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } $this->lastRequest = $request; diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 60cbc5a80fd..30106178d17 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -2,6 +2,7 @@ namespace Github\HttpClient\Listener; +use Github\Exception\TwoFactorAuthenticationRequiredException; use Github\HttpClient\Message\ResponseMediator; use Guzzle\Common\Event; use Guzzle\Http\Message\Response; @@ -45,6 +46,14 @@ public function onRequestError(Event $event) throw new ApiLimitExceedException($this->options['api_limit']); } + if (401 === $response->getStatusCode()) { + if ($response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) $response->getHeader('X-GitHub-OTP'), 'required;')) { + $type = substr((string) $response->getHeader('X-GitHub-OTP'), 9); + + throw new TwoFactorAuthenticationRequiredException($type); + } + } + $content = ResponseMediator::getContent($response); if (is_array($content) && isset($content['message'])) { if (400 == $response->getStatusCode()) { diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php index cb83e9af96d..c6a645a214f 100644 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ b/test/Github/Tests/HttpClient/HttpClientTest.php @@ -242,6 +242,29 @@ public function shouldThrowExceptionWhenApiIsExceeded() $httpClient->get($path, $parameters, $headers); } + /** + * @test + * @expectedException \Github\Exception\TwoFactorAuthenticationRequiredException + */ + public function shouldForwardTwoFactorAuthenticationExceptionWhenItHappens() + { + $path = '/some/path'; + $parameters = array('a = b'); + $headers = array('c' => 'd'); + + $response = new Response(401); + $response->addHeader('X-GitHub-OTP', 'required; sms'); + + $mockPlugin = new MockPlugin(); + $mockPlugin->addResponse($response); + + $client = new GuzzleClient('http://123.com/'); + $client->addSubscriber($mockPlugin); + + $httpClient = new TestHttpClient(array(), $client); + $httpClient->get($path, $parameters, $headers); + } + protected function getBrowserMock(array $methods = array()) { $mock = $this->getMock( diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index 8bb0bfa177f..3715ee57d3d 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -149,6 +149,38 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) $listener->onRequestError($this->getEventMock($response)); } + /** + * @test + * @expectedException \Github\Exception\TwoFactorAuthenticationRequiredException + */ + public function shouldThrowTwoFactorAuthenticationRequiredException() + { + $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); + $response->expects($this->once()) + ->method('isClientError') + ->will($this->returnValue(true)); + $response->expects($this->any()) + ->method('getStatusCode') + ->will($this->returnValue(401)); + $response->expects($this->any()) + ->method('getHeader') + ->will($this->returnCallback(function ($name) { + switch ($name) { + case 'X-RateLimit-Remaining': + return 5000; + case 'X-GitHub-OTP': + return 'required; sms'; + } + })); + $response->expects($this->any()) + ->method('hasHeader') + ->with('X-GitHub-OTP') + ->will($this->returnValue(true)); + + $listener = new ErrorListener(array()); + $listener->onRequestError($this->getEventMock($response)); + } + public function getErrorCodesProvider() { return array( From 2958ad646451d0fff0be4e8ba16a1ee1eed80755 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Sat, 14 Jun 2014 13:26:34 +0200 Subject: [PATCH 126/951] Add documentation for two factor authentication --- doc/two_factor_authentication.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 doc/two_factor_authentication.md diff --git a/doc/two_factor_authentication.md b/doc/two_factor_authentication.md new file mode 100644 index 00000000000..2b670b05ba2 --- /dev/null +++ b/doc/two_factor_authentication.md @@ -0,0 +1,19 @@ +## Two factor authentication +[Back to the navigation](index.md) + + +### Raising the exception + +```php +try { + $authorization = $github->api('authorizations')->create(); +} catch (Github\Exception\TwoFactorAuthenticationRequiredException $e { + echo sprintf("Two factor authentication of type %s is required.", $e->getType()); +} +``` + +Once the code has been retrieved (by sms for example), you can create an authorization: + +``` +$authorization = $github->api('authorizations')->create(array('note' => 'Optional'), $code); +``` From 3fbf0ddf0f08a83d3c588e315fdabba626bcbdaa Mon Sep 17 00:00:00 2001 From: Frank Klaassen Date: Wed, 18 Jun 2014 18:41:42 +0200 Subject: [PATCH 127/951] Fix tests and add defaults --- lib/Github/Api/PullRequest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib/Github/Api/PullRequest.php diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php old mode 100644 new mode 100755 index 70a6f52b632..62f85c3f575 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -25,7 +25,11 @@ class PullRequest extends AbstractApi */ public function all($username, $repository, array $params = array()) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params ); + $parameters = array_merge(array( + 'page' => 1, + 'per_page' => 30 + ), $params); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } /** From 722a46cf19e312a0f001d49c035a2e9f0966ef7b Mon Sep 17 00:00:00 2001 From: Frank Klaassen Date: Wed, 18 Jun 2014 19:33:07 +0200 Subject: [PATCH 128/951] Also fix the actual tests since it requires an array now --- test/Github/Tests/Api/PullRequestTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 test/Github/Tests/Api/PullRequestTest.php diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php old mode 100644 new mode 100755 index ac38dc4513d..a1ef074c3d5 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -33,7 +33,7 @@ public function shouldGetOpenPullRequests() ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'open')); + $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'open')); } /** @@ -49,7 +49,7 @@ public function shouldGetClosedPullRequests() ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'closed')); + $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'closed')); } /** From d84b9fffae7e88d39234a0def7db405ffc303e60 Mon Sep 17 00:00:00 2001 From: Frank Klaassen Date: Thu, 19 Jun 2014 08:35:48 +0200 Subject: [PATCH 129/951] Tabs vs spaces, missing ) --- lib/Github/Api/PullRequest.php | 9 +++++---- test/Github/Tests/Api/PullRequestTest.php | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 62f85c3f575..5151f1cd105 100755 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -25,10 +25,11 @@ class PullRequest extends AbstractApi */ public function all($username, $repository, array $params = array()) { - $parameters = array_merge(array( - 'page' => 1, - 'per_page' => 30 - ), $params); + $parameters = array_merge(array( + 'page' => 1, + 'per_page' => 30 + ), $params); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index a1ef074c3d5..0a0aa067ce4 100755 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -33,7 +33,7 @@ public function shouldGetOpenPullRequests() ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'open')); + $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'open'))); } /** @@ -49,7 +49,7 @@ public function shouldGetClosedPullRequests() ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'closed')); + $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'closed'))); } /** From 79889a66c4d02749b48dfb51b94e6efe06126838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 19 Jun 2014 17:02:26 +0200 Subject: [PATCH 130/951] Removed double header from a request --- lib/Github/HttpClient/HttpClient.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 2ba4d9cf873..cfc44fbbda0 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -135,7 +135,6 @@ public function put($path, $body, array $headers = array()) public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { $request = $this->createRequest($httpMethod, $path, $body, $headers, $options); - $request->addHeaders($headers); try { $response = $this->client->send($request); From f09548dfebac1c9756391fe3d9c8b56fb78d6e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Kooman?= Date: Sat, 21 Jun 2014 15:56:24 +0700 Subject: [PATCH 131/951] add support for retrieving current_user subscriptions --- lib/Github/Api/CurrentUser.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 7b1af4381c8..2e210f51b94 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -120,4 +120,12 @@ public function starred($page = 1) 'page' => $page )); } + + /** + * @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched + */ + public function subscriptions() + { + return $this->get('user/subscriptions'); + } } From f8cf67895280fca39497e0d669e5cdc9ef386edf Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sat, 21 Jun 2014 14:59:52 +0200 Subject: [PATCH 132/951] Corrected repository hooks documentation link --- lib/Github/Api/Repository/Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index ad9e8596ecd..f4866ad0af9 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -6,7 +6,7 @@ use Github\Exception\MissingArgumentException; /** - * @link http://developer.github.com/v3/issues/hooks/ + * @link http://developer.github.com/v3/repos/hooks/ * @author Joseph Bielawski */ class Hooks extends AbstractApi From 5dec9a8408172f25fe4fa7b757e64fa2f74e9ab3 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Tue, 24 Jun 2014 11:29:35 -0400 Subject: [PATCH 133/951] Added classes, tests, and documentation for GitHub Enterprise. --- doc/enterprise.md | 24 +++++ doc/index.md | 1 + lib/Github/Api/Enterprise.php | 32 ++++++ lib/Github/Api/Enterprise/License.php | 19 ++++ lib/Github/Api/Enterprise/Stats.php | 128 +++++++++++++++++++++++ lib/Github/Client.php | 27 ++++- test/Github/Tests/Api/EnterpriseTest.php | 38 +++++++ 7 files changed, 266 insertions(+), 3 deletions(-) create mode 100644 doc/enterprise.md create mode 100644 lib/Github/Api/Enterprise.php create mode 100644 lib/Github/Api/Enterprise/License.php create mode 100644 lib/Github/Api/Enterprise/Stats.php create mode 100644 test/Github/Tests/Api/EnterpriseTest.php diff --git a/doc/enterprise.md b/doc/enterprise.md new file mode 100644 index 00000000000..b4673061e74 --- /dev/null +++ b/doc/enterprise.md @@ -0,0 +1,24 @@ +## Enterprise API +[Back to the navigation](index.md) + +Provides information about a GitHub Enterprise installation. Wraps [GitHub Enterprise API](http://developer.github.com/v3/enterprise/). + +In order to configure the client to point to a GitHub Enterprise installation, do the following: + +```php +setEnterpriseUrl('https://ghe.host'); + +// Use the client as you would ordinarily +$repositories = $client->api('user')->repositories('ornicar'); +``` + +To use the Stats and License APIs, you will need to authenticate using a GitHub Enterprise site admin account. + diff --git a/doc/index.md b/doc/index.md index 1f447d6e457..2fd1cf8b521 100644 --- a/doc/index.md +++ b/doc/index.md @@ -4,6 +4,7 @@ Navigation APIs: * [Authorizations](authorizations.md) * [Commits](commits.md) +* [Enterprise](enterprise.md) * [Gists](gists.md) * [Issues](issues.md) * [Comments](issue/comments.md) diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php new file mode 100644 index 00000000000..38e7cbff44c --- /dev/null +++ b/lib/Github/Api/Enterprise.php @@ -0,0 +1,32 @@ + + * @author Guillermo A. Fisher + */ +class Enterprise extends AbstractApi +{ + /** + * @return Stats + */ + public function stats() + { + return new Stats($this->client); + } + + /** + * @return License + */ + public function license() + { + return new License($this->client); + } +} diff --git a/lib/Github/Api/Enterprise/License.php b/lib/Github/Api/Enterprise/License.php new file mode 100644 index 00000000000..27785ca14e3 --- /dev/null +++ b/lib/Github/Api/Enterprise/License.php @@ -0,0 +1,19 @@ +get('enterprise/settings/license'); + } +} diff --git a/lib/Github/Api/Enterprise/Stats.php b/lib/Github/Api/Enterprise/Stats.php new file mode 100644 index 00000000000..934401b769c --- /dev/null +++ b/lib/Github/Api/Enterprise/Stats.php @@ -0,0 +1,128 @@ +show('issues'); + } + + /** + * Returns the number of active and inactive hooks + * + * @return array array with totals of active and inactive hooks + */ + public function hooks() + { + return $this->show('hooks'); + } + + /** + * Returns the number of open and closed milestones + * + * @return array array with totals of open and closed milestones + */ + public function milestones() + { + return $this->show('milestones'); + } + + /** + * Returns the number of organizations, teams, team members, and disabled organizations + * + * @return array array with totals of organizations, teams, team members, and disabled organizations + */ + public function orgs() + { + return $this->show('orgs'); + } + + /** + * Returns the number of comments on issues, pull requests, commits, and gists + * + * @return array array with totals of comments on issues, pull requests, commits, and gists + */ + public function comments() + { + return $this->show('comments'); + } + + /** + * Returns the number of GitHub Pages sites + * + * @return array array with totals of GitHub Pages sites + */ + public function pages() + { + return $this->show('pages'); + } + + /** + * Returns the number of suspended and admin users + * + * @return array array with totals of suspended and admin users + */ + public function users() + { + return $this->show('users'); + } + + /** + * Returns the number of private and public gists + * + * @return array array with totals of private and public gists + */ + public function gists() + { + return $this->show('gists'); + } + + /** + * Returns the number of merged, mergeable, and unmergeable pull requests + * + * @return array array with totals of merged, mergeable, and unmergeable pull requests + */ + public function pulls() + { + return $this->show('pulls'); + } + + /** + * Returns the number of organization-owned repositories, root repositories, forks, pushed commits, and wikis + * + * @return array array with totals of organization-owned repositories, root repositories, forks, pushed commits, and wikis + */ + public function repos() + { + return $this->show('repos'); + } + + /** + * Returns all of the statistics + * + * @return array array with all of the statistics + */ + public function all() + { + return $this->show('all'); + } + + /** + * @param string $type The type of statistics to show + * + * @return array + */ + public function show($type) + { + return $this->get('enterprise/stats/' . rawurlencode($type)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 0ec20c21aa4..e84850c0532 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -173,6 +173,17 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null $this->getHttpClient()->authenticate($tokenOrLogin, $password, $authMethod); } + /** + * Sets the URL of your GitHub Enterprise instance. + * + * @param string $enterpriseUrl URL of the API in the form of http(s)://hostname + */ + public function setEnterpriseUrl($enterpriseUrl) + { + $baseUrl = (substr($enterpriseUrl, -1) == '/') ? substr($enterpriseUrl, 0, -1) : $enterpriseUrl; + $this->getHttpClient()->client->setBaseUrl($baseUrl . '/api/v3'); + } + /** * @return HttpClient */ @@ -237,11 +248,21 @@ public function setOption($name, $value) if (!array_key_exists($name, $this->options)) { throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); } - - if ('api_version' == $name && !in_array($value, array('v3', 'beta'))) { - throw new InvalidArgumentException(sprintf('Invalid API version ("%s"), valid are: %s', $name, implode(', ', array('v3', 'beta')))); + $supportedApiVersions = $this->getSupportedApiVersions(); + if ('api_version' == $name && !in_array($value, $supportedApiVersions)) { + throw new InvalidArgumentException(sprintf('Invalid API version ("%s"), valid are: %s', $name, implode(', ', $supportedApiVersions))); } $this->options[$name] = $value; } + + /** + * Returns an array of valid API versions supported by this client. + * + * @return array + */ + public function getSupportedApiVersions() + { + return array('v3', 'beta'); + } } diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php new file mode 100644 index 00000000000..d284bb59282 --- /dev/null +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -0,0 +1,38 @@ +getApiMock(); + + $this->assertInstanceOf('Github\Api\Enterprise\Stats', $api->stats()); + } + + /** + * @test + */ + public function shouldGetEnterpriseLicenseApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Enterprise\License', $api->license()); + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise'; + } +} + \ No newline at end of file From 861cf2e41a138dc74424b0f4b8fb5e358bf8cec3 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Tue, 24 Jun 2014 11:49:58 -0400 Subject: [PATCH 134/951] Added enterprise and the "ent" alias to list of valid APIs. --- lib/Github/Client.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e84850c0532..f9846d4f637 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -87,6 +87,11 @@ public function api($name) $api = new Api\CurrentUser($this); break; + case 'ent': + case 'enterprise': + $api = new Api\Enterprise($this); + break; + case 'git': case 'git_data': $api = new Api\GitData($this); From 0e7c3eccbf1c1cb33e3d64fbd1e2d95a046a99ae Mon Sep 17 00:00:00 2001 From: Oleg Zinchenko <1cdecoder@gmail.com> Date: Tue, 1 Jul 2014 14:48:22 +0300 Subject: [PATCH 135/951] added User::organizations, to be able fetch user's organizations --- lib/Github/Api/User.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 7573c6e2b98..bcbfc58f80e 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -51,6 +51,18 @@ public function show($username) return $this->get('users/'.rawurlencode($username)); } + /** + * Get extended information about a user by its username + * @link https://developer.github.com/v3/orgs/ + * + * @param string $username the username to show + * @return array information about organizations that user belongs to + */ + public function organizations($username) + { + return $this->get('users/'.rawurlencode($username).'/orgs'); + } + /** * Request the users that a specific user is following * @link http://developer.github.com/v3/users/followers/ From 2c7ce8c38ed2bf5a579774edfc6896cd04bc7ce9 Mon Sep 17 00:00:00 2001 From: Oleg Zinchenko <1cdecoder@gmail.com> Date: Tue, 1 Jul 2014 15:06:31 +0300 Subject: [PATCH 136/951] added test for User::organizations --- test/Github/Tests/Api/UserTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 05eb7061b0d..1bb0f959b52 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -20,6 +20,29 @@ public function shouldShowUser() $this->assertEquals($expectedArray, $api->show('l3l0')); } + /** + * @test + */ + public function shouldGetUserOrganizations() + { + $expectedArray = array(array( + 'id' => 202732, + 'url' => 'https://api.github.com/orgs/KnpLabs', + 'repos_url' => 'https://api.github.com/orgs/KnpLabs/repos', + 'events_url' => 'https://api.github.com/orgs/KnpLabs/events', + 'members_url' => 'https://api.github.com/orgs/KnpLabs/members{/member}', + 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}' + )); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users/l3l0/orgs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->organizations('l3l0')); + } + /** * @test */ From db8ec7a4c9e49568c8cf8b15738701cdb06e959f Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Thu, 19 Jun 2014 17:56:17 +0200 Subject: [PATCH 137/951] Added missing sort options on user repositories fetch Fixed cs --- lib/Github/Api/CurrentUser.php | 12 ++++++++++-- lib/Github/Api/User.php | 15 +++++++++++---- test/Github/Tests/Api/UserTest.php | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 7b1af4381c8..38318959589 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -89,11 +89,19 @@ public function organizations() /** * @link http://developer.github.com/v3/repos/#list-your-repositories * + * @param string $type role in the repository + * @param string $sort sort by + * @param string $direction direction of sort, ask or desc + * @return array */ - public function repositories() + public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->get('user/repos'); + return $this->get('user/repos', array( + $type, + $sort, + $direction + )); } /** diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 7573c6e2b98..f30659c2b2d 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -118,12 +118,19 @@ public function subscriptions($username) * Get the repositories of a user * @link http://developer.github.com/v3/repos/ * - * @param string $username the username - * @return array list of the user repositories + * @param string $username the username + * @param string $type role in the repository + * @param string $sort sort by + * @param string $direction direction of sort, ask or desc + * @return array list of the user repositories */ - public function repositories($username) + public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->get('users/'.rawurlencode($username).'/repos'); + return $this->get('users/'.rawurlencode($username).'/repos', array( + $type, + $sort, + $direction + )); } /** diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 05eb7061b0d..fab2969269d 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -116,7 +116,7 @@ public function shouldGetUserRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/repos') + ->with('users/l3l0/repos', array('owner', 'full_name', 'asc')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('l3l0')); From 96af37ac1110350636dfc6761cc651dd6751551f Mon Sep 17 00:00:00 2001 From: Kevin Laude Date: Mon, 7 Jul 2014 17:27:59 -0500 Subject: [PATCH 138/951] Add support to get all milestones. The GitHub API allows you to retrieve open, closed, or all milestones. Add support to retrieve all milestones in addition to just the open or the closed ones. --- lib/Github/Api/Issue/Milestones.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index c13c4aebb2b..a2e945a980b 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -13,7 +13,7 @@ class Milestones extends AbstractApi { public function all($username, $repository, array $params = array()) { - if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { + if (isset($params['state']) && !in_array($params['state'], array('open', 'closed', 'all'))) { $params['state'] = 'open'; } if (isset($params['sort']) && !in_array($params['sort'], array('due_date', 'completeness'))) { From ae01a0413cdbb3ce0c6febf3aa689353f79ae36c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 14 Jul 2014 17:25:12 +0200 Subject: [PATCH 139/951] Added PHP 5.6 and HHVM to travis.yml --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 776d6a9b15b..96f47d3d858 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,12 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 + - hhvm + +matrix: + allow_failures: + - php: hhvm before_script: - composer install --dev --prefer-source From 8234450fa365e2c2e616355e262ebefc1328c6e3 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 26 Jul 2014 12:59:01 +0100 Subject: [PATCH 140/951] Cleanup whitespace --- doc/issue/comments.md | 2 +- doc/meta.md | 2 +- lib/Github/Api/Repo.php | 10 +++++----- lib/Github/Api/Repository/Releases.php | 2 +- test/Github/Tests/Api/EnterpriseTest.php | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/issue/comments.md b/doc/issue/comments.md index 9a5f7b1d851..511bb891c3e 100644 --- a/doc/issue/comments.md +++ b/doc/issue/comments.md @@ -71,4 +71,4 @@ $client->api('issue')->comments()->remove('KnpLabs', 'php-github-api', 33793831) * `KnpLabs` : the owner of the repository * `php-github-api` : the name of the repository -* `33793831` : the id of the comment \ No newline at end of file +* `33793831` : the id of the comment diff --git a/doc/meta.md b/doc/meta.md index 24ea3bfa270..adc3e437cbb 100644 --- a/doc/meta.md +++ b/doc/meta.md @@ -26,4 +26,4 @@ array(3) { string(15) "127.0.0.1/22" } } -``` \ No newline at end of file +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 892e807d538..9be29c0cfa1 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -37,14 +37,14 @@ public function find($keyword, array $params = array()) { return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); } - + /** * Get the last year of commit activity for a repository grouped by week * @link http://developer.github.com/v3/repos/statistics/#commit-activity - * + * * @param string $username the user who owns the repository * @param string $repository the name of the repository - * + * * @return array commit activity grouped by week */ public function activity($username, $repository) @@ -171,7 +171,7 @@ public function remove($username, $repository) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } - + /** * Get the readme content for a repository by its username and repository name * @link http://developer.github.com/v3/repos/contents/#get-the-readme @@ -243,7 +243,7 @@ public function downloads() /** * Manage the releases of a repository (Currently Undocumented) - * @link http://developer.github.com/v3/repos/ + * @link http://developer.github.com/v3/repos/ * * @return Releases */ diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index a2ee5201ffe..7ac3726482f 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -79,7 +79,7 @@ public function edit($username, $repository, $id, array $params) * * @param string $username the user who owns the repo * @param string $repository the name of the repo - * @param integer $id the id of the release + * @param integer $id the id of the release * * @return array */ diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php index d284bb59282..399ecd78e67 100644 --- a/test/Github/Tests/Api/EnterpriseTest.php +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -35,4 +35,4 @@ protected function getApiClass() return 'Github\Api\Enterprise'; } } - \ No newline at end of file + From ba71fba3dae8ee3b78ef350cbe12c11395e4ba09 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 26 Jul 2014 13:08:34 +0100 Subject: [PATCH 141/951] Fixed a typo --- lib/Github/Api/Repository/Assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 039b31f896b..ccd4263c27d 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -67,7 +67,7 @@ public function show($username, $repository, $id) public function create($username, $repository, $id, $name, $contentType, $content) { if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) { - throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported se your PHP version. See http://php.net/manual/en/openssl.constsni.php.'); + throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported by your PHP version. See http://php.net/manual/en/openssl.constsni.php.'); } // Asset creation requires a separate endpoint, uploads.github.com. From d8acca3b24c85a35bca9b25e10e402cb562526e1 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 26 Jul 2014 13:08:51 +0100 Subject: [PATCH 142/951] Testing improvements --- .travis.yml | 9 +++------ test/Github/Tests/Api/Repository/AssetsTest.php | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96f47d3d858..d1f4b972c7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,9 @@ php: - 5.6 - hhvm -matrix: - allow_failures: - - php: hhvm - before_script: - - composer install --dev --prefer-source + - travis_retry composer self-update + - travis_retry composer install --no-interaction --prefer-source --dev script: - - phpunit --coverage-text + - vendor/bin/phpunit --verbose --coverage-text diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 2e560193a6c..be779cc4c65 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -46,6 +46,12 @@ public function shouldGetSingleReleaseAsset() */ public function shouldCreateReleaseAsset() { + if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) { + return $this->markTestSkipped( + 'Asset upload support requires Server Name Indication. This is not supported be your PHP version.' + ); + } + $name = 'asset.gzip'; $body = 'assetCreatedData'; $contentType = 'application/gzip'; From 30665a90514ddfb44d81bb554a64afc5aa459aeb Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 26 Jul 2014 13:24:55 +0100 Subject: [PATCH 143/951] Added a .gitattributes file --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..043395a4003 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +* text=auto + +/doc export-ignore +/test export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/README.markdown export-ignore From abaedeaef7a5fd4d9fbd264c9ff13bb91da8c785 Mon Sep 17 00:00:00 2001 From: Beleneglorion Date: Sun, 27 Jul 2014 14:40:34 +0200 Subject: [PATCH 144/951] add a getLastResponse method to CachedHttpClient that return the cached version of the response by default --- lib/Github/HttpClient/CachedHttpClient.php | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index dfbe6630f31..95e6913b373 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -18,6 +18,13 @@ class CachedHttpClient extends HttpClient * @var CacheInterface */ protected $cache; + + /** + * contains the lastResponse fetched from cache + * + * @var Guzzle\Http\Message\Response + */ + private $lastCachedResponse; /** * @return CacheInterface @@ -45,9 +52,12 @@ public function setCache(CacheInterface $cache) public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { $response = parent::request($path, $body, $httpMethod, $headers, $options); - + if (304 == $response->getStatusCode()) { - return $this->getCache()->get($path); + $cacheResponse = $this->getCache()->get($path); + $this->lastCachedResponse = $cacheResponse; + + return $cacheResponse; } $this->getCache()->set($path, $response); @@ -82,4 +92,18 @@ protected function createRequest($httpMethod, $path, $body = null, array $header return $request; } + + /** + * @return Guzzle\Http\Message\Response + */ + public function getLastResponse($force = false) + { + + $lastResponse = parent::getLastResponse(); + if (304 != $lastResponse->getStatusCode()) { + $force = true; + } + + return ($force) ? $lastResponse : $this->lastCachedResponse; + } } From 4f5debb0898c52aa3fd44f256a6f75e02c65035d Mon Sep 17 00:00:00 2001 From: Christian Flach Date: Mon, 28 Jul 2014 14:29:04 +0200 Subject: [PATCH 145/951] Do not overwrite headers. --- lib/Github/HttpClient/CachedHttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index dfbe6630f31..ead0141689e 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -62,7 +62,7 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers */ protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) { - $request = parent::createRequest($httpMethod, $path, $body, $headers = array(), $options); + $request = parent::createRequest($httpMethod, $path, $body, $headers, $options); if ($modifiedAt = $this->getCache()->getModifiedSince($path)) { $modifiedAt = new \DateTime('@'.$modifiedAt); From e862da7161aeeb52fa8602cbe51dcfc1b3590c65 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 31 Jul 2014 13:27:14 +0200 Subject: [PATCH 146/951] Remove constructor constraint from interface declaration --- lib/Github/Api/ApiInterface.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Github/Api/ApiInterface.php b/lib/Github/Api/ApiInterface.php index c5928637ac7..d55fe8fe0f3 100644 --- a/lib/Github/Api/ApiInterface.php +++ b/lib/Github/Api/ApiInterface.php @@ -2,8 +2,6 @@ namespace Github\Api; -use Github\Client; - /** * Api interface * @@ -11,7 +9,6 @@ */ interface ApiInterface { - public function __construct(Client $client); public function getPerPage(); From e17cbcbec62186b793eada671381ed5e652d9a90 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 31 Jul 2014 14:22:16 +0200 Subject: [PATCH 147/951] Add exists method to Contents API Using only HEAD method to avoid downloading file contents when the file does exist --- lib/Github/Api/AbstractApi.php | 107 +++++++++--------- lib/Github/Api/Repository/Contents.php | 37 ++++++ .../Tests/Api/Repository/ContentsTest.php | 78 +++++++++++++ test/Github/Tests/Api/TestCase.php | 2 +- 4 files changed, 168 insertions(+), 56 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 7ef6e6cf353..645121c250d 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -12,6 +12,7 @@ */ abstract class AbstractApi implements ApiInterface { + /** * The client * @@ -22,11 +23,12 @@ abstract class AbstractApi implements ApiInterface /** * number of items per page (GitHub pagination) * - * @var null|int + * @var null int */ protected $perPage; /** + * * @param Client $client */ public function __construct(Client $client) @@ -35,11 +37,11 @@ public function __construct(Client $client) } public function configure() - { - } + {} /** - * @return null|int + * + * @return null int */ public function getPerPage() { @@ -47,6 +49,7 @@ public function getPerPage() } /** + * * @param null|int $perPage */ public function setPerPage($perPage) @@ -59,14 +62,14 @@ public function setPerPage($perPage) /** * Send a GET request with query parameters. * - * @param string $path Request path. - * @param array $parameters GET parameters. - * @param array $requestHeaders Request Headers. - * @return \Guzzle\Http\EntityBodyInterface|mixed|string + * @param string $path Request path. + * @param array $parameters GET parameters. + * @param array $requestHeaders Request Headers. + * @return \Guzzle\Http\EntityBodyInterface mixed string */ protected function get($path, array $parameters = array(), $requestHeaders = array()) { - if (null !== $this->perPage && !isset($parameters['per_page'])) { + if (null !== $this->perPage && ! isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; } if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { @@ -77,94 +80,88 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr return ResponseMediator::getContent($response); } + /** + * Send a HEAD request with query parameters + * + * @param string $path Request path. + * @param array $parameters HEAD parameters. + * @param array $requestHeaders Request headers. + * @return \Guzzle\Http\Message\Response Response. + */ + protected function head($path, array $parameters = array(), $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->request($path, null, 'HEAD', $requestHeaders, array( + 'query' => $parameters + )); + + return $response; + } + /** * Send a POST request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function post($path, array $parameters = array(), $requestHeaders = array()) { - return $this->postRaw( - $path, - $this->createJsonBody($parameters), - $requestHeaders - ); + return $this->postRaw($path, $this->createJsonBody($parameters), $requestHeaders); } /** * Send a POST request with raw data. * - * @param string $path Request path. - * @param $body Request body. - * @param array $requestHeaders Request headers. - * @return \Guzzle\Http\EntityBodyInterface|mixed|string + * @param string $path Request path. + * @param $body Request body. + * @param array $requestHeaders Request headers. + * @return \Guzzle\Http\EntityBodyInterface mixed string */ protected function postRaw($path, $body, $requestHeaders = array()) { - $response = $this->client->getHttpClient()->post( - $path, - $body, - $requestHeaders - ); + $response = $this->client->getHttpClient()->post($path, $body, $requestHeaders); return ResponseMediator::getContent($response); } - /** * Send a PATCH request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function patch($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->patch( - $path, - $this->createJsonBody($parameters), - $requestHeaders - ); + $response = $this->client->getHttpClient()->patch($path, $this->createJsonBody($parameters), $requestHeaders); return ResponseMediator::getContent($response); } - /** * Send a PUT request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function put($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->put( - $path, - $this->createJsonBody($parameters), - $requestHeaders - ); + $response = $this->client->getHttpClient()->put($path, $this->createJsonBody($parameters), $requestHeaders); return ResponseMediator::getContent($response); } - /** * Send a DELETE request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function delete($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->delete( - $path, - $this->createJsonBody($parameters), - $requestHeaders - ); + $response = $this->client->getHttpClient()->delete($path, $this->createJsonBody($parameters), $requestHeaders); return ResponseMediator::getContent($response); } @@ -172,8 +169,8 @@ protected function delete($path, array $parameters = array(), $requestHeaders = /** * Create a JSON encoded version of an array of parameters. * - * @param array $parameters Request parameters - * @return null|string + * @param array $parameters Request parameters + * @return null string */ protected function createJsonBody(array $parameters) { diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 5ed185b362b..baee829770c 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -6,6 +6,7 @@ use Github\Exception\InvalidArgumentException; use Github\Exception\ErrorException; use Github\Exception\MissingArgumentException; +use Github\Exception\TwoFactorAuthenticationRequiredException; /** * @link http://developer.github.com/v3/repos/contents/ @@ -92,6 +93,42 @@ public function create($username, $repository, $path, $content, $message, $branc return $this->put($url, $parameters); } + /** + * Checks that a given path exists in a repository. + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path of file to check + * @param null|string $reference reference to a branch or commit + * @return boolean + */ + public function exists($username, $repository, $path, $reference = null) + { + $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; + + if (null !== $path) { + $url .= '/'.rawurlencode($path); + } + + try { + $response = $this->head($url, array( + 'ref' => $reference + )); + + if ($response->getStatusCode() != 200) { + return false; + } + } + catch (TwoFactorAuthenticationRequiredException $ex) { + throw $ex; + } + catch (\Exception $ex) { + return false; + } + + return true; + } + /** * Updates the contents of a file in a repository * @link http://developer.github.com/v3/repos/contents/#update-a-file diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 0f74f237fb8..1d746866224 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -3,6 +3,7 @@ namespace Github\Tests\Api\Repository; use Github\Tests\Api\TestCase; +use Github\Exception\TwoFactorAuthenticationRequiredException; class ContentsTest extends TestCase { @@ -38,6 +39,83 @@ public function shouldShowReadme() $this->assertEquals($expectedValue, $api->readme('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldReturnTrueWhenFileExists() + { + $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') + ->disableOriginalConstructor() + ->getMock(); + + $responseMock->expects($this->any()) + ->method('getStatusCode') + ->willReturn(200); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('head') + ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->will($this->returnValue($responseMock)); + + $this->assertEquals(true, $api->exists('KnpLabs', 'php-github-api', 'composer.json')); + } + + private function getGuzzleResponseMock() + { + $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') + ->disableOriginalConstructor() + ->getMock(); + + return $responseMock; + } + + public function getFailureStubsForExistsTest() + { + $nonOkResponseMock =$this->getGuzzleResponseMock(); + + $nonOkResponseMock->expects($this->any()) + ->method('getStatusCode') + ->willReturn(403); + + return array( + array($this->throwException(new \ErrorException())), + array($this->returnValue($nonOkResponseMock)) + ); + } + + /** + * @test + * @dataProvider getFailureStubsForExistsTest + */ + public function shouldReturnFalseWhenFileIsNotFound(\PHPUnit_Framework_MockObject_Stub $failureStub) + { + $expectedValue = array('some-header' => 'value'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('head') + ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->will($failureStub); + + $this->assertFalse($api->exists('KnpLabs', 'php-github-api', 'composer.json')); + } + + /** + * @test + * @expectedException \Github\Exception\TwoFactorAuthenticationRequiredException + */ + public function shouldBubbleTwoFactorAuthenticationRequiredExceptionsWhenCheckingFileRequiringAuth() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('head') + ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->will($this->throwException(new TwoFactorAuthenticationRequiredException(0))); + + $api->exists('KnpLabs', 'php-github-api', 'composer.json'); + } + /** * @test */ diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index b96f0e43bbb..a8f322e31e7 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -19,7 +19,7 @@ protected function getApiMock() $client->setHttpClient($mock); return $this->getMockBuilder($this->getApiClass()) - ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put')) + ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) ->setConstructorArgs(array($client)) ->getMock(); } From aa672395508a8646f00c05beec36ada958090d75 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 31 Jul 2014 14:59:18 +0200 Subject: [PATCH 148/951] Fix doc comment formatting --- lib/Github/Api/AbstractApi.php | 95 +++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 645121c250d..7ed7e56ca24 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -23,7 +23,7 @@ abstract class AbstractApi implements ApiInterface /** * number of items per page (GitHub pagination) * - * @var null int + * @var null|int */ protected $perPage; @@ -37,11 +37,12 @@ public function __construct(Client $client) } public function configure() - {} + { + } /** * - * @return null int + * @return null|int */ public function getPerPage() { @@ -62,14 +63,14 @@ public function setPerPage($perPage) /** * Send a GET request with query parameters. * - * @param string $path Request path. - * @param array $parameters GET parameters. - * @param array $requestHeaders Request Headers. - * @return \Guzzle\Http\EntityBodyInterface mixed string + * @param string $path Request path. + * @param array $parameters GET parameters. + * @param array $requestHeaders Request Headers. + * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ protected function get($path, array $parameters = array(), $requestHeaders = array()) { - if (null !== $this->perPage && ! isset($parameters['per_page'])) { + if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; } if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { @@ -83,13 +84,17 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr /** * Send a HEAD request with query parameters * - * @param string $path Request path. - * @param array $parameters HEAD parameters. - * @param array $requestHeaders Request headers. - * @return \Guzzle\Http\Message\Response Response. + * @param string $path Request path. + * @param array $parameters HEAD parameters. + * @param array $requestHeaders Request headers. + * @return \Guzzle\Http\Message\Response */ protected function head($path, array $parameters = array(), $requestHeaders = array()) { + if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { + unset($parameters['ref']); + } + $response = $this->client->getHttpClient()->request($path, null, 'HEAD', $requestHeaders, array( 'query' => $parameters )); @@ -100,26 +105,34 @@ protected function head($path, array $parameters = array(), $requestHeaders = ar /** * Send a POST request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function post($path, array $parameters = array(), $requestHeaders = array()) { - return $this->postRaw($path, $this->createJsonBody($parameters), $requestHeaders); + return $this->postRaw( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); } /** * Send a POST request with raw data. * - * @param string $path Request path. - * @param $body Request body. - * @param array $requestHeaders Request headers. - * @return \Guzzle\Http\EntityBodyInterface mixed string + * @param string $path Request path. + * @param $body Request body. + * @param array $requestHeaders Request headers. + * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ protected function postRaw($path, $body, $requestHeaders = array()) { - $response = $this->client->getHttpClient()->post($path, $body, $requestHeaders); + $response = $this->client->getHttpClient()->post( + $path, + $body, + $requestHeaders + ); return ResponseMediator::getContent($response); } @@ -127,13 +140,17 @@ protected function postRaw($path, $body, $requestHeaders = array()) /** * Send a PATCH request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function patch($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->patch($path, $this->createJsonBody($parameters), $requestHeaders); + $response = $this->client->getHttpClient()->patch( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); return ResponseMediator::getContent($response); } @@ -141,13 +158,17 @@ protected function patch($path, array $parameters = array(), $requestHeaders = a /** * Send a PUT request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function put($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->put($path, $this->createJsonBody($parameters), $requestHeaders); + $response = $this->client->getHttpClient()->put( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); return ResponseMediator::getContent($response); } @@ -155,13 +176,17 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr /** * Send a DELETE request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function delete($path, array $parameters = array(), $requestHeaders = array()) { - $response = $this->client->getHttpClient()->delete($path, $this->createJsonBody($parameters), $requestHeaders); + $response = $this->client->getHttpClient()->delete( + $path, + $this->createJsonBody($parameters), + $requestHeaders + ); return ResponseMediator::getContent($response); } @@ -169,8 +194,8 @@ protected function delete($path, array $parameters = array(), $requestHeaders = /** * Create a JSON encoded version of an array of parameters. * - * @param array $parameters Request parameters - * @return null string + * @param array $parameters Request parameters + * @return null|string */ protected function createJsonBody(array $parameters) { From b402495acfecbe9a61079c7151917da17bda44ae Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 31 Jul 2014 16:17:41 +0200 Subject: [PATCH 149/951] Undo extra/removed lines by autoformat --- lib/Github/Api/AbstractApi.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 7ed7e56ca24..724aaf44b35 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -12,7 +12,6 @@ */ abstract class AbstractApi implements ApiInterface { - /** * The client * @@ -28,7 +27,6 @@ abstract class AbstractApi implements ApiInterface protected $perPage; /** - * * @param Client $client */ public function __construct(Client $client) @@ -41,7 +39,6 @@ public function configure() } /** - * * @return null|int */ public function getPerPage() @@ -50,7 +47,6 @@ public function getPerPage() } /** - * * @param null|int $perPage */ public function setPerPage($perPage) @@ -194,7 +190,7 @@ protected function delete($path, array $parameters = array(), $requestHeaders = /** * Create a JSON encoded version of an array of parameters. * - * @param array $parameters Request parameters + * @param array $parameters Request parameters * @return null|string */ protected function createJsonBody(array $parameters) From f9d2df810e41ef0650ccde86e3f7035b2259e61e Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 31 Jul 2014 16:38:31 +0200 Subject: [PATCH 150/951] Add doc for Contents API --- doc/index.md | 1 + doc/repo/contents.md | 56 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 doc/repo/contents.md diff --git a/doc/index.md b/doc/index.md index 6c3c8152de4..e278e2c931b 100644 --- a/doc/index.md +++ b/doc/index.md @@ -15,6 +15,7 @@ APIs: * [Pull Requests](pull_requests.md) * [Comments](pull_request/comments.md) * [Repositories](repos.md) + * [Contents](repo/contents.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) * [Users](users.md) diff --git a/doc/repo/contents.md b/doc/repo/contents.md new file mode 100644 index 00000000000..6307f5d449b --- /dev/null +++ b/doc/repo/contents.md @@ -0,0 +1,56 @@ +## Repo / Contents API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) + +### Get a repository's README + +```php +$readme = $client->api('repo')->contents()->readme('knp-labs', 'php-github-api', $reference); +``` + +### Get information about a repository file or directory + +```php +$fileInfo = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $reference); +``` + +### Check that a file or directory exists in the repository +```php +$fileExists = $client->api('repo')->contents()->exists('knp-labs', 'php-github-api', $path, $reference); +``` + +### Create a file +```php +$committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); + +$fileInfo = $client->api('repo')->contents()->create('knp-labs', 'php-github-api', $path, $content, $commitMessage, $branch, $committer); +``` + +### Update a file + +```php +$committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); +$oldFile = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $branch); + +$fileInfo = $client->api('repo')->contents()->create('knp-labs', 'php-github-api', $path, $content, $commitMessage, $oldFile['sha'], $branch, $committer); +``` + +### Remove a file + +```php +$committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); +$oldFile = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $branch); + +$fileInfo = $client->api('repo')->contents()->rm('knp-labs', 'php-github-api', $path, $commitMessage, $oldFile['sha'], $branch, $committer); +``` + +### Get repository archive + +```php +// @todo Document +``` + +### Download a file + +```php +$fileContent = $client->api('repo')->contents()->download('knp-labs', 'php-github-api', $path, $reference); +``` From b4f3acd8616a5d047a538a4ce5ee11ebd4761f53 Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Fri, 1 Aug 2014 02:36:36 +0200 Subject: [PATCH 151/951] Formatting --- lib/Github/Api/Repository/Contents.php | 6 ++---- .../Tests/Api/Repository/ContentsTest.php | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index baee829770c..2889c1c7e8b 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -118,11 +118,9 @@ public function exists($username, $repository, $path, $reference = null) if ($response->getStatusCode() != 200) { return false; } - } - catch (TwoFactorAuthenticationRequiredException $ex) { + } catch (TwoFactorAuthenticationRequiredException $ex) { throw $ex; - } - catch (\Exception $ex) { + } catch (\Exception $ex) { return false; } diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 1d746866224..a57ed3245ac 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -61,15 +61,6 @@ public function shouldReturnTrueWhenFileExists() $this->assertEquals(true, $api->exists('KnpLabs', 'php-github-api', 'composer.json')); } - private function getGuzzleResponseMock() - { - $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') - ->disableOriginalConstructor() - ->getMock(); - - return $responseMock; - } - public function getFailureStubsForExistsTest() { $nonOkResponseMock =$this->getGuzzleResponseMock(); @@ -324,4 +315,14 @@ protected function getApiClass() { return 'Github\Api\Repository\Contents'; } + + + private function getGuzzleResponseMock() + { + $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') + ->disableOriginalConstructor() + ->getMock(); + + return $responseMock; + } } From 377878463ef7c959ce92b18534e392b6af055a53 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 1 Aug 2014 10:50:03 +0100 Subject: [PATCH 152/951] Added a Laravel usage section --- README.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.markdown b/README.markdown index ff29b648a9f..85d9453e962 100755 --- a/README.markdown +++ b/README.markdown @@ -44,6 +44,18 @@ Now we can use autoloader from Composer by: > `php-github-api` follows the PSR-0 convention names for its classes, which means you can easily integrate `php-github-api` classes loading in your own autoloader. +## Using Laravel? + +[Laravel GitHub](https://github.com/GrahamCampbell/Laravel-GitHub) by [Graham Campbell](https://github.com/GrahamCampbell) might interest you. + +```json +{ + "require": { + "graham-campbell/github": "0.1.*" + } +} +``` + ## Basic usage of `php-github-api` client ```php From 9f4773d877a2bbc925d7cf2452acad199371731f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 1 Aug 2014 10:51:38 +0100 Subject: [PATCH 153/951] Updated the readme --- README.markdown | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index ff29b648a9f..1c3b4452b26 100755 --- a/README.markdown +++ b/README.markdown @@ -33,12 +33,11 @@ $ php composer.phar install ``` Now we can use autoloader from Composer by: -```yaml +```json { "require": { - "knplabs/github-api": "*" - }, - "minimum-stability": "dev" + "knplabs/github-api": "~1.2" + } } ``` From c59df207f903449cd4a8259b62d6fbb12164f0cb Mon Sep 17 00:00:00 2001 From: Sergey Polischook Date: Sat, 9 Aug 2014 22:44:13 +0300 Subject: [PATCH 154/951] Update gists.md fixed typo --- doc/gists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/gists.md b/doc/gists.md index 696fda9d1a6..9cbfb0a1624 100644 --- a/doc/gists.md +++ b/doc/gists.md @@ -60,7 +60,7 @@ $data = array( 'description' => 'This is new description' ); -$gist = $github->api('gists')->update($data); +$gist = $github->api('gists')->update(1234, $data); ``` You can update ``content`` of a previous file's version. From 1d2a00a8961897d220088f2382d7d56f57ffcc8e Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Wed, 13 Aug 2014 23:53:45 +1000 Subject: [PATCH 155/951] Add support for filtering organisation members by 2FA status --- lib/Github/Api/Organization/Members.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 691f11c335c..034cffbff36 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -10,13 +10,20 @@ */ class Members extends AbstractApi { - public function all($organization, $type = null) + public function all($organization, $type = null, $filter = 'all') { + $parameters = array(); + $path = 'orgs/'.rawurlencode($organization).'/'; if (null === $type) { - return $this->get('orgs/'.rawurlencode($organization).'/members'); + $path .= 'members'; + if (null !== $filter) { + $parameters['filter'] = $filter; + } + } else { + $path .= 'public_members'; } - return $this->get('orgs/'.rawurlencode($organization).'/public_members'); + return $this->get($path, $parameters); } public function show($organization, $username) From e715465d222a15403de7bb28f11acb55a95f22fc Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Sat, 16 Aug 2014 01:53:52 +0200 Subject: [PATCH 156/951] Add support for the combined view of commit statuses --- lib/Github/Api/Repository/Statuses.php | 16 +++- .../Tests/Api/Repository/StatusesTest.php | 94 +++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 test/Github/Tests/Api/Repository/StatusesTest.php diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index 918b2bd4cd6..6d69ef3965f 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -22,7 +22,21 @@ class Statuses extends AbstractApi */ public function show($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/statuses'); + } + + /** + * @link https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref + * + * @param string $username + * @param string $repository + * @param string $sha + * + * @return array + */ + public function combined($username, $repository, $sha) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/status'); } /** diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php new file mode 100644 index 00000000000..c27f09b404e --- /dev/null +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -0,0 +1,94 @@ + 'success', 'context' => 'Travis'), + array('state' => 'pending', 'context' => 'Travis') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/statuses') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'commitSHA123456')); + } + + /** + * @test + */ + public function shouldShowCombinedCommitStatuses() + { + $expectedValue = array( + array( + 'state' => 'success', + 'statuses' => array( + array( + 'state' => 'success', + 'context' => 'Travis' + ), + array( + 'state' => 'success', + 'context' => 'Jenkins' + ) + ) + ) + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/status') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->combined('KnpLabs', 'php-github-api', 'commitSHA123456')); + } + + /** + * @test + * @expectedException Github\Exception\MissingArgumentException + */ + public function shouldNotCreateWithoutStatus() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data); + } + + /** + * @test + */ + public function shouldCreateCommitStatus() + { + $expectedValue = array('state' => 'success'); + $data = array('state' => 'success'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('repos/KnpLabs/php-github-api/statuses/commitSHA123456', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data)); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Statuses'; + } +} From 81aa33e822c949e2a58d2aee8bb510f64ac643e6 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 21 Aug 2014 10:12:35 +0100 Subject: [PATCH 157/951] Closes #177 - use the magic __call method for IDE completion --- lib/Github/Client.php | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 5c102ba11f5..686791cc079 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -10,6 +10,34 @@ /** * Simple yet very cool PHP GitHub client * + * @method Api\CurrentUser currentUser() + * @method Api\CurrentUser me() + * @method Api\Enterprise ent() + * @method Api\Enterprise enterprise() + * @method Api\GitData git() + * @method Api\GitData gitData() + * @method Api\Gists gist() + * @method Api\Gists gists() + * @method Api\Issue issue() + * @method Api\Issue issues() + * @method Api\Markdown markdown() + * @method Api\Organization organization() + * @method Api\Organization organizations() + * @method Api\PullRequest pr() + * @method Api\PullRequest pullRequest() + * @method Api\PullRequest pullRequests() + * @method Api\Repo repo() + * @method Api\Repo repos() + * @method Api\Repo repository() + * @method Api\Repo repositories() + * @method Api\Organization team() + * @method Api\Organization teams() + * @method Api\User user() + * @method Api\User users() + * @method Api\Authorizations authorization() + * @method Api\Authorizations authorizations() + * @method Api\Meta meta() + * * @author Joseph Bielawski * * Website: http://github.com/KnpLabs/php-github-api @@ -274,4 +302,86 @@ public function getSupportedApiVersions() { return array('v3', 'beta'); } + + /** + * @param string $name + * + * @return ApiInterface + * + * @throws InvalidArgumentException + */ + public function __call($name) { + switch ($name) { + case 'me': + case 'currentUser': + $api = new Api\CurrentUser($this); + break; + + case 'ent': + case 'enterprise': + $api = new Api\Enterprise($this); + break; + + case 'git': + case 'gitData': + $api = new Api\GitData($this); + break; + + case 'gist': + case 'gists': + $api = new Api\Gists($this); + break; + + case 'issue': + case 'issues': + $api = new Api\Issue($this); + break; + + case 'markdown': + $api = new Api\Markdown($this); + break; + + case 'organization': + case 'organizations': + $api = new Api\Organization($this); + break; + + case 'pr': + case 'pullRequest': + case 'pullRequests': + $api = new Api\PullRequest($this); + break; + + case 'repo': + case 'repos': + case 'repository': + case 'repositories': + $api = new Api\Repo($this); + break; + + case 'team': + case 'teams': + $api = new Api\Organization\Teams($this); + break; + + case 'user': + case 'users': + $api = new Api\User($this); + break; + + case 'authorization': + case 'authorizations': + $api = new Api\Authorizations($this); + break; + + case 'meta': + $api = new Api\Meta($this); + break; + + default: + throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); + } + + return $api; + } } From 34b5186a76cc22fb88532a1673e34066776e01aa Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 21 Aug 2014 10:14:05 +0100 Subject: [PATCH 158/951] Forgot about the missing args param --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 686791cc079..e3e9939ebc6 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -310,7 +310,7 @@ public function getSupportedApiVersions() * * @throws InvalidArgumentException */ - public function __call($name) { + public function __call($name, $args) { switch ($name) { case 'me': case 'currentUser': From af024a609c9e878b66e833a73ea132fa22b928d9 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 21 Aug 2014 10:15:48 +0100 Subject: [PATCH 159/951] Make use of the api method and move the camelCase aliases into it --- lib/Github/Client.php | 77 +++---------------------------------------- 1 file changed, 5 insertions(+), 72 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e3e9939ebc6..bac289f0d29 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -112,6 +112,7 @@ public function api($name) switch ($name) { case 'me': case 'current_user': + case 'currentUser': $api = new Api\CurrentUser($this); break; @@ -122,6 +123,7 @@ public function api($name) case 'git': case 'git_data': + case 'gitData': $api = new Api\GitData($this); break; @@ -145,7 +147,9 @@ public function api($name) break; case 'pr': + case 'pullRequest': case 'pull_request': + case 'pullRequests': case 'pull_requests': $api = new Api\PullRequest($this); break; @@ -311,77 +315,6 @@ public function getSupportedApiVersions() * @throws InvalidArgumentException */ public function __call($name, $args) { - switch ($name) { - case 'me': - case 'currentUser': - $api = new Api\CurrentUser($this); - break; - - case 'ent': - case 'enterprise': - $api = new Api\Enterprise($this); - break; - - case 'git': - case 'gitData': - $api = new Api\GitData($this); - break; - - case 'gist': - case 'gists': - $api = new Api\Gists($this); - break; - - case 'issue': - case 'issues': - $api = new Api\Issue($this); - break; - - case 'markdown': - $api = new Api\Markdown($this); - break; - - case 'organization': - case 'organizations': - $api = new Api\Organization($this); - break; - - case 'pr': - case 'pullRequest': - case 'pullRequests': - $api = new Api\PullRequest($this); - break; - - case 'repo': - case 'repos': - case 'repository': - case 'repositories': - $api = new Api\Repo($this); - break; - - case 'team': - case 'teams': - $api = new Api\Organization\Teams($this); - break; - - case 'user': - case 'users': - $api = new Api\User($this); - break; - - case 'authorization': - case 'authorizations': - $api = new Api\Authorizations($this); - break; - - case 'meta': - $api = new Api\Meta($this); - break; - - default: - throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); - } - - return $api; + return $this->api($name); } } From 3e0839f0036d2663a1bb256aea44a884f700cd7a Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 21 Aug 2014 10:32:25 +0100 Subject: [PATCH 160/951] Tests and catching of InvalidArgumentException within __call --- lib/Github/Client.php | 6 +++++- test/Github/Tests/ClientTest.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index bac289f0d29..a46bb9fe749 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -315,6 +315,10 @@ public function getSupportedApiVersions() * @throws InvalidArgumentException */ public function __call($name, $args) { - return $this->api($name); + try { + return $this->api($name); + } catch (InvalidArgumentException $e) { + throw new BadMethodCallException(sprintf('Undefined method called: "%s"', $name)); + } } } diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 8ebe27f785f..c9e2f447e41 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -124,6 +124,17 @@ public function shouldGetApiInstance($apiName, $class) $this->assertInstanceOf($class, $client->api($apiName)); } + /** + * @test + * @dataProvider getApiClassesProvider + */ + public function shouldGetMagicApiInstance($apiName, $class) + { + $client = new Client(); + + $this->assertInstanceOf($class, $client->$apiName()); + } + /** * @test * @expectedException InvalidArgumentException @@ -142,9 +153,11 @@ public function getApiClassesProvider() array('me', 'Github\Api\CurrentUser'), array('current_user', 'Github\Api\CurrentUser'), + array('currentUser', 'Github\Api\CurrentUser'), array('git', 'Github\Api\GitData'), array('git_data', 'Github\Api\GitData'), + array('gitData', 'Github\Api\GitData'), array('gist', 'Github\Api\Gists'), array('gists', 'Github\Api\Gists'), @@ -163,7 +176,9 @@ public function getApiClassesProvider() array('repositories', 'Github\Api\Repo'), array('pr', 'Github\Api\PullRequest'), + array('pullRequest', 'Github\Api\PullRequest'), array('pull_request', 'Github\Api\PullRequest'), + array('pullRequests', 'Github\Api\PullRequest'), array('pull_requests', 'Github\Api\PullRequest'), array('authorization', 'Github\Api\Authorizations'), From b84ee93f2c03e6282a7b6a8e39ef21bfa61535ce Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 21 Aug 2014 10:36:28 +0100 Subject: [PATCH 161/951] New BadMethodCallException exception. Tests for BadMethodCallException too. --- lib/Github/Client.php | 1 + lib/Github/Exception/BadMethodCallException.php | 13 +++++++++++++ test/Github/Tests/ClientTest.php | 11 +++++++++++ 3 files changed, 25 insertions(+) create mode 100644 lib/Github/Exception/BadMethodCallException.php diff --git a/lib/Github/Client.php b/lib/Github/Client.php index a46bb9fe749..6909264ed66 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -4,6 +4,7 @@ use Github\Api\ApiInterface; use Github\Exception\InvalidArgumentException; +use Github\Exception\BadMethodCallException; use Github\HttpClient\HttpClient; use Github\HttpClient\HttpClientInterface; diff --git a/lib/Github/Exception/BadMethodCallException.php b/lib/Github/Exception/BadMethodCallException.php new file mode 100644 index 00000000000..5c43d20a485 --- /dev/null +++ b/lib/Github/Exception/BadMethodCallException.php @@ -0,0 +1,13 @@ + + */ +class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface +{ + +} diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index c9e2f447e41..04b3a710397 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -4,6 +4,7 @@ use Github\Client; use Github\Exception\InvalidArgumentException; +use Github\Exception\BadMethodCallException; class ClientTest extends \PHPUnit_Framework_TestCase { @@ -145,6 +146,16 @@ public function shouldNotGetApiInstance() $client->api('do_not_exist'); } + /** + * @test + * @expectedException BadMethodCallException + */ + public function shouldNotGetMagicApiInstance() + { + $client = new Client(); + $client->doNotExist(); + } + public function getApiClassesProvider() { return array( From 1e929f3b2a613764c30b3573ddfea6172e64f635 Mon Sep 17 00:00:00 2001 From: Greg Payne Date: Mon, 8 Sep 2014 13:37:40 -0500 Subject: [PATCH 162/951] KnpLabs/php-github-api#178 - adds a basic search api implementation. --- lib/Github/Api/Search.php | 38 ++++++++++++++++++++++++++++++++++++++ lib/Github/Client.php | 6 +++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 lib/Github/Api/Search.php diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php new file mode 100644 index 00000000000..4d3416a73fe --- /dev/null +++ b/lib/Github/Api/Search.php @@ -0,0 +1,38 @@ + + */ +class Search extends AbstractApi +{ + /** + * Search by filter (q) + * @link http://developer.github.com/v3/search/ + * + * @param string $type the search type + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc + * + * @return array list of issues found + */ + public function find($type = 'issues', $q = '', $sort = 'updated', $order = 'desc') + { + if (!in_array($type, array('issues', 'repositories', 'code', 'users'))) { + $type = 'issues'; + } + return $this->get("/search/$type", array('q' => $q, 'sort' => $sort, 'order' => $order)); + } + +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 6909264ed66..92e81254e56 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -162,6 +162,10 @@ public function api($name) $api = new Api\Repo($this); break; + case 'search': + $api = new Api\Search($this); + break; + case 'team': case 'teams': $api = new Api\Organization\Teams($this); @@ -310,7 +314,7 @@ public function getSupportedApiVersions() /** * @param string $name - * + * * @return ApiInterface * * @throws InvalidArgumentException From 3dd65b7bae223030c102b9ca985daa48e451c58a Mon Sep 17 00:00:00 2001 From: Greg Payne Date: Mon, 8 Sep 2014 15:00:59 -0500 Subject: [PATCH 163/951] Split find into 4 methods. --- lib/Github/Api/Search.php | 58 +++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 4d3416a73fe..26ee09debed 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -16,23 +16,65 @@ */ class Search extends AbstractApi { + + /** + * Search repositories by filter (q) + * @link https://developer.github.com/v3/search/#search-repositories + * + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc + * + * @return array list of repositories found + */ + public function repositories($q, $sort = 'updated', $order = 'desc') + { + return $this->get("/search/repositories", array('q' => $q, 'sort' => $sort, 'order' => $order)); + } + /** - * Search by filter (q) - * @link http://developer.github.com/v3/search/ + * Search issues by filter (q) + * @link https://developer.github.com/v3/search/#search-issues * - * @param string $type the search type * @param string $q the filter * @param string $sort the sort field * @param string $order asc/desc * * @return array list of issues found */ - public function find($type = 'issues', $q = '', $sort = 'updated', $order = 'desc') + public function issues($q, $sort = 'updated', $order = 'desc') + { + return $this->get("/search/issues", array('q' => $q, 'sort' => $sort, 'order' => $order)); + } + + /** + * Search code by filter (q) + * @link https://developer.github.com/v3/search/#search-code + * + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc + * + * @return array list of code found + */ + public function code($q, $sort = 'updated', $order = 'desc') + { + return $this->get("/search/code", array('q' => $q, 'sort' => $sort, 'order' => $order)); + } + + /** + * Search users by filter (q) + * @link https://developer.github.com/v3/search/#search-users + * + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc + * + * @return array list of users found + */ + public function users($q, $sort = 'updated', $order = 'desc') { - if (!in_array($type, array('issues', 'repositories', 'code', 'users'))) { - $type = 'issues'; - } - return $this->get("/search/$type", array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get("/search/users", array('q' => $q, 'sort' => $sort, 'order' => $order)); } } From 32ae587ee22e15dd89f20cd1a9607a504c780f47 Mon Sep 17 00:00:00 2001 From: Greg Payne Date: Mon, 8 Sep 2014 15:11:31 -0500 Subject: [PATCH 164/951] Added method phpdoc. --- lib/Github/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 92e81254e56..c1779663858 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -31,6 +31,7 @@ * @method Api\Repo repos() * @method Api\Repo repository() * @method Api\Repo repositories() + * @method Api\Search search() * @method Api\Organization team() * @method Api\Organization teams() * @method Api\User user() From ea22c841c10a1835221118a2b35bbdcc8130e5d9 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Tue, 9 Sep 2014 13:59:45 +0200 Subject: [PATCH 165/951] Handle the additional arguments correctly from the user->repositories() method. --- lib/Github/Api/User.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 6142dffe1bd..50545caa510 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -139,9 +139,9 @@ public function subscriptions($username) public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') { return $this->get('users/'.rawurlencode($username).'/repos', array( - $type, - $sort, - $direction + 'type' => $type, + 'sort' => $sort, + 'direction' => $direction )); } From 406e848b97eee46e0d9be37588bfed4b3b96bcd6 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Tue, 9 Sep 2014 14:19:20 +0200 Subject: [PATCH 166/951] Fix the UserTest according to the new expected arguments structure. --- test/Github/Tests/Api/UserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 189e52c26fa..dec69d7944b 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -139,7 +139,7 @@ public function shouldGetUserRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/repos', array('owner', 'full_name', 'asc')) + ->with('users/l3l0/repos', array('type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('l3l0')); From d765ca441e3f693f10fbe06f8d26e631b8c8e672 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Tue, 9 Sep 2014 18:34:23 +0200 Subject: [PATCH 167/951] Fixed not clear documentation --- doc/result_pager.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/result_pager.md b/doc/result_pager.md index 52ac2993696..d9e58ff705a 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -3,7 +3,7 @@ ### Usage examples -Get all repositories of a organization +#### Get all repositories of a organization ```php $client = new Github\Client(); @@ -15,7 +15,14 @@ $parameters = array('github'); $result = $paginator->fetchAll($organizationApi, 'repositories', $parameters); ``` -Get the first page +Parameters of the `fetchAll` method: + +* The API object you're working with +* The method of the API object you're using +* The parameters of the method + +#### Get the first page + ```php $client = new Github\Client(); @@ -26,22 +33,26 @@ $parameters = array('github'); $result = $paginator->fetch($organizationApi, 'repositories', $parameters); ``` -Check for a next page: +#### Check for a next page: + ```php $paginator->hasNext(); ``` -Get next page: +#### Get next page: + ```php $paginator->fetchNext(); ``` -Check for previous page: +#### Check for previous page: + ```php $paginator->hasPrevious(); ``` -Get previous page: +#### Get previous page: + ```php $paginator->fetchPrevious(); ``` From b04ef4f85c435226fb036188a8694c2427c30ed6 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Wed, 10 Sep 2014 14:21:05 +0200 Subject: [PATCH 168/951] Fixing a typo, asc instead of ask --- lib/Github/Api/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 50545caa510..20323934fca 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -133,7 +133,7 @@ public function subscriptions($username) * @param string $username the username * @param string $type role in the repository * @param string $sort sort by - * @param string $direction direction of sort, ask or desc + * @param string $direction direction of sort, asc or desc * @return array list of the user repositories */ public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') From fb54d8a8e85520eaa6d1997edbf6441e83b6dfdd Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 12:08:32 +0000 Subject: [PATCH 169/951] added starring api --- lib/Github/Api/CurrentUser.php | 11 ++--- lib/Github/Api/CurrentUser/Starred.php | 65 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 lib/Github/Api/CurrentUser/Starred.php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 38318959589..1ae2f013845 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -7,6 +7,7 @@ use Github\Api\CurrentUser\Followers; use Github\Api\CurrentUser\Notifications; use Github\Api\CurrentUser\Watchers; +use Github\Api\CurrentUser\Starred; /** * @link http://developer.github.com/v3/users/ @@ -119,13 +120,11 @@ public function watched($page = 1) )); } - /** - * @link http://developer.github.com/changes/2012-9-5-watcher-api/ + /** + * @return Starred */ - public function starred($page = 1) + public function starred() { - return $this->get('user/starred', array( - 'page' => $page - )); + return new Starred($this->client); } } diff --git a/lib/Github/Api/CurrentUser/Starred.php b/lib/Github/Api/CurrentUser/Starred.php new file mode 100644 index 00000000000..54d1bb949ca --- /dev/null +++ b/lib/Github/Api/CurrentUser/Starred.php @@ -0,0 +1,65 @@ + + */ +class Starred extends AbstractApi +{ + /** + * List repositories starred by the authenticated user + * @link https://developer.github.com/v3/activity/starring/ + * + * @param integer $page + * @return array + */ + public function all($page = 1) + { + return $this->get('user/starred', array( + 'page' => $page + )); + } + + /** + * Check that the authenticated user starres a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function check($username, $repository) + { + return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user star a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function star($username, $repository) + { + return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user unstar a repository + * @link https://developer.github.com/v3/activity/starring + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function unstar($username, $repository) + { + return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } +} From 784a087090eae6ff957da53b50afe507789a37c2 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 09:11:26 -0300 Subject: [PATCH 170/951] updated documentation --- doc/users.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/users.md b/doc/users.md index b8a8e09949e..b39da069c83 100644 --- a/doc/users.md +++ b/doc/users.md @@ -113,6 +113,16 @@ Returns an array of followed users. $users = $client->api('user')->watched('ornicar'); ``` +For authenticated user use. + +> Requires [authentication](security.md). + +```php +$users = $client->api('current_user')->watched(); +``` + +Returns an array of watched repos. + ### Get repos that a specific user has starred ```php @@ -124,10 +134,10 @@ For authenticated user use. > Requires [authentication](security.md). ```php -$users = $client->api('current_user')->watched(); +$users = $client->api('current_user')->starred()->all(); ``` -Returns an array of watched repos. +Returns an array of starred repos. ### Get the authenticated user emails From 3bf25e84cbe75f6e65b4f28610b367a03fcc61b4 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 12:28:25 +0000 Subject: [PATCH 171/951] added tests for Starred API --- .../Tests/Api/CurrentUser/StarredTest.php | 74 +++++++++++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 10 +++ 2 files changed, 84 insertions(+) create mode 100644 test/Github/Tests/Api/CurrentUser/StarredTest.php diff --git a/test/Github/Tests/Api/CurrentUser/StarredTest.php b/test/Github/Tests/Api/CurrentUser/StarredTest.php new file mode 100644 index 00000000000..9a4af991559 --- /dev/null +++ b/test/Github/Tests/Api/CurrentUser/StarredTest.php @@ -0,0 +1,74 @@ + 'l3l0/test'), + array('name' => 'cordoval/test') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all()); + } + + /** + * @test + */ + public function shouldCheckStar() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->check('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldStarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->star('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldUnstarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->unstar('l3l0', 'test')); + } + + protected function getApiClass() + { + return 'Github\Api\CurrentUser\Starred'; + } +} diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 36316f3c02e..2ef0b920e68 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -133,6 +133,16 @@ public function shouldGetWatchersApiObject() $this->assertInstanceOf('Github\Api\CurrentUser\Watchers', $api->watchers()); } + + /** + * @test + */ + public function shouldGetStarredApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\CurrentUser\Starred', $api->starred()); + } protected function getApiClass() { From 59bdcf7b4c96a1538c1102b829768464e9514ae1 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 15:01:35 +0000 Subject: [PATCH 172/951] improved documentation --- doc/activity.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ doc/index.md | 1 + doc/users.md | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 doc/activity.md diff --git a/doc/activity.md b/doc/activity.md new file mode 100644 index 00000000000..7726509135b --- /dev/null +++ b/doc/activity.md @@ -0,0 +1,51 @@ +## Activity API (incomplete) +[Back to the navigation](index.md) + +Access to Starring and Watching a Repository for authenticated users. +Wrap [GitHub Activity API](https://developer.github.com/v3/activity/). + +> No authentication required. + +### Get repos that a specific user has starred + +```php +$users = $client->api('user')->starred('ornicar'); +``` + +Returns an array of starred repos. + +> Requires [authentication](security.md). + +### Get repos that a authenticated user has starred + +```php +$activity = $client->api('current_user')->starred()->all(); +``` +Returns an array of starred repos. + +### Check if authenticated user has starred a specific repo + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->starred()->check($owner, $repo); +``` +Throws an Exception with code 404 in case that the repo is not starred by the authenticated user or NULL in case that it is starred by the authenticated user. + +### Star a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->starred()->star($owner, $repo); +``` +Throws an Exception in case of failure or NULL in case of success. + +### Unstar a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->starred()->unstar($owner, $repo); +``` +Throws an Exception in case of failure or NULL in case of success. \ No newline at end of file diff --git a/doc/index.md b/doc/index.md index e278e2c931b..176e5a2b51d 100644 --- a/doc/index.md +++ b/doc/index.md @@ -20,6 +20,7 @@ APIs: * [Assets](repo/assets.md) * [Users](users.md) * [Meta](meta.md) +* [Activity](activity.md) Additional features: diff --git a/doc/users.md b/doc/users.md index b39da069c83..c3e1e85dd8b 100644 --- a/doc/users.md +++ b/doc/users.md @@ -108,6 +108,7 @@ $client->api('current_user')->follow()->unfollow('symfony'); Returns an array of followed users. ### Get repos that a specific user is watching +> See [more](activity.md). ```php $users = $client->api('user')->watched('ornicar'); @@ -124,6 +125,7 @@ $users = $client->api('current_user')->watched(); Returns an array of watched repos. ### Get repos that a specific user has starred +> See [more](activity.md). ```php $users = $client->api('user')->starred('ornicar'); From af276bc115d7bad93acfe01295201d8e5c5ab0ce Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:09:06 +0000 Subject: [PATCH 173/951] changed documentation and watch repo api endpoint --- doc/activity.md | 49 +++++++++++++++++++++++-- lib/Github/Api/CurrentUser/Watchers.php | 8 ++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/doc/activity.md b/doc/activity.md index 7726509135b..ab1b338ce58 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -1,10 +1,10 @@ ## Activity API (incomplete) [Back to the navigation](index.md) -Access to Starring and Watching a Repository for authenticated users. +Access to Starring and Watching a Repository for [non] authenticated users. Wrap [GitHub Activity API](https://developer.github.com/v3/activity/). -> No authentication required. +> *** No authentication required. *** ### Get repos that a specific user has starred @@ -14,7 +14,15 @@ $users = $client->api('user')->starred('ornicar'); Returns an array of starred repos. -> Requires [authentication](security.md). +### Get repos that a specific user is watching + +```php +$users = $client->api('user')->watched('ornicar'); +``` + +Returns an array of watched repos. + +> *** Requires [authentication](security.md). *** ### Get repos that a authenticated user has starred @@ -48,4 +56,39 @@ $owner = "KnpLabs"; $repo = "php-github-api"; $activity = $client->api('current_user')->starred()->unstar($owner, $repo); ``` +Throws an Exception in case of failure or NULL in case of success. + + +### Get repos that a authenticated user is watching + +```php +$activity = $client->api('current_user')->watchers()->all(); +``` +Returns an array of watched repos. + +### Check if authenticated user is watching a specific repo + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->watchers()->check($owner, $repo); +``` +Throws an Exception with code 404 in case that the repo is not beeing watched by the authenticated user or NULL in case that it is beeing watched by the authenticated user. + +### Watch a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->watchers()->watch($owner, $repo); +``` +Throws an Exception in case of failure or NULL in case of success. + +### Stop watching a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->watchers()->unwatch($owner, $repo); +``` Throws an Exception in case of failure or NULL in case of success. \ No newline at end of file diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 398ac58536a..07d6e51e0ac 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -19,7 +19,7 @@ class Watchers extends AbstractApi */ public function all($page = 1) { - return $this->get('user/watched', array( + return $this->get('user/subscriptions', array( 'page' => $page )); } @@ -34,7 +34,7 @@ public function all($page = 1) */ public function check($username, $repository) { - return $this->get('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -47,7 +47,7 @@ public function check($username, $repository) */ public function watch($username, $repository) { - return $this->put('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->put('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -60,6 +60,6 @@ public function watch($username, $repository) */ public function unwatch($username, $repository) { - return $this->delete('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } } From ab0752a275cbc79315bb0060fb331e4ae4715e52 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:18:35 +0000 Subject: [PATCH 174/951] changed current_user watch repo method --- doc/users.md | 2 +- lib/Github/Api/CurrentUser.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/users.md b/doc/users.md index c3e1e85dd8b..d90290a727f 100644 --- a/doc/users.md +++ b/doc/users.md @@ -119,7 +119,7 @@ For authenticated user use. > Requires [authentication](security.md). ```php -$users = $client->api('current_user')->watched(); +$users = $client->api('current_user')->watchers()->all(); ``` Returns an array of watched repos. diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 1ae2f013845..6856d9c1ba0 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -112,7 +112,10 @@ public function watchers() { return new Watchers($this->client); } - + + /** + * @Deprecated + */ public function watched($page = 1) { return $this->get('user/watched', array( From 2ed99b2133a6bd4896ba34dd7988e6c73aa5257a Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:30:17 +0000 Subject: [PATCH 175/951] revised comments --- lib/Github/Api/CurrentUser.php | 1 + lib/Github/Api/CurrentUser/Watchers.php | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 6856d9c1ba0..d4e64348001 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -12,6 +12,7 @@ /** * @link http://developer.github.com/v3/users/ * @author Joseph Bielawski + * @revised Felipe Valtl de Mello */ class CurrentUser extends AbstractApi { diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 07d6e51e0ac..035b78f568e 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -5,14 +5,15 @@ use Github\Api\AbstractApi; /** - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * @author Joseph Bielawski + * @revised Felipe Valtl de Mello */ class Watchers extends AbstractApi { /** * List repositories watched by the authenticated user - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param integer $page * @return array @@ -26,7 +27,7 @@ public function all($page = 1) /** * Check that the authenticated user watches a repository - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param string $username the user who owns the repo * @param string $repository the name of the repo @@ -39,7 +40,7 @@ public function check($username, $repository) /** * Make the authenticated user watch a repository - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param string $username the user who owns the repo * @param string $repository the name of the repo @@ -52,7 +53,7 @@ public function watch($username, $repository) /** * Make the authenticated user unwatch a repository - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param string $username the user who owns the repo * @param string $repository the name of the repo From 3fdd77138da446e0a1a5638aa0295bf4b76f947b Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:47:04 +0000 Subject: [PATCH 176/951] corrected watchers test --- test/Github/Tests/Api/CurrentUser/WatchersTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index 15e009f6a08..e2234ed7efb 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -19,7 +19,7 @@ public function shouldGetWatchers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched') + ->with('user/subscriptions') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -33,7 +33,7 @@ public function shouldCheckWatcher() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->check('l3l0', 'test')); @@ -47,7 +47,7 @@ public function shouldWatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->watch('l3l0', 'test')); @@ -61,7 +61,7 @@ public function shouldUnwatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->unwatch('l3l0', 'test')); From 3eec9e7540206aee6132c3c3383f5c4b42d12694 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 17:20:02 +0000 Subject: [PATCH 177/951] fix current version break --- doc/activity.md | 8 +- doc/users.md | 2 +- lib/Github/Api/CurrentUser.php | 18 ++++- lib/Github/Api/CurrentUser/Starring.php | 65 ++++++++++++++++ .../Tests/Api/CurrentUser/StarringTest.php | 74 +++++++++++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 2 +- 6 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 lib/Github/Api/CurrentUser/Starring.php create mode 100644 test/Github/Tests/Api/CurrentUser/StarringTest.php diff --git a/doc/activity.md b/doc/activity.md index ab1b338ce58..ca8c74bf3a1 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -27,7 +27,7 @@ Returns an array of watched repos. ### Get repos that a authenticated user has starred ```php -$activity = $client->api('current_user')->starred()->all(); +$activity = $client->api('current_user')->starring()->all(); ``` Returns an array of starred repos. @@ -36,7 +36,7 @@ Returns an array of starred repos. ```php $owner = "KnpLabs"; $repo = "php-github-api"; -$activity = $client->api('current_user')->starred()->check($owner, $repo); +$activity = $client->api('current_user')->starring()->check($owner, $repo); ``` Throws an Exception with code 404 in case that the repo is not starred by the authenticated user or NULL in case that it is starred by the authenticated user. @@ -45,7 +45,7 @@ Throws an Exception with code 404 in case that the repo is not starred by the au ```php $owner = "KnpLabs"; $repo = "php-github-api"; -$activity = $client->api('current_user')->starred()->star($owner, $repo); +$activity = $client->api('current_user')->starring()->star($owner, $repo); ``` Throws an Exception in case of failure or NULL in case of success. @@ -54,7 +54,7 @@ Throws an Exception in case of failure or NULL in case of success. ```php $owner = "KnpLabs"; $repo = "php-github-api"; -$activity = $client->api('current_user')->starred()->unstar($owner, $repo); +$activity = $client->api('current_user')->starring()->unstar($owner, $repo); ``` Throws an Exception in case of failure or NULL in case of success. diff --git a/doc/users.md b/doc/users.md index d90290a727f..810226af55b 100644 --- a/doc/users.md +++ b/doc/users.md @@ -136,7 +136,7 @@ For authenticated user use. > Requires [authentication](security.md). ```php -$users = $client->api('current_user')->starred()->all(); +$users = $client->api('current_user')->starring()->all(); ``` Returns an array of starred repos. diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index d4e64348001..d69185c320c 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -7,7 +7,7 @@ use Github\Api\CurrentUser\Followers; use Github\Api\CurrentUser\Notifications; use Github\Api\CurrentUser\Watchers; -use Github\Api\CurrentUser\Starred; +use Github\Api\CurrentUser\Starring; /** * @link http://developer.github.com/v3/users/ @@ -123,12 +123,22 @@ public function watched($page = 1) 'page' => $page )); } + + /** + * @return Starring + */ + public function starring() + { + return new Starring($this->client); + } /** - * @return Starred + * @Deprecated */ - public function starred() + public function starred($page = 1) { - return new Starred($this->client); + return $this->get('user/starred', array( + 'page' => $page + )); } } diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php new file mode 100644 index 00000000000..97e0b017c9b --- /dev/null +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -0,0 +1,65 @@ + + */ +class Starring extends AbstractApi +{ + /** + * List repositories starred by the authenticated user + * @link https://developer.github.com/v3/activity/starring/ + * + * @param integer $page + * @return array + */ + public function all($page = 1) + { + return $this->get('user/starred', array( + 'page' => $page + )); + } + + /** + * Check that the authenticated user starres a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function check($username, $repository) + { + return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user star a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function star($username, $repository) + { + return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user unstar a repository + * @link https://developer.github.com/v3/activity/starring + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function unstar($username, $repository) + { + return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } +} diff --git a/test/Github/Tests/Api/CurrentUser/StarringTest.php b/test/Github/Tests/Api/CurrentUser/StarringTest.php new file mode 100644 index 00000000000..c2cba90cfb1 --- /dev/null +++ b/test/Github/Tests/Api/CurrentUser/StarringTest.php @@ -0,0 +1,74 @@ + 'l3l0/test'), + array('name' => 'cordoval/test') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all()); + } + + /** + * @test + */ + public function shouldCheckStar() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->check('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldStarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->star('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldUnstarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->unstar('l3l0', 'test')); + } + + protected function getApiClass() + { + return 'Github\Api\CurrentUser\Starring'; + } +} diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 2ef0b920e68..902b53957b8 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -141,7 +141,7 @@ public function shouldGetStarredApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Starred', $api->starred()); + $this->assertInstanceOf('Github\Api\CurrentUser\Starring', $api->starring()); } protected function getApiClass() From 65894c482748e2d2750686700a659508b76e512f Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 18 Sep 2014 10:48:01 +0000 Subject: [PATCH 178/951] removed unused class and changed docblock --- lib/Github/Api/CurrentUser.php | 4 +- lib/Github/Api/CurrentUser/Starred.php | 65 -------------------------- 2 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 lib/Github/Api/CurrentUser/Starred.php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index d69185c320c..6f920668ad7 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -115,7 +115,7 @@ public function watchers() } /** - * @Deprecated + * @Deprecated Use watchers() instead */ public function watched($page = 1) { @@ -133,7 +133,7 @@ public function starring() } /** - * @Deprecated + * @Deprecated Use starring() instead */ public function starred($page = 1) { diff --git a/lib/Github/Api/CurrentUser/Starred.php b/lib/Github/Api/CurrentUser/Starred.php deleted file mode 100644 index 54d1bb949ca..00000000000 --- a/lib/Github/Api/CurrentUser/Starred.php +++ /dev/null @@ -1,65 +0,0 @@ - - */ -class Starred extends AbstractApi -{ - /** - * List repositories starred by the authenticated user - * @link https://developer.github.com/v3/activity/starring/ - * - * @param integer $page - * @return array - */ - public function all($page = 1) - { - return $this->get('user/starred', array( - 'page' => $page - )); - } - - /** - * Check that the authenticated user starres a repository - * @link https://developer.github.com/v3/activity/starring/ - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @return array - */ - public function check($username, $repository) - { - return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); - } - - /** - * Make the authenticated user star a repository - * @link https://developer.github.com/v3/activity/starring/ - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @return array - */ - public function star($username, $repository) - { - return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); - } - - /** - * Make the authenticated user unstar a repository - * @link https://developer.github.com/v3/activity/starring - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @return array - */ - public function unstar($username, $repository) - { - return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); - } -} From 6acfc0f3f557fb3c28a6a6b963e690bb46fd6c06 Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 18 Sep 2014 10:55:01 +0000 Subject: [PATCH 179/951] removed test --- .../Tests/Api/CurrentUser/StarredTest.php | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 test/Github/Tests/Api/CurrentUser/StarredTest.php diff --git a/test/Github/Tests/Api/CurrentUser/StarredTest.php b/test/Github/Tests/Api/CurrentUser/StarredTest.php deleted file mode 100644 index 9a4af991559..00000000000 --- a/test/Github/Tests/Api/CurrentUser/StarredTest.php +++ /dev/null @@ -1,74 +0,0 @@ - 'l3l0/test'), - array('name' => 'cordoval/test') - ); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('user/starred') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->all()); - } - - /** - * @test - */ - public function shouldCheckStar() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('user/starred/l3l0/test') - ->will($this->returnValue(null)); - - $this->assertNull($api->check('l3l0', 'test')); - } - - /** - * @test - */ - public function shouldStarUser() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('put') - ->with('user/starred/l3l0/test') - ->will($this->returnValue(null)); - - $this->assertNull($api->star('l3l0', 'test')); - } - - /** - * @test - */ - public function shouldUnstarUser() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('user/starred/l3l0/test') - ->will($this->returnValue(null)); - - $this->assertNull($api->unstar('l3l0', 'test')); - } - - protected function getApiClass() - { - return 'Github\Api\CurrentUser\Starred'; - } -} From fc2bd5531d221f1f9e7d49238a680e50570bf60b Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Tue, 23 Sep 2014 08:58:10 +0300 Subject: [PATCH 180/951] Fix docblocks spacing and case --- lib/Github/Api/CurrentUser.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 6f920668ad7..edc1d764a23 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -115,7 +115,7 @@ public function watchers() } /** - * @Deprecated Use watchers() instead + * @deprecated Use watchers() instead */ public function watched($page = 1) { @@ -124,7 +124,7 @@ public function watched($page = 1) )); } - /** + /** * @return Starring */ public function starring() @@ -132,8 +132,8 @@ public function starring() return new Starring($this->client); } - /** - * @Deprecated Use starring() instead + /** + * @deprecated Use starring() instead */ public function starred($page = 1) { From bb2b30e76a084df80b792f6d7134ea5018e8b3de Mon Sep 17 00:00:00 2001 From: Greg Payne Date: Tue, 23 Sep 2014 12:17:36 -0500 Subject: [PATCH 181/951] Changed to single quotes. --- lib/Github/Api/Search.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 26ee09debed..bf7dab21ce7 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -29,7 +29,7 @@ class Search extends AbstractApi */ public function repositories($q, $sort = 'updated', $order = 'desc') { - return $this->get("/search/repositories", array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -44,7 +44,7 @@ public function repositories($q, $sort = 'updated', $order = 'desc') */ public function issues($q, $sort = 'updated', $order = 'desc') { - return $this->get("/search/issues", array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -59,7 +59,7 @@ public function issues($q, $sort = 'updated', $order = 'desc') */ public function code($q, $sort = 'updated', $order = 'desc') { - return $this->get("/search/code", array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -74,7 +74,7 @@ public function code($q, $sort = 'updated', $order = 'desc') */ public function users($q, $sort = 'updated', $order = 'desc') { - return $this->get("/search/users", array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); } } From 3f93ee7a7ac1b6a7286ee178bd0e4a6325b8c549 Mon Sep 17 00:00:00 2001 From: Bryan Crowe Date: Fri, 26 Sep 2014 21:35:59 -0400 Subject: [PATCH 182/951] Convert tabs to spaces --- lib/Github/Api/Repo.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 9be29c0cfa1..f950b95b11f 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -49,10 +49,10 @@ public function find($keyword, array $params = array()) */ public function activity($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity'); } - /** + /** * Get contributor commit statistics for a repository * @link http://developer.github.com/v3/repos/statistics/#contributors * @@ -61,10 +61,10 @@ public function activity($username, $repository) * * @return array list of contributors and their commit statistics */ - public function statistics($username, $repository) - { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); - } + public function statistics($username, $repository) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); + } /** * List all repositories for an organization From ed37a0dc2dc6ec54b6c262758ece3cfea0427237 Mon Sep 17 00:00:00 2001 From: Maxime Horcholle Date: Wed, 8 Oct 2014 10:10:27 +0200 Subject: [PATCH 183/951] fix indent related https://github.com/KnpLabs/php-github-api/pull/200 --- lib/Github/Api/Repo.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index f950b95b11f..071eab4843d 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -53,14 +53,14 @@ public function activity($username, $repository) } /** - * Get contributor commit statistics for a repository - * @link http://developer.github.com/v3/repos/statistics/#contributors - * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * - * @return array list of contributors and their commit statistics - */ + * Get contributor commit statistics for a repository + * @link http://developer.github.com/v3/repos/statistics/#contributors + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * + * @return array list of contributors and their commit statistics + */ public function statistics($username, $repository) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); From 33517c089c7fc393327f5bef440bdf3507669633 Mon Sep 17 00:00:00 2001 From: Alex Grin Date: Wed, 15 Oct 2014 10:17:35 -0400 Subject: [PATCH 184/951] Add missing parameter names to user/repos endpoint --- lib/Github/Api/CurrentUser.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index edc1d764a23..c7a16b7a51c 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -100,9 +100,9 @@ public function organizations() public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc') { return $this->get('user/repos', array( - $type, - $sort, - $direction + 'type' => $type, + 'sort' => $sort, + 'direction' => $direction )); } From 6bed12820d52c742e910f03bffcbed499d70c21b Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:56:52 -0400 Subject: [PATCH 185/951] Added the ManagementConsole class. --- .../Api/Enterprise/ManagementConsole.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/Github/Api/Enterprise/ManagementConsole.php diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php new file mode 100644 index 00000000000..2c61ccddeee --- /dev/null +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -0,0 +1,80 @@ +get('/setup/api/configcheck', $hash); + } + + /** + * Retrieves your installation’s settings. + * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings + * + * @param string $hash md5 hash of your license + * @return array array of settings + */ + public function settings($hash) + { + return $this->get('/setup/api/settings', $hash); + } + + /** + * Checks your installation’s maintenance status. + * @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status + * + * @param string $hash md5 hash of your license + * @return array array of maintenance status information + */ + public function maintenance($hash) + { + return $this->get('/setup/api/maintenance', $hash); + } + + /** + * Retrieves your installation’s authorized SSH keys. + * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys + * + * @param string $hash md5 hash of your license + * @return array array of authorized keys + */ + public function keys($hash) + { + return $this->get('/setup/api/settings/authorized-keys', $hash); + } + + public function getClient() + { + return $this->client; + } + + /** + * Sends an authenticated GET request. + * + * @see \Github\Api\AbstractApi::get() + * @param string $uri + * @param array $hash + * @return \Guzzle\Http\EntityBodyInterface|mixed|string + */ + protected function get($uri, $hash) + { + return parent::get($uri, array('auth' => array('license', rawurlencode($hash)))); + } +} From de4eeb4e79d410cb38569ddd230c622db0cbfd24 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:57:43 -0400 Subject: [PATCH 186/951] Added a convenience method to the Enterprise class. --- lib/Github/Api/Enterprise.php | 9 +++++++++ test/Github/Tests/Api/EnterpriseTest.php | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index 38e7cbff44c..48f90f06b27 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Enterprise\ManagementConsole; use Github\Api\Enterprise\Stats; use Github\Api\Enterprise\License; @@ -29,4 +30,12 @@ public function license() { return new License($this->client); } + + /** + * @return ManagementConsole + */ + public function console() + { + return new ManagementConsole($this->client); + } } diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php index 399ecd78e67..ad21b9aa167 100644 --- a/test/Github/Tests/Api/EnterpriseTest.php +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -30,9 +30,18 @@ public function shouldGetEnterpriseLicenseApiObject() $this->assertInstanceOf('Github\Api\Enterprise\License', $api->license()); } + /** + * @test + */ + public function shouldGetEnterpriseManagementConsoleApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console()); + } + protected function getApiClass() { return 'Github\Api\Enterprise'; } } - From 944ef805a60b39b44eb1ee668333450644afb02d Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:58:05 -0400 Subject: [PATCH 187/951] Added ManagementConsole tests. --- .../Api/Enterprise/ManagementConsoleTest.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php new file mode 100644 index 00000000000..8d222b65360 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -0,0 +1,121 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/configcheck') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash())); + } + + /** + * @test + */ + public function shouldShowSettingsData() + { + $expectedJson = '{ "enterprise": { "private_mode": false, "github_hostname": "ghe.local", "auth_mode": + "default", "storage_mode": "rootfs", "admin_password": null, "configuration_id": 1401777404, + "configuration_run_count": 4, "package_version": "11.10.332", "avatar": { "enabled": false, "uri": "" }, + "customer": { "name": "GitHub", "email": "stannis@themannis.biz", "uuid": + "af6cac80-e4e1-012e-d822-1231380e52e9", + "secret_key_data": "-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nlQcYBE5TCgsBEACk4yHpUcapplebaumBMXYMiLF+nCQ0lxpx...\n-----END PGP PRIVATE KEY BLOCK-----\n", + "public_key_data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nmI0ETqzZYgEEALSe6snowdenXyqvLfSQ34HWD6C7....\n-----END PGP PUBLIC KEY BLOCK-----\n" }, + "license": { "seats": 0, "evaluation": false, "expire_at": "2015-04-27T00:00:00-07:00", "perpetual": false, + "unlimited_seating": true, "support_key": "ssh-rsa AAAAB3N....", "ssh_allowed": true }, "github_ssl": + { "enabled": false, "cert": null, "key": null }, "ldap": { "host": "", "port": "", "base": [ ], "uid": "", + "bind_dn": "", "password": "", "method": "Plain", "user_groups": [ ], "admin_group": "" }, "cas": { "url": "" }, + "github_oauth": { "client_id": "12313412", "client_secret": "kj123131132", "organization_name": + "Homestar Runners", "organization_team": "homestarrunners/owners" }, "smtp": { "enabled": true, "address": + "smtp.example.com", "authentication": "plain", "port": "1234", "domain": "blah", "username": "foo", "user_name": + "mr_foo", "enable_starttls_auto": true, "password": "bar", "support_address": "enterprise@github.com", + "noreply_address": "noreply@github.com" }, "dns": { "primary_nameserver": "8.8.8.8", "secondary_nameserver": + "8.8.4.4" }, "ntp": { "primary_server": "0.ubuntu.pool.ntp.org", "secondary_server": "1.ubuntu.pool.ntp.org" }, + "timezone": { "identifier": "UTC" }, "device": { "path": "/dev/xyz" }, "snmp": { "enabled": false, + "community": "" }, "rsyslog": { "enabled": false, "server": "", "protocol_name": "TCP" }, "assets": { "storage": + "file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, + "collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": + "bar" } }, "run_list": [ "role[configure]" ] }'; + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/settings') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->settings($this->getLicenseHash())); + } + + /** + * @test + */ + public function shouldShowMaintenanceStatus() + { + $expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", + "connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, + { "name": "resque jobs", "number": 54 } ] }'; + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/maintenance') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash())); + } + + /** + * @test + */ + public function shouldShowAuthorizedKeys() + { + $expectedJson = '[ { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": + "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, + { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": + "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/settings/authorized-keys') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->keys($this->getLicenseHash())); + } + + protected function getLicenseHash() + { + return '1234567890abcdefghijklmnopqrstuv'; + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\ManagementConsole'; + } +} From a6031261f8b8cb31589337c68a027a861a076b01 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:58:28 -0400 Subject: [PATCH 188/951] Back-filled other Enterprise tests. --- .../Tests/Api/Enterprise/LicenseTest.php | 42 ++++++++++++++++ .../Github/Tests/Api/Enterprise/StatsTest.php | 49 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 test/Github/Tests/Api/Enterprise/LicenseTest.php create mode 100644 test/Github/Tests/Api/Enterprise/StatsTest.php diff --git a/test/Github/Tests/Api/Enterprise/LicenseTest.php b/test/Github/Tests/Api/Enterprise/LicenseTest.php new file mode 100644 index 00000000000..3b10c34dad4 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/LicenseTest.php @@ -0,0 +1,42 @@ + 1400, + 'seats_used' => 1316, + 'seats_available' => 84, + 'kind' => 'standard', + 'days_until_expiration' => 365, + 'expire_at' => '2016/02/06 12:41:52 -0600' + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('enterprise/settings/license') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show()); + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\License'; + } +} diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php new file mode 100644 index 00000000000..9c4a02f9ff4 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -0,0 +1,49 @@ +getJson(); + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('enterprise/stats/all') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('all')); + } + + protected function getJson() + { + return '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, + "total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23, + "inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0, + "total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45, + "suspended_users": 21 }, "pulls": { "total_pulls": 86, "merged_pulls": 60, "mergeable_pulls": 21, + "unmergeable_pulls": 3 }, "issues": { "total_issues": 179, "open_issues": 83, "closed_issues": 96 }, + "milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists": + { "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6, + "total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } }'; + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\Stats'; + } +} From daad20d4cda8b4f2d32899839b0200eeb3684d78 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 10:01:49 -0400 Subject: [PATCH 189/951] Removed the unneeded docblocks. --- lib/Github/Api/Enterprise/ManagementConsole.php | 6 ------ test/Github/Tests/Api/Enterprise/LicenseTest.php | 6 ------ test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php | 6 ------ test/Github/Tests/Api/Enterprise/StatsTest.php | 6 ------ test/Github/Tests/Api/EnterpriseTest.php | 6 ------ 5 files changed, 30 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 2c61ccddeee..7c68d2459c8 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -1,10 +1,4 @@ Date: Fri, 31 Oct 2014 11:10:03 -0400 Subject: [PATCH 190/951] Sending the hash as a parameter for now. Not ideal, but will refactor at a future date. --- lib/Github/Api/Enterprise/ManagementConsole.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 7c68d2459c8..98406dd2d11 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -54,11 +54,6 @@ public function keys($hash) return $this->get('/setup/api/settings/authorized-keys', $hash); } - public function getClient() - { - return $this->client; - } - /** * Sends an authenticated GET request. * @@ -69,6 +64,6 @@ public function getClient() */ protected function get($uri, $hash) { - return parent::get($uri, array('auth' => array('license', rawurlencode($hash)))); + return parent::get($uri, array('license_md5' => rawurlencode($hash))); } } From 5529dea149c46fb43a5eb6d4bab9e1bdb54c20e2 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 11:22:58 -0400 Subject: [PATCH 191/951] Fixed docblock; no longer overriding "get" -- added "getWithLicenseHash". --- lib/Github/Api/Enterprise/ManagementConsole.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 98406dd2d11..5b7f2bf3149 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -15,7 +15,7 @@ class ManagementConsole extends AbstractApi */ public function configcheck($hash) { - return $this->get('/setup/api/configcheck', $hash); + return $this->getWithLicenseHash('/setup/api/configcheck', $hash); } /** @@ -27,7 +27,7 @@ public function configcheck($hash) */ public function settings($hash) { - return $this->get('/setup/api/settings', $hash); + return $this->getWithLicenseHash('/setup/api/settings', $hash); } /** @@ -39,7 +39,7 @@ public function settings($hash) */ public function maintenance($hash) { - return $this->get('/setup/api/maintenance', $hash); + return $this->getWithLicenseHash('/setup/api/maintenance', $hash); } /** @@ -51,18 +51,17 @@ public function maintenance($hash) */ public function keys($hash) { - return $this->get('/setup/api/settings/authorized-keys', $hash); + return $this->getWithLicenseHash('/setup/api/settings/authorized-keys', $hash); } /** * Sends an authenticated GET request. * - * @see \Github\Api\AbstractApi::get() - * @param string $uri - * @param array $hash + * @param string $uri the request URI + * @param string $hash md5 hash of your license * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ - protected function get($uri, $hash) + protected function getWithLicenseHash($uri, $hash) { return parent::get($uri, array('license_md5' => rawurlencode($hash))); } From 5b361942cf076ebe27a51a5d9885b78410f81e9f Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 11:31:38 -0400 Subject: [PATCH 192/951] Should be decoding and not encoding the JSON. --- lib/Github/Api/Enterprise/ManagementConsole.php | 2 +- .../Github/Tests/Api/Enterprise/ManagementConsoleTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 5b7f2bf3149..59315b45478 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -63,6 +63,6 @@ public function keys($hash) */ protected function getWithLicenseHash($uri, $hash) { - return parent::get($uri, array('license_md5' => rawurlencode($hash))); + return $this->get($uri, array('license_md5' => rawurlencode($hash))); } } diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php index cfd9b228147..ed2972c103d 100644 --- a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -15,7 +15,7 @@ public function shouldShowConfigData() { "status": "DONE", "key": "GitHub utilities" }, { "status": "DONE", "key": "GitHub applications" }, { "status": "CONFIGURING", "key": "GitHub services" }, { "status": "PENDING", "key": "Reloading appliance services" } ] }'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) @@ -53,7 +53,7 @@ public function shouldShowSettingsData() "file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, "collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": "bar" } }, "run_list": [ "role[configure]" ] }'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) @@ -72,7 +72,7 @@ public function shouldShowMaintenanceStatus() $expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", "connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, { "name": "resque jobs", "number": 54 } ] }'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) @@ -92,7 +92,7 @@ public function shouldShowAuthorizedKeys() "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) From 9d4b5931f7d41628243ec0a673f0966842874efc Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 11:35:36 -0400 Subject: [PATCH 193/951] Should be decoding and not encoding the JSON in the StatsTest as well. --- test/Github/Tests/Api/Enterprise/StatsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 5bb7d223fd6..1a3e3acf0d2 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -12,7 +12,7 @@ class StatsTest extends TestCase public function shouldShowStats() { $expectedJson = $this->getJson(); - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) From cc01bcedec888101df7389dd0ed6adc34b6e4249 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 12:08:04 -0400 Subject: [PATCH 194/951] Added second param to json_decode calls; checking that the license hash is sent with the request. --- .../Api/Enterprise/ManagementConsoleTest.php | 17 ++++++++--------- test/Github/Tests/Api/Enterprise/StatsTest.php | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php index ed2972c103d..60755693f82 100644 --- a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -15,12 +15,12 @@ public function shouldShowConfigData() { "status": "DONE", "key": "GitHub utilities" }, { "status": "DONE", "key": "GitHub applications" }, { "status": "CONFIGURING", "key": "GitHub services" }, { "status": "PENDING", "key": "Reloading appliance services" } ] }'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/configcheck') + ->with('/setup/api/configcheck', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash())); @@ -53,12 +53,12 @@ public function shouldShowSettingsData() "file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, "collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": "bar" } }, "run_list": [ "role[configure]" ] }'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/settings') + ->with('/setup/api/settings', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->settings($this->getLicenseHash())); @@ -72,12 +72,12 @@ public function shouldShowMaintenanceStatus() $expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", "connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, { "name": "resque jobs", "number": 54 } ] }'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/maintenance') + ->with('/setup/api/maintenance', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash())); @@ -92,14 +92,13 @@ public function shouldShowAuthorizedKeys() "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/settings/authorized-keys') + ->with('/setup/api/settings/authorized-keys', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->keys($this->getLicenseHash())); } diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 1a3e3acf0d2..5ee76194625 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -12,7 +12,7 @@ class StatsTest extends TestCase public function shouldShowStats() { $expectedJson = $this->getJson(); - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) From 31ca1163c0ee86d6b76aefa56d7aa7ac8d913177 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 12:30:41 -0400 Subject: [PATCH 195/951] Added remaining Stats tests. --- .../Github/Tests/Api/Enterprise/StatsTest.php | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 5ee76194625..97e28962556 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -11,8 +11,7 @@ class StatsTest extends TestCase */ public function shouldShowStats() { - $expectedJson = $this->getJson(); - $expectedArray = json_decode($expectedJson, true); + $expectedArray = $this->getStatsData(); $api = $this->getApiMock(); $api->expects($this->once()) @@ -23,9 +22,50 @@ public function shouldShowStats() $this->assertEquals($expectedArray, $api->show('all')); } - protected function getJson() + /** + * @test + * @dataProvider getTypes + */ + public function shouldShowStatsByType($type) + { + $expectedArray = $this->getStatsData($type); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with(sprintf('enterprise/stats/%s', $type)) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, call_user_func(array($api, $type))); + } + + /** + * @return array + */ + public function getTypes() + { + return array( + array('issues'), + array('hooks'), + array('milestones'), + array('orgs'), + array('comments'), + array('pages'), + array('users'), + array('gists'), + array('pulls'), + array('repos'), + array('all') + ); + } + + /** + * @param string $key + * @return mixed + */ + protected function getStatsData($key = '') { - return '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, + $json = '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, "total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23, "inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0, "total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45, @@ -34,6 +74,12 @@ protected function getJson() "milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists": { "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6, "total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } }'; + $stats = json_decode($json, true); + if (is_null($key)) { + return $stats; + } elseif (array_key_exists($key, $stats)) { + return $stats[$key]; + } } protected function getApiClass() From dc6208a8061439809d74a8d32676997b79debf15 Mon Sep 17 00:00:00 2001 From: Dave Hall Date: Sun, 16 Nov 2014 15:27:21 +1100 Subject: [PATCH 196/951] Switch from deprecated team member API to team memberships API --- lib/Github/Api/Organization/Teams.php | 6 +++--- test/Github/Tests/Api/Organization/TeamsTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 5cdf876db74..6acca32a054 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -60,17 +60,17 @@ public function members($team) public function check($team, $username) { - return $this->get('teams/'.rawurlencode($team).'/members/'.rawurlencode($username)); + return $this->get('teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function addMember($team, $username) { - return $this->put('teams/'.rawurlencode($team).'/members/'.rawurlencode($username)); + return $this->put('teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function removeMember($team, $username) { - return $this->delete('teams/'.rawurlencode($team).'/members/'.rawurlencode($username)); + return $this->delete('teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function repositories($team) diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 6877b3b480c..4fdea74bd14 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -32,7 +32,7 @@ public function shouldCheckIfMemberIsInOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('teams/KnpWorld/members/l3l0') + ->with('teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0')); @@ -96,7 +96,7 @@ public function shouldAddTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('teams/KnpWorld/members/l3l0') + ->with('teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0')); @@ -112,7 +112,7 @@ public function shouldRemoveTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('teams/KnpWorld/members/l3l0') + ->with('teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0')); From 5c1f9fc7f526d3f12ef8248e3f071b826e563347 Mon Sep 17 00:00:00 2001 From: Yevgen Kovalienia Date: Sat, 29 Nov 2014 22:39:50 +0100 Subject: [PATCH 197/951] KnpLabs/php-github-api#178: Added "Search" check to Github\ClientTest --- test/Github/Tests/ClientTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 04b3a710397..b7a8751fb39 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -186,6 +186,8 @@ public function getApiClassesProvider() array('repository', 'Github\Api\Repo'), array('repositories', 'Github\Api\Repo'), + array('search', 'Github\Api\Search'), + array('pr', 'Github\Api\PullRequest'), array('pullRequest', 'Github\Api\PullRequest'), array('pull_request', 'Github\Api\PullRequest'), From 164c142f224b1659b5169e44448f6af157bbd094 Mon Sep 17 00:00:00 2001 From: Yevgen Kovalienia Date: Sat, 29 Nov 2014 22:59:36 +0100 Subject: [PATCH 198/951] KnpLabs/php-github-api#178: Added tests for Github\Api\Search --- test/Github/Tests/Api/SearchTest.php | 183 +++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 test/Github/Tests/Api/SearchTest.php diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php new file mode 100644 index 00000000000..d5fe9b08494 --- /dev/null +++ b/test/Github/Tests/Api/SearchTest.php @@ -0,0 +1,183 @@ + '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/repositories', + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->repositories('query text')); + } + + /** + * @test + */ + public function shouldSearchRepositoriesRegardingSortAndOrder() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/repositories', + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->repositories('query text', 'created', 'asc') + ); + } + + /** + * @test + */ + public function shouldSearchIssuesByQuery() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/issues', + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->issues('query text')); + } + + /** + * @test + */ + public function shouldSearchIssuesRegardingSortAndOrder() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/issues', + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->issues('query text', 'created', 'asc') + ); + } + + /** + * @test + */ + public function shouldSearchCodeByQuery() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/code', + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->code('query text')); + } + + /** + * @test + */ + public function shouldSearchCodeRegardingSortAndOrder() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/code', + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->code('query text', 'created', 'asc') + ); + } + + /** + * @test + */ + public function shouldSearchUsersByQuery() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/users', + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->users('query text')); + } + + /** + * @test + */ + public function shouldSearchUsersRegardingSortAndOrder() + { + $expectedArray = array(array('total_count' => '0')); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/users', + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->users('query text', 'created', 'asc') + ); + } + + protected function getApiClass() + { + return 'Github\Api\Search'; + } +} From a7e394687c0acc49e653b02ab188b44cf44abbb1 Mon Sep 17 00:00:00 2001 From: Yevgen Kovalienia Date: Sun, 30 Nov 2014 13:04:57 +0100 Subject: [PATCH 199/951] KnpLabs/php-github-api#178: Documentation added for Github\Client\Search --- doc/search.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 doc/search.md diff --git a/doc/search.md b/doc/search.md new file mode 100644 index 00000000000..85936170162 --- /dev/null +++ b/doc/search.md @@ -0,0 +1,48 @@ +## Search API +[Back to the navigation](index.md) + +Searching repositories, code, issues and users. +Wrap [GitHub Search API](http://developer.github.com/v3/search/). All methods are described on that page. + +### Search repositories + +```php +$repos = $client->api('search')->repositories('github language:php'); +``` + +Returns a list of repositories found by such criteria. + +### Search code + +```php +$repos = $client->api('search')->code('@todo language:php'); +``` + +Returns a list of files found by such criteria (containing "@todo" and language==php). + +### Search issues + +```php +$repos = $client->api('search')->issues('bug language:php'); +``` + +Returns a list of issues found by such criteria. + +### Search users + +```php +$repos = $client->api('search')->users('location:Amsterdam language:php'); +``` + +Returns a list of users found by such criteria. + +### Sorting results + +You can sort results using 2-3 arguments. + +```php +$repos = $client->api('repo')->repositories('...', 'created', 'asc'); +$repos = $client->api('repo')->code('...........', 'indexed', 'desc'); +$repos = $client->api('repo')->issues('.........', 'comments', 'asc'); +$repos = $client->api('repo')->users('..........', 'followers', 'asc'); +``` From 32c32b84a04bded69adf07d5d609b5308c761ed3 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 2 Dec 2014 19:58:38 +0000 Subject: [PATCH 200/951] Removed the installation instructions for my package --- README.markdown | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.markdown b/README.markdown index 3ac7f37b83f..3a8dfd544ad 100755 --- a/README.markdown +++ b/README.markdown @@ -47,14 +47,6 @@ Now we can use autoloader from Composer by: [Laravel GitHub](https://github.com/GrahamCampbell/Laravel-GitHub) by [Graham Campbell](https://github.com/GrahamCampbell) might interest you. -```json -{ - "require": { - "graham-campbell/github": "0.1.*" - } -} -``` - ## Basic usage of `php-github-api` client ```php From cde103f5237e49421efbdc8707a4626f061367da Mon Sep 17 00:00:00 2001 From: mAAdhaTTah Date: Sun, 7 Dec 2014 13:49:59 -0500 Subject: [PATCH 201/951] Add commits api for Gists --- doc/gists.md | 6 ++++++ lib/Github/Api/Gists.php | 5 +++++ test/Github/Tests/Api/GistsTest.php | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/doc/gists.md b/doc/gists.md index 9cbfb0a1624..604ee142344 100644 --- a/doc/gists.md +++ b/doc/gists.md @@ -33,6 +33,12 @@ $gists = $github->api('gists')->all(); $gist = $github->api('gists')->show(1); ``` +#### Get commits for a single gist + +```php +$commits = $github->api('gists')->commits(1); +``` + #### Create a gist ```php diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 7514d99e6ff..ffdc5e3201e 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -44,6 +44,11 @@ public function update($id, array $params) return $this->patch('gists/'.rawurlencode($id), $params); } + public function commits($id) + { + return $this->get('gists/'.rawurlencode($id).'/commits'); + } + public function fork($id) { return $this->post('gists/'.rawurlencode($id).'/fork'); diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 1ba6a8c7386..fb231016b75 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -52,6 +52,22 @@ public function shouldShowGist() $this->assertEquals($expectedArray, $api->show(123)); } + /** + * @test + */ + public function shouldShowCommits() + { + $expectedArray = array('id' => '123'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/commits') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->commits(123)); + } + /** * @test */ From 8218263295eb209f1cc061b47126f60b6e25a927 Mon Sep 17 00:00:00 2001 From: "guillermo.fisher" Date: Fri, 26 Dec 2014 11:03:48 -0500 Subject: [PATCH 202/951] Added user suspension & unsuspension, resolves #207. --- doc/users.md | 16 +++++++++++++++ lib/Github/Api/User.php | 28 ++++++++++++++++++++++++++ test/Github/Tests/Api/UserTest.php | 32 ++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/doc/users.md b/doc/users.md index 810226af55b..6824a482c03 100644 --- a/doc/users.md +++ b/doc/users.md @@ -174,3 +174,19 @@ $emails = $client->api('current_user')->emails()->remove(array('first@provider.o ``` Return an array of the authenticated user emails. + +### Suspend a user (Enterprise only) + +> Requires [authentication](security.md). + +```php +$client->api('user')->suspend('ornicar'); +``` + +### Unsuspend a user (Enterprise only) + +> Requires [authentication](security.md). + +```php +$client->api('user')->unsuspend('ornicar'); +``` \ No newline at end of file diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 20323934fca..0ab7562b8aa 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -182,4 +182,32 @@ public function publicEvents($username) { return $this->get('users/'.rawurlencode($username) . '/events/public'); } + + /** + * Suspend a user + * + * @link https://developer.github.com/v3/users/administration/#suspend-a-user + * + * @param string $username + * + * @return array + */ + public function suspend($username) + { + return $this->put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); + } + + /** + * Unsuspend a user + * + * @link https://developer.github.com/v3/users/administration/#unsuspend-a-user + * + * @param string $username + * + * @return array + */ + public function unsuspend($username) + { + return $this->delete('users/'.rawurldecode($username).'/suspended'); + } } diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index dec69d7944b..ac40fe7ecc5 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -161,6 +161,38 @@ public function shouldGetUserGists() $this->assertEquals($expectedArray, $api->gists('l3l0')); } + /** + * @test + */ + public function shouldSuspendUser() + { + $expectedArray = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('users/l3l0/suspended') + ->will($this->returnValue($expectedArray)); + $this->assertEquals($expectedArray, $api->suspend('l3l0')); + } + + /** + * @test + */ + public function shouldUnsuspendUser() + { + $expectedArray = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('users/l3l0/suspended') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->unsuspend('l3l0')); + } + + protected function getApiClass() { return 'Github\Api\User'; From 657fb9dc3d87522ce19b3ca6d0a3ce7407f6744f Mon Sep 17 00:00:00 2001 From: Ashley Clarke Date: Tue, 30 Dec 2014 16:20:49 +0000 Subject: [PATCH 203/951] fix typo - missing bracket --- doc/two_factor_authentication.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/two_factor_authentication.md b/doc/two_factor_authentication.md index 2b670b05ba2..7270239974f 100644 --- a/doc/two_factor_authentication.md +++ b/doc/two_factor_authentication.md @@ -7,7 +7,7 @@ ```php try { $authorization = $github->api('authorizations')->create(); -} catch (Github\Exception\TwoFactorAuthenticationRequiredException $e { +} catch (Github\Exception\TwoFactorAuthenticationRequiredException $e) { echo sprintf("Two factor authentication of type %s is required.", $e->getType()); } ``` From 81105b8a78e3b44b3cbec305291688f3569e24b3 Mon Sep 17 00:00:00 2001 From: "guillermo.fisher" Date: Fri, 2 Jan 2015 10:38:15 -0500 Subject: [PATCH 204/951] Moved methods to `UserAdmin` class. --- doc/enterprise.md | 21 ++++++++- doc/users.md | 16 ------- lib/Github/Api/Enterprise.php | 9 ++++ lib/Github/Api/Enterprise/UserAdmin.php | 36 ++++++++++++++++ lib/Github/Api/User.php | 28 ------------ .../Tests/Api/Enterprise/UserAdminTest.php | 43 +++++++++++++++++++ test/Github/Tests/Api/EnterpriseTest.php | 10 +++++ test/Github/Tests/Api/UserTest.php | 32 -------------- 8 files changed, 118 insertions(+), 77 deletions(-) create mode 100644 lib/Github/Api/Enterprise/UserAdmin.php create mode 100644 test/Github/Tests/Api/Enterprise/UserAdminTest.php diff --git a/doc/enterprise.md b/doc/enterprise.md index b4673061e74..9e38f13dce6 100644 --- a/doc/enterprise.md +++ b/doc/enterprise.md @@ -3,6 +3,7 @@ Provides information about a GitHub Enterprise installation. Wraps [GitHub Enterprise API](http://developer.github.com/v3/enterprise/). +### Configuration In order to configure the client to point to a GitHub Enterprise installation, do the following: ```php @@ -20,5 +21,23 @@ $client->setEnterpriseUrl('https://ghe.host'); $repositories = $client->api('user')->repositories('ornicar'); ``` -To use the Stats and License APIs, you will need to authenticate using a GitHub Enterprise site admin account. +### Authentication +The Admin Stats, License, and User Administration API endpoints are only accessible to GitHub Enterprise site administrators. The Management Console API endpoints are only accessible via the Management Console password. +### User Administration + +#### Suspend a user (Enterprise only) + +> Requires [authentication](security.md). + +```php +$client->api('enterprise')->userAdmin()->suspend('ornicar'); +``` + +#### Unsuspend a user (Enterprise only) + +> Requires [authentication](security.md). + +```php +$client->api('enterprise')->userAdmin()->unsuspend('ornicar'); +``` diff --git a/doc/users.md b/doc/users.md index 6824a482c03..810226af55b 100644 --- a/doc/users.md +++ b/doc/users.md @@ -174,19 +174,3 @@ $emails = $client->api('current_user')->emails()->remove(array('first@provider.o ``` Return an array of the authenticated user emails. - -### Suspend a user (Enterprise only) - -> Requires [authentication](security.md). - -```php -$client->api('user')->suspend('ornicar'); -``` - -### Unsuspend a user (Enterprise only) - -> Requires [authentication](security.md). - -```php -$client->api('user')->unsuspend('ornicar'); -``` \ No newline at end of file diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index 48f90f06b27..c23171a6614 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -5,6 +5,7 @@ use Github\Api\Enterprise\ManagementConsole; use Github\Api\Enterprise\Stats; use Github\Api\Enterprise\License; +use Github\Api\Enterprise\UserAdmin; /** * Getting information about a GitHub Enterprise instance. @@ -38,4 +39,12 @@ public function console() { return new ManagementConsole($this->client); } + + /** + * @return UserAdmin + */ + public function userAdmin() + { + return new UserAdmin($this->client); + } } diff --git a/lib/Github/Api/Enterprise/UserAdmin.php b/lib/Github/Api/Enterprise/UserAdmin.php new file mode 100644 index 00000000000..d01a975515c --- /dev/null +++ b/lib/Github/Api/Enterprise/UserAdmin.php @@ -0,0 +1,36 @@ +put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); + } + + /** + * Unsuspend a user + * + * @link https://developer.github.com/v3/users/administration/#unsuspend-a-user + * + * @param string $username + * + * @return array + */ + public function unsuspend($username) + { + return $this->delete('users/'.rawurldecode($username).'/suspended'); + } +} diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 0ab7562b8aa..20323934fca 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -182,32 +182,4 @@ public function publicEvents($username) { return $this->get('users/'.rawurlencode($username) . '/events/public'); } - - /** - * Suspend a user - * - * @link https://developer.github.com/v3/users/administration/#suspend-a-user - * - * @param string $username - * - * @return array - */ - public function suspend($username) - { - return $this->put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); - } - - /** - * Unsuspend a user - * - * @link https://developer.github.com/v3/users/administration/#unsuspend-a-user - * - * @param string $username - * - * @return array - */ - public function unsuspend($username) - { - return $this->delete('users/'.rawurldecode($username).'/suspended'); - } } diff --git a/test/Github/Tests/Api/Enterprise/UserAdminTest.php b/test/Github/Tests/Api/Enterprise/UserAdminTest.php new file mode 100644 index 00000000000..42e6358bfff --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/UserAdminTest.php @@ -0,0 +1,43 @@ +getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('users/l3l0/suspended') + ->will($this->returnValue($expectedArray)); + $this->assertEquals($expectedArray, $api->suspend('l3l0')); + } + + /** + * @test + */ + public function shouldUnsuspendUser() + { + $expectedArray = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('users/l3l0/suspended') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->unsuspend('l3l0')); + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\UserAdmin'; + } +} \ No newline at end of file diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php index cccd446c6d9..319e6e16232 100644 --- a/test/Github/Tests/Api/EnterpriseTest.php +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -34,6 +34,16 @@ public function shouldGetEnterpriseManagementConsoleApiObject() $this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console()); } + /** + * @test + */ + public function shouldGetEnterpriseUserAdminApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Enterprise\UserAdmin', $api->userAdmin()); + } + protected function getApiClass() { return 'Github\Api\Enterprise'; diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index ac40fe7ecc5..dec69d7944b 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -161,38 +161,6 @@ public function shouldGetUserGists() $this->assertEquals($expectedArray, $api->gists('l3l0')); } - /** - * @test - */ - public function shouldSuspendUser() - { - $expectedArray = array(); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('put') - ->with('users/l3l0/suspended') - ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->suspend('l3l0')); - } - - /** - * @test - */ - public function shouldUnsuspendUser() - { - $expectedArray = array(); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('users/l3l0/suspended') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->unsuspend('l3l0')); - } - - protected function getApiClass() { return 'Github\Api\User'; From 5b7872381a9d3f8eb4aa6d0f3495eb2201169824 Mon Sep 17 00:00:00 2001 From: Yevgen Kovalienia Date: Fri, 2 Jan 2015 20:53:07 +0100 Subject: [PATCH 205/951] doc/search.md typo fixed --- doc/search.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/search.md b/doc/search.md index 85936170162..75b79640d4c 100644 --- a/doc/search.md +++ b/doc/search.md @@ -41,8 +41,8 @@ Returns a list of users found by such criteria. You can sort results using 2-3 arguments. ```php -$repos = $client->api('repo')->repositories('...', 'created', 'asc'); -$repos = $client->api('repo')->code('...........', 'indexed', 'desc'); -$repos = $client->api('repo')->issues('.........', 'comments', 'asc'); -$repos = $client->api('repo')->users('..........', 'followers', 'asc'); +$repos = $client->api('search')->repositories('...', 'created', 'asc'); +$repos = $client->api('search')->code('...........', 'indexed', 'desc'); +$repos = $client->api('search')->issues('.........', 'comments', 'asc'); +$repos = $client->api('search')->users('..........', 'followers', 'asc'); ``` From d6fd1a28ffbe1ee9b80814cd7ba82732a4037bce Mon Sep 17 00:00:00 2001 From: heimonsy Date: Mon, 5 Jan 2015 14:22:10 +0800 Subject: [PATCH 206/951] CurentUser add teams --- lib/Github/Api/CurrentUser.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index edc1d764a23..6c28159a9dc 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -88,6 +88,16 @@ public function organizations() return $this->get('user/orgs'); } + /** + * @link https://developer.github.com/v3/orgs/teams/#list-user-teams + * + * @return array + */ + public function teams() + { + return $this->get('user/teams'); + } + /** * @link http://developer.github.com/v3/repos/#list-your-repositories * @@ -113,7 +123,7 @@ public function watchers() { return new Watchers($this->client); } - + /** * @deprecated Use watchers() instead */ @@ -123,7 +133,7 @@ public function watched($page = 1) 'page' => $page )); } - + /** * @return Starring */ From fada3f3cf088b332655183517d043eea495f6c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Ram=C3=B3n=20L=C3=B3pez?= Date: Sat, 17 Jan 2015 18:58:22 +0100 Subject: [PATCH 207/951] Fixed archive download by reference According to the API docs, the reference should be passed directly as the last URL segment, not as a GET parameter. Check https://developer.github.com/v3/repos/contents/#get-archive-link Bug triaged by @garak. Closes #225 --- lib/Github/Api/Repository/Contents.php | 5 ++--- .../Tests/Api/Repository/ContentsTest.php | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 2889c1c7e8b..de6596ffa6c 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -225,9 +225,8 @@ public function archive($username, $repository, $format, $reference = null) $format = 'tarball'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format), array( - 'ref' => $reference - )); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format). + ((null !== $reference) ? ('/'.rawurlencode($reference)) : '')); } /** diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index a57ed3245ac..da1bb37c552 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -233,7 +233,7 @@ public function shouldFetchTarballArchiveWhenFormatNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/tarball', array('ref' => null)) + ->with('repos/KnpLabs/php-github-api/tarball') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'someFormat')); @@ -249,7 +249,7 @@ public function shouldFetchTarballArchive() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/tarball', array('ref' => null)) + ->with('repos/KnpLabs/php-github-api/tarball') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'tarball')); @@ -265,12 +265,28 @@ public function shouldFetchZipballArchive() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/zipball', array('ref' => null)) + ->with('repos/KnpLabs/php-github-api/zipball') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball')); } + /** + * @test + */ + public function shouldFetchZipballArchiveByReference() + { + $expectedValue = 'zip'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/zipball/master') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball', 'master')); + } + /** * @test */ From c5926eec18eab450057300a48f59aee1e36b0167 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 22 Jan 2015 13:28:52 +0100 Subject: [PATCH 208/951] In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. --- test/Github/Tests/Functional/MarkdownTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Functional/MarkdownTest.php b/test/Github/Tests/Functional/MarkdownTest.php index 6bf704e85c5..0e7e2b033ba 100644 --- a/test/Github/Tests/Functional/MarkdownTest.php +++ b/test/Github/Tests/Functional/MarkdownTest.php @@ -22,7 +22,7 @@ public function shouldRetrieveParsedMarkdownContent() $input = 'Hello world KnpLabs/KnpBundles#1 **cool**, and #1!'; $output = '

Hello world KnpLabs/KnpBundles#1 cool, and #1!

'; - $html = $api->render($input, 'gfm' , 'KnpLabs/KnpMenu'); + $html = $api->render($input, 'gfm', 'KnpLabs/KnpMenu'); $this->assertEquals($output, $html); } From e5b8155f3c4d4921782c9b5a2d9f2ba45b7c8cc0 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 22 Jan 2015 13:30:30 +0100 Subject: [PATCH 209/951] The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented. --- lib/Github/Api/CurrentUser.php | 2 +- lib/Github/Api/Organization/Members.php | 8 ++++---- lib/Github/Api/Search.php | 1 - lib/Github/Client.php | 3 ++- lib/Github/Exception/BadMethodCallException.php | 1 - lib/Github/Exception/ErrorException.php | 1 - lib/Github/Exception/ExceptionInterface.php | 1 - .../Exception/InvalidArgumentException.php | 1 - lib/Github/Exception/RuntimeException.php | 1 - .../Exception/ValidationFailedException.php | 1 - lib/Github/HttpClient/CachedHttpClient.php | 1 - test/Github/Tests/Api/AuthorizationsTest.php | 6 +++--- test/Github/Tests/Api/GistsTest.php | 16 ++++++++-------- test/Github/Tests/Api/RepoTest.php | 8 ++++---- .../Github/Tests/Api/Repository/ContentsTest.php | 2 +- 15 files changed, 23 insertions(+), 30 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 6c28159a9dc..5b21a41d175 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -139,7 +139,7 @@ public function watched($page = 1) */ public function starring() { - return new Starring($this->client); + return new Starring($this->client); } /** diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 034cffbff36..7358ed27689 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -15,10 +15,10 @@ public function all($organization, $type = null, $filter = 'all') $parameters = array(); $path = 'orgs/'.rawurlencode($organization).'/'; if (null === $type) { - $path .= 'members'; - if (null !== $filter) { - $parameters['filter'] = $filter; - } + $path .= 'members'; + if (null !== $filter) { + $parameters['filter'] = $filter; + } } else { $path .= 'public_members'; } diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index bf7dab21ce7..8897feaa291 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -76,5 +76,4 @@ public function users($q, $sort = 'updated', $order = 'desc') { return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); } - } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c1779663858..ec5b8464039 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -320,7 +320,8 @@ public function getSupportedApiVersions() * * @throws InvalidArgumentException */ - public function __call($name, $args) { + public function __call($name, $args) + { try { return $this->api($name); } catch (InvalidArgumentException $e) { diff --git a/lib/Github/Exception/BadMethodCallException.php b/lib/Github/Exception/BadMethodCallException.php index 5c43d20a485..f12a8ce2cfb 100644 --- a/lib/Github/Exception/BadMethodCallException.php +++ b/lib/Github/Exception/BadMethodCallException.php @@ -9,5 +9,4 @@ */ class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface { - } diff --git a/lib/Github/Exception/ErrorException.php b/lib/Github/Exception/ErrorException.php index dbc0056ef56..33f902edbe9 100644 --- a/lib/Github/Exception/ErrorException.php +++ b/lib/Github/Exception/ErrorException.php @@ -9,5 +9,4 @@ */ class ErrorException extends \ErrorException implements ExceptionInterface { - } diff --git a/lib/Github/Exception/ExceptionInterface.php b/lib/Github/Exception/ExceptionInterface.php index 5984e3a4e75..cba560542bb 100644 --- a/lib/Github/Exception/ExceptionInterface.php +++ b/lib/Github/Exception/ExceptionInterface.php @@ -4,5 +4,4 @@ interface ExceptionInterface { - } diff --git a/lib/Github/Exception/InvalidArgumentException.php b/lib/Github/Exception/InvalidArgumentException.php index ae30c05125c..cecc11b8bba 100644 --- a/lib/Github/Exception/InvalidArgumentException.php +++ b/lib/Github/Exception/InvalidArgumentException.php @@ -9,5 +9,4 @@ */ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { - } diff --git a/lib/Github/Exception/RuntimeException.php b/lib/Github/Exception/RuntimeException.php index d3cc9fdeebc..e4e9712b481 100644 --- a/lib/Github/Exception/RuntimeException.php +++ b/lib/Github/Exception/RuntimeException.php @@ -9,5 +9,4 @@ */ class RuntimeException extends \RuntimeException implements ExceptionInterface { - } diff --git a/lib/Github/Exception/ValidationFailedException.php b/lib/Github/Exception/ValidationFailedException.php index 43e357b4be5..0de17aea3e7 100644 --- a/lib/Github/Exception/ValidationFailedException.php +++ b/lib/Github/Exception/ValidationFailedException.php @@ -9,5 +9,4 @@ */ class ValidationFailedException extends ErrorException { - } diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 16ace027643..ee9da5ed9ee 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -98,7 +98,6 @@ protected function createRequest($httpMethod, $path, $body = null, array $header */ public function getLastResponse($force = false) { - $lastResponse = parent::getLastResponse(); if (304 != $lastResponse->getStatusCode()) { $force = true; diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php index 901c5095244..89534e50965 100644 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -17,7 +17,7 @@ public function shouldGetAllAuthorizations() ->with('authorizations') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all()); + $this->assertEquals($expectedArray, $api->all()); } /** @@ -34,7 +34,7 @@ public function shouldShowAuthorization() ->with('authorizations/'.$id) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->show($id)); + $this->assertEquals($expectedArray, $api->show($id)); } /** @@ -52,7 +52,7 @@ public function shouldCheckAuthorization() ->with('authorizations/'.$id.'/tokens/'.$token) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->check($id, $token)); + $this->assertEquals($expectedArray, $api->check($id, $token)); } /** diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index fb231016b75..8a01dca3ddd 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -17,7 +17,7 @@ public function shouldGetStarredGists() ->with('gists/starred') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('starred')); + $this->assertEquals($expectedArray, $api->all('starred')); } /** @@ -33,7 +33,7 @@ public function shouldGetAllGists() ->with('gists') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all()); + $this->assertEquals($expectedArray, $api->all()); } /** @@ -49,7 +49,7 @@ public function shouldShowGist() ->with('gists/123') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->show(123)); + $this->assertEquals($expectedArray, $api->show(123)); } /** @@ -65,7 +65,7 @@ public function shouldShowCommits() ->with('gists/123/commits') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->commits(123)); + $this->assertEquals($expectedArray, $api->commits(123)); } /** @@ -81,7 +81,7 @@ public function shouldForkGist() ->with('gists/123/fork') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->fork(123)); + $this->assertEquals($expectedArray, $api->fork(123)); } /** @@ -115,7 +115,7 @@ public function shouldCheckGist() ->with('gists/123/star') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->check(123)); + $this->assertEquals($expectedArray, $api->check(123)); } /** @@ -131,7 +131,7 @@ public function shouldStarGist() ->with('gists/123/star') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->star(123)); + $this->assertEquals($expectedArray, $api->star(123)); } /** @@ -147,7 +147,7 @@ public function shouldUnstarGist() ->with('gists/123/star') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->unstar(123)); + $this->assertEquals($expectedArray, $api->unstar(123)); } /** diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 90366110110..79bc2679567 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -422,15 +422,15 @@ public function shouldGetReleasesApiObject() */ public function shouldGetCommitActivity() { - $expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400)); + $expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400)); - $api = $this->getApiMock(); - $api->expects($this->once()) + $api = $this->getApiMock(); + $api->expects($this->once()) ->method('get') ->with('repos/KnpLabs/php-github-api/stats/commit_activity') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); + $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); } protected function getApiClass() diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index a57ed3245ac..402b6c42f14 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -53,7 +53,7 @@ public function shouldReturnTrueWhenFileExists() ->willReturn(200); $api = $this->getApiMock(); - $api->expects($this->once()) + $api->expects($this->once()) ->method('head') ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) ->will($this->returnValue($responseMock)); From 5142fa02f3b0663a6a0e6a7a69aafcdaa83af08b Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 22 Jan 2015 13:33:37 +0100 Subject: [PATCH 210/951] The PHP constants true, false, and null MUST be in lower case. --- lib/Github/Api/Repository/Commits.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 6753c8b5a2e..9098498684a 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -15,10 +15,10 @@ public function all($username, $repository, array $params) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params); } - public function compare($username, $repository, $base, $head, $mediaType = NULL) + public function compare($username, $repository, $base, $head, $mediaType = null) { $headers = array(); - if (NULL !== $mediaType) { + if (null !== $mediaType) { $headers['Accept'] = $mediaType; } return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), array(), $headers); From 5d0cc9474956d644743a37980bcf7df61c94b336 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 22 Jan 2015 13:35:33 +0100 Subject: [PATCH 211/951] There SHOULD be one import block per namespace --- lib/Github/HttpClient/HttpClient.php | 1 - lib/Github/HttpClient/Listener/ErrorListener.php | 1 - test/Github/Tests/HttpClient/Listener/AuthListenerTest.php | 1 - 3 files changed, 3 deletions(-) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index cfc44fbbda0..5e907419221 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -7,7 +7,6 @@ use Guzzle\Http\ClientInterface; use Guzzle\Http\Message\Request; use Guzzle\Http\Message\Response; - use Github\Exception\ErrorException; use Github\Exception\RuntimeException; use Github\HttpClient\Listener\AuthListener; diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 30106178d17..a945c45c621 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -6,7 +6,6 @@ use Github\HttpClient\Message\ResponseMediator; use Guzzle\Common\Event; use Guzzle\Http\Message\Response; - use Github\Exception\ApiLimitExceedException; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; diff --git a/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php b/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php index d071687488d..68fd4387401 100644 --- a/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php @@ -3,7 +3,6 @@ namespace Github\Tests\HttpClient; use Guzzle\Http\Message\Request; - use Github\Client; use Github\HttpClient\Listener\AuthListener; From 2f89429b5637639881dc6f6e0ea458f6f2ce6375 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Thu, 22 Jan 2015 13:36:31 +0100 Subject: [PATCH 212/951] Remove trailing whitespace at the end of non-blank lines. --- lib/Github/HttpClient/CachedHttpClient.php | 4 ++-- test/Github/Tests/Api/Repository/StatusesTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 16ace027643..3d91bc2d279 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -21,8 +21,8 @@ class CachedHttpClient extends HttpClient /** * contains the lastResponse fetched from cache - * - * @var Guzzle\Http\Message\Response + * + * @var Guzzle\Http\Message\Response */ private $lastCachedResponse; diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php index c27f09b404e..8845a523b4d 100644 --- a/test/Github/Tests/Api/Repository/StatusesTest.php +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -71,7 +71,7 @@ public function shouldNotCreateWithoutStatus() } /** - * @test + * @test */ public function shouldCreateCommitStatus() { From 5cf3da7198ec803cafa2faf34e9e258fa1aa493a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 1 Feb 2015 18:22:52 +0000 Subject: [PATCH 213/951] Fixed the branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8202e6656f6..dc16d3e77fd 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "1.4.x-dev" } } } From 7e5e260f88d7a015d29c9d3cc0b267cec7eaeba4 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Sun, 8 Feb 2015 14:12:42 +0100 Subject: [PATCH 214/951] Implemented notifications from github API --- lib/Github/Api/Activity/Notification.php | 62 ++++++++++++++++++++++++ lib/Github/Client.php | 5 ++ 2 files changed, 67 insertions(+) create mode 100644 lib/Github/Api/Activity/Notification.php diff --git a/lib/Github/Api/Activity/Notification.php b/lib/Github/Api/Activity/Notification.php new file mode 100644 index 00000000000..0fc2c8940e5 --- /dev/null +++ b/lib/Github/Api/Activity/Notification.php @@ -0,0 +1,62 @@ + + */ +class Notification extends AbstractApi +{ + /** + * Get a listing of a notifications + * @link https://developer.github.com/v3/activity/notifications/ + * + * @param bool $includingRead + * @param bool $participating + * @param null $since + * + * @return array array of notifications + */ + public function all($includingRead = false, $participating = false, $since = null) + { + $parameters = array( + 'all' => $includingRead, + 'participating' => $participating + ); + + if($since !== null) { + $parameters['since'] = $since; + } + + return $this->get('notifications', $parameters); + } + + /** + * Marks all notifications as read from the current date + * Optionally give DateTimeInterface to mark as read before that date + * + * @link https://developer.github.com/v3/activity/notifications/#mark-as-read + * + * @param DateTimeInterface $since + * + */ + public function markRead(DateTimeInterface $since = null) + { + $parameters = array(); + + if($since !== null) { + $parameters['last_read_at'] = $since->format(DateTime::ISO8601); + } + + $this->put('notifications', $parameters); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c1779663858..46434b7ed92 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -143,6 +143,11 @@ public function api($name) $api = new Api\Markdown($this); break; + case 'notification': + case 'notifications': + $api = new Api\Activity\Notification($this); + break; + case 'organization': case 'organizations': $api = new Api\Organization($this); From c7cd41a3ce6d8c8cd0b2f57a8f34e02f1c0ed12c Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Mon, 9 Feb 2015 22:48:50 +0100 Subject: [PATCH 215/951] Added method declarations to docblock to describe __call functionality --- lib/Github/Client.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 46434b7ed92..ac17f5e3084 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -22,6 +22,8 @@ * @method Api\Issue issue() * @method Api\Issue issues() * @method Api\Markdown markdown() + * @method Api\Activity\Notification notification() + * @method Api\Activity\Notification notifications() * @method Api\Organization organization() * @method Api\Organization organizations() * @method Api\PullRequest pr() From 300a09194226a66fd5a85c7949b8dbb07b6493b2 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Tue, 10 Feb 2015 16:03:53 +0100 Subject: [PATCH 216/951] Moved the Notification API outside of Activity --- lib/Github/Api/{Activity => }/Notification.php | 3 +-- lib/Github/Client.php | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) rename lib/Github/Api/{Activity => }/Notification.php (96%) diff --git a/lib/Github/Api/Activity/Notification.php b/lib/Github/Api/Notification.php similarity index 96% rename from lib/Github/Api/Activity/Notification.php rename to lib/Github/Api/Notification.php index 0fc2c8940e5..0d090c5e848 100644 --- a/lib/Github/Api/Activity/Notification.php +++ b/lib/Github/Api/Notification.php @@ -1,10 +1,9 @@ Date: Thu, 12 Feb 2015 08:32:22 -0500 Subject: [PATCH 217/951] Fix: Docblock says 'had', paramater 'has' --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 071eab4843d..8cab5b4d13c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -105,7 +105,7 @@ public function show($username, $repository) * @param null|string $organization username of organization if applicable * @param boolean $hasIssues `true` to enable issues for this repository, `false` to disable them * @param boolean $hasWiki `true` to enable the wiki for this repository, `false` to disable it - * @param boolean $hadDownloads `true` to enable downloads for this repository, `false` to disable them + * @param boolean $hasDownloads `true` to enable downloads for this repository, `false` to disable them * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. * @param boolean $autoInit `true` to create an initial commit with empty README, `false` for no initial commit * From 18b4ac7f2d061e93d307b96dbe1c10e5548b7f08 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 12 Feb 2015 23:09:22 +0000 Subject: [PATCH 218/951] Fixed indentation --- test/Github/Tests/Api/RepoTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 79bc2679567..d14df11e650 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -426,9 +426,9 @@ public function shouldGetCommitActivity() $api = $this->getApiMock(); $api->expects($this->once()) - ->method('get') - ->with('repos/KnpLabs/php-github-api/stats/commit_activity') - ->will($this->returnValue($expectedArray)); + ->method('get') + ->with('repos/KnpLabs/php-github-api/stats/commit_activity') + ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); } From aca95fc221db4ccbe58f73fd9dd2b373eae2b0b7 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Fri, 13 Feb 2015 00:36:19 +0100 Subject: [PATCH 219/951] Compatability with PHP 5.3 and 5.4 --- lib/Github/Api/Notification.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 0d090c5e848..289598815c8 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -45,10 +45,9 @@ public function all($includingRead = false, $participating = false, $since = nul * * @link https://developer.github.com/v3/activity/notifications/#mark-as-read * - * @param DateTimeInterface $since - * + * @param \DateTime $since */ - public function markRead(DateTimeInterface $since = null) + public function markRead(DateTime $since = null) { $parameters = array(); From 55df423cba997eb681b85f4b19d0adbe017464f0 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Fri, 13 Feb 2015 01:14:48 +0100 Subject: [PATCH 220/951] Added test for Notification API --- test/Github/Tests/Api/NotificationTest.php | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 test/Github/Tests/Api/NotificationTest.php diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php new file mode 100644 index 00000000000..5b4e233f85d --- /dev/null +++ b/test/Github/Tests/Api/NotificationTest.php @@ -0,0 +1,104 @@ + false, + 'participating' => false, + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('notifications', $parameters); + + $api->all(); + } + + /** + * @test + */ + public function shouldGetNotificationsSince() + { + $since = '2015-01-01 00:00:00'; + + $parameters = array( + 'all' => false, + 'participating' => false, + 'since' => $since, + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('notifications', $parameters); + + $api->all(false, false, $since); + } + + /** + * @test + */ + public function shouldGetNotificationsIncludingAndParticipating() + { + $parameters = array( + 'all' => true, + 'participating' => true, + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('notifications', $parameters); + + $api->all(true, true); + } + + /** + * @test + */ + public function shouldMarkNotificationsAsRead() + { + $parameters = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('notifications', $parameters); + + $api->markRead(); + } + + /** + * @test + */ + public function shouldMarkNotificationsAsReadForGivenDate() + { + $since = new DateTime('now'); + + $parameters = array( + 'last_read_at' => $since->format(DateTime::ISO8601), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('notifications', $parameters); + + $api->markRead($since); + } + + protected function getApiClass() + { + return 'Github\Api\Notification'; + } +} From 985755b0ccda05a9fbbe25d066322aa50b7d11fb Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Fri, 13 Feb 2015 01:16:20 +0100 Subject: [PATCH 221/951] Forgot to remove old use statement --- lib/Github/Api/Notification.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 289598815c8..914c046a1e9 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -3,7 +3,6 @@ namespace Github\Api; use DateTime; -use DateTimeInterface; /** * API for accessing Notifications from your Git/Github repositories. From be2433092799f09ee66db32c3a7cfeec942fff26 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Fri, 13 Feb 2015 10:39:20 +0100 Subject: [PATCH 222/951] Fixed weird sentence --- lib/Github/Api/Notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 914c046a1e9..83d83f0032d 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -15,7 +15,7 @@ class Notification extends AbstractApi { /** - * Get a listing of a notifications + * Get a listing of notifications * @link https://developer.github.com/v3/activity/notifications/ * * @param bool $includingRead From 49488d87ea6e33fdf28b7b669144a501169aa317 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Fri, 13 Feb 2015 10:44:48 +0100 Subject: [PATCH 223/951] Made implementation more consistent with DateTime, altered comments and tests accordingly --- lib/Github/Api/Notification.php | 15 ++++++++------- test/Github/Tests/Api/NotificationTest.php | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 83d83f0032d..75831137df3 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -16,15 +16,16 @@ class Notification extends AbstractApi { /** * Get a listing of notifications + * * @link https://developer.github.com/v3/activity/notifications/ * - * @param bool $includingRead - * @param bool $participating - * @param null $since + * @param bool $includingRead + * @param bool $participating + * @param DateTime|null $since * * @return array array of notifications */ - public function all($includingRead = false, $participating = false, $since = null) + public function all($includingRead = false, $participating = false, DateTime $since = null) { $parameters = array( 'all' => $includingRead, @@ -32,7 +33,7 @@ public function all($includingRead = false, $participating = false, $since = nul ); if($since !== null) { - $parameters['since'] = $since; + $parameters['since'] = $since->format(DateTime::ISO8601); } return $this->get('notifications', $parameters); @@ -40,11 +41,11 @@ public function all($includingRead = false, $participating = false, $since = nul /** * Marks all notifications as read from the current date - * Optionally give DateTimeInterface to mark as read before that date + * Optionally give DateTime to mark as read before that date * * @link https://developer.github.com/v3/activity/notifications/#mark-as-read * - * @param \DateTime $since + * @param DateTime|null $since */ public function markRead(DateTime $since = null) { diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index 5b4e233f85d..a212530fffd 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -29,12 +29,12 @@ public function shouldGetNotifications() */ public function shouldGetNotificationsSince() { - $since = '2015-01-01 00:00:00'; + $since = new DateTime('now'); $parameters = array( 'all' => false, 'participating' => false, - 'since' => $since, + 'since' => $since->format(DateTime::ISO8601), ); $api = $this->getApiMock(); From 6188f4ba765fe2034c25cfcc0b195940471fdd8f Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 14 Feb 2015 16:51:16 +0100 Subject: [PATCH 224/951] Update contents.md --- doc/repo/contents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/contents.md b/doc/repo/contents.md index 6307f5d449b..56967101ac6 100644 --- a/doc/repo/contents.md +++ b/doc/repo/contents.md @@ -31,7 +31,7 @@ $fileInfo = $client->api('repo')->contents()->create('knp-labs', 'php-github-api $committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); $oldFile = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $branch); -$fileInfo = $client->api('repo')->contents()->create('knp-labs', 'php-github-api', $path, $content, $commitMessage, $oldFile['sha'], $branch, $committer); +$fileInfo = $client->api('repo')->contents()->update('knp-labs', 'php-github-api', $path, $content, $commitMessage, $oldFile['sha'], $branch, $committer); ``` ### Remove a file From 8246468b0e758323635e80a0a5cc34c3898fc548 Mon Sep 17 00:00:00 2001 From: Dennis de Greef Date: Sun, 15 Feb 2015 23:02:10 +0100 Subject: [PATCH 225/951] Added documentation for new notification API --- doc/notification.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 doc/notification.md diff --git a/doc/notification.md b/doc/notification.md new file mode 100644 index 00000000000..e2d941ec02b --- /dev/null +++ b/doc/notification.md @@ -0,0 +1,38 @@ +## Notification API +[Back to the navigation](index.md) + +Listing notifications and marking them as read. +Wraps [GitHub Notification API](https://developer.github.com/v3/activity/notifications/). + +### List notifications + +```php +$issues = $client->api('notification')->all(); +``` + +Returns an array of unread notifications. + +### Include already read notifications, including participating, or since a certain date + +```php +$includingRead = true; +$participating = true; +$since = new DateTime('1970/01/01'); +$issues = $client->api('notification')->all($includingRead, $participating, $since); +``` + +Returns an array of all notifications + +### Mark notifications as read + +```php +$client->api('notification')->markRead(); +``` + +or up until a certain date + +```php +$client->api('notification')->markRead(new DateTime('2015/01/01')); +``` + +Marks all notifications as read up until the current date, unless a date is given From bad69912222420d4db666a17b9aa72f164f28842 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:08:12 +1300 Subject: [PATCH 226/951] Fixed missing import --- lib/Github/Api/Issue/Labels.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 5628201f50c..7481d2bdc18 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -4,6 +4,7 @@ use Github\Api\AbstractApi; use Github\Exception\InvalidArgumentException; +use Github\Exception\MissingArgumentException; /** * @link http://developer.github.com/v3/issues/labels/ From fe4fd74fda4ebbb4e56ab1cb3b813b37349d55d5 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:10:02 +1300 Subject: [PATCH 227/951] Rename index.md to README.md That way the page will show on github --- doc/{index.md => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/{index.md => README.md} (100%) diff --git a/doc/index.md b/doc/README.md similarity index 100% rename from doc/index.md rename to doc/README.md From 4b8a05a6785b66a6b66edbb2b105121b24c62a2b Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:15:08 +1300 Subject: [PATCH 228/951] Added support for deleting a label --- lib/Github/Api/Issue/Labels.php | 5 +++++ test/Github/Tests/Api/Issue/LabelsTest.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 7481d2bdc18..d04e536860d 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -33,6 +33,11 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } + public function deleteLabel($username, $repository, $label) + { + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); + } + public function add($username, $repository, $issue, $labels) { if (is_string($labels)) { diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index 1bfa73c69ca..da749f5c213 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -6,7 +6,6 @@ class LabelsTest extends TestCase { - /** * @test */ @@ -76,6 +75,22 @@ public function shouldCreateLabelWithColor() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } + /** + * @test + */ + public function shouldDeleteLabel() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('repos/KnpLabs/php-github-api/labels/foo') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteLabel('KnpLabs', 'php-github-api', 'foo')); + } + /** * @test */ From f31725ff0c97b7491fb0e33f97094aa6a170b6ea Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:18:50 +1300 Subject: [PATCH 229/951] Added support for updating a label --- lib/Github/Api/Issue/Labels.php | 10 ++++++++++ test/Github/Tests/Api/Issue/LabelsTest.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index d04e536860d..bdce1437186 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -38,6 +38,16 @@ public function deleteLabel($username, $repository, $label) return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } + public function update($username, $repository, $label, $newName, $color) + { + $params = array( + 'name' => $newName, + 'color' => $color, + ); + + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); + } + public function add($username, $repository, $issue, $labels) { if (is_string($labels)) { diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index da749f5c213..3a6b7009e5d 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -91,6 +91,23 @@ public function shouldDeleteLabel() $this->assertEquals($expectedValue, $api->deleteLabel('KnpLabs', 'php-github-api', 'foo')); } + /** + * @test + */ + public function shouldUpdateLabel() + { + $expectedValue = array(array('name' => 'bar', 'color' => 'FFF')); + $data = array('name' => 'bar', 'color' => 'FFF'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('repos/KnpLabs/php-github-api/labels/foo', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'foo', 'bar', 'FFF')); + } + /** * @test */ From 70f16ecde69c5636eab3f9ca0e79a918b3c57a42 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:22:53 +1300 Subject: [PATCH 230/951] Added documentation for managing labels. --- doc/issue/labels.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 797d9a50427..37aa0b052bb 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -12,6 +12,33 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api'); List all project labels by username and repo. Returns an array of project labels. +### Create a label + +```php +$labels = $client->api('issue')->labels()->create('KnpLabs', 'php-github-api', array( + 'name' => 'Bug', + 'color' => 'FFFFFF', +)); +``` + +Create a new label in the repository. + +### Update a label + +```php +$labels = $client->api('issue')->labels()->update('KnpLabs', 'php-github-api', 'Enhancement', 'Feature', 'FFFFFF'); +``` + +Update the label name and color. + +### Delete a label + +```php +$labels = $client->api('issue')->labels()->deleteLabel('KnpLabs', 'php-github-api', 'Bug'); +``` + +Delete a new label from the repository. + ### Add a label on an issue > Requires [authentication](../security.md). From f25dfc576fd98ab20f8cd5dd6ff7e971066b6b27 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 28 Feb 2015 16:23:06 +1300 Subject: [PATCH 231/951] Updated links to the documentation index --- README.markdown | 2 +- doc/activity.md | 2 +- doc/authorizations.md | 2 +- doc/commits.md | 2 +- doc/customize.md | 2 +- doc/enterprise.md | 2 +- doc/gists.md | 2 +- doc/issue/comments.md | 2 +- doc/issue/labels.md | 2 +- doc/issues.md | 2 +- doc/meta.md | 2 +- doc/notification.md | 2 +- doc/organization.md | 2 +- doc/organization/members.md | 2 +- doc/organization/teams.md | 2 +- doc/pull_request/comments.md | 2 +- doc/pull_requests.md | 2 +- doc/repo/assets.md | 2 +- doc/repo/contents.md | 2 +- doc/repo/releases.md | 2 +- doc/repos.md | 2 +- doc/request_any_route.md | 2 +- doc/result_pager.md | 2 +- doc/search.md | 2 +- doc/security.md | 2 +- doc/two_factor_authentication.md | 2 +- doc/users.md | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.markdown b/README.markdown index 3a8dfd544ad..d370ff79ac3 100755 --- a/README.markdown +++ b/README.markdown @@ -90,7 +90,7 @@ Using cache, the client will get cached responses if resources haven't changed s ## Documentation -See the `doc` directory for more detailed documentation. +See the [`doc` directory](doc/) for more detailed documentation. ## License diff --git a/doc/activity.md b/doc/activity.md index ca8c74bf3a1..6f1429e157d 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -1,5 +1,5 @@ ## Activity API (incomplete) -[Back to the navigation](index.md) +[Back to the navigation](README.md) Access to Starring and Watching a Repository for [non] authenticated users. Wrap [GitHub Activity API](https://developer.github.com/v3/activity/). diff --git a/doc/authorizations.md b/doc/authorizations.md index 5386c6acab5..037bca839d9 100644 --- a/doc/authorizations.md +++ b/doc/authorizations.md @@ -1,5 +1,5 @@ ## Authorizations API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Creating, deleting and listing authorizations. Wraps [GitHub Authorizations API](http://developer.github.com/v3/oauth/). diff --git a/doc/commits.md b/doc/commits.md index c48ce3126f8..741af0713a2 100644 --- a/doc/commits.md +++ b/doc/commits.md @@ -1,5 +1,5 @@ ## Commits API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Getting information on specific commits, the diffs they introduce, the files they've changed. Wrap [GitHub Commit API](http://developer.github.com/v3/git/commits/). diff --git a/doc/customize.md b/doc/customize.md index 0b58ee69bd5..94888056be2 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -1,5 +1,5 @@ ## Customize `php-github-api` and testing -[Back to the navigation](index.md) +[Back to the navigation](README.md) ### Configure the http client diff --git a/doc/enterprise.md b/doc/enterprise.md index 9e38f13dce6..7308d2dc1f2 100644 --- a/doc/enterprise.md +++ b/doc/enterprise.md @@ -1,5 +1,5 @@ ## Enterprise API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Provides information about a GitHub Enterprise installation. Wraps [GitHub Enterprise API](http://developer.github.com/v3/enterprise/). diff --git a/doc/gists.md b/doc/gists.md index 604ee142344..168ca3629c3 100644 --- a/doc/gists.md +++ b/doc/gists.md @@ -1,5 +1,5 @@ ## Gists API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Creating, editing, deleting and listing gists. Wraps [GitHub Gists API](http://developer.github.com/v3/gists/). diff --git a/doc/issue/comments.md b/doc/issue/comments.md index 511bb891c3e..632bd3459b1 100644 --- a/doc/issue/comments.md +++ b/doc/issue/comments.md @@ -1,5 +1,5 @@ ## Issues / Comments API -[Back to the "Issues API"](../issues.md) | [Back to the navigation](../index.md) +[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md) Wraps [GitHub Issue Comments API](http://developer.github.com/v3/issues/comments/). diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 797d9a50427..e0e50b87a25 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -1,5 +1,5 @@ ## Issues / Labels API -[Back to the "Issues API"](../issues.md) | [Back to the navigation](../index.md) +[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md) Wraps [GitHub Issue Labels API](http://developer.github.com/v3/issues/labels/). diff --git a/doc/issues.md b/doc/issues.md index a92ade373ec..1251d078673 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -1,5 +1,5 @@ ## Issues API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Listing issues, searching, editing and closing your projects issues. Wraps [GitHub Issue API](http://developer.github.com/v3/issues/). diff --git a/doc/meta.md b/doc/meta.md index adc3e437cbb..06cb7b8681f 100644 --- a/doc/meta.md +++ b/doc/meta.md @@ -1,5 +1,5 @@ ## Users API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Wrap [GitHub User API](http://developer.github.com/v3/meta/). diff --git a/doc/notification.md b/doc/notification.md index e2d941ec02b..d586b364c74 100644 --- a/doc/notification.md +++ b/doc/notification.md @@ -1,5 +1,5 @@ ## Notification API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Listing notifications and marking them as read. Wraps [GitHub Notification API](https://developer.github.com/v3/activity/notifications/). diff --git a/doc/organization.md b/doc/organization.md index 6763a8f845b..0bfdd299b98 100644 --- a/doc/organization.md +++ b/doc/organization.md @@ -1,5 +1,5 @@ ## Organization API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Wraps [GitHub Organization API](http://developer.github.com/v3/organization/). diff --git a/doc/organization/members.md b/doc/organization/members.md index 730836da497..b22b79c6008 100644 --- a/doc/organization/members.md +++ b/doc/organization/members.md @@ -1,5 +1,5 @@ ## Organization / Members API -[Back to the "Organization API"](../organization.md) | [Back to the navigation](../index.md) +[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md) Wraps [GitHub Organization Members API](http://developer.github.com/v3/organization/members/). diff --git a/doc/organization/teams.md b/doc/organization/teams.md index 1f932139493..7fc1c8b1075 100644 --- a/doc/organization/teams.md +++ b/doc/organization/teams.md @@ -1,5 +1,5 @@ ## Organization / Teams API -[Back to the "Organization API"](../organization.md) | [Back to the navigation](../index.md) +[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md) Wraps [GitHub Organization Teams API](http://developer.github.com/v3/organization/teams/). diff --git a/doc/pull_request/comments.md b/doc/pull_request/comments.md index dfeb5be3333..baca6ce363e 100644 --- a/doc/pull_request/comments.md +++ b/doc/pull_request/comments.md @@ -1,5 +1,5 @@ ## Pull Requests / Review Comments API -[Back to the "Pull Requests API"](../pull_requests.md) | [Back to the navigation](../index.md) +[Back to the "Pull Requests API"](../pull_requests.md) | [Back to the navigation](../README.md) Review Comments are comments on a portion of the unified diff. These are separate from Commit Comments (which are applied directly to a commit, outside of the Pull Request view), and Issue Comments (which do not reference diff --git a/doc/pull_requests.md b/doc/pull_requests.md index 8f8ad29b7d3..2b952b35b1f 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -1,5 +1,5 @@ ## Pull Requests API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Additional APIs: * [Review Comments](pull_request/comments.md) diff --git a/doc/repo/assets.md b/doc/repo/assets.md index 9e6ac8b8f20..3df3eae2b72 100644 --- a/doc/repo/assets.md +++ b/doc/repo/assets.md @@ -1,5 +1,5 @@ ## Repo / Releases API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) ### List all assets by release diff --git a/doc/repo/contents.md b/doc/repo/contents.md index 56967101ac6..56947c5e318 100644 --- a/doc/repo/contents.md +++ b/doc/repo/contents.md @@ -1,5 +1,5 @@ ## Repo / Contents API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) ### Get a repository's README diff --git a/doc/repo/releases.md b/doc/repo/releases.md index cfbf5721338..35478d80387 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -1,5 +1,5 @@ ## Repo / Releases API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) This Github API Endpoint is currently undocumented because it's new, but works just fine. diff --git a/doc/repos.md b/doc/repos.md index e8f35b9e586..5949dc05aaf 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -1,5 +1,5 @@ ## Repositories API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Searching repositories, getting repository information and managing repository information for authenticated users. Wrap [GitHub Repo API](http://developer.github.com/v3/repos/). All methods are described on that page. diff --git a/doc/request_any_route.md b/doc/request_any_route.md index 1465ff7934d..76680fe857f 100644 --- a/doc/request_any_route.md +++ b/doc/request_any_route.md @@ -1,5 +1,5 @@ ## Request any Route -[Back to the navigation](index.md) +[Back to the navigation](README.md) The method you need does not exist yet? You can access any GitHub route by using the "get" and "post" methods. For example: diff --git a/doc/result_pager.md b/doc/result_pager.md index d9e58ff705a..1147674edcc 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -1,5 +1,5 @@ ## Result Pager -[Back to the navigation](index.md) +[Back to the navigation](README.md) ### Usage examples diff --git a/doc/search.md b/doc/search.md index 75b79640d4c..77b6eb9816d 100644 --- a/doc/search.md +++ b/doc/search.md @@ -1,5 +1,5 @@ ## Search API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Searching repositories, code, issues and users. Wrap [GitHub Search API](http://developer.github.com/v3/search/). All methods are described on that page. diff --git a/doc/security.md b/doc/security.md index 4d74fcb9aa2..358bfe8abab 100644 --- a/doc/security.md +++ b/doc/security.md @@ -1,5 +1,5 @@ ## Authentication & Security -[Back to the navigation](index.md) +[Back to the navigation](README.md) Most GitHub services do not require authentication, but some do. For example the methods that allow you to change properties on Repositories and some others. Therefore this step is facultative. diff --git a/doc/two_factor_authentication.md b/doc/two_factor_authentication.md index 7270239974f..46e84e0daa5 100644 --- a/doc/two_factor_authentication.md +++ b/doc/two_factor_authentication.md @@ -1,5 +1,5 @@ ## Two factor authentication -[Back to the navigation](index.md) +[Back to the navigation](README.md) ### Raising the exception diff --git a/doc/users.md b/doc/users.md index 810226af55b..5e76343d54e 100644 --- a/doc/users.md +++ b/doc/users.md @@ -1,5 +1,5 @@ ## Users API -[Back to the navigation](index.md) +[Back to the navigation](README.md) Searching users, getting user information and managing authenticated user account information. Wrap [GitHub User API](http://developer.github.com/v3/users/). From 21184c343bc0a6e74a8d4784da00c0dc991587f0 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Sat, 28 Feb 2015 16:23:23 +1300 Subject: [PATCH 232/951] Renamed the README file for consistency --- README.markdown => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.markdown => README.md (100%) diff --git a/README.markdown b/README.md similarity index 100% rename from README.markdown rename to README.md From 40cbb265b6731a89c4fa478009c718fa4f65284d Mon Sep 17 00:00:00 2001 From: Alex Demchenko Date: Sat, 28 Feb 2015 23:20:39 +0200 Subject: [PATCH 233/951] Fix knplabs logo url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d370ff79ac3..aa9c6e6a4a0 100755 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ See the [`doc` directory](doc/) for more detailed documentation. ### Sponsored by -[![KnpLabs Team](http://knplabs.pl/bundles/knpcorporate/images/logo.png)](http://knplabs.com) +[![KnpLabs Team](http://knplabs.com/front/images/knp-labs-logo.png)](http://knplabs.com) ### Contributors From c659249e7a1ba5fc009baed8f2cc3341c8bde726 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 1 Mar 2015 10:08:08 +0000 Subject: [PATCH 234/951] Fixed a load of docblocks --- lib/Github/Api/AbstractApi.php | 54 +++++---- lib/Github/Api/ApiInterface.php | 2 +- lib/Github/Api/Authorizations.php | 2 +- lib/Github/Api/CurrentUser.php | 14 +-- lib/Github/Api/CurrentUser/DeployKeys.php | 33 ++++-- lib/Github/Api/CurrentUser/Emails.php | 19 +-- lib/Github/Api/CurrentUser/Followers.php | 24 ++-- lib/Github/Api/CurrentUser/Notifications.php | 45 ++++--- lib/Github/Api/CurrentUser/Starring.php | 30 +++-- lib/Github/Api/CurrentUser/Watchers.php | 30 +++-- lib/Github/Api/Enterprise/License.php | 1 + .../Api/Enterprise/ManagementConsole.php | 11 +- lib/Github/Api/Enterprise/Stats.php | 22 ++-- lib/Github/Api/Enterprise/UserAdmin.php | 4 +- lib/Github/Api/Gists.php | 4 +- lib/Github/Api/Issue.php | 64 ++++++---- lib/Github/Api/Markdown.php | 2 +- lib/Github/Api/Meta.php | 4 +- lib/Github/Api/Notification.php | 4 +- lib/Github/Api/Organization.php | 6 +- lib/Github/Api/PullRequest.php | 15 ++- lib/Github/Api/Repo.php | 112 +++++++++++------- lib/Github/Api/Repository/Assets.php | 49 ++++---- lib/Github/Api/Repository/Contents.php | 33 ++++-- lib/Github/Api/Repository/Downloads.php | 21 ++-- lib/Github/Api/Repository/Releases.php | 40 +++---- lib/Github/Api/Repository/Statuses.php | 4 +- lib/Github/Api/Search.php | 36 +++--- lib/Github/Api/User.php | 101 ++++++++++------ lib/Github/Client.php | 24 ++-- .../Exception/ApiLimitExceedException.php | 2 +- .../Exception/BadMethodCallException.php | 2 +- lib/Github/Exception/ErrorException.php | 2 +- .../Exception/InvalidArgumentException.php | 2 +- .../Exception/MissingArgumentException.php | 2 +- lib/Github/Exception/RuntimeException.php | 2 +- .../Exception/ValidationFailedException.php | 2 +- .../HttpClient/Cache/CacheInterface.php | 8 +- .../HttpClient/Cache/GaufretteCache.php | 2 +- lib/Github/HttpClient/CachedHttpClient.php | 18 +-- lib/Github/HttpClient/HttpClient.php | 2 +- lib/Github/HttpClient/HttpClientInterface.php | 41 +++---- lib/Github/ResultPager.php | 21 ++-- lib/Github/ResultPagerInterface.php | 32 +++-- test/Github/Tests/Api/CurrentUserTest.php | 2 +- .../Github/Tests/Api/Enterprise/StatsTest.php | 1 + test/Github/Tests/ResultPagerTest.php | 2 +- 47 files changed, 558 insertions(+), 395 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 724aaf44b35..e7209936ea5 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -6,21 +6,21 @@ use Github\HttpClient\Message\ResponseMediator; /** - * Abstract class for Api classes + * Abstract class for Api classes. * * @author Joseph Bielawski */ abstract class AbstractApi implements ApiInterface { /** - * The client + * The client. * * @var Client */ protected $client; /** - * number of items per page (GitHub pagination) + * Number of items per page (GitHub pagination). * * @var null|int */ @@ -59,9 +59,10 @@ public function setPerPage($perPage) /** * Send a GET request with query parameters. * - * @param string $path Request path. - * @param array $parameters GET parameters. - * @param array $requestHeaders Request Headers. + * @param string $path Request path. + * @param array $parameters GET parameters. + * @param array $requestHeaders Request Headers. + * * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ protected function get($path, array $parameters = array(), $requestHeaders = array()) @@ -78,11 +79,12 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr } /** - * Send a HEAD request with query parameters + * Send a HEAD request with query parameters. + * + * @param string $path Request path. + * @param array $parameters HEAD parameters. + * @param array $requestHeaders Request headers. * - * @param string $path Request path. - * @param array $parameters HEAD parameters. - * @param array $requestHeaders Request headers. * @return \Guzzle\Http\Message\Response */ protected function head($path, array $parameters = array(), $requestHeaders = array()) @@ -101,9 +103,9 @@ protected function head($path, array $parameters = array(), $requestHeaders = ar /** * Send a POST request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function post($path, array $parameters = array(), $requestHeaders = array()) { @@ -117,9 +119,10 @@ protected function post($path, array $parameters = array(), $requestHeaders = ar /** * Send a POST request with raw data. * - * @param string $path Request path. + * @param string $path Request path. * @param $body Request body. - * @param array $requestHeaders Request headers. + * @param array $requestHeaders Request headers. + * * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ protected function postRaw($path, $body, $requestHeaders = array()) @@ -136,9 +139,9 @@ protected function postRaw($path, $body, $requestHeaders = array()) /** * Send a PATCH request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function patch($path, array $parameters = array(), $requestHeaders = array()) { @@ -154,9 +157,9 @@ protected function patch($path, array $parameters = array(), $requestHeaders = a /** * Send a PUT request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function put($path, array $parameters = array(), $requestHeaders = array()) { @@ -172,9 +175,9 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr /** * Send a DELETE request with JSON-encoded parameters. * - * @param string $path Request path. - * @param array $parameters POST parameters to be JSON encoded. - * @param array $requestHeaders Request headers. + * @param string $path Request path. + * @param array $parameters POST parameters to be JSON encoded. + * @param array $requestHeaders Request headers. */ protected function delete($path, array $parameters = array(), $requestHeaders = array()) { @@ -190,7 +193,8 @@ protected function delete($path, array $parameters = array(), $requestHeaders = /** * Create a JSON encoded version of an array of parameters. * - * @param array $parameters Request parameters + * @param array $parameters Request parameters + * * @return null|string */ protected function createJsonBody(array $parameters) diff --git a/lib/Github/Api/ApiInterface.php b/lib/Github/Api/ApiInterface.php index d55fe8fe0f3..893f538e1ab 100644 --- a/lib/Github/Api/ApiInterface.php +++ b/lib/Github/Api/ApiInterface.php @@ -3,7 +3,7 @@ namespace Github\Api; /** - * Api interface + * Api interface. * * @author Joseph Bielawski */ diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index 68f9414fd0c..014e08b4486 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -5,7 +5,7 @@ use Github\Api\AbstractApi; /** - * Creating, deleting and listing authorizations + * Creating, deleting and listing authorizations. * * @link http://developer.github.com/v3/oauth/ */ diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 5b21a41d175..3ab571d47fe 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -12,7 +12,7 @@ /** * @link http://developer.github.com/v3/users/ * @author Joseph Bielawski - * @revised Felipe Valtl de Mello + * @author Felipe Valtl de Mello */ class CurrentUser extends AbstractApi { @@ -52,8 +52,8 @@ public function followers($page = 1) /** * @link http://developer.github.com/v3/issues/#list-issues * - * @param array $params - * @param boolean $includeOrgIssues + * @param array $params + * @param bool $includeOrgIssues * * @return array */ @@ -101,10 +101,10 @@ public function teams() /** * @link http://developer.github.com/v3/repos/#list-your-repositories * - * @param string $type role in the repository - * @param string $sort sort by - * @param string $direction direction of sort, ask or desc - + * @param string $type role in the repository + * @param string $sort sort by + * @param string $direction direction of sort, ask or desc + * * @return array */ public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc') diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/DeployKeys.php index 87a0eaed843..d4f8b080d77 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/DeployKeys.php @@ -12,7 +12,8 @@ class DeployKeys extends AbstractApi { /** - * List deploy keys for the authenticated user + * List deploy keys for the authenticated user. + * * @link http://developer.github.com/v3/repos/keys/ * * @return array @@ -23,10 +24,12 @@ public function all() } /** - * Shows deploy key for the authenticated user + * Shows deploy key for the authenticated user. + * * @link http://developer.github.com/v3/repos/keys/ * - * @param string $id + * @param string $id + * * @return array */ public function show($id) @@ -35,13 +38,15 @@ public function show($id) } /** - * Adds deploy key for the authenticated user + * Adds deploy key for the authenticated user. + * * @link http://developer.github.com/v3/repos/keys/ * - * @param array $params - * @return array + * @param array $params * * @throws MissingArgumentException + * + * @return array */ public function create(array $params) { @@ -53,14 +58,16 @@ public function create(array $params) } /** - * Updates deploy key for the authenticated user + * Updates deploy key for the authenticated user. + * * @link http://developer.github.com/v3/repos/keys/ * - * @param string $id - * @param array $params - * @return array + * @param string $id + * @param array $params * * @throws MissingArgumentException + * + * @return array */ public function update($id, array $params) { @@ -72,10 +79,12 @@ public function update($id, array $params) } /** - * Removes deploy key for the authenticated user + * Removes deploy key for the authenticated user. + * * @link http://developer.github.com/v3/repos/keys/ * - * @param string $id + * @param string $id + * * @return array */ public function remove($id) diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index ec8c78d5986..587aa12c744 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -12,7 +12,8 @@ class Emails extends AbstractApi { /** - * List emails for the authenticated user + * List emails for the authenticated user. + * * @link http://developer.github.com/v3/users/emails/ * * @return array @@ -23,13 +24,15 @@ public function all() } /** - * Adds one or more email for the authenticated user + * Adds one or more email for the authenticated user. + * * @link http://developer.github.com/v3/users/emails/ * - * @param string|array $emails - * @return array + * @param string|array $emails * * @throws InvalidArgumentException + * + * @return array */ public function add($emails) { @@ -43,13 +46,15 @@ public function add($emails) } /** - * Removes one or more email for the authenticated user + * Removes one or more email for the authenticated user. + * * @link http://developer.github.com/v3/users/emails/ * - * @param string|array $emails - * @return array + * @param string|array $emails * * @throws InvalidArgumentException + * + * @return array */ public function remove($emails) { diff --git a/lib/Github/Api/CurrentUser/Followers.php b/lib/Github/Api/CurrentUser/Followers.php index ea356d85e32..303637740cc 100644 --- a/lib/Github/Api/CurrentUser/Followers.php +++ b/lib/Github/Api/CurrentUser/Followers.php @@ -11,10 +11,12 @@ class Followers extends AbstractApi { /** - * List followed users by the authenticated user + * List followed users by the authenticated user. + * * @link http://developer.github.com/v3/repos/followers/ * - * @param integer $page + * @param int $page + * * @return array */ public function all($page = 1) @@ -25,10 +27,12 @@ public function all($page = 1) } /** - * Check that the authenticated user follows a user + * Check that the authenticated user follows a user. + * * @link http://developer.github.com/v3/repos/followers/ * - * @param string $username the username to follow + * @param string $username the username to follow + * * @return array */ public function check($username) @@ -37,10 +41,12 @@ public function check($username) } /** - * Make the authenticated user follow a user + * Make the authenticated user follow a user. + * * @link http://developer.github.com/v3/repos/followers/ * - * @param string $username the username to follow + * @param string $username the username to follow + * * @return array */ public function follow($username) @@ -49,10 +55,12 @@ public function follow($username) } /** - * Make the authenticated user un-follow a user + * Make the authenticated user un-follow a user. + * * @link http://developer.github.com/v3/repos/followers/ * - * @param string $username the username to un-follow + * @param string $username the username to un-follow + * * @return array */ public function unfollow($username) diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index a35519df783..92dc0a570c9 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -11,10 +11,12 @@ class Notifications extends AbstractApi { /** - * List all notifications for the authenticated user + * List all notifications for the authenticated user. + * * @link http://developer.github.com/v3/activity/notifications/#list-your-notifications * - * @param array $params + * @param array $params + * * @return array */ public function all(array $params = array()) @@ -23,12 +25,14 @@ public function all(array $params = array()) } /** - * List all notifications for the authenticated user in selected repository + * List all notifications for the authenticated user in selected repository. + * * @link http://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param array $params + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param array $params + * * @return array */ public function allInRepository($username, $repository, array $params = array()) @@ -39,7 +43,8 @@ public function allInRepository($username, $repository, array $params = array()) /** * @link http://developer.github.com/v3/activity/notifications/#mark-as-read * - * @param array $params + * @param array $params + * * @return array */ public function markAsReadAll(array $params = array()) @@ -50,9 +55,10 @@ public function markAsReadAll(array $params = array()) /** * @link http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param array $params + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param array $params + * * @return array */ public function markAsReadInRepository($username, $repository, array $params = array()) @@ -63,8 +69,9 @@ public function markAsReadInRepository($username, $repository, array $params = a /** * @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read * - * @param string $id the notification number - * @param array $params + * @param string $id the notification number + * @param array $params + * * @return array */ public function markAsRead($id, array $params) @@ -75,7 +82,8 @@ public function markAsRead($id, array $params) /** * @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread * - * @param string $id the notification number + * @param string $id the notification number + * * @return array */ public function show($id) @@ -86,7 +94,8 @@ public function show($id) /** * @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription * - * @param string $id the notification number + * @param string $id the notification number + * * @return array */ public function showSubscription($id) @@ -97,8 +106,9 @@ public function showSubscription($id) /** * @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription * - * @param string $id the notification number - * @param array $params + * @param string $id the notification number + * @param array $params + * * @return array */ public function createSubscription($id, array $params) @@ -109,7 +119,8 @@ public function createSubscription($id, array $params) /** * @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription * - * @param string $id the notification number + * @param string $id the notification number + * * @return array */ public function removeSubscription($id) diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index 97e0b017c9b..0e75da2c576 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -11,10 +11,12 @@ class Starring extends AbstractApi { /** - * List repositories starred by the authenticated user + * List repositories starred by the authenticated user. + * * @link https://developer.github.com/v3/activity/starring/ * - * @param integer $page + * @param int $page + * * @return array */ public function all($page = 1) @@ -25,11 +27,13 @@ public function all($page = 1) } /** - * Check that the authenticated user starres a repository + * Check that the authenticated user starres a repository. + * * @link https://developer.github.com/v3/activity/starring/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * * @return array */ public function check($username, $repository) @@ -38,11 +42,13 @@ public function check($username, $repository) } /** - * Make the authenticated user star a repository + * Make the authenticated user star a repository. + * * @link https://developer.github.com/v3/activity/starring/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * * @return array */ public function star($username, $repository) @@ -51,11 +57,13 @@ public function star($username, $repository) } /** - * Make the authenticated user unstar a repository + * Make the authenticated user unstar a repository. + * * @link https://developer.github.com/v3/activity/starring * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * * @return array */ public function unstar($username, $repository) diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 035b78f568e..7f7b55457b5 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -12,10 +12,12 @@ class Watchers extends AbstractApi { /** - * List repositories watched by the authenticated user + * List repositories watched by the authenticated user. + * * @link https://developer.github.com/v3/activity/watching/ * - * @param integer $page + * @param int $page + * * @return array */ public function all($page = 1) @@ -26,11 +28,13 @@ public function all($page = 1) } /** - * Check that the authenticated user watches a repository + * Check that the authenticated user watches a repository. + * * @link https://developer.github.com/v3/activity/watching/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * * @return array */ public function check($username, $repository) @@ -39,11 +43,13 @@ public function check($username, $repository) } /** - * Make the authenticated user watch a repository + * Make the authenticated user watch a repository. + * * @link https://developer.github.com/v3/activity/watching/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * * @return array */ public function watch($username, $repository) @@ -52,11 +58,13 @@ public function watch($username, $repository) } /** - * Make the authenticated user unwatch a repository + * Make the authenticated user unwatch a repository. + * * @link https://developer.github.com/v3/activity/watching/ * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * * @return array */ public function unwatch($username, $repository) diff --git a/lib/Github/Api/Enterprise/License.php b/lib/Github/Api/Enterprise/License.php index 27785ca14e3..de14f23eac3 100644 --- a/lib/Github/Api/Enterprise/License.php +++ b/lib/Github/Api/Enterprise/License.php @@ -8,6 +8,7 @@ class License extends AbstractApi { /** * Provides information about your Enterprise license (only available to site admins). + * * @link https://developer.github.com/v3/enterprise/license/ * * @return array array of license information diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 59315b45478..8554425f365 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -8,9 +8,11 @@ class ManagementConsole extends AbstractApi { /** * Checks the status of your installation’s most recent configuration process. + * * @link https://developer.github.com/v3/enterprise/management_console/#check-configuration-status * * @param string $hash md5 hash of your license + * * @return array array of configuration status information */ public function configcheck($hash) @@ -20,9 +22,11 @@ public function configcheck($hash) /** * Retrieves your installation’s settings. + * * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings * * @param string $hash md5 hash of your license + * * @return array array of settings */ public function settings($hash) @@ -32,9 +36,11 @@ public function settings($hash) /** * Checks your installation’s maintenance status. + * * @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status * * @param string $hash md5 hash of your license + * * @return array array of maintenance status information */ public function maintenance($hash) @@ -44,9 +50,11 @@ public function maintenance($hash) /** * Retrieves your installation’s authorized SSH keys. + * * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys * * @param string $hash md5 hash of your license + * * @return array array of authorized keys */ public function keys($hash) @@ -57,8 +65,9 @@ public function keys($hash) /** * Sends an authenticated GET request. * - * @param string $uri the request URI + * @param string $uri the request URI * @param string $hash md5 hash of your license + * * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ protected function getWithLicenseHash($uri, $hash) diff --git a/lib/Github/Api/Enterprise/Stats.php b/lib/Github/Api/Enterprise/Stats.php index 934401b769c..7af932945a7 100644 --- a/lib/Github/Api/Enterprise/Stats.php +++ b/lib/Github/Api/Enterprise/Stats.php @@ -7,7 +7,7 @@ class Stats extends AbstractApi { /** - * Returns the number of open and closed issues + * Returns the number of open and closed issues. * * @return array array with totals of open and closed issues */ @@ -17,7 +17,7 @@ public function issues() } /** - * Returns the number of active and inactive hooks + * Returns the number of active and inactive hooks. * * @return array array with totals of active and inactive hooks */ @@ -27,7 +27,7 @@ public function hooks() } /** - * Returns the number of open and closed milestones + * Returns the number of open and closed milestones. * * @return array array with totals of open and closed milestones */ @@ -37,7 +37,7 @@ public function milestones() } /** - * Returns the number of organizations, teams, team members, and disabled organizations + * Returns the number of organizations, teams, team members, and disabled organizations. * * @return array array with totals of organizations, teams, team members, and disabled organizations */ @@ -47,7 +47,7 @@ public function orgs() } /** - * Returns the number of comments on issues, pull requests, commits, and gists + * Returns the number of comments on issues, pull requests, commits, and gists. * * @return array array with totals of comments on issues, pull requests, commits, and gists */ @@ -57,7 +57,7 @@ public function comments() } /** - * Returns the number of GitHub Pages sites + * Returns the number of GitHub Pages sites. * * @return array array with totals of GitHub Pages sites */ @@ -67,7 +67,7 @@ public function pages() } /** - * Returns the number of suspended and admin users + * Returns the number of suspended and admin users. * * @return array array with totals of suspended and admin users */ @@ -77,7 +77,7 @@ public function users() } /** - * Returns the number of private and public gists + * Returns the number of private and public gists. * * @return array array with totals of private and public gists */ @@ -87,7 +87,7 @@ public function gists() } /** - * Returns the number of merged, mergeable, and unmergeable pull requests + * Returns the number of merged, mergeable, and unmergeable pull requests. * * @return array array with totals of merged, mergeable, and unmergeable pull requests */ @@ -97,7 +97,7 @@ public function pulls() } /** - * Returns the number of organization-owned repositories, root repositories, forks, pushed commits, and wikis + * Returns the number of organization-owned repositories, root repositories, forks, pushed commits, and wikis. * * @return array array with totals of organization-owned repositories, root repositories, forks, pushed commits, and wikis */ @@ -107,7 +107,7 @@ public function repos() } /** - * Returns all of the statistics + * Returns all of the statistics. * * @return array array with all of the statistics */ diff --git a/lib/Github/Api/Enterprise/UserAdmin.php b/lib/Github/Api/Enterprise/UserAdmin.php index d01a975515c..5a14114bca2 100644 --- a/lib/Github/Api/Enterprise/UserAdmin.php +++ b/lib/Github/Api/Enterprise/UserAdmin.php @@ -7,7 +7,7 @@ class UserAdmin extends AbstractApi { /** - * Suspend a user + * Suspend a user. * * @link https://developer.github.com/v3/users/administration/#suspend-a-user * @@ -21,7 +21,7 @@ public function suspend($username) } /** - * Unsuspend a user + * Unsuspend a user. * * @link https://developer.github.com/v3/users/administration/#unsuspend-a-user * diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index ffdc5e3201e..12fe9ec5d00 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -6,7 +6,7 @@ use Github\Exception\MissingArgumentException; /** - * Creating, editing, deleting and listing gists + * Creating, editing, deleting and listing gists. * * @link http://developer.github.com/v3/gists/ * @author Joseph Bielawski @@ -34,7 +34,7 @@ public function create(array $params) throw new MissingArgumentException('files'); } - $params['public'] = (boolean) $params['public']; + $params['public'] = (bool) $params['public']; return $this->post('gists', $params); } diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index c4aae96e994..c1b9a6e7992 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -12,19 +12,22 @@ * Listing issues, searching, editing and closing your projects issues. * * @link http://develop.github.com/p/issues.html + * * @author Thibault Duplessis * @author Joseph Bielawski */ class Issue extends AbstractApi { /** - * List issues by username, repo and state + * List issues by username, repo and state. + * * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction - * @return array list of issues found + * @param string $username the username + * @param string $repository the repository + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * + * @return array list of issues found */ public function all($username, $repository, array $params = array()) { @@ -32,7 +35,8 @@ public function all($username, $repository, array $params = array()) } /** - * Search issues by username, repo, state and keyword + * Search issues by username, repo, state and keyword. + * * @link http://developer.github.com/v3/search/#search-issues * * @param string $username the username @@ -52,13 +56,15 @@ public function find($username, $repository, $state, $keyword) } /** - * List issues by organization + * List issues by organization. + * * @link http://developer.github.com/v3/issues/ * - * @param string $organization the organization - * @param string $state the issue state, can be open or closed - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction - * @return array list of issues found + * @param string $organization the organization + * @param string $state the issue state, can be open or closed + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * + * @return array list of issues found */ public function org($organization, $state, array $params = array()) { @@ -70,13 +76,15 @@ public function org($organization, $state, array $params = array()) } /** - * Get extended information about an issue by its username, repo and number + * Get extended information about an issue by its username, repo and number. + * * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param string $id the issue number - * @return array information about the issue + * @param string $username the username + * @param string $repository the repository + * @param string $id the issue number + * + * @return array information about the issue */ public function show($username, $repository, $id) { @@ -86,14 +94,16 @@ public function show($username, $repository, $id) /** * Create a new issue for the given username and repo. * The issue is assigned to the authenticated user. Requires authentication. + * * @link http://developer.github.com/v3/issues/ * - * @param string $username the username - * @param string $repository the repository - * @param array $params the new issue data - * @return array information about the issue + * @param string $username the username + * @param string $repository the repository + * @param array $params the new issue data * * @throws MissingArgumentException + * + * @return array information about the issue */ public function create($username, $repository, array $params) { @@ -106,6 +116,7 @@ public function create($username, $repository, array $params) /** * Update issue information's by username, repo and issue number. Requires authentication. + * * @link http://developer.github.com/v3/issues/ * * @param string $username the username @@ -113,6 +124,7 @@ public function create($username, $repository, array $params) * @param string $id the issue number * @param array $params key=>value user attributes to update. * key can be title or body + * * @return array information about the issue */ public function update($username, $repository, $id, array $params) @@ -121,7 +133,8 @@ public function update($username, $repository, $id, array $params) } /** - * List an issue comments + * List an issue comments. + * * @link http://developer.github.com/v3/issues/comments/ * * @return Comments @@ -132,7 +145,8 @@ public function comments() } /** - * List all project events + * List all project events. + * * @link http://developer.github.com/v3/issues/events/ * * @return Events @@ -143,7 +157,8 @@ public function events() } /** - * List all project labels + * List all project labels. + * * @link http://developer.github.com/v3/issues/labels/ * * @return Labels @@ -154,7 +169,8 @@ public function labels() } /** - * List all project milestones + * List all project milestones. + * * @link http://developer.github.com/v3/issues/milestones/ * * @return Milestones diff --git a/lib/Github/Api/Markdown.php b/lib/Github/Api/Markdown.php index 8620ee86757..f97a142df5f 100644 --- a/lib/Github/Api/Markdown.php +++ b/lib/Github/Api/Markdown.php @@ -3,7 +3,7 @@ namespace Github\Api; /** - * Markdown Rendering API + * Markdown Rendering API. * * @link http://developer.github.com/v3/markdown/ * @author Joseph Bielawski diff --git a/lib/Github/Api/Meta.php b/lib/Github/Api/Meta.php index a10c1361b12..73a43301f9e 100644 --- a/lib/Github/Api/Meta.php +++ b/lib/Github/Api/Meta.php @@ -3,7 +3,7 @@ namespace Github\Api; /** - * Getting GitHub service information + * Getting GitHub service information. * * @link https://developer.github.com/v3/meta/ * @author Claude Dioudonnat @@ -11,7 +11,7 @@ class Meta extends AbstractApi { /** - * Get the ip address of the hook and git servers for the GitHub.com service + * Get the ip address of the hook and git servers for the GitHub.com service. * * @return array Informations about the service of GitHub.com */ diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 75831137df3..c351927ec5d 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -15,7 +15,7 @@ class Notification extends AbstractApi { /** - * Get a listing of notifications + * Get a listing of notifications. * * @link https://developer.github.com/v3/activity/notifications/ * @@ -41,7 +41,7 @@ public function all($includingRead = false, $participating = false, DateTime $si /** * Marks all notifications as read from the current date - * Optionally give DateTime to mark as read before that date + * Optionally give DateTime to mark as read before that date. * * @link https://developer.github.com/v3/activity/notifications/#mark-as-read * diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index da46badcfcd..37322b218d8 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -15,7 +15,8 @@ class Organization extends AbstractApi { /** - * Get extended information about an organization by its name + * Get extended information about an organization by its name. + * * @link http://developer.github.com/v3/orgs/#get * * @param string $organization the organization to show @@ -33,7 +34,8 @@ public function update($organization, array $params) } /** - * List all repositories across all the organizations that you can access + * List all repositories across all the organizations that you can access. + * * @link http://developer.github.com/v3/repos/#list-organization-repositories * * @param string $organization the user name diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 5151f1cd105..1af5778284c 100755 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -15,11 +15,12 @@ class PullRequest extends AbstractApi { /** * Get a listing of a project's pull requests by the username, repository and (optionally) state. + * * @link http://developer.github.com/v3/pulls/ * - * @param string $username the username - * @param string $repository the repository - * @param array $params a list of extra parameters. + * @param string $username the username + * @param string $repository the repository + * @param array $params a list of extra parameters. * * @return array array of pull requests for the project */ @@ -35,6 +36,7 @@ public function all($username, $repository, array $params = array()) /** * Show all details of a pull request, including the discussions. + * * @link http://developer.github.com/v3/pulls/ * * @param string $username the username @@ -64,7 +66,8 @@ public function comments() } /** - * Create a pull request + * Create a pull request. + * * @link http://developer.github.com/v3/pulls/ * * @param string $username the username @@ -75,9 +78,9 @@ public function comments() * "my-user:some-branch". The String title of the Pull Request. The String body of * the Pull Request. The issue number. Used when title and body is not set. * - * @return array - * * @throws MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 8cab5b4d13c..fcafd4b2517 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -25,7 +25,8 @@ class Repo extends AbstractApi { /** - * Search repositories by keyword: + * Search repositories by keyword. + * * @link http://developer.github.com/v3/search/#search-repositories * * @param string $keyword the search query @@ -39,7 +40,8 @@ public function find($keyword, array $params = array()) } /** - * Get the last year of commit activity for a repository grouped by week + * Get the last year of commit activity for a repository grouped by week. + * * @link http://developer.github.com/v3/repos/statistics/#commit-activity * * @param string $username the user who owns the repository @@ -53,7 +55,8 @@ public function activity($username, $repository) } /** - * Get contributor commit statistics for a repository + * Get contributor commit statistics for a repository. + * * @link http://developer.github.com/v3/repos/statistics/#contributors * * @param string $username the user who owns the repository @@ -67,7 +70,8 @@ public function statistics($username, $repository) } /** - * List all repositories for an organization + * List all repositories for an organization. + * * @link http://developer.github.com/v3/repos/#list-organization-repositories * * @param string $organization the name of the organization @@ -81,7 +85,8 @@ public function org($organization, array $params = array()) } /** - * Get extended information about a repository by its username and repository name + * Get extended information about a repository by its username and repository name. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the user who owns the repository @@ -95,19 +100,20 @@ public function show($username, $repository) } /** - * Create repository + * Create repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $name name of the repository * @param string $description repository description * @param string $homepage homepage url - * @param boolean $public `true` for public, `false` for private + * @param bool $public `true` for public, `false` for private * @param null|string $organization username of organization if applicable - * @param boolean $hasIssues `true` to enable issues for this repository, `false` to disable them - * @param boolean $hasWiki `true` to enable the wiki for this repository, `false` to disable it - * @param boolean $hasDownloads `true` to enable downloads for this repository, `false` to disable them - * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. - * @param boolean $autoInit `true` to create an initial commit with empty README, `false` for no initial commit + * @param bool $hasIssues `true` to enable issues for this repository, `false` to disable them + * @param bool $hasWiki `true` to enable the wiki for this repository, `false` to disable it + * @param bool $hasDownloads `true` to enable downloads for this repository, `false` to disable them + * @param int $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. + * @param bool $autoInit `true` to create an initial commit with empty README, `false` for no initial commit * * @return array returns repository data */ @@ -144,7 +150,8 @@ public function create( } /** - * Set information of a repository + * Set information of a repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the user who owns the repository @@ -159,7 +166,8 @@ public function update($username, $repository, array $values) } /** - * Delete a repository + * Delete a repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the user who owns the repository @@ -173,7 +181,8 @@ public function remove($username, $repository) } /** - * Get the readme content for a repository by its username and repository name + * Get the readme content for a repository by its username and repository name. + * * @link http://developer.github.com/v3/repos/contents/#get-the-readme * * @param string $username the user who owns the repository @@ -187,7 +196,8 @@ public function readme($username, $repository) } /** - * Manage the collaborators of a repository + * Manage the collaborators of a repository. + * * @link http://developer.github.com/v3/repos/collaborators/ * * @return Collaborators @@ -198,7 +208,8 @@ public function collaborators() } /** - * Manage the comments of a repository + * Manage the comments of a repository. + * * @link http://developer.github.com/v3/repos/comments/ * * @return Comments @@ -209,7 +220,8 @@ public function comments() } /** - * Manage the commits of a repository + * Manage the commits of a repository. + * * @link http://developer.github.com/v3/repos/commits/ * * @return Commits @@ -220,7 +232,8 @@ public function commits() } /** - * Manage the content of a repository + * Manage the content of a repository. + * * @link http://developer.github.com/v3/repos/contents/ * * @return Contents @@ -231,7 +244,8 @@ public function contents() } /** - * Manage the content of a repository + * Manage the content of a repository. + * * @link http://developer.github.com/v3/repos/downloads/ * * @return Downloads @@ -242,7 +256,8 @@ public function downloads() } /** - * Manage the releases of a repository (Currently Undocumented) + * Manage the releases of a repository (Currently Undocumented). + * * @link http://developer.github.com/v3/repos/ * * @return Releases @@ -253,7 +268,8 @@ public function releases() } /** - * Manage the deploy keys of a repository + * Manage the deploy keys of a repository. + * * @link http://developer.github.com/v3/repos/keys/ * * @return DeployKeys @@ -264,7 +280,8 @@ public function keys() } /** - * Manage the forks of a repository + * Manage the forks of a repository. + * * @link http://developer.github.com/v3/repos/forks/ * * @return Forks @@ -275,7 +292,8 @@ public function forks() } /** - * Manage the hooks of a repository + * Manage the hooks of a repository. + * * @link http://developer.github.com/v3/issues/jooks/ * * @return Hooks @@ -286,7 +304,8 @@ public function hooks() } /** - * Manage the labels of a repository + * Manage the labels of a repository. + * * @link http://developer.github.com/v3/issues/labels/ * * @return Labels @@ -297,7 +316,8 @@ public function labels() } /** - * Manage the statuses of a repository + * Manage the statuses of a repository. + * * @link http://developer.github.com/v3/repos/statuses/ * * @return Statuses @@ -308,7 +328,8 @@ public function statuses() } /** - * Get the branch(es) of a repository + * Get the branch(es) of a repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the username @@ -328,13 +349,15 @@ public function branches($username, $repository, $branch = null) } /** - * Get the contributors of a repository + * Get the contributors of a repository. + * * @link http://developer.github.com/v3/repos/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param boolean $includingAnonymous by default, the list only shows GitHub users. - * You can include non-users too by setting this to true + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param bool $includingAnonymous by default, the list only shows GitHub users. + * You can include non-users too by setting this to true + * * @return array list of the repo contributors */ public function contributors($username, $repository, $includingAnonymous = false) @@ -345,7 +368,8 @@ public function contributors($username, $repository, $includingAnonymous = false } /** - * Get the language breakdown of a repository + * Get the language breakdown of a repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the user who owns the repository @@ -359,7 +383,8 @@ public function languages($username, $repository) } /** - * Get the tags of a repository + * Get the tags of a repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the user who owns the repository @@ -373,7 +398,8 @@ public function tags($username, $repository) } /** - * Get the teams of a repository + * Get the teams of a repository. + * * @link http://developer.github.com/v3/repos/ * * @param string $username the user who owns the repo @@ -388,9 +414,10 @@ public function teams($username, $repository) /** * @deprecated see subscribers method - * @param string $username - * @param string $repository - * @param integer $page + * + * @param string $username + * @param string $repository + * @param int $page * * @return array */ @@ -402,9 +429,9 @@ public function watchers($username, $repository, $page = 1) } /** - * @param string $username - * @param string $repository - * @param integer $page + * @param string $username + * @param string $repository + * @param int $page * * @return array */ @@ -416,7 +443,8 @@ public function subscribers($username, $repository, $page = 1) } /** - * Perform a merge + * Perform a merge. + * * @link http://developer.github.com/v3/repos/merging/ * * @param string $username diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index ccd4263c27d..dbd448c7e28 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -15,11 +15,11 @@ class Assets extends AbstractApi { /** * Get all release's assets in selected repository - * GET /repos/:owner/:repo/releases/:id/assets + * GET /repos/:owner/:repo/releases/:id/assets. * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the release + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release * * @return array */ @@ -30,11 +30,11 @@ public function all($username, $repository, $id) /** * Get an asset in selected repository's release - * GET /repos/:owner/:repo/releases/assets/:id + * GET /repos/:owner/:repo/releases/assets/:id. * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the asset + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the asset * * @return array */ @@ -45,19 +45,20 @@ public function show($username, $repository, $id) /** * Create an asset for selected repository's release - * POST /repos/:owner/:repo/releases/:id/assets?name=:filename + * POST /repos/:owner/:repo/releases/:id/assets?name=:filename. * * Creating an asset requires support for server name indentification (SNI) * so this must be supported by your PHP version. + * * @see http://developer.github.com/v3/repos/releases/#upload-a-release-asset * @see http://php.net/manual/en/openssl.constsni.php * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the release - * @param string $name the filename for the asset - * @param string $contentType the content type for the asset - * @param string $content the content of the asset + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release + * @param string $name the filename for the asset + * @param string $contentType the content type for the asset + * @param string $content the content of the asset * * @throws MissingArgumentException * @throws ErrorException @@ -86,12 +87,12 @@ public function create($username, $repository, $id, $name, $contentType, $conten /** * Edit an asset in selected repository's release - * PATCH /repos/:owner/:repo/releases/assets/:id + * PATCH /repos/:owner/:repo/releases/assets/:id. * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the asset - * @param array $params request parameters + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the asset + * @param array $params request parameters * * @throws MissingArgumentException * @@ -108,11 +109,11 @@ public function edit($username, $repository, $id, array $params) /** * Delete an asset in selected repository's release - * DELETE /repos/:owner/:repo/releases/assets/:id + * DELETE /repos/:owner/:repo/releases/assets/:id. * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the asset + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the asset * * @return array */ diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index de6596ffa6c..c98898af63a 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -15,7 +15,8 @@ class Contents extends AbstractApi { /** - * Get content of README file in a repository + * Get content of README file in a repository. + * * @link http://developer.github.com/v3/repos/contents/ * * @param string $username the user who owns the repository @@ -32,7 +33,8 @@ public function readme($username, $repository, $reference = null) } /** - * Get contents of any file or directory in a repository + * Get contents of any file or directory in a repository. + * * @link http://developer.github.com/v3/repos/contents/ * * @param string $username the user who owns the repository @@ -55,7 +57,8 @@ public function show($username, $repository, $path = null, $reference = null) } /** - * Creates a new file in a repository + * Creates a new file in a repository. + * * @link http://developer.github.com/v3/repos/contents/#create-a-file * * @param string $username the user who owns the repository @@ -96,11 +99,12 @@ public function create($username, $repository, $path, $content, $message, $branc /** * Checks that a given path exists in a repository. * - * @param string $username the user who owns the repository + * @param string $username the user who owns the repository * @param string $repository the name of the repository - * @param string $path path of file to check - * @param null|string $reference reference to a branch or commit - * @return boolean + * @param string $path path of file to check + * @param null|string $reference reference to a branch or commit + * + * @return bool */ public function exists($username, $repository, $path, $reference = null) { @@ -128,7 +132,8 @@ public function exists($username, $repository, $path, $reference = null) } /** - * Updates the contents of a file in a repository + * Updates the contents of a file in a repository. + * * @link http://developer.github.com/v3/repos/contents/#update-a-file * * @param string $username the user who owns the repository @@ -170,7 +175,8 @@ public function update($username, $repository, $path, $content, $message, $sha, /** - * Deletes a file from a repository + * Deletes a file from a repository. + * * @link http://developer.github.com/v3/repos/contents/#delete-a-file * * @param string $username the user who owns the repository @@ -209,7 +215,8 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null } /** - * Get content of archives in a repository + * Get content of archives in a repository. + * * @link http://developer.github.com/v3/repos/contents/ * * @param string $username the user who owns the repository @@ -230,17 +237,17 @@ public function archive($username, $repository, $format, $reference = null) } /** - * Get the contents of a file in a repository + * Get the contents of a file in a repository. * * @param string $username the user who owns the repository * @param string $repository the name of the repository * @param string $path path to file * @param null|string $reference reference to a branch or commit * - * @return null|string content of file, or null in case of base64_decode failure - * * @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64 * @throws ErrorException If $path doesn't include a 'content' index + * + * @return null|string content of file, or null in case of base64_decode failure */ public function download($username, $repository, $path, $reference = null) { diff --git a/lib/Github/Api/Repository/Downloads.php b/lib/Github/Api/Repository/Downloads.php index f3b96891c77..63177e49903 100644 --- a/lib/Github/Api/Repository/Downloads.php +++ b/lib/Github/Api/Repository/Downloads.php @@ -11,7 +11,8 @@ class Downloads extends AbstractApi { /** - * List downloads in selected repository + * List downloads in selected repository. + * * @link http://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository * * @param string $username the user who owns the repo @@ -25,12 +26,13 @@ public function all($username, $repository) } /** - * Get a download in selected repository + * Get a download in selected repository. + * * @link http://developer.github.com/v3/repos/downloads/#get-a-single-download * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the download file + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the download file * * @return array */ @@ -40,12 +42,13 @@ public function show($username, $repository, $id) } /** - * Delete a download in selected repository + * Delete a download in selected repository. + * * @link http://developer.github.com/v3/repos/downloads/#delete-a-download * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the download file + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the download file * * @return array */ diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 7ac3726482f..652c1b3a601 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -13,10 +13,10 @@ class Releases extends AbstractApi { /** - * List releases in selected repository + * List releases in selected repository. * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo + * @param string $username the user who owns the repo + * @param string $repository the name of the repo * * @return array */ @@ -26,11 +26,11 @@ public function all($username, $repository) } /** - * Get a release in selected repository + * Get a release in selected repository. * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the release + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release * * @return array */ @@ -40,11 +40,11 @@ public function show($username, $repository, $id) } /** - * Create new release in selected repository + * Create new release in selected repository. * - * @param string $username - * @param string $repository - * @param array $params + * @param string $username + * @param string $repository + * @param array $params * * @throws MissingArgumentException * @@ -60,12 +60,12 @@ public function create($username, $repository, array $params) } /** - * Edit release in selected repository + * Edit release in selected repository. * - * @param string $username - * @param string $repository - * @param integer $id - * @param array $params + * @param string $username + * @param string $repository + * @param int $id + * @param array $params * * @return array */ @@ -75,11 +75,11 @@ public function edit($username, $repository, $id, array $params) } /** - * Delete a release in selected repository (Not thoroughly tested!) + * Delete a release in selected repository (Not thoroughly tested!). * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param integer $id the id of the release + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release * * @return array */ diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index 6d69ef3965f..caab1e2b524 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -47,9 +47,9 @@ public function combined($username, $repository, $sha) * @param string $sha * @param array $params * - * @return array - * * @throws MissingArgumentException + * + * @return array */ public function create($username, $repository, $sha, array $params = array()) { diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 8897feaa291..e3c69e5f21e 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -18,12 +18,13 @@ class Search extends AbstractApi { /** - * Search repositories by filter (q) + * Search repositories by filter (q). + * * @link https://developer.github.com/v3/search/#search-repositories * - * @param string $q the filter - * @param string $sort the sort field - * @param string $order asc/desc + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc * * @return array list of repositories found */ @@ -33,12 +34,13 @@ public function repositories($q, $sort = 'updated', $order = 'desc') } /** - * Search issues by filter (q) + * Search issues by filter (q). + * * @link https://developer.github.com/v3/search/#search-issues * - * @param string $q the filter - * @param string $sort the sort field - * @param string $order asc/desc + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc * * @return array list of issues found */ @@ -48,12 +50,13 @@ public function issues($q, $sort = 'updated', $order = 'desc') } /** - * Search code by filter (q) + * Search code by filter (q). + * * @link https://developer.github.com/v3/search/#search-code * - * @param string $q the filter - * @param string $sort the sort field - * @param string $order asc/desc + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc * * @return array list of code found */ @@ -63,12 +66,13 @@ public function code($q, $sort = 'updated', $order = 'desc') } /** - * Search users by filter (q) + * Search users by filter (q). + * * @link https://developer.github.com/v3/search/#search-users * - * @param string $q the filter - * @param string $sort the sort field - * @param string $order asc/desc + * @param string $q the filter + * @param string $sort the sort field + * @param string $order asc/desc * * @return array list of users found */ diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 20323934fca..0cc707b0bd7 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -3,7 +3,7 @@ namespace Github\Api; /** - * Searching users, getting user information + * Searching users, getting user information. * * @link http://developer.github.com/v3/users/ * @author Joseph Bielawski @@ -12,7 +12,8 @@ class User extends AbstractApi { /** - * Search users by username: + * Search users by username. + * * @link http://developer.github.com/v3/search/#search-users * * @param string $keyword the keyword to search @@ -25,26 +26,30 @@ public function find($keyword) } /** - * Request all users: + * Request all users. + * * @link https://developer.github.com/v3/users/#get-all-users * - * @param integer|null $id ID of the last user that you've seen + * @param int|null $id ID of the last user that you've seen + * * @return array list of users found */ public function all($id = null) { - if (!is_integer($id)) { + if (!is_int($id)) { return $this->get('users'); } return $this->get('users?since=' . rawurldecode($id)); } /** - * Get extended information about a user by its username + * Get extended information about a user by its username. + * * @link http://developer.github.com/v3/users/ * - * @param string $username the username to show - * @return array informations about the user + * @param string $username the username to show + * + * @return array informations about the user */ public function show($username) { @@ -52,11 +57,13 @@ public function show($username) } /** - * Get extended information about a user by its username + * Get extended information about a user by its username. + * * @link https://developer.github.com/v3/orgs/ * - * @param string $username the username to show - * @return array information about organizations that user belongs to + * @param string $username the username to show + * + * @return array information about organizations that user belongs to */ public function organizations($username) { @@ -64,11 +71,13 @@ public function organizations($username) } /** - * Request the users that a specific user is following + * Request the users that a specific user is following. + * * @link http://developer.github.com/v3/users/followers/ * - * @param string $username the username - * @return array list of followed users + * @param string $username the username + * + * @return array list of followed users */ public function following($username) { @@ -76,11 +85,13 @@ public function following($username) } /** - * Request the users following a specific user + * Request the users following a specific user. + * * @link http://developer.github.com/v3/users/followers/ * - * @param string $username the username - * @return array list of following users + * @param string $username the username + * + * @return array list of following users */ public function followers($username) { @@ -88,11 +99,13 @@ public function followers($username) } /** - * Request the repository that a specific user is watching + * Request the repository that a specific user is watching. + * * @deprecated see subscriptions method * - * @param string $username the username - * @return array list of watched repositories + * @param string $username the username + * + * @return array list of watched repositories */ public function watched($username) { @@ -100,11 +113,13 @@ public function watched($username) } /** - * Request starred repositories that a specific user has starred + * Request starred repositories that a specific user has starred. + * * @link http://developer.github.com/v3/activity/starring/ * - * @param string $username the username - * @param int $page the page number of the paginated result set + * @param string $username the username + * @param int $page the page number of the paginated result set + * * @return array list of starred repositories */ public function starred($username, $page = 1) @@ -115,11 +130,13 @@ public function starred($username, $page = 1) } /** - * Request the repository that a specific user is watching + * Request the repository that a specific user is watching. + * * @link http://developer.github.com/v3/activity/watching/ * - * @param string $username the username - * @return array list of watched repositories + * @param string $username the username + * + * @return array list of watched repositories */ public function subscriptions($username) { @@ -127,14 +144,16 @@ public function subscriptions($username) } /** - * Get the repositories of a user + * Get the repositories of a user. + * * @link http://developer.github.com/v3/repos/ * - * @param string $username the username - * @param string $type role in the repository - * @param string $sort sort by - * @param string $direction direction of sort, asc or desc - * @return array list of the user repositories + * @param string $username the username + * @param string $type role in the repository + * @param string $sort sort by + * @param string $direction direction of sort, asc or desc + * + * @return array list of the user repositories */ public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') { @@ -146,11 +165,13 @@ public function repositories($username, $type = 'owner', $sort = 'full_name', $d } /** - * Get the public gists for a user + * Get the public gists for a user. + * * @link http://developer.github.com/v3/gists/ * - * @param string $username the username - * @return array list of the user gists + * @param string $username the username + * + * @return array list of the user gists */ public function gists($username) { @@ -158,11 +179,13 @@ public function gists($username) } /** - * Get the public keys for a user + * Get the public keys for a user. + * * @link http://developer.github.com/v3/users/keys/#list-public-keys-for-a-user * - * @param string $username the username - * @return array list of the user public keys + * @param string $username the username + * + * @return array list of the user public keys */ public function keys($username) { @@ -170,7 +193,7 @@ public function keys($username) } /** - * List events performed by a user + * List events performed by a user. * * @link http://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user * diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e63af775507..997b5d84626 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -9,7 +9,7 @@ use Github\HttpClient\HttpClientInterface; /** - * Simple yet very cool PHP GitHub client + * Simple yet very cool PHP GitHub client. * * @method Api\CurrentUser currentUser() * @method Api\CurrentUser me() @@ -56,7 +56,7 @@ class Client /** * Constant for authentication method. Not indicates the new login, but allows - * usage of unauthenticated rate limited requests for given client_id + client_secret + * usage of unauthenticated rate limited requests for given client_id + client_secret. */ const AUTH_URL_CLIENT_ID = 'url_client_id'; @@ -88,14 +88,14 @@ class Client ); /** - * The Buzz instance used to communicate with GitHub + * The Buzz instance used to communicate with GitHub. * * @var HttpClient */ private $httpClient; /** - * Instantiate a new GitHub client + * Instantiate a new GitHub client. * * @param null|HttpClientInterface $httpClient Github http client */ @@ -107,9 +107,9 @@ public function __construct(HttpClientInterface $httpClient = null) /** * @param string $name * - * @return ApiInterface - * * @throws InvalidArgumentException + * + * @return ApiInterface */ public function api($name) { @@ -201,7 +201,7 @@ public function api($name) } /** - * Authenticate a user for all next requests + * Authenticate a user for all next requests. * * @param string $tokenOrLogin GitHub private token/username/client ID * @param null|string $password GitHub password/secret (optionally can contain $authMethod) @@ -259,7 +259,7 @@ public function setHttpClient(HttpClientInterface $httpClient) } /** - * Clears used headers + * Clears used headers. */ public function clearHeaders() { @@ -277,9 +277,9 @@ public function setHeaders(array $headers) /** * @param string $name * - * @return mixed - * * @throws InvalidArgumentException + * + * @return mixed */ public function getOption($name) { @@ -323,9 +323,9 @@ public function getSupportedApiVersions() /** * @param string $name * - * @return ApiInterface - * * @throws InvalidArgumentException + * + * @return ApiInterface */ public function __call($name, $args) { diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index 851631cccf8..539243a6837 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * ApiLimitExceedException + * ApiLimitExceedException. * * @author Joseph Bielawski */ diff --git a/lib/Github/Exception/BadMethodCallException.php b/lib/Github/Exception/BadMethodCallException.php index f12a8ce2cfb..83e05437b11 100644 --- a/lib/Github/Exception/BadMethodCallException.php +++ b/lib/Github/Exception/BadMethodCallException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * BadMethodCallException + * BadMethodCallException. * * @author James Brooks */ diff --git a/lib/Github/Exception/ErrorException.php b/lib/Github/Exception/ErrorException.php index 33f902edbe9..61f61f36f18 100644 --- a/lib/Github/Exception/ErrorException.php +++ b/lib/Github/Exception/ErrorException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * ErrorException + * ErrorException. * * @author Joseph Bielawski */ diff --git a/lib/Github/Exception/InvalidArgumentException.php b/lib/Github/Exception/InvalidArgumentException.php index cecc11b8bba..558b3b0f3dc 100644 --- a/lib/Github/Exception/InvalidArgumentException.php +++ b/lib/Github/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * InvalidArgumentException + * InvalidArgumentException. * * @author Joseph Bielawski */ diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index fd14ba01953..4a7e372e97c 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * MissingArgumentException + * MissingArgumentException. * * @author Joseph Bielawski */ diff --git a/lib/Github/Exception/RuntimeException.php b/lib/Github/Exception/RuntimeException.php index e4e9712b481..676cb95736a 100644 --- a/lib/Github/Exception/RuntimeException.php +++ b/lib/Github/Exception/RuntimeException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * RuntimeException + * RuntimeException. * * @author Joseph Bielawski */ diff --git a/lib/Github/Exception/ValidationFailedException.php b/lib/Github/Exception/ValidationFailedException.php index 0de17aea3e7..e43bc43e067 100644 --- a/lib/Github/Exception/ValidationFailedException.php +++ b/lib/Github/Exception/ValidationFailedException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * ValidationFailedException + * ValidationFailedException. * * @author Joseph Bielawski */ diff --git a/lib/Github/HttpClient/Cache/CacheInterface.php b/lib/Github/HttpClient/Cache/CacheInterface.php index e669f72fe1a..77bb4f89ec9 100644 --- a/lib/Github/HttpClient/Cache/CacheInterface.php +++ b/lib/Github/HttpClient/Cache/CacheInterface.php @@ -5,7 +5,7 @@ use Guzzle\Http\Message\Response; /** - * Caches github api responses + * Caches github api responses. * * @author Florian Klein */ @@ -21,7 +21,7 @@ public function has($id); /** * @param string $id The id of the cached resource * - * @return null|integer The modified since timestamp + * @return null|int The modified since timestamp */ public function getModifiedSince($id); @@ -35,9 +35,9 @@ public function getETag($id); /** * @param string $id The id of the cached resource * - * @return Response The cached response object - * * @throws \InvalidArgumentException If cache data don't exists + * + * @return Response The cached response object */ public function get($id); diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php index 0797a043b91..b72a104c9af 100644 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -6,7 +6,7 @@ use Gaufrette\Filesystem; /** - * Gaufrette Cache + * Gaufrette Cache. * * @author Massimiliano Arione */ diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index d7003c6bde9..f0e1368e6f3 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -8,7 +8,7 @@ /** * Performs requests on GitHub API using If-Modified-Since headers. * Returns a cached version if not modified - * Avoids increasing the X-Rate-Limit, which is cool + * Avoids increasing the X-Rate-Limit, which is cool. * * @author Florian Klein */ @@ -18,9 +18,9 @@ class CachedHttpClient extends HttpClient * @var CacheInterface */ protected $cache; - + /** - * contains the lastResponse fetched from cache + * Contains the lastResponse fetched from cache. * * @var Guzzle\Http\Message\Response */ @@ -52,11 +52,11 @@ public function setCache(CacheInterface $cache) public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { $response = parent::request($path, $body, $httpMethod, $headers, $options); - + if (304 == $response->getStatusCode()) { $cacheResponse = $this->getCache()->get($path); $this->lastCachedResponse = $cacheResponse; - + return $cacheResponse; } @@ -66,7 +66,7 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers } /** - * Create requests with If-Modified-Since headers + * Create requests with If-Modified-Since headers. * * {@inheritdoc} */ @@ -92,8 +92,8 @@ protected function createRequest($httpMethod, $path, $body = null, array $header return $request; } - - /** + + /** * @return Guzzle\Http\Message\Response */ public function getLastResponse($force = false) @@ -102,7 +102,7 @@ public function getLastResponse($force = false) if (304 != $lastResponse->getStatusCode()) { $force = true; } - + return ($force) ? $lastResponse : $this->lastCachedResponse; } } diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 5e907419221..84b2b09bc46 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -68,7 +68,7 @@ public function setHeaders(array $headers) } /** - * Clears used headers + * Clears used headers. */ public function clearHeaders() { diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php index 0961b8cc7a7..5ed0a9e34e5 100644 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ b/lib/Github/HttpClient/HttpClientInterface.php @@ -13,7 +13,7 @@ interface HttpClientInterface { /** - * Send a GET request + * Send a GET request. * * @param string $path Request path * @param array $parameters GET Parameters @@ -24,45 +24,46 @@ interface HttpClientInterface public function get($path, array $parameters = array(), array $headers = array()); /** - * Send a POST request + * Send a POST request. * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param mixed $body Request body + * @param array $headers Reconfigure the request headers for this call only * * @return Response */ public function post($path, $body = null, array $headers = array()); /** - * Send a PATCH request + * Send a PATCH request. * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param mixed $body Request body + * @param array $headers Reconfigure the request headers for this call only * * @internal param array $parameters Request body + * * @return Response */ public function patch($path, $body = null, array $headers = array()); /** - * Send a PUT request + * Send a PUT request. * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param mixed $body Request body + * @param array $headers Reconfigure the request headers for this call only * * @return Response */ public function put($path, $body, array $headers = array()); /** - * Send a DELETE request + * Send a DELETE request. * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only + * @param string $path Request path + * @param mixed $body Request body + * @param array $headers Reconfigure the request headers for this call only * * @return Response */ @@ -70,7 +71,7 @@ public function delete($path, $body = null, array $headers = array()); /** * Send a request to the server, receive a response, - * decode the response and returns an associative array + * decode the response and returns an associative array. * * @param string $path Request path * @param mixed $body Request body @@ -92,14 +93,14 @@ public function request($path, $body, $httpMethod = 'GET', array $headers = arra public function setOption($name, $value); /** - * Set HTTP headers + * Set HTTP headers. * * @param array $headers */ public function setHeaders(array $headers); /** - * Authenticate a user for all next requests + * Authenticate a user for all next requests. * * @param string $tokenOrLogin GitHub private token/username/client ID * @param null|string $password GitHub password/secret (optionally can contain $authMethod) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 7483194ba3b..01c689a58d9 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -6,7 +6,7 @@ use Github\HttpClient\Message\ResponseMediator; /** - * Pager class for supporting pagination in github classes + * Pager class for supporting pagination in github classes. * * @author Ramon de la Fuente * @author Mitchel Verschoof @@ -14,26 +14,31 @@ class ResultPager implements ResultPagerInterface { /** - * @var \Github\Client client + * The GitHub Client to use for pagination. + * + * @var \Github\Client */ protected $client; /** - * @var array pagination - * Comes from pagination headers in Github API results + * Comes from pagination headers in Github API results. + * + * @var array */ protected $pagination; /** - * The Github client to use for pagination. This must be the same - * instance that you got the Api instance from, i.e.: + * The Github client to use for pagination. + * + * This must be the same instance that you got the Api instance from. + * + * Example code: * * $client = new \Github\Client(); * $api = $client->api('someApi'); * $pager = new \Github\ResultPager($client); * * @param \Github\Client $client - * */ public function __construct(Client $client) { @@ -67,7 +72,7 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = array() // get the perPage from the api $perPage = $api->getPerPage(); - // Set parameters per_page to GitHub max to minimize number of requests + // set parameters per_page to GitHub max to minimize number of requests $api->setPerPage(100); $result = array(); diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 7604fd0ecea..1130e8ec409 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -5,21 +5,20 @@ use Github\Api\ApiInterface; /** - * Pager interface + * Pager interface. * * @author Ramon de la Fuente * @author Mitchel Verschoof */ interface ResultPagerInterface { - /** - * @return null|array pagination result of last request + * @return null|array pagination result of last request */ public function getPagination(); /** - * Fetch a single result (page) from an api call + * Fetch a single result (page) from an api call. * * @param ApiInterface $api the Api instance * @param string $method the method name to call on the Api instance @@ -30,8 +29,9 @@ public function getPagination(); public function fetch(ApiInterface $api, $method, array $parameters = array()); /** - * Fetch all results (pages) from an api call - * Use with care - there is no maximum + * Fetch all results (pages) from an api call. + * + * Use with care - there is no maximum. * * @param ApiInterface $api the Api instance * @param string $method the method name to call on the Api instance @@ -42,42 +42,48 @@ public function fetch(ApiInterface $api, $method, array $parameters = array()); public function fetchAll(ApiInterface $api, $method, array $parameters = array()); /** - * Method that performs the actual work to refresh the pagination property + * Method that performs the actual work to refresh the pagination property. */ public function postFetch(); /** - * Check to determine the availability of a next page + * Check to determine the availability of a next page. + * * @return bool */ public function hasNext(); /** - * Check to determine the availability of a previous page + * Check to determine the availability of a previous page. + * * @return bool */ public function hasPrevious(); /** - * Fetch the next page + * Fetch the next page. + * * @return array */ public function fetchNext(); /** - * Fetch the previous page + * Fetch the previous page. + * * @return array */ public function fetchPrevious(); /** - * Fetch the first page + * Fetch the first page. + * * @return array */ public function fetchFirst(); /** - * Fetch the last page + * Fetch the last page. + * * @return array */ public function fetchLast(); diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 902b53957b8..1549f3621c0 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -134,7 +134,7 @@ public function shouldGetWatchersApiObject() $this->assertInstanceOf('Github\Api\CurrentUser\Watchers', $api->watchers()); } - /** + /** * @test */ public function shouldGetStarredApiObject() diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 97e28962556..3bd34ef3fae 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -61,6 +61,7 @@ public function getTypes() /** * @param string $key + * * @return mixed */ protected function getStatsData($key = '') diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index df7f0e11c85..075226587f7 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -9,7 +9,7 @@ use Github\Tests\Mock\TestResponse; /** - * ResultPagerTest + * ResultPagerTest. * * @author Ramon de la Fuente * @author Mitchel Verschoof From 1f066866a032451655cccacd1f510e4071d57696 Mon Sep 17 00:00:00 2001 From: "Eric J. Duran" Date: Wed, 13 Aug 2014 02:15:59 -0400 Subject: [PATCH 235/951] Adding basic deployment api support --- lib/Github/Api/Deployment.php | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/Github/Api/Deployment.php diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php new file mode 100644 index 00000000000..6fbfff4041f --- /dev/null +++ b/lib/Github/Api/Deployment.php @@ -0,0 +1,53 @@ +get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', array(), + ['Accept' => 'application/vnd.github.cannonball-preview+json'] + ); + } + + + + /** + * Create a new deployment for the given username and repo. + * + * @param string $username the username + * @param string $repository the repository + * @param array $params the new deployment data + * @return array information about the deployment + * + * @throws MissingArgumentException + */ + public function create($username, $repository, array $params) + { + if (!isset($params['ref'])) { + throw new MissingArgumentException(array('ref')); + } + + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params, ['Accept' => 'application/vnd.github.cannonball-preview+json']); + } + + /** + * Update deployment information's by username, repo and deployment number. Requires authentication. + * + * @param string $username the username + * @param string $repository the repository + * @param string $id the deployment number + * @return array information about the deployment + */ + public function update($username, $repository, $id, array $params) + { + if (!isset($params['state'])) { + throw new MissingArgumentException(array('state')); + } + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params, ['Accept' => 'application/vnd.github.cannonball-preview+json']); + } +} From 8d48ea5a3ec056f7e6478dec59a372d9502866b5 Mon Sep 17 00:00:00 2001 From: "Eric J. Duran" Date: Wed, 13 Aug 2014 19:14:35 -0400 Subject: [PATCH 236/951] Update Client.php --- lib/Github/Client.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e63af775507..964481aad58 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -120,6 +120,11 @@ public function api($name) $api = new Api\CurrentUser($this); break; + case 'deployment': + case 'deployments': + $api = new Api\Deployment($this); + break; + case 'ent': case 'enterprise': $api = new Api\Enterprise($this); From 7c74ebe4a823e6b12ba2a28492f6f5316de6b4cc Mon Sep 17 00:00:00 2001 From: "Eric J. Duran" Date: Tue, 27 Jan 2015 17:44:05 -0500 Subject: [PATCH 237/951] updating to fix latest comment. --- lib/Github/Api/Deployment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 6fbfff4041f..51343a88585 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -10,7 +10,7 @@ class Deployment extends AbstractApi public function all($username, $repository, array $params = array()) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', array(), - ['Accept' => 'application/vnd.github.cannonball-preview+json'] + array('Accept' => 'application/vnd.github.cannonball-preview+json') ); } From 88c83378ba167074c052394ed8cbf021cdeab8aa Mon Sep 17 00:00:00 2001 From: lol768 Date: Fri, 20 Feb 2015 20:35:59 +0000 Subject: [PATCH 238/951] No need for a special header on deployment API requests --- lib/Github/Api/Deployment.php | 55 ++++++++++++++++++------ test/Github/Tests/Api/DeploymentTest.php | 26 +++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 test/Github/Tests/Api/DeploymentTest.php diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 51343a88585..f8f3dbac953 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -4,20 +4,33 @@ use Github\Exception\MissingArgumentException; +/** + * Listing, creating and updating deployments. + * + * @link https://developer.github.com/v3/repos/deployments/ + */ class Deployment extends AbstractApi { - + /** + * List deployments for a particular repository + * @link https://developer.github.com/v3/repos/deployments/#list-deployments + * + * @param string $username the username of the user who owns the repository + * @param string $repository the name of the repository + * @param array $params query parameters to filter deployments by (see link) + * @return array the deployments requested + */ public function all($username, $repository, array $params = array()) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', array(), - array('Accept' => 'application/vnd.github.cannonball-preview+json') - ); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } - - /** * Create a new deployment for the given username and repo. + * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment + * + * Important: Once a deployment is created, it cannot be updated. Changes are indicated by creating new statuses. + * @see updateStatus * * @param string $username the username * @param string $repository the repository @@ -32,22 +45,40 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('ref')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params, ['Accept' => 'application/vnd.github.cannonball-preview+json']); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } /** - * Update deployment information's by username, repo and deployment number. Requires authentication. + * Updates a deployment by creating a new status update. + * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status * - * @param string $username the username + * @param string $username the username * @param string $repository the repository - * @param string $id the deployment number + * @param string $id the deployment number + * @param array $params The information about the deployment update. + * Must include a "state" field of pending, success, error, or failure. + * May also be given a target_url and description, ßee link for more details. * @return array information about the deployment + * + * @throws MissingArgumentException */ - public function update($username, $repository, $id, array $params) + public function updateStatus($username, $repository, $id, array $params) { if (!isset($params['state'])) { throw new MissingArgumentException(array('state')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params, ['Accept' => 'application/vnd.github.cannonball-preview+json']); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); + } + + /** + * Gets all of the status updates tied to a given deployment. + * + * @param string $username the username + * @param string $repository the repository + * @param int $id the deployment identifier + * @return array the deployment statuses + */ + public function getStatuses($username, $repository, $id) { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses'); } } diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php new file mode 100644 index 00000000000..a9c15c3bb71 --- /dev/null +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -0,0 +1,26 @@ +getApiMock(); + $deploymentData = array("ref" => "fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9"); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/deployments', $deploymentData); + + $api->create("KnpLabs", "php-github-api", $deploymentData); + } + + protected function getApiClass() + { + return 'Github\Api\Deployment'; + } +} From 5d94a88f0b4233aa176948b22528df3ab42a2d38 Mon Sep 17 00:00:00 2001 From: lol768 Date: Fri, 20 Feb 2015 20:42:52 +0000 Subject: [PATCH 239/951] Add some more tests --- test/Github/Tests/Api/DeploymentTest.php | 71 +++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index a9c15c3bb71..8334f8fd3ea 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -9,16 +9,83 @@ class DeploymentTest extends TestCase */ public function shouldCreateDeployment() { - /** @var \Github\Api\Deployment $api */ $api = $this->getApiMock(); $deploymentData = array("ref" => "fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9"); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/deployments', $deploymentData); + ->with('repos/KnpLabs/php-github-api/deployments', $deploymentData); $api->create("KnpLabs", "php-github-api", $deploymentData); } + /** + * @test + */ + public function shouldGetAllDeployments() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/deployments'); + + $api->all("KnpLabs", "php-github-api"); + } + + /** + * @test + */ + public function shouldGetAllDeploymentsWithFilterParameters() + { + $api = $this->getApiMock(); + $filterData = ["foo" => "bar", "bar" => "foo"]; + + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/deployments', $filterData); + + $api->all("KnpLabs", "php-github-api", $filterData); + } + + /** + * @test + */ + public function shouldCreateStatusUpdate() + { + $api = $this->getApiMock(); + $statusData = ["state" => "pending", "description" => "waiting to start"]; + + $api->expects($this->once()) + ->method('post') + ->with('repos/KnpLabs/php-github-api/deployments/1/statuses', $statusData); + + $api->updateStatus("KnpLabs", "php-github-api", 1, $statusData); + } + + /** + * @test + * @expectedException GitHub\Exception\MissingArgumentException + */ + public function shouldRejectStatusUpdateWithoutStateField() + { + $api = $this->getApiMock(); + $statusData = [ "description" => "waiting to start"]; + + $api->updateStatus("KnpLabs", "php-github-api", 1, $statusData); + } + + /** + * @test + */ + public function shouldGetAllStatuses() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/deployments/1/statuses'); + + $api->getStatuses("KnpLabs", "php-github-api", 1); + } + protected function getApiClass() { return 'Github\Api\Deployment'; From 77fe71131b4c8a2d2edaf1520acf79339c160f98 Mon Sep 17 00:00:00 2001 From: lol768 Date: Fri, 20 Feb 2015 20:55:50 +0000 Subject: [PATCH 240/951] Add documentation for deployments API --- doc/README.md | 1 + doc/repo/deployments.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 doc/repo/deployments.md diff --git a/doc/README.md b/doc/README.md index 176e5a2b51d..5989a7d3edc 100644 --- a/doc/README.md +++ b/doc/README.md @@ -18,6 +18,7 @@ APIs: * [Contents](repo/contents.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) + * [Deployments](repo/deployments.md) * [Users](users.md) * [Meta](meta.md) * [Activity](activity.md) diff --git a/doc/repo/deployments.md b/doc/repo/deployments.md new file mode 100644 index 00000000000..386025d936f --- /dev/null +++ b/doc/repo/deployments.md @@ -0,0 +1,40 @@ +## Repo / Deployments API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) + +Provides information about deployments for a repository. Wraps [GitHub Deployments API](https://developer.github.com/v3/repos/deployments/). + +#### List all deployments. + +```php +$deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api'); +``` + +You can also filter the returned results (see [the documentation](https://developer.github.com/v3/repos/deployments/#list-deployments) for more information): + +```php +$deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api', array('environment' => 'production')); +``` + +#### Create a new deployments. + +The `ref` parameter is required. + +```php +$data = $client->api('deployment')->create('KnpLabs', 'php-github-api', array('ref' => 'fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9')); +``` + +Please note that once a deployment is created it cannot be edited. Only status updates can be created. + +#### Create a new status update. + +The `state` parameter is required. At the time of writing, this must be pending, success, error, or failure. + +```php +$data = $client->api('deployment')->updateStatus('KnpLabs', 'php-github-api', 1, array('state' => 'error', 'description' => 'syntax error')); +``` + +#### Get all status updates for a deployment. + +```php +$statusUpdates = $client->api('deployment')->getStatuses('KnpLabs', 'php-github-api', 1); +``` From 4e62664a506e9664c4fc25075cc9c5fdad7f4104 Mon Sep 17 00:00:00 2001 From: "Eric J. Duran" Date: Sat, 21 Feb 2015 17:31:43 -0500 Subject: [PATCH 241/951] Making DeploymentTest php 5.3 compatible --- test/Github/Tests/Api/DeploymentTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 8334f8fd3ea..cfc4712de18 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -37,7 +37,7 @@ public function shouldGetAllDeployments() public function shouldGetAllDeploymentsWithFilterParameters() { $api = $this->getApiMock(); - $filterData = ["foo" => "bar", "bar" => "foo"]; + $filterData = array("foo" => "bar", "bar" => "foo"); $api->expects($this->once()) ->method('get') @@ -52,7 +52,7 @@ public function shouldGetAllDeploymentsWithFilterParameters() public function shouldCreateStatusUpdate() { $api = $this->getApiMock(); - $statusData = ["state" => "pending", "description" => "waiting to start"]; + $statusData = array("state" => "pending", "description" => "waiting to start"); $api->expects($this->once()) ->method('post') @@ -68,7 +68,7 @@ public function shouldCreateStatusUpdate() public function shouldRejectStatusUpdateWithoutStateField() { $api = $this->getApiMock(); - $statusData = [ "description" => "waiting to start"]; + $statusData = array("description" => "waiting to start"); $api->updateStatus("KnpLabs", "php-github-api", 1, $statusData); } From ce1319b8a42c300c7fa4bf33884f1db264b721dd Mon Sep 17 00:00:00 2001 From: Tiago Brito Date: Fri, 20 Mar 2015 14:20:23 +0000 Subject: [PATCH 242/951] Update dead link Update dead link that point to github organizations documentation --- doc/organization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/organization.md b/doc/organization.md index 0bfdd299b98..3a1ee9434e7 100644 --- a/doc/organization.md +++ b/doc/organization.md @@ -1,7 +1,7 @@ ## Organization API [Back to the navigation](README.md) -Wraps [GitHub Organization API](http://developer.github.com/v3/organization/). +Wraps [GitHub Organization API](http://developer.github.com/v3/orgs/). Additional APIs: * [Members API](organization/members.md) From f0c217966b897f8f953bb8134433cde51ab3549d Mon Sep 17 00:00:00 2001 From: Tiago Brito Date: Fri, 20 Mar 2015 16:43:14 +0000 Subject: [PATCH 243/951] Add missing parentheses --- doc/pull_request/comments.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/pull_request/comments.md b/doc/pull_request/comments.md index baca6ce363e..87ca5f8e443 100644 --- a/doc/pull_request/comments.md +++ b/doc/pull_request/comments.md @@ -37,7 +37,7 @@ $comment = $client->api('pull_request')->comments()->create('KnpLabs', 'php-gith 'path' => 'README.markdown', 'position' => 37, 'line' => 31 -); +)); ``` This returns the details of the comment. @@ -50,7 +50,7 @@ This returns the details of the comment. $comment = $client->api('pull_request')->comments()->create('KnpLabs', 'php-github-api', 8, array( 'body' => 'Yeah! Really nice change', 'in_reply_to' => 2 -); +)); ``` This returns the details of the comment. @@ -62,7 +62,7 @@ This returns the details of the comment. ```php $comment = $client->api('pull_request')->comments()->update('KnpLabs', 'php-github-api', 2, array( 'body' => 'Hell Yeah! Awesome change!' -); +)); ``` This returns the details of the updated comment. From 72e2c08d816839b435072b197bc64e0e3ecd38ef Mon Sep 17 00:00:00 2001 From: Ignasi Fosch Date: Mon, 23 Mar 2015 16:14:58 +0100 Subject: [PATCH 244/951] Fixes GitHub Runtime Exception when message is null Current Github API complains when the commit_message is null. --- lib/Github/Api/PullRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 1af5778284c..14db3bc7a60 100755 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -115,7 +115,7 @@ public function merged($username, $repository, $id) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); } - public function merge($username, $repository, $id, $message = null) + public function merge($username, $repository, $id, $message = '') { return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', array( 'commit_message' => $message From 25bdb5c1878a59de7e62a81f7ba86711f1af4e54 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Wed, 25 Mar 2015 21:17:51 -0400 Subject: [PATCH 245/951] Added support for gist comments --- lib/Github/Api/Gist/Comments.php | 44 +++++++++ lib/Github/Api/Gists.php | 15 +++- test/Github/Tests/Api/Gist/CommentsTest.php | 98 +++++++++++++++++++++ test/Github/Tests/Api/GistsTest.php | 10 +++ 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 lib/Github/Api/Gist/Comments.php create mode 100644 test/Github/Tests/Api/Gist/CommentsTest.php diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php new file mode 100644 index 00000000000..3e10caddf40 --- /dev/null +++ b/lib/Github/Api/Gist/Comments.php @@ -0,0 +1,44 @@ + + * @author Edoardo Rivello + */ +class Comments extends AbstractApi +{ + // GET /gists/:gist_id/comments + public function all($gist) + { + return $this->get('gists/'.rawurlencode($gist)."/comments"); + } + + //GET /gists/:gist_id/comments/:id + public function show($gist, $comment) + { + return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + } + + //POST /gists/:gist_id/comments + public function create($gist, $body) + { + return $this->post('gists/'.rawurlencode($gist)."/comments", array($body)); + } + + //PATCH /gists/:gist_id/comments/:id + public function update($gist, $comment_id, $body) + { + return $this->patch('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment_id), array($body)); + } + + //DELETE /gists/:gist_id/comments/:id + public function remove($gist, $comment) + { + return $this->delete('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment)); + } +} diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 12fe9ec5d00..442774fac83 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -2,8 +2,8 @@ namespace Github\Api; -use Github\Api\AbstractApi; use Github\Exception\MissingArgumentException; +use Github\Api\Gist\Comments; /** * Creating, editing, deleting and listing gists. @@ -73,4 +73,17 @@ public function unstar($id) { return $this->delete('gists/'.rawurlencode($id).'/star'); } + + /** + * List an gists comments. + * + * @link http://developer.github.com/v3/gists/comments/ + * + * @return Comments + */ + public function comments() + { + return new Comments($this->client); + } + } diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php new file mode 100644 index 00000000000..0055f6f95f1 --- /dev/null +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -0,0 +1,98 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/comments') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('123')); + } + + /** + * @test + */ + public function shouldShowGistComment() + { + $expectedValue = array('comment1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('gists/123/comments/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show(123, 123)); + } + + + /** + * @test + */ + public function shouldCreateGistComment() + { + $expectedValue = array('comment1data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('gists/123/comments', array("Test body")) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('123', "Test body")); + } + + + /** + * @test + */ + public function shouldUpdateGistComment() + { + $expectedValue = array('comment1data'); + $data = array('body test'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('gists/123/comments/233', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(123, 233, 'body test')); + } + + /** + * @test + */ + public function shouldRemoveComment() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('gists/123/comments/233') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(123, 233)); + } + + protected function getApiClass() + { + return 'Github\Api\Gist\Comments'; + } +} diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 8a01dca3ddd..aa53b0f6176 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -68,6 +68,16 @@ public function shouldShowCommits() $this->assertEquals($expectedArray, $api->commits(123)); } + /** + * @test + */ + public function shouldGetCommentsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Gist\Comments', $api->comments()); + } + /** * @test */ From 5efad64be360d97f701129b8a583cfe90fd10340 Mon Sep 17 00:00:00 2001 From: lol768 Date: Fri, 27 Mar 2015 23:30:50 +0000 Subject: [PATCH 246/951] Use single quotes for strings --- test/Github/Tests/Api/DeploymentTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index cfc4712de18..2bcbb4d5d25 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -10,12 +10,12 @@ class DeploymentTest extends TestCase public function shouldCreateDeployment() { $api = $this->getApiMock(); - $deploymentData = array("ref" => "fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9"); + $deploymentData = array('ref' => 'fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9'); $api->expects($this->once()) ->method('post') ->with('repos/KnpLabs/php-github-api/deployments', $deploymentData); - $api->create("KnpLabs", "php-github-api", $deploymentData); + $api->create('KnpLabs', 'php-github-api', $deploymentData); } /** @@ -28,7 +28,7 @@ public function shouldGetAllDeployments() ->method('get') ->with('repos/KnpLabs/php-github-api/deployments'); - $api->all("KnpLabs", "php-github-api"); + $api->all('KnpLabs', 'php-github-api'); } /** @@ -37,13 +37,13 @@ public function shouldGetAllDeployments() public function shouldGetAllDeploymentsWithFilterParameters() { $api = $this->getApiMock(); - $filterData = array("foo" => "bar", "bar" => "foo"); + $filterData = array('foo' => 'bar', 'bar' => 'foo'); $api->expects($this->once()) ->method('get') ->with('repos/KnpLabs/php-github-api/deployments', $filterData); - $api->all("KnpLabs", "php-github-api", $filterData); + $api->all('KnpLabs', 'php-github-api', $filterData); } /** @@ -52,13 +52,13 @@ public function shouldGetAllDeploymentsWithFilterParameters() public function shouldCreateStatusUpdate() { $api = $this->getApiMock(); - $statusData = array("state" => "pending", "description" => "waiting to start"); + $statusData = array('state' => 'pending', 'description' => 'waiting to start'); $api->expects($this->once()) ->method('post') ->with('repos/KnpLabs/php-github-api/deployments/1/statuses', $statusData); - $api->updateStatus("KnpLabs", "php-github-api", 1, $statusData); + $api->updateStatus('KnpLabs', 'php-github-api', 1, $statusData); } /** @@ -68,9 +68,9 @@ public function shouldCreateStatusUpdate() public function shouldRejectStatusUpdateWithoutStateField() { $api = $this->getApiMock(); - $statusData = array("description" => "waiting to start"); + $statusData = array('description' => 'waiting to start'); - $api->updateStatus("KnpLabs", "php-github-api", 1, $statusData); + $api->updateStatus('KnpLabs', 'php-github-api', 1, $statusData); } /** @@ -83,7 +83,7 @@ public function shouldGetAllStatuses() ->method('get') ->with('repos/KnpLabs/php-github-api/deployments/1/statuses'); - $api->getStatuses("KnpLabs", "php-github-api", 1); + $api->getStatuses('KnpLabs', 'php-github-api', 1); } protected function getApiClass() From 6bbe4d819b58aeb9e247745e47f4e483837fdc18 Mon Sep 17 00:00:00 2001 From: Kayla Daniels Date: Wed, 25 Mar 2015 21:17:51 -0400 Subject: [PATCH 247/951] Added support for gist comments --- lib/Github/Api/Gist/Comments.php | 17 +++++------------ lib/Github/Api/Gists.php | 3 +-- test/Github/Tests/Api/Gist/CommentsTest.php | 10 +++------- test/Github/Tests/Api/GistsTest.php | 2 +- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 3e10caddf40..2d889650015 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -5,40 +5,33 @@ use Github\Api\AbstractApi; /** - * * @link https://developer.github.com/v3/gists/comments/ * @author Kayla Daniels - * @author Edoardo Rivello */ class Comments extends AbstractApi { - // GET /gists/:gist_id/comments public function all($gist) { - return $this->get('gists/'.rawurlencode($gist)."/comments"); + return $this->get('gists/'.rawurlencode($gist).'/comments'); } - //GET /gists/:gist_id/comments/:id public function show($gist, $comment) { return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } - //POST /gists/:gist_id/comments public function create($gist, $body) { - return $this->post('gists/'.rawurlencode($gist)."/comments", array($body)); + return $this->post('gists/'.rawurlencode($gist).'/comments', array($body)); } - //PATCH /gists/:gist_id/comments/:id public function update($gist, $comment_id, $body) { - return $this->patch('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment_id), array($body)); + return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array($body)); } - //DELETE /gists/:gist_id/comments/:id public function remove($gist, $comment) { - return $this->delete('gists/'.rawurlencode($gist)."/comments/".rawurlencode($comment)); + return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } -} +} \ No newline at end of file diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 442774fac83..eb24f0b3fdf 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -75,7 +75,7 @@ public function unstar($id) } /** - * List an gists comments. + * Get a gist's comments. * * @link http://developer.github.com/v3/gists/comments/ * @@ -85,5 +85,4 @@ public function comments() { return new Comments($this->client); } - } diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index 0055f6f95f1..77f3ca50faa 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -9,8 +9,6 @@ class CommentsTest extends TestCase /** * @test */ - -// GET /gists/:gist_id/comments public function shouldGetAllGistComments() { $expectedValue = array(array('comment1data'), array('comment2data')); @@ -40,7 +38,6 @@ public function shouldShowGistComment() $this->assertEquals($expectedValue, $api->show(123, 123)); } - /** * @test */ @@ -51,13 +48,12 @@ public function shouldCreateGistComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('gists/123/comments', array("Test body")) + ->with('gists/123/comments', array('Test body')) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('123', "Test body")); + $this->assertEquals($expectedValue, $api->create('123', 'Test body')); } - /** * @test */ @@ -95,4 +91,4 @@ protected function getApiClass() { return 'Github\Api\Gist\Comments'; } -} +} \ No newline at end of file diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index aa53b0f6176..4d2cdf7f346 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -226,4 +226,4 @@ protected function getApiClass() { return 'Github\Api\Gists'; } -} +} \ No newline at end of file From 52c88ca3d1ac071a34908e1d56c0381556d14473 Mon Sep 17 00:00:00 2001 From: Daniel Lienert Date: Sun, 29 Mar 2015 13:43:34 +0200 Subject: [PATCH 248/951] [FIX] Add missing closing bracket in pullRequest example code --- doc/pull_requests.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index 2b952b35b1f..6c9b3f746d2 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -67,6 +67,7 @@ $pullRequest = $client->api('pull_request')->create('ezsystems', 'ezpublish', ar 'head' => 'testbranch', 'title' => 'My nifty pull request', 'body' => 'This pull request contains a bunch of enhancements and bug-fixes, happily shared with you' + ) ); ``` From a0d3b846ed7c288b0b3a69b111fe5382ea1c3645 Mon Sep 17 00:00:00 2001 From: Daniel Lienert Date: Mon, 30 Mar 2015 08:47:13 +0200 Subject: [PATCH 249/951] Update pull_requests.md --- doc/pull_requests.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index 6c9b3f746d2..f92bf7657f5 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -67,8 +67,7 @@ $pullRequest = $client->api('pull_request')->create('ezsystems', 'ezpublish', ar 'head' => 'testbranch', 'title' => 'My nifty pull request', 'body' => 'This pull request contains a bunch of enhancements and bug-fixes, happily shared with you' - ) -); + )); ``` This returns the details of the pull request. From c0e29472d0c3e4608d323a114ebc82b545e6a999 Mon Sep 17 00:00:00 2001 From: Daniel Lienert Date: Mon, 30 Mar 2015 10:05:33 +0200 Subject: [PATCH 250/951] Update pull_requests.md --- doc/pull_requests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index f92bf7657f5..711fcc91e6b 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -83,7 +83,7 @@ $pullRequest = $client->api('pull_request')->create('ezsystems', 'ezpublish', ar 'base' => 'master', 'head' => 'testbranch', 'issue' => 15 -); +)); ``` This returns the details of the pull request. From 7e2a63013b526708604a54a7534b12e50a262a52 Mon Sep 17 00:00:00 2001 From: Daniel Lienert Date: Mon, 30 Mar 2015 10:06:55 +0200 Subject: [PATCH 251/951] Update pull_requests.md --- doc/pull_requests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index 711fcc91e6b..ec181c67bc2 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -67,7 +67,7 @@ $pullRequest = $client->api('pull_request')->create('ezsystems', 'ezpublish', ar 'head' => 'testbranch', 'title' => 'My nifty pull request', 'body' => 'This pull request contains a bunch of enhancements and bug-fixes, happily shared with you' - )); +)); ``` This returns the details of the pull request. From 5e610d0f38bd16f9891ff7fc0da97bd283479a62 Mon Sep 17 00:00:00 2001 From: James Solomon Date: Tue, 7 Apr 2015 01:21:02 -0400 Subject: [PATCH 252/951] Fixing the search endpoint * By removing the leading "/", the base path can now be appended. * The path being used was /search and not /api/v3/search --- lib/Github/Api/Search.php | 8 ++++---- test/Github/Tests/Api/SearchTest.php | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index e3c69e5f21e..bd9f79110a3 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -30,7 +30,7 @@ class Search extends AbstractApi */ public function repositories($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -46,7 +46,7 @@ public function repositories($q, $sort = 'updated', $order = 'desc') */ public function issues($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -62,7 +62,7 @@ public function issues($q, $sort = 'updated', $order = 'desc') */ public function code($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -78,6 +78,6 @@ public function code($q, $sort = 'updated', $order = 'desc') */ public function users($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); } } diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index d5fe9b08494..d5c41f2e0ed 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -16,7 +16,7 @@ public function shouldSearchRepositoriesByQuery() $api->expects($this->once()) ->method('get') ->with( - '/search/repositories', + 'search/repositories', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -36,7 +36,7 @@ public function shouldSearchRepositoriesRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - '/search/repositories', + 'search/repositories', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); @@ -59,7 +59,7 @@ public function shouldSearchIssuesByQuery() $api->expects($this->once()) ->method('get') ->with( - '/search/issues', + 'search/issues', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -79,7 +79,7 @@ public function shouldSearchIssuesRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - '/search/issues', + 'search/issues', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); @@ -102,7 +102,7 @@ public function shouldSearchCodeByQuery() $api->expects($this->once()) ->method('get') ->with( - '/search/code', + 'search/code', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -122,7 +122,7 @@ public function shouldSearchCodeRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - '/search/code', + 'search/code', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); @@ -145,7 +145,7 @@ public function shouldSearchUsersByQuery() $api->expects($this->once()) ->method('get') ->with( - '/search/users', + 'search/users', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -165,7 +165,7 @@ public function shouldSearchUsersRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - '/search/users', + 'search/users', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); From 6e000c2b26131e120b888e3404076d60fa1a3485 Mon Sep 17 00:00:00 2001 From: jrean Date: Sat, 25 Apr 2015 16:27:11 +0800 Subject: [PATCH 253/951] Add the missing return statement Simply return the 'X-RateLimit-Remaining' as expected. --- lib/Github/HttpClient/Message/ResponseMediator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 72fe7c7129e..a8491898ad9 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -46,5 +46,7 @@ public static function getApiLimit(Response $response) if (null !== $remainingCalls && 1 > $remainingCalls) { throw new ApiLimitExceedException($remainingCalls); } + + return $remainingCalls; } } From 2bcaeb926ef5b660cdf2982bf0408c248908e76f Mon Sep 17 00:00:00 2001 From: jrean Date: Thu, 30 Apr 2015 17:48:24 +0800 Subject: [PATCH 254/951] Update CachedHttpClient.php I used your implementation of the filesystem cache. - Delete all files under the cache directory `github-api-cache`. - Set properly your authentication method (I used token). - Run the following code once after a proper Client instantiation with cache: ``` $commits_article_1 = ResponseMediator::getContent($client->getHttpClient()->get("repos/jrean/askjong.com/commits?sha=master&path=articles/hello-world.md")); $rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit")); var_dump($rateLimit); $commits_article_2 = ResponseMediator::getContent($client->getHttpClient()->get("repos/jrean/askjong.com/commits?sha=master&path=articles/this-is-a-first-article.md")); $rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit")); var_dump($rateLimit); ``` 4 requests against Github Api: - 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 200) - 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 200) - 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200) Once this code has run the cache directory `github-api-cache` will have 6 files (3 for each queries including the `rate_limit` query + 3 `.etag` files) **The `rate_limit` should / must decrease by 2** (a call to `rate_limit` doesn't count against Github). -- - Run the same code again. 4 requests against Github Api: - 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 304, cache is used) - 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 304, cache is user) - 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200) **The `rate_limit` don't move** (a call to `rate_limit` doesn't count against Github). -- - Run the following code which use your wrapping methods against Github Api (Notice we are requesting the same informations): **It should use the cache but it will not.** (I explain why just after). ``` $commits_article_1 = $client->api('repo')->commits()->all('jrean', 'askjong.com', array('sha' => 'master', 'path' => 'articles/hello-world.md')); $rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit")); var_dump($rateLimit); $commits_article_2 = $client->api('repo')->commits()->all('jrean', 'askjong.com', array('sha' => 'master', 'path' => 'articles/this-is-a-first-article.md')); $rateLimit = ResponseMediator::getContent($client->getHttpClient()->get("rate_limit")); var_dump($rateLimit); ``` 4 requests against Github Api: - 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 200) - 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 200) - 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200) Once this code has run the cache directory `github-api-cache` will have new files... **The `rate_limit` decreases by 2** (a call to `rate_limit` doesn't count against Github). It should not decrease because we should use the cache! -- - Run the same code again. 4 requests against Github Api: - 1 query to fetch the commits for the `articles/hello-world.md` file. (`Guzzle\Http\Message\Response` status code is 200) - 1 query to fetch the commits for the `articles/this-is-a-first-article.md` file. (`Guzzle\Http\Message\Response` status code is 200) - 2 queries to fetch the rate_limit (doesn't count again the rate limit). (`Guzzle\Http\Message\Response` status code is 200) **The `rate_limit` decreases by 2 again** (a call to `rate_limit` doesn't count against Github). It should not decrease because we should use the cache! - Run the same code again and it will still decrease your `rate_limit`... -- # Solution This issue comes from the use of `$path`: `protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array())` Then here: `if ($modifiedAt = $this->getCache()->getModifiedSince($path)) {` And: `if ($etag = $this->getCache()->getETag($path)) {` `$path` doesn't take care of the `$options` array which contains the sub array for the `query` parameters! So each time `getModifiedSince($path)` and `getETag($path)` will work with an incomplete path because it doesn't know query parameters (if they exists). In that exemple `$path` value will always be `repos/jrean/askjong.com/commits` and it should be `repos/jrean/askjong.com/commits?sha=master&path=articles/hello-world.md`. See my code modifications to fix the problem. (I didn't use `$request->getQuery()` because it returns query parameters but encoded and it is not acceptable because when we want to construct our own queries like `repos/jrean/askjong.com/commits?sha=master&path=articles/hello-world.md` we won't encode parameters) By applying this patch we can now use the cache as it should be :) I started this issue a few days ago. https://github.com/KnpLabs/php-github-api/issues/262 --- lib/Github/HttpClient/CachedHttpClient.php | 44 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index f0e1368e6f3..ef5d80b9708 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -26,6 +26,13 @@ class CachedHttpClient extends HttpClient */ private $lastCachedResponse; + /** + * $path + query parameter(s) if they exist. + * + * @var string + */ + private $path; + /** * @return CacheInterface */ @@ -51,16 +58,18 @@ public function setCache(CacheInterface $cache) */ public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { + $this->formatPath($path, $options); + $response = parent::request($path, $body, $httpMethod, $headers, $options); if (304 == $response->getStatusCode()) { - $cacheResponse = $this->getCache()->get($path); + $cacheResponse = $this->getCache()->get($this->path); $this->lastCachedResponse = $cacheResponse; return $cacheResponse; } - $this->getCache()->set($path, $response); + $this->getCache()->set($this->path, $response); return $response; } @@ -74,7 +83,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header { $request = parent::createRequest($httpMethod, $path, $body, $headers, $options); - if ($modifiedAt = $this->getCache()->getModifiedSince($path)) { + if ($modifiedAt = $this->getCache()->getModifiedSince($this->path)) { $modifiedAt = new \DateTime('@'.$modifiedAt); $modifiedAt->setTimezone(new \DateTimeZone('GMT')); @@ -83,7 +92,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) ); } - if ($etag = $this->getCache()->getETag($path)) { + if ($etag = $this->getCache()->getETag($this->path)) { $request->addHeader( 'If-None-Match', $etag @@ -105,4 +114,31 @@ public function getLastResponse($force = false) return ($force) ? $lastResponse : $this->lastCachedResponse; } + + /** + * Format the path and add query parameters if they exist. + * + * @param string $path + * @param array $options + * @return void + */ + private function formatPath($path, array $options) + { + $this->path = $path; + + if (array_key_exists('query', $options) && !empty($options['query'])) { + $this->path .= '?'; + + $i = 0; + foreach ($options['query'] as $key => $value) { + if ($i > 0) { + $this->path .= '&'; + } + + $this->path .= $key . '=' . $value; + + $i++; + } + } + } } From ba9983d8c9af8f3b006fd8143f7df6eb72d79172 Mon Sep 17 00:00:00 2001 From: Greg Szczotka Date: Thu, 30 Apr 2015 16:15:48 +0200 Subject: [PATCH 255/951] fixes mistake in languages section --- doc/repos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index 5949dc05aaf..0da8b9bd61b 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -212,7 +212,7 @@ Returns list of the forks of the 'php-github-api' owned by 'ornicar', including ### Get the languages for a repository ```php -$contributors = $client->api('repo')->languages('ornicar', 'php-github-api'); +$languages = $client->api('repo')->languages('ornicar', 'php-github-api'); ``` Returns a list of languages. From ec371af5694d1ee80a28c5f1365d28e535008a50 Mon Sep 17 00:00:00 2001 From: jrean Date: Fri, 1 May 2015 20:53:03 +0800 Subject: [PATCH 256/951] Update CachedHttpClient.php Some cleaning according the chat with @stof + format the identifier (`$id`) with encoded query parameters. --- lib/Github/HttpClient/CachedHttpClient.php | 48 ++++++---------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index ef5d80b9708..c753fe4ab07 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -27,11 +27,12 @@ class CachedHttpClient extends HttpClient private $lastCachedResponse; /** - * $path + query parameter(s) if they exist. + * Identifier used for the cache file(s). + * $path + encoded query parameter(s) if they exist. * * @var string */ - private $path; + private $id; /** * @return CacheInterface @@ -58,18 +59,16 @@ public function setCache(CacheInterface $cache) */ public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { - $this->formatPath($path, $options); - $response = parent::request($path, $body, $httpMethod, $headers, $options); if (304 == $response->getStatusCode()) { - $cacheResponse = $this->getCache()->get($this->path); + $cacheResponse = $this->getCache()->get($this->id); $this->lastCachedResponse = $cacheResponse; return $cacheResponse; } - $this->getCache()->set($this->path, $response); + $this->getCache()->set($this->id, $response); return $response; } @@ -82,8 +81,14 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) { $request = parent::createRequest($httpMethod, $path, $body, $headers, $options); + + $this->id = $path; + + if (array_key_exists('query', $options) && !empty($options['query'])) { + $this->id .= '?' . $request->getQuery(); + } - if ($modifiedAt = $this->getCache()->getModifiedSince($this->path)) { + if ($modifiedAt = $this->getCache()->getModifiedSince($this->id)) { $modifiedAt = new \DateTime('@'.$modifiedAt); $modifiedAt->setTimezone(new \DateTimeZone('GMT')); @@ -92,7 +97,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) ); } - if ($etag = $this->getCache()->getETag($this->path)) { + if ($etag = $this->getCache()->getETag($this->id)) { $request->addHeader( 'If-None-Match', $etag @@ -114,31 +119,4 @@ public function getLastResponse($force = false) return ($force) ? $lastResponse : $this->lastCachedResponse; } - - /** - * Format the path and add query parameters if they exist. - * - * @param string $path - * @param array $options - * @return void - */ - private function formatPath($path, array $options) - { - $this->path = $path; - - if (array_key_exists('query', $options) && !empty($options['query'])) { - $this->path .= '?'; - - $i = 0; - foreach ($options['query'] as $key => $value) { - if ($i > 0) { - $this->path .= '&'; - } - - $this->path .= $key . '=' . $value; - - $i++; - } - } - } } From 90bbfee0516775f930abf54049df49384744c397 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 7 May 2015 12:45:08 +0700 Subject: [PATCH 257/951] Update composer version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa9c6e6a4a0..fff12e642d2 100755 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Now we can use autoloader from Composer by: ```json { "require": { - "knplabs/github-api": "~1.2" + "knplabs/github-api": "~1.4" } } ``` From ed0272f6b1bd8402cbc6da1f39277c5a4264817c Mon Sep 17 00:00:00 2001 From: usdjared Date: Tue, 12 May 2015 15:23:30 +0100 Subject: [PATCH 258/951] Missing word in user doc The word 'user' had been missed off a heading. --- doc/users.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/users.md b/doc/users.md index 5e76343d54e..4aa3d864673 100644 --- a/doc/users.md +++ b/doc/users.md @@ -95,7 +95,7 @@ $client->api('current_user')->follow()->follow('symfony'); Returns an array of followed users. -### Unfollow a +### Unfollow a user > Requires [authentication](security.md). From d890eececc561522aedbe8b0ad87adb7ac859dfa Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 18 May 2015 16:07:24 +0800 Subject: [PATCH 259/951] Add gist comments docs --- doc/README.md | 1 + doc/gists.md | 6 ++++- doc/gists/comments.md | 51 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 doc/gists/comments.md diff --git a/doc/README.md b/doc/README.md index 5989a7d3edc..890ac85e7f2 100644 --- a/doc/README.md +++ b/doc/README.md @@ -6,6 +6,7 @@ APIs: * [Commits](commits.md) * [Enterprise](enterprise.md) * [Gists](gists.md) + * [Comments](gists/comments.md) * [Issues](issues.md) * [Comments](issue/comments.md) * [Labels](issue/labels.md) diff --git a/doc/gists.md b/doc/gists.md index 168ca3629c3..c106005927b 100644 --- a/doc/gists.md +++ b/doc/gists.md @@ -1,7 +1,11 @@ ## Gists API [Back to the navigation](README.md) -Creating, editing, deleting and listing gists. Wraps [GitHub Gists API](http://developer.github.com/v3/gists/). +Creating, editing, deleting and listing gists. +Wraps [GitHub Gists API](http://developer.github.com/v3/gists/). + +Additional APIs: +* [Comments](gists/comments.md) #### List all public gists. diff --git a/doc/gists/comments.md b/doc/gists/comments.md new file mode 100644 index 00000000000..2df9966537a --- /dev/null +++ b/doc/gists/comments.md @@ -0,0 +1,51 @@ +## Gists / Comments API + +[Back to the "Gists API"](../gists.md) | [Back to the navigation](../README.md) + +Wraps [GitHub Issue Comments API](http://developer.github.com/v3/gists/comments/). + +### List a gist comments + +```php +// for gist https://gist.github.com/danvbe/4476697 +$comments = $client->api('gist')->comments()->all('4476697'); +``` + +* `4476697` : the id of the gist + +### Show a gist comment + +```php +$comment = $client->api('gist')->comments()->show('4476697', '779656'); +``` + +* `4476697` : the id of the gist +* `779656` : the id of the comment + +### Create a gist comment + +```php +$client->api('gist')->comments()->create('4476697', 'Hello World'); +``` + +* `4476697` : the id of the gist +* `Hello World` : the body of the comment + +### Update a gist comment + +```php +$client->api('gist')->comments()->create('4476697', '123456', 'Hello Dolly'); +``` + +* `4476697` : the id of the gist +* `123456` : the id of the comment +* `Hello Dolly` : the body of the updated comment + +### Remove a gist comment + +```php +$client->api('gist')->comments()->remove('4476697', '123456'); +``` + +* `4476697` : the id of the gist +* `123456` : the id of the comment From 818d8a4bdfc06ae2b5ec56d4da6537a8c2fcc900 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 18 May 2015 16:54:16 +0800 Subject: [PATCH 260/951] Add search api functional test --- .../Tests/Functional/ResultPagerTest.php | 23 ++++++++++++++++++- test/Github/Tests/ResultPagerTest.php | 2 -- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/test/Github/Tests/Functional/ResultPagerTest.php b/test/Github/Tests/Functional/ResultPagerTest.php index 9c67b39d25a..67b23eeb70f 100644 --- a/test/Github/Tests/Functional/ResultPagerTest.php +++ b/test/Github/Tests/Functional/ResultPagerTest.php @@ -17,7 +17,7 @@ public function shouldPaginateGetRequests() $repositoriesApi = $this->client->api('user'); $repositoriesApi->setPerPage(10); - $pager = new ResultPager($this->client); + $pager = $this->createPager(); $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); $this->assertCount(10, $repositories); @@ -26,4 +26,25 @@ public function shouldPaginateGetRequests() $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); $this->assertCount(20, $repositories); } + + /** + * @test + * + * results in a search api has different format, see docs + */ + public function shouldGetAllResultsFromSearchApi() + { + $searchApi = $this->client->search(); + $searchApi->setPerPage(10); + + $pager = $this->createPager(); + + $users = $pager->fetch($searchApi, 'users', array('location:Kyiv')); + $this->assertCount(10, $users); + } + + private function createPager() + { + return new ResultPager($this->client); + } } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 075226587f7..95c349d688b 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -3,8 +3,6 @@ namespace Github\Tests; use Github; -use Github\Client; -use Github\ResultPager; use Github\HttpClient\HttpClientInterface; use Github\Tests\Mock\TestResponse; From 0e0c8e0ce9cd1a6135b73b5d1d9a2b8c5903e1d6 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 21 May 2015 15:24:07 +0800 Subject: [PATCH 261/951] Support Search Api response in pager --- lib/Github/ResultPager.php | 15 ++++++- .../Tests/Functional/ResultPagerTest.php | 10 ++++- test/Github/Tests/ResultPagerTest.php | 44 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 01c689a58d9..21bc08ec3f4 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -3,6 +3,7 @@ namespace Github; use Github\Api\ApiInterface; +use Github\Api\Search; use Github\HttpClient\Message\ResponseMediator; /** @@ -69,6 +70,8 @@ public function fetch(ApiInterface $api, $method, array $parameters = array()) */ public function fetchAll(ApiInterface $api, $method, array $parameters = array()) { + $isSearch = $api instanceof Search; + // get the perPage from the api $perPage = $api->getPerPage(); @@ -79,8 +82,18 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = array() $result = call_user_func_array(array($api, $method), $parameters); $this->postFetch(); + if ($isSearch) { + $result = isset($result['items']) ? $result['items'] : $result; + } + while ($this->hasNext()) { - $result = array_merge($result, $this->fetchNext()); + $next = $this->fetchNext(); + + if ($isSearch) { + $result = array_merge($result, $next['items']); + } else { + $result = array_merge($result, $next); + } } // restore the perPage diff --git a/test/Github/Tests/Functional/ResultPagerTest.php b/test/Github/Tests/Functional/ResultPagerTest.php index 67b23eeb70f..9978a75ad82 100644 --- a/test/Github/Tests/Functional/ResultPagerTest.php +++ b/test/Github/Tests/Functional/ResultPagerTest.php @@ -30,7 +30,15 @@ public function shouldPaginateGetRequests() /** * @test * - * results in a search api has different format, see docs + * results in a search api has different format: + * + * { + * "total_count": 1, + * "incomplete_results": false, + * "items": [] + * } + * + * and we need to extract result from `items` */ public function shouldGetAllResultsFromSearchApi() { diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 95c349d688b..f512caf3848 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -51,6 +51,50 @@ public function shouldGetAllResults() $this->assertEquals($amountLoops * count($content), count($result)); } + /** + * @test + * + * results in a search api has different format: + * + * { + * "total_count": 1, + * "incomplete_results": false, + * "items": [] + * } + * + * and we need to extract result from `items` + */ + public function shouldGetAllSearchResults() + { + $amountLoops = 3; + + $content = array( + 'total_count' => 12, + 'items' => array(1, 2, 3, 4) + ); + $responseMock = new TestResponse($amountLoops, $content); + + $httpClientMock = $this->getHttpClientMock($responseMock); + $httpClientMock + ->expects($this->exactly($amountLoops)) + ->method('get') + ->will($this->returnValue($responseMock)); + + $clientMock = $this->getClientMock($httpClientMock); + + $searchApiMock = $this->getApiMock('Github\Api\Search'); + $searchApiMock + ->expects($this->once()) + ->method('users') + ->will($this->returnValue(array())); + + $method = 'users'; + $paginator = new Github\ResultPager($clientMock); + $result = $paginator->fetchAll($searchApiMock, $method); + + $this->assertEquals($amountLoops * count($content['items']), count($result)); + } + /** * @test * From c89ebe4726ce7b4b9ddeac7bf124a96425b28a7f Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 21 May 2015 15:33:59 +0800 Subject: [PATCH 262/951] Missing argument in test --- test/Github/Tests/ResultPagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index f512caf3848..a678cbdeb4b 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -90,7 +90,7 @@ public function shouldGetAllSearchResults() $method = 'users'; $paginator = new Github\ResultPager($clientMock); - $result = $paginator->fetchAll($searchApiMock, $method); + $result = $paginator->fetchAll($searchApiMock, $method, ['knplabs']); $this->assertEquals($amountLoops * count($content['items']), count($result)); } From 2ea276ad49beb638d76eb5099daf2577caf17f69 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 21 May 2015 15:40:02 +0800 Subject: [PATCH 263/951] Old array --- test/Github/Tests/ResultPagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index a678cbdeb4b..3dee96edaa1 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -90,7 +90,7 @@ public function shouldGetAllSearchResults() $method = 'users'; $paginator = new Github\ResultPager($clientMock); - $result = $paginator->fetchAll($searchApiMock, $method, ['knplabs']); + $result = $paginator->fetchAll($searchApiMock, $method, array('knplabs')); $this->assertEquals($amountLoops * count($content['items']), count($result)); } From d892d6299b5e53d8e28ce1037081cac2e8c674b1 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 21 May 2015 16:07:59 +0800 Subject: [PATCH 264/951] Update ResultPagerTest.php --- test/Github/Tests/Functional/ResultPagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Functional/ResultPagerTest.php b/test/Github/Tests/Functional/ResultPagerTest.php index 9978a75ad82..9c4abc7b699 100644 --- a/test/Github/Tests/Functional/ResultPagerTest.php +++ b/test/Github/Tests/Functional/ResultPagerTest.php @@ -30,7 +30,7 @@ public function shouldPaginateGetRequests() /** * @test * - * results in a search api has different format: + * response in a search api has different format: * * { * "total_count": 1, From 892a25f7a850596ddfe9b48e6544d97f62a28a4b Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 21 May 2015 16:08:17 +0800 Subject: [PATCH 265/951] Update ResultPagerTest.php --- test/Github/Tests/ResultPagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 3dee96edaa1..494731523db 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -54,7 +54,7 @@ public function shouldGetAllResults() /** * @test * - * results in a search api has different format: + * response in a search api has different format: * * { * "total_count": 1, From 8371af8f8d3a0097dd7f831c66abd372e4a0463e Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 21 May 2015 10:52:51 +0200 Subject: [PATCH 266/951] Fix the documentation for the PR API --- doc/pull_requests.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index ec181c67bc2..ee15fb642c5 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -15,10 +15,10 @@ Wraps [GitHub Pull Request API](http://developer.github.com/v3/pulls/). ```php api('pull_request')->all('ezsystems', 'ezpublish', 'open'); +$openPullRequests = $client->api('pull_request')->all('ezsystems', 'ezpublish', array('state' => 'open')); ``` -The last parameter of the listPullRequests method default to 'open'. The call above is equivalent to: +The state parameter of the listPullRequests method default to 'open'. The call above is equivalent to: ```php api('pull_request')->all('ezsystems', 'ezpublish'); ```php api('pull_request')->all('ezsystems', 'ezpublish', 'closed'); +$closedPullRequests = $client->api('pull_request')->all('ezsystems', 'ezpublish', array('state' => 'closed')); ``` ``$closedPullRequests`` contains an array of closed pull-requests for this repository. From bd6f1a5999842df94fc42c1123113cb3a332f8b6 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Fri, 22 May 2015 12:03:15 +0800 Subject: [PATCH 267/951] Add latest, tag to Releases api, update docs --- doc/repo/releases.md | 11 ++++++ lib/Github/Api/Repository/Releases.php | 27 ++++++++++++++ .../Tests/Api/Repository/ReleasesTest.php | 36 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index 35478d80387..de7ab130082 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -3,6 +3,17 @@ This Github API Endpoint is currently undocumented because it's new, but works just fine. +### Get latest actual release + +```php +$release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); +``` + +### List releases for a tag + +```php +$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec'); +``` ### List all releases diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 652c1b3a601..ec5bac4d4e5 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -12,6 +12,33 @@ */ class Releases extends AbstractApi { + /** + * Get the latest release. + * + * @param $username + * @param $repository + * + * @return array + */ + public function latest($username, $repository) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); + } + + /** + * List releases for a tag. + * + * @param $username + * @param $repository + * @param $tag + * + * @return array + */ + public function tag($username, $repository, $tag) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); + } + /** * List releases in selected repository. * diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index c9fac0a0f80..ad42461c928 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -6,6 +6,42 @@ class ReleasesTest extends TestCase { + /** + * @test + */ + public function shouldGetLatestRelease() + { + $expectedValue = array('latest_release_data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/releases/latest') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetReleaseByTag() + { + $expectedValue = array('latest_release_data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->tag( + 'KnpLabs', + 'php-github-api', + '5f078080e01e0365690920d618f12342d2c941c8' + )); + } + /** * @test */ From ee45d48b7280c9ea47f68ecf3913bef0d06bc0d8 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Fri, 22 May 2015 11:41:46 +0700 Subject: [PATCH 268/951] Add note about moved repositories --- doc/repos.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 0da8b9bd61b..8dc996d6434 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -238,3 +238,14 @@ $activity = $client->api('repo')->activity('ornicar', 'php-github-api'); ``` Returns an array of commit activity group by week. + +### `Moved` repositories +Github repositories can be moved to another org/user, but it remains the `id`. +In case if you can't no more find repo, you can retrieve it by `id`: + +```php +use Github\HttpClient\Message\ResponseMediator; + +$data = $client->getHttpClient()->get('/repositories/24560307'); +$repo = ResponseMediator::getContent($data); +``` From 3c36776a347b86088100533e8459f49b8b469de9 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Fri, 22 May 2015 12:46:37 +0800 Subject: [PATCH 269/951] Add guzzle events to customize.md --- doc/customize.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/customize.md b/doc/customize.md index 94888056be2..82274dc5e4a 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -11,6 +11,25 @@ $client->getHttpClient()->setOption('user_agent', 'My new User Agent'); See all available options in `Github/HttpClient/HttpClient.php` +### Guzzle events + +If you need to perform any special action on request/response use guzzle events: + +```php +use Guzzle\Common\Event; +use Github\HttpClient\Message\ResponseMediator; + +$client->getHttpClient()->addListener('request.success', function(Event $event) { + $remaining = ResponseMediator::getApiLimit($event['response']); + + var_dump($remaining); +}); + +$client->user()->show('cursedcoder'); +``` + +see list of events http://guzzle3.readthedocs.org/http-client/request.html#plugins-and-events + ### Inject a new http client instance `php-github-api` provides a curl-based implementation of a http client. From a275448d02172d1c40b1dcdee4e4392c703618d0 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Fri, 22 May 2015 13:30:32 +0800 Subject: [PATCH 270/951] Use actual api limit from header --- .../HttpClient/Listener/ErrorListener.php | 3 +- .../HttpClient/Listener/ErrorListenerTest.php | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index a945c45c621..72736255429 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -40,9 +40,10 @@ public function onRequestError(Event $event) if ($response->isClientError() || $response->isServerError()) { $remaining = (string) $response->getHeader('X-RateLimit-Remaining'); + $limit = $response->getHeader('X-RateLimit-Limit'); if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getResource(), 1, 10)) { - throw new ApiLimitExceedException($this->options['api_limit']); + throw new ApiLimitExceedException($limit); } if (401 === $response->getStatusCode()) { diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index 3715ee57d3d..ee783a888b6 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -30,10 +30,14 @@ public function shouldFailWhenApiLimitWasExceed() $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); - $response->expects($this->once()) + $response->expects($this->at(1)) ->method('getHeader') ->with('X-RateLimit-Remaining') ->will($this->returnValue(0)); + $response->expects($this->at(2)) + ->method('getHeader') + ->with('X-RateLimit-Limit') + ->will($this->returnValue(5000)); $listener = new ErrorListener(array('api_limit' => 5000)); $listener->onRequestError($this->getEventMock($response)); @@ -49,10 +53,15 @@ public function shouldNotPassWhenContentWasNotValidJson() $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); - $response->expects($this->once()) + $response->expects($this->at(1)) ->method('getHeader') ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); + $response->expects($this->at(2)) + ->method('getHeader') + ->with('X-RateLimit-Limit') + ->will($this->returnValue(5000)); + $response->expects($this->once()) ->method('getBody') ->will($this->returnValue('fail')); @@ -71,10 +80,14 @@ public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); - $response->expects($this->once()) + $response->expects($this->at(1)) ->method('getHeader') ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); + $response->expects($this->at(2)) + ->method('getHeader') + ->with('X-RateLimit-Limit') + ->will($this->returnValue(5000)); $response->expects($this->once()) ->method('getBody') ->will($this->returnValue(json_encode(array('message' => 'test')))); @@ -96,10 +109,14 @@ public function shouldNotPassWhen400IsSent() $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); - $response->expects($this->once()) + $response->expects($this->at(1)) ->method('getHeader') ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); + $response->expects($this->at(2)) + ->method('getHeader') + ->with('X-RateLimit-Limit') + ->will($this->returnValue(5000)); $response->expects($this->once()) ->method('getBody') ->will($this->returnValue(json_encode(array('message' => 'test')))); @@ -134,10 +151,14 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) $response->expects($this->once()) ->method('isClientError') ->will($this->returnValue(true)); - $response->expects($this->once()) + $response->expects($this->at(1)) ->method('getHeader') ->with('X-RateLimit-Remaining') ->will($this->returnValue(5000)); + $response->expects($this->at(2)) + ->method('getHeader') + ->with('X-RateLimit-Limit') + ->will($this->returnValue(5000)); $response->expects($this->once()) ->method('getBody') ->will($this->returnValue($content)); @@ -170,6 +191,8 @@ public function shouldThrowTwoFactorAuthenticationRequiredException() return 5000; case 'X-GitHub-OTP': return 'required; sms'; + case 'X-RateLimit-Limit': + return 5000; } })); $response->expects($this->any()) From 5b234d12d6c5699ac68cad6e6f6bd6ced84ec0aa Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Wed, 20 May 2015 17:43:08 -0700 Subject: [PATCH 271/951] Adding get milestones for repository --- doc/repos.md | 8 ++++++++ lib/Github/Api/Repo.php | 10 ++++++++++ test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 8dc996d6434..ca8a8b4da74 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -249,3 +249,11 @@ use Github\HttpClient\Message\ResponseMediator; $data = $client->getHttpClient()->get('/repositories/24560307'); $repo = ResponseMediator::getContent($data); ``` + +### Get the milestones of a repository + +```php +milestones = $client->api('repo')->milestones('ornicar', 'php-github-api'); +``` + +Returns a list of milestones. diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index fcafd4b2517..34d9dcbb25e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -463,4 +463,14 @@ public function merge($username, $repository, $base, $head, $message = null) 'commit_message' => $message )); } + + /** + * @param string $username + * @param string $repository + * @return array + */ + public function milestones($username, $repository) + { + return $this->get('repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones'); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index d14df11e650..200b9cbf447 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -188,6 +188,22 @@ public function shouldGetRepositoryLanguages() $this->assertEquals($expectedArray, $api->languages('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldGetRepositoryMilestones() + { + $expectedArray = array('milestone1', 'milestone2'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/milestones') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->milestones('KnpLabs', 'php-github-api')); + } + /** * @test */ From 2ea5d50a7692433124d165cad1e9f8fce3846b24 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 25 May 2015 13:46:30 +0800 Subject: [PATCH 272/951] Update Authorizations API --- lib/Github/Api/Authorizations.php | 100 +++++++++++++++++-- test/Github/Tests/Api/AuthorizationsTest.php | 81 +++++++++++---- 2 files changed, 153 insertions(+), 28 deletions(-) diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index 014e08b4486..1fca52e3af8 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -2,25 +2,44 @@ namespace Github\Api; -use Github\Api\AbstractApi; - /** * Creating, deleting and listing authorizations. * - * @link http://developer.github.com/v3/oauth/ + * @link http://developer.github.com/v3/oauth_authorizations/ + * @author Evgeniy Guseletov */ class Authorizations extends AbstractApi { + /** + * List all authorizations. + * + * @return array + */ public function all() { return $this->get('authorizations'); } - public function show($number) + /** + * Show a single authorization. + * + * @param $clientId + * + * @return array + */ + public function show($clientId) { - return $this->get('authorizations/'.rawurlencode($number)); + return $this->get('authorizations/'.rawurlencode($clientId)); } + /** + * Create an authorization. + * + * @param array $params + * @param null $OTPCode + * + * @return array + */ public function create(array $params, $OTPCode = null) { $headers = null === $OTPCode ? array() : array('X-GitHub-OTP' => $OTPCode); @@ -28,18 +47,77 @@ public function create(array $params, $OTPCode = null) return $this->post('authorizations', $params, $headers); } - public function update($id, array $params) + /** + * Update an authorization. + * + * @param $clientId + * @param array $params + * + * @return array + */ + public function update($clientId, array $params) + { + return $this->patch('authorizations/'.rawurlencode($clientId), $params); + } + + /** + * Remove an authorization. + * + * @param $clientId + * + * @return array + */ + public function remove($clientId) + { + return $this->delete('authorizations/'.rawurlencode($clientId)); + } + + /** + * Check an authorization. + * + * @param $clientId + * @param $token + * + * @return array + */ + public function check($clientId, $token) + { + return $this->get('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); + } + + /** + * Reset an authorization. + * + * @param $clientId + * @param $token + * + * @return array + */ + public function reset($clientId, $token) { - return $this->patch('authorizations/'.rawurlencode($id), $params); + return $this->post('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } - public function remove($id) + /** + * Remove an authorization. + * + * @param $clientId + * @param $token + * + * @return array + */ + public function revoke($clientId, $token) { - return $this->delete('authorizations/'.rawurlencode($id)); + return $this->delete('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } - public function check($id, $token) + /** + * Revoke all authorizations. + * + * @param $clientId + */ + public function revokeAll($clientId) { - return $this->get('authorizations/'.rawurlencode($id).'/tokens/'.rawurlencode($token)); + $this->delete('applications/'.rawurlencode($clientId).'/tokens'); } } diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php index 89534e50965..059c2ffe7f8 100644 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -37,6 +37,55 @@ public function shouldShowAuthorization() $this->assertEquals($expectedArray, $api->show($id)); } + /** + * @test + */ + public function shouldAuthorization() + { + $input = array( + 'note' => '', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('authorizations', $input); + + $api->create($input); + } + + /** + * @test + */ + public function shouldUpdateAuthorization() + { + $id = 123; + $input = array( + 'note' => '', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('authorizations/'.$id, $input); + + $api->update($id, $input); + } + + /** + * @test + */ + public function shouldDeleteAuthorization() + { + $id = 123; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('authorizations/'.$id); + + $api->remove($id); + } + /** * @test */ @@ -49,7 +98,7 @@ public function shouldCheckAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('authorizations/'.$id.'/tokens/'.$token) + ->with('applications/'.$id.'/tokens/'.$token) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->check($id, $token)); @@ -58,50 +107,48 @@ public function shouldCheckAuthorization() /** * @test */ - public function shouldAuthorization() + public function shouldResetAuthorization() { - $input = array( - 'note' => '', - ); + $id = 123; + $token = 'abcde'; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('authorizations', $input); + ->with('applications/'.$id.'/tokens/'.$token); - $api->create($input); + $api->reset($id, $token); } /** * @test */ - public function shouldUpdateAuthorization() + public function shouldRevokeAuthorization() { $id = 123; - $input = array( - 'note' => '', - ); + $token = 'abcde'; $api = $this->getApiMock(); $api->expects($this->once()) - ->method('patch') - ->with('authorizations/'.$id, $input); + ->method('delete') + ->with('applications/'.$id.'/tokens/'.$token); - $api->update($id, $input); + $api->revoke($id, $token); } /** * @test */ - public function shouldDeleteAuthorization() + public function shouldRevokeAllAuthorizations() { $id = 123; + $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('authorizations/'.$id); + ->with('applications/'.$id.'/tokens'); - $api->remove($id); + $api->revokeAll($id); } protected function getApiClass() From 2bcb8a5a4181b627a5786582e09ed1c1b6585bf3 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 25 May 2015 13:48:17 +0800 Subject: [PATCH 273/951] Update Authroziations doc --- doc/authorizations.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/doc/authorizations.md b/doc/authorizations.md index 037bca839d9..225ec032741 100644 --- a/doc/authorizations.md +++ b/doc/authorizations.md @@ -1,7 +1,7 @@ ## Authorizations API [Back to the navigation](README.md) -Creating, deleting and listing authorizations. Wraps [GitHub Authorizations API](http://developer.github.com/v3/oauth/). +Creating, deleting and listing authorizations. Wraps [GitHub Authorizations API](http://developer.github.com/v3/oauth_authorizations/). #### List all authorizations. @@ -50,3 +50,21 @@ $authorization = $github->api('authorizations')->remove(1234); ```php $authorization = $github->api('authorizations')->check(1234, 'token'); ``` + +#### Reset an authorization + +```php +$authorization = $github->api('authorizations')->reset(1234, 'token'); +``` + +#### Revoke an authorization + +```php +$authorization = $github->api('authorizations')->revoke(1234, 'token'); +``` + +#### Revoke all authorizations + +```php +$authorization = $github->api('authorizations')->revokeAll(1234); +``` From 10c66900199199f84d947a8521e1e80077e7bf8d Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 25 May 2015 13:49:39 +0800 Subject: [PATCH 274/951] Update return types --- doc/authorizations.md | 4 ++-- lib/Github/Api/Authorizations.php | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/authorizations.md b/doc/authorizations.md index 225ec032741..2865fd63e19 100644 --- a/doc/authorizations.md +++ b/doc/authorizations.md @@ -60,11 +60,11 @@ $authorization = $github->api('authorizations')->reset(1234, 'token'); #### Revoke an authorization ```php -$authorization = $github->api('authorizations')->revoke(1234, 'token'); +$github->api('authorizations')->revoke(1234, 'token'); ``` #### Revoke all authorizations ```php -$authorization = $github->api('authorizations')->revokeAll(1234); +$github->api('authorizations')->revokeAll(1234); ``` diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index 1fca52e3af8..b8c4f5bd8fe 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -103,12 +103,10 @@ public function reset($clientId, $token) * * @param $clientId * @param $token - * - * @return array */ public function revoke($clientId, $token) { - return $this->delete('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); + $this->delete('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } /** From 619bc56b984641dbff135947c26cc41fb1af89f8 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 25 May 2015 11:31:59 +0100 Subject: [PATCH 275/951] Fixed the api version --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 8182bf18bee..3ae16a3a040 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -82,7 +82,7 @@ class Client 'timeout' => 10, 'api_limit' => 5000, - 'api_version' => 'beta', + 'api_version' => 'v3', 'cache_dir' => null ); From 2d57b479336f6d38ffddd8a942f7b6faebd34ba5 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 25 May 2015 11:46:40 +0100 Subject: [PATCH 276/951] Supported api versions makes no sense --- lib/Github/Client.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 8182bf18bee..30ce8eab6a7 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -307,24 +307,10 @@ public function setOption($name, $value) if (!array_key_exists($name, $this->options)) { throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); } - $supportedApiVersions = $this->getSupportedApiVersions(); - if ('api_version' == $name && !in_array($value, $supportedApiVersions)) { - throw new InvalidArgumentException(sprintf('Invalid API version ("%s"), valid are: %s', $name, implode(', ', $supportedApiVersions))); - } $this->options[$name] = $value; } - /** - * Returns an array of valid API versions supported by this client. - * - * @return array - */ - public function getSupportedApiVersions() - { - return array('v3', 'beta'); - } - /** * @param string $name * From 3622ddc1496582148eeedaa41bdba5abeab5e0ff Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 25 May 2015 20:45:07 +0800 Subject: [PATCH 277/951] Add milestones doc, closes #142 --- doc/issue/milestones.md | 40 +++++++++++++++++++++++++++++ doc/issues.md | 1 + lib/Github/Api/Issue/Milestones.php | 12 ++++----- 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 doc/issue/milestones.md diff --git a/doc/issue/milestones.md b/doc/issue/milestones.md new file mode 100644 index 00000000000..59ef47cb629 --- /dev/null +++ b/doc/issue/milestones.md @@ -0,0 +1,40 @@ +## Issues / Milestones API +[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md) + +Wraps [GitHub Issue Milestones API](http://developer.github.com/v3/issues/milestones/). + +### List project milestones + +```php +$milestones = $client->api('issue')->milestones()->all('KnpLabs', 'php-github-api'); +``` + +### Get information about milestone + +```php +$milestone = $client->api('issue')->milestones()->show('KnpLabs', 'php-github-api', 123); +``` + +### Create a new milestone + +```php +$milestone = $client->api('issue')->milestones()->create('KnpLabs', 'php-github-api', array('title' => '3.0')); +``` + +### Update a milestone + +```php +$milestone = $client->api('issue')->milestones()->update('KnpLabs', 'php-github-api', 123); +``` + +### Remove a milestonre + +```php +$client->api('issue')->milestones()->remove('KnpLabs', 'php-github-api', 123); +``` + +### List milestone labels + +```php +$labels = $client->api('issue')->milestones()->labels('KnpLabs', 'php-github-api', 123); +``` diff --git a/doc/issues.md b/doc/issues.md index 1251d078673..983bf5ec53b 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -7,6 +7,7 @@ Wraps [GitHub Issue API](http://developer.github.com/v3/issues/). Additional APIs: * [Comments](issue/comments.md) * [Labels](issue/labels.md) +* [Milestones](issue/milestones.md) ### List issues in a project diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index a2e945a980b..049e2b35a33 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -43,22 +43,22 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); } - public function update($username, $repository, $milestone, array $params) + public function update($username, $repository, $id, array $params) { if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { $params['state'] = 'open'; } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($milestone), $params); + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params); } - public function remove($username, $repository, $milestone) + public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($milestone)); + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } - public function labels($username, $repository, $milestone) + public function labels($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($milestone).'/labels'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels'); } } From 5532f800f8dcf01357b33deaeb5ef443b5e9d223 Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 25 May 2015 20:54:06 +0800 Subject: [PATCH 278/951] Last missing gists method, closes #143 --- lib/Github/Api/Gists.php | 5 +++++ test/Github/Tests/Api/GistsTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index eb24f0b3fdf..07e8e1342f7 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -54,6 +54,11 @@ public function fork($id) return $this->post('gists/'.rawurlencode($id).'/fork'); } + public function forks($id) + { + return $this->get('gists/'.rawurlencode($id).'/forks'); + } + public function remove($id) { return $this->delete('gists/'.rawurlencode($id)); diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 4d2cdf7f346..5d0d74ce9af 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -94,6 +94,22 @@ public function shouldForkGist() $this->assertEquals($expectedArray, $api->fork(123)); } + /** + * @test + */ + public function shouldListGistForks() + { + $expectedArray = array('id' => '123'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('gists/123/forks') + ->will($this->returnValue($expectedArray)); + + $api->forks(123); + } + /** * @test * @expectedException Github\Exception\MissingArgumentException From 8592103a90c1d4e27659f1acaef0d203ff51369b Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Mon, 25 May 2015 21:02:17 +0800 Subject: [PATCH 279/951] Fix wrong request --- test/Github/Tests/Api/GistsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 5d0d74ce9af..77e6e132958 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -103,7 +103,7 @@ public function shouldListGistForks() $api = $this->getApiMock(); $api->expects($this->once()) - ->method('post') + ->method('get') ->with('gists/123/forks') ->will($this->returnValue($expectedArray)); From 8727a7fecf4a484416244985449bcae680eb6d8c Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Tue, 26 May 2015 11:06:44 +0800 Subject: [PATCH 280/951] Update ResponseMediator to use type conversion, closes #263 --- lib/Github/HttpClient/Message/ResponseMediator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index a8491898ad9..23982ae3144 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -21,7 +21,7 @@ public static function getContent(Response $response) public static function getPagination(Response $response) { - $header = $response->getHeader('Link'); + $header = (string) $response->getHeader('Link'); if (empty($header)) { return null; @@ -41,7 +41,7 @@ public static function getPagination(Response $response) public static function getApiLimit(Response $response) { - $remainingCalls = $response->getHeader('X-RateLimit-Remaining'); + $remainingCalls = (string) $response->getHeader('X-RateLimit-Remaining'); if (null !== $remainingCalls && 1 > $remainingCalls) { throw new ApiLimitExceedException($remainingCalls); From ccf5e49a2454c1b102333586d80ce67012b5080f Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Wed, 17 Jun 2015 16:02:22 +0800 Subject: [PATCH 281/951] Update References to handle slashes in reference values --- lib/Github/Api/GitData/References.php | 17 ++++++++++++++--- .../Tests/Api/GitData/ReferencesTest.php | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/GitData/References.php b/lib/Github/Api/GitData/References.php index 70d8fa37afa..582900a57d5 100644 --- a/lib/Github/Api/GitData/References.php +++ b/lib/Github/Api/GitData/References.php @@ -28,7 +28,9 @@ public function tags($username, $repository) public function show($username, $repository, $reference) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference)); + $reference = $this->encodeReference($reference); + + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); } public function create($username, $repository, array $params) @@ -46,11 +48,20 @@ public function update($username, $repository, $reference, array $params) throw new MissingArgumentException('sha'); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference), $params); + $reference = $this->encodeReference($reference); + + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params); } public function remove($username, $repository, $reference) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference)); + $reference = $this->encodeReference($reference); + + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); + } + + private function encodeReference($rawReference) + { + return implode('/', array_map('rawurlencode', explode('/', $rawReference))); } } diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 39d44ac7ee6..06c4adb4ced 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -2,10 +2,24 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class ReferencesTest extends TestCase { + /** + * @test + */ + public function shouldNotEscapeSlashesInReferences() + { + $expectedValue = array('reference' => 'some data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/l3l0/l3l0repo/git/refs/master/some%2A%26%40%23branch/dasd1212') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('l3l0', 'l3l0repo', 'master/some*&@#branch/dasd1212')); + } + /** * @test */ From 7c25f51119031717ea45a5bedf968d6d57099d2f Mon Sep 17 00:00:00 2001 From: Chris Gmyr Date: Wed, 1 Jul 2015 17:10:14 -0400 Subject: [PATCH 282/951] added "body" for correct json schema --- lib/Github/Api/Gist/Comments.php | 4 ++-- test/Github/Tests/Api/Gist/CommentsTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 2d889650015..9d439290f2c 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -22,12 +22,12 @@ public function show($gist, $comment) public function create($gist, $body) { - return $this->post('gists/'.rawurlencode($gist).'/comments', array($body)); + return $this->post('gists/'.rawurlencode($gist).'/comments', array('body' => $body)); } public function update($gist, $comment_id, $body) { - return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array($body)); + return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array('body' => $body)); } public function remove($gist, $comment) diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index 77f3ca50faa..557fae070f0 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -48,7 +48,7 @@ public function shouldCreateGistComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('gists/123/comments', array('Test body')) + ->with('gists/123/comments', array('body' => 'Test body')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('123', 'Test body')); @@ -60,7 +60,7 @@ public function shouldCreateGistComment() public function shouldUpdateGistComment() { $expectedValue = array('comment1data'); - $data = array('body test'); + $data = array('body' => 'body test'); $api = $this->getApiMock(); $api->expects($this->once()) From e30fc955f3a422555e5994b1e25b1dd34ef7b709 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 13:26:44 +0200 Subject: [PATCH 283/951] Add some style fixers --- .editorconfig | 13 +++++++++++++ .gitignore | 1 + .php_cs | 14 ++++++++++++++ .styleci.yml | 4 ++++ 4 files changed, 32 insertions(+) create mode 100644 .editorconfig create mode 100644 .php_cs create mode 100644 .styleci.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..ed1247ac692 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index fbeabd9bcd2..2c9d04ccd11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.php_cs.cache phpunit.xml composer.lock composer.phar diff --git a/.php_cs b/.php_cs new file mode 100644 index 00000000000..28ec2062129 --- /dev/null +++ b/.php_cs @@ -0,0 +1,14 @@ +in(__DIR__); + +$fixers = array( + 'long_array_syntax', +); + +return Symfony\CS\Config\Config::create() + ->setUsingCache(true) + ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) + ->fixers($fixers) + ->finder($finder); diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000000..e92503292bf --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,4 @@ +preset: psr2 + +enabled: + - long_array_syntax From c297da1677996d59ccbe657aa90b2bc840679604 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 13:27:51 +0200 Subject: [PATCH 284/951] Fix code --- lib/Github/Api/ApiInterface.php | 1 - lib/Github/Api/Deployment.php | 21 ++++++++++--------- lib/Github/Api/Gist/Comments.php | 2 +- lib/Github/Api/Notification.php | 4 ++-- lib/Github/Api/Repository/Releases.php | 2 +- lib/Github/Api/Search.php | 1 - .../Tests/Api/Enterprise/UserAdminTest.php | 2 +- test/Github/Tests/Api/Gist/CommentsTest.php | 2 +- test/Github/Tests/Api/GistsTest.php | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/Github/Api/ApiInterface.php b/lib/Github/Api/ApiInterface.php index 893f538e1ab..49d5167c29d 100644 --- a/lib/Github/Api/ApiInterface.php +++ b/lib/Github/Api/ApiInterface.php @@ -9,7 +9,6 @@ */ interface ApiInterface { - public function getPerPage(); public function setPerPage($perPage); diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index f8f3dbac953..c86e7a073ab 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -21,7 +21,7 @@ class Deployment extends AbstractApi * @return array the deployments requested */ public function all($username, $repository, array $params = array()) - { + { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } @@ -41,11 +41,11 @@ public function all($username, $repository, array $params = array()) */ public function create($username, $repository, array $params) { - if (!isset($params['ref'])) { - throw new MissingArgumentException(array('ref')); - } + if (!isset($params['ref'])) { + throw new MissingArgumentException(array('ref')); + } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } /** @@ -64,10 +64,10 @@ public function create($username, $repository, array $params) */ public function updateStatus($username, $repository, $id, array $params) { - if (!isset($params['state'])) { - throw new MissingArgumentException(array('state')); - } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); + if (!isset($params['state'])) { + throw new MissingArgumentException(array('state')); + } + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); } /** @@ -78,7 +78,8 @@ public function updateStatus($username, $repository, $id, array $params) * @param int $id the deployment identifier * @return array the deployment statuses */ - public function getStatuses($username, $repository, $id) { + public function getStatuses($username, $repository, $id) + { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses'); } } diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 2d889650015..c0c5980aa3e 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -34,4 +34,4 @@ public function remove($gist, $comment) { return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } -} \ No newline at end of file +} diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index c351927ec5d..a2ed530ad28 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -32,7 +32,7 @@ public function all($includingRead = false, $participating = false, DateTime $si 'participating' => $participating ); - if($since !== null) { + if ($since !== null) { $parameters['since'] = $since->format(DateTime::ISO8601); } @@ -51,7 +51,7 @@ public function markRead(DateTime $since = null) { $parameters = array(); - if($since !== null) { + if ($since !== null) { $parameters['last_read_at'] = $since->format(DateTime::ISO8601); } diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index ec5bac4d4e5..94d130ef031 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -17,7 +17,7 @@ class Releases extends AbstractApi * * @param $username * @param $repository - * + * * @return array */ public function latest($username, $repository) diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index bd9f79110a3..cd55d5a1f94 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -16,7 +16,6 @@ */ class Search extends AbstractApi { - /** * Search repositories by filter (q). * diff --git a/test/Github/Tests/Api/Enterprise/UserAdminTest.php b/test/Github/Tests/Api/Enterprise/UserAdminTest.php index 42e6358bfff..34e6b6e910b 100644 --- a/test/Github/Tests/Api/Enterprise/UserAdminTest.php +++ b/test/Github/Tests/Api/Enterprise/UserAdminTest.php @@ -40,4 +40,4 @@ protected function getApiClass() { return 'Github\Api\Enterprise\UserAdmin'; } -} \ No newline at end of file +} diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index 77f3ca50faa..f44838c4c5a 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -91,4 +91,4 @@ protected function getApiClass() { return 'Github\Api\Gist\Comments'; } -} \ No newline at end of file +} diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 77e6e132958..6a979c5ee19 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -242,4 +242,4 @@ protected function getApiClass() { return 'Github\Api\Gists'; } -} \ No newline at end of file +} From 84ac636302a65e074ee4742c60a80ae8e83d198c Mon Sep 17 00:00:00 2001 From: Evgeniy Guseletov Date: Thu, 2 Jul 2015 19:23:30 +0300 Subject: [PATCH 285/951] Add style-ci badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fff12e642d2..cc569524322 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # PHP GitHub API [![Build Status](https://secure.travis-ci.org/KnpLabs/php-github-api.png)](http://travis-ci.org/KnpLabs/php-github-api) +[![StyleCI](https://styleci.io/repos/3948501/shield)](https://styleci.io/repos/3948501) A simple Object Oriented wrapper for GitHub API, written with PHP5. From 958b152f2200249b85dfc19f2579394f301d456b Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 13:11:38 +0200 Subject: [PATCH 286/951] Add memberships --- lib/Github/Api/CurrentUser.php | 9 ++ lib/Github/Api/CurrentUser/Memberships.php | 44 +++++++++ .../Tests/Api/CurrentUser/MembershipsTest.php | 91 +++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 lib/Github/Api/CurrentUser/Memberships.php create mode 100644 test/Github/Tests/Api/CurrentUser/MembershipsTest.php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index f9e9cd79f6c..b525ee185a9 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -5,6 +5,7 @@ use Github\Api\CurrentUser\DeployKeys; use Github\Api\CurrentUser\Emails; use Github\Api\CurrentUser\Followers; +use Github\Api\CurrentUser\Memberships; use Github\Api\CurrentUser\Notifications; use Github\Api\CurrentUser\Watchers; use Github\Api\CurrentUser\Starring; @@ -78,6 +79,14 @@ public function notifications() return new Notifications($this->client); } + /** + * @return Memberships + */ + public function memberships() + { + return new Memberships($this->client); + } + /** * @link http://developer.github.com/v3/orgs/#list-user-organizations * diff --git a/lib/Github/Api/CurrentUser/Memberships.php b/lib/Github/Api/CurrentUser/Memberships.php new file mode 100644 index 00000000000..c02c0122ef6 --- /dev/null +++ b/lib/Github/Api/CurrentUser/Memberships.php @@ -0,0 +1,44 @@ +get('user/memberships/orgs'); + } + + /** + * Get your organization membership. + * + * @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership + * + * @return array + */ + public function organization($organization) + { + return $this->get('user/memberships/orgs/'.rawurlencode($organization)); + } + + /** + * Edit your organization membership + * + * @link https://developer.github.com/v3/orgs/members/#edit-your-organization-membership + * + * @return array + */ + public function edit($organization) + { + return $this->patch('user/memberships/orgs/'.rawurlencode($organization), array('state' => 'active')); + } +} diff --git a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php new file mode 100644 index 00000000000..571f1bce41d --- /dev/null +++ b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php @@ -0,0 +1,91 @@ + array( + 'login' => 'octocat', + 'id' => 1, + ), + 'user' => array( + 'login' => 'defunkt', + 'id' => 3, + ), + ), + array( + 'organization' => array( + 'login' => 'invitocat', + 'id' => 2, + ), + 'user' => array( + 'login' => 'defunkt', + 'id' => 3, + ), + ), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/memberships/orgs') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all()); + } + + /** + * @test + */ + public function shouldGetMembershipsForOrganization() + { + $expectedValue = array( + 'organization' => array( + 'login' => 'invitocat', + 'id' => 2, + ), + 'user' => array( + 'login' => 'defunkt', + 'id' => 3, + ), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/memberships/orgs/invitocat') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->organization('invitocat')); + } + + /** + * @test + */ + public function shouldEditMembershipsForOrganization() + { + $expectedValue = array( + 'state' => 'active', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('user/memberships/orgs/invitocat') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->edit('invitocat')); + } + + protected function getApiClass() + { + return 'Github\Api\CurrentUser\Memberships'; + } +} From 1367eb4d5e513835df20f2579b6159462f63897b Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 18:45:46 +0200 Subject: [PATCH 287/951] Add some documentation for memberships --- doc/currentuser/memberships.md | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 doc/currentuser/memberships.md diff --git a/doc/currentuser/memberships.md b/doc/currentuser/memberships.md new file mode 100644 index 00000000000..989766bc254 --- /dev/null +++ b/doc/currentuser/memberships.md @@ -0,0 +1,36 @@ +## Current user / Memberships API +[Back to the navigation](../README.md) + +Wraps [GitHub Issue Comments API](https://developer.github.com/v3/orgs/members/#get-your-organization-membership). + +### List your memberships + +> Requires [authentication](../security.md). + +```php +$memberships = $client->user()->memberships()->all(); +``` + +Returns an array of your memberships in all organizations you are part of. + +### Show an organization membership + +> Requires [authentication](../security.md). + +```php +$membership = $client->user()->memberships()->organization('KnpLabs'); +``` +* `KnpLabs` : the organization + +Returns an array of one membership in a specific organization. + +### Update an organization membership + +> Requires [authentication](../security.md). + +```php +$membership = $client->user()->memberships()->edit('KnpLabs'); +``` +* `KnpLabs` : the organization + +Update your membership to an organization. The only possible action is to activate your membership. From 33fb56f1ddcd6ce02afcbbf3f916edd5351f0666 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 16:14:22 +0200 Subject: [PATCH 288/951] Add organizations webhooks --- lib/Github/Api/Organization.php | 9 + lib/Github/Api/Organization/Hooks.php | 99 +++++++++++ .../Tests/Api/Organization/HooksTest.php | 156 ++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 lib/Github/Api/Organization/Hooks.php create mode 100644 test/Github/Tests/Api/Organization/HooksTest.php diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 37322b218d8..a506702dae3 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; use Github\Api\Organization\Teams; @@ -58,6 +59,14 @@ public function members() return new Members($this->client); } + /** + * @return Hooks + */ + public function hooks() + { + return new Hooks($this->client); + } + /** * @return Teams */ diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php new file mode 100644 index 00000000000..627b193f77c --- /dev/null +++ b/lib/Github/Api/Organization/Hooks.php @@ -0,0 +1,99 @@ +get('orgs/'.rawurlencode($organization).'/hooks'); + } + + /** + * Get a single hook. + * @Link https://developer.github.com/v3/orgs/hooks/#get-single-hook + * + * @param string $organization + * @param int $id + * @return array + */ + public function show($organization, $id) + { + return $this->get('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); + } + + /** + * Create a hook. + * + * @link https://developer.github.com/v3/orgs/hooks/#create-a-hook + * @param string $organization + * @param array $params + * @return array + * @throws \Github\Exception\MissingArgumentException + */ + public function create($organization, array $params) + { + if (!isset($params['name'], $params['config'])) + { + throw new MissingArgumentException(array('name', 'config')); + } + + return $this->post('orgs/'.rawurlencode($organization).'/hooks', $params); + } + + /** + * Edit a hook. + * + * @link https://developer.github.com/v3/orgs/hooks/#edit-a-hook + * @param string $organization + * @param int $id + * @param array $params + * @return array + * @throws \Github\Exception\MissingArgumentException + */ + public function update($organization, $id, array $params) + { + if (!isset($params['config'])) + { + throw new MissingArgumentException(array('config')); + } + + return $this->patch('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id), $params); + } + + /** + * Ping a hook. + * + * @link https://developer.github.com/v3/orgs/hooks/#ping-a-hook + * @param string $organization + * @param int $id + * @return null + */ + public function ping($organization, $id) + { + return $this->post('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id).'/pings'); + } + + /** + * Delete a hook. + * + * @link https://developer.github.com/v3/orgs/hooks/#delete-a-hook + * @param $organization + * @param $id + * @return null + */ + public function remove($organization, $id) + { + return $this->delete('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); + } +} diff --git a/test/Github/Tests/Api/Organization/HooksTest.php b/test/Github/Tests/Api/Organization/HooksTest.php new file mode 100644 index 00000000000..a3cdd4fcba4 --- /dev/null +++ b/test/Github/Tests/Api/Organization/HooksTest.php @@ -0,0 +1,156 @@ + 'hook')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('orgs/KnpLabs/hooks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldShowHook() + { + $expectedValue = array('hook' => 'somename'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('orgs/KnpLabs/hooks/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 123)); + } + + /** + * @test + */ + public function shouldRemoveHook() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('orgs/KnpLabs/hooks/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 123)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateHookWithoutName() + { + $data = array('config' => 'conf'); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateHookWithoutConfig() + { + $data = array('name' => 'test'); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', $data); + } + + /** + * @test + */ + public function shouldCreateHook() + { + $expectedValue = array('hook' => 'somename'); + $data = array('name' => 'test', 'config' => 'someconfig'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('orgs/KnpLabs/hooks', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotUpdateHookWithoutConfig() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('patch'); + + $api->update('KnpLabs', 123, $data); + } + + /** + * @test + */ + public function shouldUpdateHook() + { + $expectedValue = array('hook' => 'somename'); + $data = array('config' => 'config'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('orgs/KnpLabs/hooks/123', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 123, $data)); + } + + /** + * @test + */ + public function shouldPingHook() + { + $expectedValue = null; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('orgs/KnpLabs/hooks/123/pings') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->ping('KnpLabs', 123)); + } + + protected function getApiClass() + { + return 'Github\Api\Organization\Hooks'; + } +} From d285fd61eba7b9d109a2f70b27e624b08aa3295b Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 16:16:42 +0200 Subject: [PATCH 289/951] Respect PSR-2 --- lib/Github/Api/Organization/Hooks.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index 627b193f77c..9124e7845a6 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -43,8 +43,7 @@ public function show($organization, $id) */ public function create($organization, array $params) { - if (!isset($params['name'], $params['config'])) - { + if (!isset($params['name'], $params['config'])) { throw new MissingArgumentException(array('name', 'config')); } @@ -63,8 +62,7 @@ public function create($organization, array $params) */ public function update($organization, $id, array $params) { - if (!isset($params['config'])) - { + if (!isset($params['config'])) { throw new MissingArgumentException(array('config')); } From 1b855e59e0a56fb1812966c7a114e1cff28e6cb5 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 16:20:42 +0200 Subject: [PATCH 290/951] Add missing docblocks arguments types --- lib/Github/Api/Organization/Hooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index 9124e7845a6..3a7b595e213 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -86,8 +86,8 @@ public function ping($organization, $id) * Delete a hook. * * @link https://developer.github.com/v3/orgs/hooks/#delete-a-hook - * @param $organization - * @param $id + * @param string $organization + * @param int $id * @return null */ public function remove($organization, $id) From b07a7da48226022bf4b89c4a0e68499440f49b6d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 18:15:51 +0200 Subject: [PATCH 291/951] Update case on docblock --- lib/Github/Api/Organization/Hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index 3a7b595e213..109b7b3b6d6 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -21,7 +21,7 @@ public function all($organization) /** * Get a single hook. - * @Link https://developer.github.com/v3/orgs/hooks/#get-single-hook + * @link https://developer.github.com/v3/orgs/hooks/#get-single-hook * * @param string $organization * @param int $id From 648bc8614e77894532343fa4d0d762e77886af3f Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 2 Jul 2015 18:36:57 +0200 Subject: [PATCH 292/951] Add some documentation --- doc/organization/webhooks.md | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 doc/organization/webhooks.md diff --git a/doc/organization/webhooks.md b/doc/organization/webhooks.md new file mode 100644 index 00000000000..4844748fa20 --- /dev/null +++ b/doc/organization/webhooks.md @@ -0,0 +1,95 @@ +## Organization / Webhooks API +[Back to the navigation](README.md) + +Listing, showing, creating, updating, testing and removing organizations webhooks. +Wraps [GitHub Organization Webhooks API](https://developer.github.com/v3/orgs/hooks/). + +Additional APIs: +* [Organization](issue/organization.md) + +### List webhooks for an organization + +> Requires [authentication](security.md). + +```php +$webhooks = $client->organization()->all('KnpLabs'); +``` + +Returns an array of webhooks for the organization. + +### Get a webhook for an organization + +> Requires [authentication](security.md). + +```php +$webhook = $client->organization()->show('KnpLabs', 123); +``` + +Returns the webhook with the ID 123 as an array for the organization. + +### Create a new webhook for an organization + +> Requires [authentication](security.md). + +```php +$webhook = $client->organization()->create('KnpLabs', array( + 'name' => 'web', + 'active' => true, + 'events' => array( + 'push', + 'pull_request' + ), + 'config' => array( + 'url' => 'http=>//example.com/webhook', + 'content_type' => 'json' + ) +)); +``` + +Creates a new webhook for the organization. +*name* and *url* parameters are required. + +The create webhook will be returned as an array. + +### Update an existing webhook for an organization + +> Requires [authentication](security.md). + +```php +$success = $client->organization()->update('KnpLabs', 123, array( + 'active' => true, + 'events' => array( + 'push', + 'pull_request' + ), + 'config' => array( + 'url' => 'http=>//example.com/webhook', + 'content_type' => 'json' + ) +)); +``` + +Update an existing webhook with ID 123 for the organization. +*url* parameter is required. + +In case of success, an array of informations about the webhook will be returned. + +### Ping a webhook for an organization + +> Requires [authentication](security.md). + +```php +$client->organization()->pings('KnpLabs', 123); +``` + +No content is returned. + +### Delete a webhook for an organization + +> Requires [authentication](security.md). + +```php +$client->organization()->delete('KnpLabs', 123); +``` + +No content is returned. \ No newline at end of file From d6602e746a90a17339db4b3835891631d66972f6 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Jul 2015 16:36:16 +0200 Subject: [PATCH 293/951] Some fixes --- lib/Github/Api/Repository/Assets.php | 1 - lib/Github/Api/Repository/Contents.php | 1 - lib/Github/Api/Search.php | 6 ------ .../HttpClient/Listener/ErrorListener.php | 1 - .../Tests/Api/CurrentUser/DeployKeysTest.php | 10 ++++------ .../Tests/Api/CurrentUser/EmailsTest.php | 6 ++---- .../Tests/Api/CurrentUser/FollowersTest.php | 2 -- .../Tests/Api/CurrentUser/StarringTest.php | 2 -- .../Tests/Api/CurrentUser/WatchersTest.php | 2 -- test/Github/Tests/Api/CurrentUserTest.php | 2 +- test/Github/Tests/Api/DeploymentTest.php | 2 +- test/Github/Tests/Api/GistsTest.php | 2 +- test/Github/Tests/Api/GitData/BlobsTest.php | 6 ++---- test/Github/Tests/Api/GitData/CommitsTest.php | 8 +++----- .../Tests/Api/GitData/ReferencesTest.php | 6 +++--- test/Github/Tests/Api/GitData/TagsTest.php | 18 ++++++++---------- test/Github/Tests/Api/GitData/TreesTest.php | 14 ++++++-------- test/Github/Tests/Api/Issue/CommentsTest.php | 4 ++-- test/Github/Tests/Api/Issue/LabelsTest.php | 2 +- test/Github/Tests/Api/Issue/MilestonesTest.php | 2 +- test/Github/Tests/Api/IssueTest.php | 4 ++-- .../Tests/Api/Organization/TeamsTest.php | 4 ++-- test/Github/Tests/Api/PullRequestTest.php | 8 ++++---- .../Github/Tests/Api/Repository/AssetsTest.php | 2 +- .../Tests/Api/Repository/CommentsTest.php | 4 ++-- .../Tests/Api/Repository/ContentsTest.php | 7 +++---- .../Tests/Api/Repository/DeployKeysTest.php | 8 ++++---- test/Github/Tests/Api/Repository/HooksTest.php | 8 ++++---- .../Github/Tests/Api/Repository/LabelsTest.php | 8 ++++---- .../Tests/Api/Repository/ReleasesTest.php | 2 +- .../Tests/Api/Repository/StatusesTest.php | 2 +- test/Github/Tests/ClientTest.php | 5 ++--- 32 files changed, 65 insertions(+), 94 deletions(-) diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index dbd448c7e28..b386561796e 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -5,7 +5,6 @@ use Github\Api\AbstractApi; use Github\Exception\ErrorException; use Github\Exception\MissingArgumentException; -use Github\HttpClient\HttpClient; /** * @link http://developer.github.com/v3/repos/releases/ diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index c98898af63a..450c14b5845 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -173,7 +173,6 @@ public function update($username, $repository, $path, $content, $message, $sha, return $this->put($url, $parameters); } - /** * Deletes a file from a repository. * diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index cd55d5a1f94..6ca29ea62b7 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -2,12 +2,6 @@ namespace Github\Api; -use Github\Api\Issue\Comments; -use Github\Api\Issue\Events; -use Github\Api\Issue\Labels; -use Github\Api\Issue\Milestones; -use Github\Exception\MissingArgumentException; - /** * Implement the Search API. * diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 72736255429..1f6cd5187b5 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -5,7 +5,6 @@ use Github\Exception\TwoFactorAuthenticationRequiredException; use Github\HttpClient\Message\ResponseMediator; use Guzzle\Common\Event; -use Guzzle\Http\Message\Response; use Github\Exception\ApiLimitExceedException; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index 4075e44040b..f813ca80673 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class DeployKeysTest extends TestCase { /** @@ -57,7 +55,7 @@ public function shouldCreateKey() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateKeyWithoutTitleParam() { @@ -72,7 +70,7 @@ public function shouldNotCreateKeyWithoutTitleParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateKeyWithoutKeyParam() { @@ -104,7 +102,7 @@ public function shouldUpdateKey() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateKeyWithoutTitleParam() { @@ -119,7 +117,7 @@ public function shouldNotUpdateKeyWithoutTitleParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateKeyWithoutKeyParam() { diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index 9dbf81ac697..33e1f704c7f 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class EmailsTest extends TestCase { /** @@ -56,7 +54,7 @@ public function shouldRemoveEmails() /** * @test - * @expectedException Github\Exception\InvalidArgumentException + * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotRemoveEmailsWhenAreNotPass() { @@ -101,7 +99,7 @@ public function shouldAddEmails() /** * @test - * @expectedException Github\Exception\InvalidArgumentException + * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotAddEmailsWhenAreNotPass() { diff --git a/test/Github/Tests/Api/CurrentUser/FollowersTest.php b/test/Github/Tests/Api/CurrentUser/FollowersTest.php index 9d0174fc2ea..d2e74ec438b 100644 --- a/test/Github/Tests/Api/CurrentUser/FollowersTest.php +++ b/test/Github/Tests/Api/CurrentUser/FollowersTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class FollowersTest extends TestCase { /** diff --git a/test/Github/Tests/Api/CurrentUser/StarringTest.php b/test/Github/Tests/Api/CurrentUser/StarringTest.php index c2cba90cfb1..bc5943ee4e3 100644 --- a/test/Github/Tests/Api/CurrentUser/StarringTest.php +++ b/test/Github/Tests/Api/CurrentUser/StarringTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class StarringTest extends TestCase { /** diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index e2234ed7efb..c8383935b70 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class WatchersTest extends TestCase { /** diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 1549f3621c0..f1dd27b0b77 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -133,7 +133,7 @@ public function shouldGetWatchersApiObject() $this->assertInstanceOf('Github\Api\CurrentUser\Watchers', $api->watchers()); } - + /** * @test */ diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 2bcbb4d5d25..baa692e430b 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -63,7 +63,7 @@ public function shouldCreateStatusUpdate() /** * @test - * @expectedException GitHub\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldRejectStatusUpdateWithoutStateField() { diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 6a979c5ee19..7f5ffe35843 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -112,7 +112,7 @@ public function shouldListGistForks() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateGistWithoutFile() { diff --git a/test/Github/Tests/Api/GitData/BlobsTest.php b/test/Github/Tests/Api/GitData/BlobsTest.php index cd9d1c8e1b3..4df2c67a723 100644 --- a/test/Github/Tests/Api/GitData/BlobsTest.php +++ b/test/Github/Tests/Api/GitData/BlobsTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class BlobsTest extends TestCase { /** @@ -69,7 +67,7 @@ public function shouldCreateBlob() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateBlobWithoutEncoding() { @@ -84,7 +82,7 @@ public function shouldNotCreateBlobWithoutEncoding() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateBlobWithoutContent() { diff --git a/test/Github/Tests/Api/GitData/CommitsTest.php b/test/Github/Tests/Api/GitData/CommitsTest.php index a665d90a495..fa3cd60f1a8 100644 --- a/test/Github/Tests/Api/GitData/CommitsTest.php +++ b/test/Github/Tests/Api/GitData/CommitsTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class CommitsTest extends TestCase { /** @@ -41,7 +39,7 @@ public function shouldCreateCommit() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateCommitWithoutMessageParam() { @@ -56,7 +54,7 @@ public function shouldNotCreateCommitWithoutMessageParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateCommitWithoutTreeParam() { @@ -71,7 +69,7 @@ public function shouldNotCreateCommitWithoutTreeParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateCommitWithoutParentsParam() { diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 06c4adb4ced..48f1775c6e5 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -119,7 +119,7 @@ public function shouldCreateReference() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReferenceWithoutShaParam() { @@ -134,7 +134,7 @@ public function shouldNotCreateReferenceWithoutShaParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReferenceWithoutRefsParam() { @@ -166,7 +166,7 @@ public function shouldUpdateReference() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNoUpdateReferenceWithoutSha() { diff --git a/test/Github/Tests/Api/GitData/TagsTest.php b/test/Github/Tests/Api/GitData/TagsTest.php index cd9cf8e536d..3062e5bba2f 100644 --- a/test/Github/Tests/Api/GitData/TagsTest.php +++ b/test/Github/Tests/Api/GitData/TagsTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class TagsTest extends TestCase { /** @@ -67,7 +65,7 @@ public function shouldCreateTag() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutMessageParam() { @@ -91,7 +89,7 @@ public function shouldNotCreateTagWithoutMessageParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerParam() { @@ -111,7 +109,7 @@ public function shouldNotCreateTagWithoutTaggerParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerNameParam() { @@ -135,7 +133,7 @@ public function shouldNotCreateTagWithoutTaggerNameParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerEmailParam() { @@ -159,7 +157,7 @@ public function shouldNotCreateTagWithoutTaggerEmailParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerDateParam() { @@ -183,7 +181,7 @@ public function shouldNotCreateTagWithoutTaggerDateParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTagParam() { @@ -207,7 +205,7 @@ public function shouldNotCreateTagWithoutTagParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutObjectParam() { @@ -231,7 +229,7 @@ public function shouldNotCreateTagWithoutObjectParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTypeParam() { diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index dc4a8211b20..2281331542b 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -2,8 +2,6 @@ namespace Github\Tests\Api; -use Github\Tests\Api\TestCase; - class TreesTest extends TestCase { /** @@ -88,7 +86,7 @@ public function shouldCreateTreeUsingContent() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutShaAndContentParam() { @@ -109,7 +107,7 @@ public function shouldNotCreateTreeWithoutShaAndContentParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutPathParam() { @@ -130,7 +128,7 @@ public function shouldNotCreateTreeWithoutPathParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutModeParam() { @@ -151,7 +149,7 @@ public function shouldNotCreateTreeWithoutModeParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutTypeParam() { @@ -172,7 +170,7 @@ public function shouldNotCreateTreeWithoutTypeParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutTreeParam() { @@ -187,7 +185,7 @@ public function shouldNotCreateTreeWithoutTreeParam() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWhenTreeParamIsNotArray() { diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 687dc3a35f7..eca7bf45a98 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -40,7 +40,7 @@ public function shouldShowIssueComment() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutBody() { @@ -72,7 +72,7 @@ public function shouldCreateIssueComment() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateWithoutBody() { diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index 3a6b7009e5d..c8a457e0ac5 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -175,7 +175,7 @@ public function shouldReplaceLabels() /** * @test - * @expectedException Github\Exception\InvalidArgumentException + * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotAddWhenDoNotHaveLabelsToAdd() { diff --git a/test/Github/Tests/Api/Issue/MilestonesTest.php b/test/Github/Tests/Api/Issue/MilestonesTest.php index 7ada6eff888..85594f69844 100644 --- a/test/Github/Tests/Api/Issue/MilestonesTest.php +++ b/test/Github/Tests/Api/Issue/MilestonesTest.php @@ -41,7 +41,7 @@ public function shouldCreateMilestone() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateMilestoneWithoutTitle() { diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index cdd7ba7f3b1..52bb39a240c 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -88,7 +88,7 @@ public function shouldCreateIssue() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateIssueWithoutTitle() { @@ -105,7 +105,7 @@ public function shouldNotCreateIssueWithoutTitle() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateIssueWithoutBody() { diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 4fdea74bd14..5a38555f1d5 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -184,7 +184,7 @@ public function shouldRemoveTeamRepository() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTeamWithoutName() { @@ -250,7 +250,7 @@ public function shouldCreateWithPullPermissionWhenPermissionParamNotRecognized() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateTeamWithoutName() { diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 0a0aa067ce4..e35599e4448 100755 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -190,7 +190,7 @@ public function shouldCreatePullRequestUsingIssueId() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestWithoutBase() { @@ -209,7 +209,7 @@ public function shouldNotCreatePullRequestWithoutBase() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestWithoutHead() { @@ -228,7 +228,7 @@ public function shouldNotCreatePullRequestWithoutHead() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { @@ -247,7 +247,7 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestWithoutIssueIdOrTitle() { diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index be779cc4c65..dc6e6146b0b 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -86,7 +86,7 @@ public function shouldEditReleaseAsset() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotEditReleaseAssetWithoutName() { diff --git a/test/Github/Tests/Api/Repository/CommentsTest.php b/test/Github/Tests/Api/Repository/CommentsTest.php index b8220905a43..586736a183f 100644 --- a/test/Github/Tests/Api/Repository/CommentsTest.php +++ b/test/Github/Tests/Api/Repository/CommentsTest.php @@ -56,7 +56,7 @@ public function shouldShowComment() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutBody() { @@ -105,7 +105,7 @@ public function shouldCreateRepositoryCommitCommentWithoutLine() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateWithoutBody() { diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 82009962f59..ddce2c9e905 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -135,7 +135,7 @@ public function shouldCreateNewFile() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! */ public function shouldThrowExceptionWhenCreateNewFileWithInvalidCommitter() @@ -175,7 +175,7 @@ public function shouldUpdateFile() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! */ public function shouldThrowExceptionWhenUpdateFileWithInvalidCommitter() @@ -213,7 +213,7 @@ public function shouldDeleteFile() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! */ public function shouldThrowExceptionWhenDeleteFileWithInvalidCommitter() @@ -332,7 +332,6 @@ protected function getApiClass() return 'Github\Api\Repository\Contents'; } - private function getGuzzleResponseMock() { $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index a235bad8f0b..1654471b69e 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -56,7 +56,7 @@ public function shouldRemoveDeployKey() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateDeployKeyWithoutName() { @@ -71,7 +71,7 @@ public function shouldNotCreateDeployKeyWithoutName() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateDeployKeyWithoutColor() { @@ -103,7 +103,7 @@ public function shouldCreateDeployKey() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateDeployKeyWithoutTitle() { @@ -118,7 +118,7 @@ public function shouldNotUpdateDeployKeyWithoutTitle() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateDeployKeyWithoutKey() { diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index 6744d8c9158..aa8e32b485d 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -56,7 +56,7 @@ public function shouldRemoveHook() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateHookWithoutName() { @@ -71,7 +71,7 @@ public function shouldNotCreateHookWithoutName() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateHookWithoutColor() { @@ -103,7 +103,7 @@ public function shouldCreateHook() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateHookWithoutName() { @@ -118,7 +118,7 @@ public function shouldNotUpdateHookWithoutName() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateHookWithoutConfig() { diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index 6526ec4b3bb..8b430e6b3f1 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -56,7 +56,7 @@ public function shouldRemoveLabel() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateLabelWithoutName() { @@ -71,7 +71,7 @@ public function shouldNotCreateLabelWithoutName() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateLabelWithoutColor() { @@ -103,7 +103,7 @@ public function shouldCreateLabel() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateLabelWithoutName() { @@ -118,7 +118,7 @@ public function shouldNotUpdateLabelWithoutName() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateLabelWithoutColor() { diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index ad42461c928..f9188e137a0 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -94,7 +94,7 @@ public function shouldCreateRepositoryRelease() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateRepositoryReleaseWithoutTagName() { diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php index 8845a523b4d..68667fca7b1 100644 --- a/test/Github/Tests/Api/Repository/StatusesTest.php +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -57,7 +57,7 @@ public function shouldShowCombinedCommitStatuses() /** * @test - * @expectedException Github\Exception\MissingArgumentException + * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutStatus() { diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index b7a8751fb39..a51996319d7 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -3,7 +3,6 @@ namespace Github\Tests; use Github\Client; -use Github\Exception\InvalidArgumentException; use Github\Exception\BadMethodCallException; class ClientTest extends \PHPUnit_Framework_TestCase @@ -78,7 +77,7 @@ public function getAuthenticationPartialData() /** * @test - * @expectedException InvalidArgumentException + * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet() { @@ -138,7 +137,7 @@ public function shouldGetMagicApiInstance($apiName, $class) /** * @test - * @expectedException InvalidArgumentException + * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotGetApiInstance() { From ce88b27bac091a73c3058294ef96015ce39233e1 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 3 Jul 2015 15:51:24 +0100 Subject: [PATCH 294/951] Move to non-deprecated autoloading standard --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dc16d3e77fd..f44e75bcd0a 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "knplabs/gaufrette": "Needed for optional Gaufrette cache" }, "autoload": { - "psr-0": { "Github\\": "lib/" } + "psr-4": { "Github\\": "lib/Github/" } }, "extra": { "branch-alias": { From df85b57f3158611d3af7f5c6893b576a8122e088 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Jul 2015 17:01:50 +0200 Subject: [PATCH 295/951] Work on current user --- lib/Github/Api/CurrentUser/DeployKeys.php | 4 ++-- lib/Github/Api/CurrentUser/Emails.php | 4 ++-- lib/Github/Api/CurrentUser/Memberships.php | 4 ++++ lib/Github/Api/CurrentUser/Notifications.php | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/DeployKeys.php index d4f8b080d77..66b51033da5 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/DeployKeys.php @@ -44,7 +44,7 @@ public function show($id) * * @param array $params * - * @throws MissingArgumentException + * @throws \Github\Exception\MissingArgumentException * * @return array */ @@ -65,7 +65,7 @@ public function create(array $params) * @param string $id * @param array $params * - * @throws MissingArgumentException + * @throws \Github\Exception\MissingArgumentException * * @return array */ diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index 587aa12c744..9a1ce1e6c6d 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -30,7 +30,7 @@ public function all() * * @param string|array $emails * - * @throws InvalidArgumentException + * @throws \Github\Exception\InvalidArgumentException * * @return array */ @@ -52,7 +52,7 @@ public function add($emails) * * @param string|array $emails * - * @throws InvalidArgumentException + * @throws \Github\Exception\InvalidArgumentException * * @return array */ diff --git a/lib/Github/Api/CurrentUser/Memberships.php b/lib/Github/Api/CurrentUser/Memberships.php index c02c0122ef6..650b348ad9f 100644 --- a/lib/Github/Api/CurrentUser/Memberships.php +++ b/lib/Github/Api/CurrentUser/Memberships.php @@ -23,6 +23,8 @@ public function all() * * @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership * + * @param string $organization + * * @return array */ public function organization($organization) @@ -35,6 +37,8 @@ public function organization($organization) * * @link https://developer.github.com/v3/orgs/members/#edit-your-organization-membership * + * @param string $organization + * * @return array */ public function edit($organization) diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index 92dc0a570c9..fa575eb8e21 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -41,6 +41,8 @@ public function allInRepository($username, $repository, array $params = array()) } /** + * Mark all notifications as read. + * * @link http://developer.github.com/v3/activity/notifications/#mark-as-read * * @param array $params @@ -53,6 +55,8 @@ public function markAsReadAll(array $params = array()) } /** + * Mark all notifications for a repository as read. + * * @link http://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository * * @param string $username the user who owns the repo @@ -67,6 +71,8 @@ public function markAsReadInRepository($username, $repository, array $params = a } /** + * Mark a notification as read. + * * @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read * * @param string $id the notification number @@ -80,6 +86,8 @@ public function markAsRead($id, array $params) } /** + * Show a notification. + * * @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread * * @param string $id the notification number @@ -92,6 +100,8 @@ public function show($id) } /** + * Show a subscription. + * * @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription * * @param string $id the notification number @@ -104,6 +114,8 @@ public function showSubscription($id) } /** + * Create a subscription. + * * @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription * * @param string $id the notification number @@ -117,6 +129,8 @@ public function createSubscription($id, array $params) } /** + * Delete a subscription. + * * @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription * * @param string $id the notification number From 833124a116eac05fa19e5c236523162add8776fa Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Jul 2015 17:09:39 +0200 Subject: [PATCH 296/951] Add docblocks for gist comments --- lib/Github/Api/Gist/Comments.php | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index f565f737908..7db73e59b29 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -10,26 +10,66 @@ */ class Comments extends AbstractApi { + /** + * Get all comments for a gist. + * + * @param string $gist + * + * @return array + */ public function all($gist) { return $this->get('gists/'.rawurlencode($gist).'/comments'); } + /** + * Get a comment of a gist. + * + * @param string $gist + * @param int $comment + * + * @return array + */ public function show($gist, $comment) { return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } + /** + * Create a comment for gist. + * + * @param string $gist + * @param string $body + * + * @return array + */ public function create($gist, $body) { return $this->post('gists/'.rawurlencode($gist).'/comments', array('body' => $body)); } + /** + * Create a comment for a gist. + * + * @param string $gist + * @param int $comment_id + * @param string $body + * + * @return array + */ public function update($gist, $comment_id, $body) { return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array('body' => $body)); } + /** + * Delete a comment for a gist. + * + * @param string $gist + * @param int $comment + * + * @return array + */ public function remove($gist, $comment) { return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); From b5d61c34e42dce03a5ba38659dddbf1fcc4d64ab Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Jul 2015 17:26:40 +0200 Subject: [PATCH 297/951] Add docblocks for git data --- lib/Github/Api/GitData/Blobs.php | 25 ++++++++++ lib/Github/Api/GitData/Commits.php | 20 ++++++++ lib/Github/Api/GitData/References.php | 72 +++++++++++++++++++++++++++ lib/Github/Api/GitData/Tags.php | 28 +++++++++++ lib/Github/Api/GitData/Trees.php | 21 ++++++++ 5 files changed, 166 insertions(+) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index 2ff844db24a..fe9cfc6123a 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -11,6 +11,11 @@ */ class Blobs extends AbstractApi { + /** + * Configure the Acccept header depending on the blob type. + * + * @param string|null $bodyType + */ public function configure($bodyType = null) { if ('raw' == $bodyType) { @@ -20,6 +25,15 @@ public function configure($bodyType = null) } } + /** + * Show a blob of a sha for a repository. + * + * @param string $username + * @param string $repository + * @param string $sha + * + * @return array + */ public function show($username, $repository, $sha) { $response = $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha)); @@ -27,6 +41,17 @@ public function show($username, $repository, $sha) return $response; } + /** + * Create a blob of a sha for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['content'], $params['encoding'])) { diff --git a/lib/Github/Api/GitData/Commits.php b/lib/Github/Api/GitData/Commits.php index 1c161e1d790..f2f5d217cda 100644 --- a/lib/Github/Api/GitData/Commits.php +++ b/lib/Github/Api/GitData/Commits.php @@ -11,11 +11,31 @@ */ class Commits extends AbstractApi { + /** + * Show a commit for a repository. + * + * @param string $username + * @param string $repository + * @param string $sha + * + * @return array + */ public function show($username, $repository, $sha) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits/'.rawurlencode($sha)); } + /** + * Create a commit for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['message'], $params['tree'], $params['parents'])) { diff --git a/lib/Github/Api/GitData/References.php b/lib/Github/Api/GitData/References.php index 582900a57d5..3277b79e2b7 100644 --- a/lib/Github/Api/GitData/References.php +++ b/lib/Github/Api/GitData/References.php @@ -11,21 +11,54 @@ */ class References extends AbstractApi { + /** + * Get all references of a repository. + * + * @param string $username + * @param string $repository + * + * @return array + */ public function all($username, $repository) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs'); } + /** + * Get all branches of a repository. + * + * @param string $username + * @param string $repository + * + * @return array + */ public function branches($username, $repository) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads'); } + /** + * Get all tags of a repository. + * + * @param string $username + * @param string $repository + * + * @return array + */ public function tags($username, $repository) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } + /** + * Show the reference of a repository. + * + * @param string $username + * @param string $repository + * @param string $reference + * + * @return array + */ public function show($username, $repository, $reference) { $reference = $this->encodeReference($reference); @@ -33,6 +66,17 @@ public function show($username, $repository, $reference) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); } + /** + * Create a reference for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['ref'], $params['sha'])) { @@ -42,6 +86,18 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params); } + /** + * Update a reference for a repository. + * + * @param string $username + * @param string $repository + * @param string $reference + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function update($username, $repository, $reference, array $params) { if (!isset($params['sha'])) { @@ -53,6 +109,15 @@ public function update($username, $repository, $reference, array $params) return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params); } + /** + * Delete a reference of a repository. + * + * @param string $username + * @param string $repository + * @param string $reference + * + * @return array + */ public function remove($username, $repository, $reference) { $reference = $this->encodeReference($reference); @@ -60,6 +125,13 @@ public function remove($username, $repository, $reference) return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); } + /** + * Encode the raw reference. + * + * @param string $rawReference + * + * @return string + */ private function encodeReference($rawReference) { return implode('/', array_map('rawurlencode', explode('/', $rawReference))); diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index b27dddd12f4..4b2d0341ef3 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -11,16 +11,44 @@ */ class Tags extends AbstractApi { + /** + * Get all tags for a repository. + * + * @param string $username + * @param string $repository + * + * @return array + */ public function all($username, $repository) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } + /** + * Get a tag for a repository. + * + * @param string $username + * @param string $repository + * @param string $sha + * + * @return array + */ public function show($username, $repository, $sha) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags/'.rawurlencode($sha)); } + /** + * Create a tag for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['tag'], $params['message'], $params['object'], $params['type'])) { diff --git a/lib/Github/Api/GitData/Trees.php b/lib/Github/Api/GitData/Trees.php index 92bd21ac433..3ce35a476ac 100644 --- a/lib/Github/Api/GitData/Trees.php +++ b/lib/Github/Api/GitData/Trees.php @@ -11,11 +11,32 @@ */ class Trees extends AbstractApi { + /** + * Get the tree for a repository. + * + * @param string $username + * @param string $repository + * @param string $sha + * @param bool $recursive + * + * @return array + */ public function show($username, $repository, $sha, $recursive = false) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), array('recursive' => $recursive ? 1 : null)); } + /** + * Create tree for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['tree']) || !is_array($params['tree'])) { From 83e368353ce760c0189e1ee9b52c9c4d084eb518 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 30 Jul 2015 09:10:25 +0200 Subject: [PATCH 298/951] Fix "update milestone" documentation --- doc/issue/milestones.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issue/milestones.md b/doc/issue/milestones.md index 59ef47cb629..25ead337894 100644 --- a/doc/issue/milestones.md +++ b/doc/issue/milestones.md @@ -24,7 +24,7 @@ $milestone = $client->api('issue')->milestones()->create('KnpLabs', 'php-github- ### Update a milestone ```php -$milestone = $client->api('issue')->milestones()->update('KnpLabs', 'php-github-api', 123); +$milestone = $client->api('issue')->milestones()->update('KnpLabs', 'php-github-api', 123, array('title' => '3.0')); ``` ### Remove a milestonre From 433380b9396ba1f7bec04bd780fa7da29e06e5e1 Mon Sep 17 00:00:00 2001 From: Emerson Loustau Date: Wed, 5 Aug 2015 09:27:26 -0400 Subject: [PATCH 299/951] mention search api in issues.md --- doc/issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issues.md b/doc/issues.md index 983bf5ec53b..547e885665a 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -23,7 +23,7 @@ Returns an array of issues. $issues = $client->api('issue')->find('KnpLabs', 'php-github-api', 'closed', 'bug'); ``` -Returns an array of closed issues matching the "bug" term. +Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](/search.md) which supports the advanced github search syntax. ### Get information about an issue From 1a2cbe6dc1d7addbb94b7ff863f2ce9621529c97 Mon Sep 17 00:00:00 2001 From: Emerson Loustau Date: Wed, 5 Aug 2015 09:30:59 -0400 Subject: [PATCH 300/951] fixed url --- doc/issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issues.md b/doc/issues.md index 547e885665a..02b2c840a61 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -23,7 +23,7 @@ Returns an array of issues. $issues = $client->api('issue')->find('KnpLabs', 'php-github-api', 'closed', 'bug'); ``` -Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](/search.md) which supports the advanced github search syntax. +Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](/doc/search.md) which supports the advanced github search syntax. ### Get information about an issue From 9fcb9f1f1da5984b245810d10da6fd6fe67ebd35 Mon Sep 17 00:00:00 2001 From: emersonthis Date: Wed, 5 Aug 2015 12:31:26 -0400 Subject: [PATCH 301/951] relative link --- doc/issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issues.md b/doc/issues.md index 02b2c840a61..7188661c358 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -23,7 +23,7 @@ Returns an array of issues. $issues = $client->api('issue')->find('KnpLabs', 'php-github-api', 'closed', 'bug'); ``` -Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](/doc/search.md) which supports the advanced github search syntax. +Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](../search.md) which supports the advanced github search syntax. ### Get information about an issue From 8a2a93b5f54ace91bb2c8d2c0c8d0f9479a6ee12 Mon Sep 17 00:00:00 2001 From: emersonthis Date: Wed, 5 Aug 2015 12:32:01 -0400 Subject: [PATCH 302/951] Update issues.md --- doc/issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issues.md b/doc/issues.md index 7188661c358..ab00f189ab9 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -23,7 +23,7 @@ Returns an array of issues. $issues = $client->api('issue')->find('KnpLabs', 'php-github-api', 'closed', 'bug'); ``` -Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](../search.md) which supports the advanced github search syntax. +Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](search.md) which supports the advanced github search syntax. ### Get information about an issue From 8b3050b9fe2e544149169a2d468b7e4823d67384 Mon Sep 17 00:00:00 2001 From: emersonthis Date: Wed, 5 Aug 2015 18:58:11 -0400 Subject: [PATCH 303/951] Update issues.md --- doc/issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issues.md b/doc/issues.md index ab00f189ab9..67ff9556a4b 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -23,7 +23,7 @@ Returns an array of issues. $issues = $client->api('issue')->find('KnpLabs', 'php-github-api', 'closed', 'bug'); ``` -Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](search.md) which supports the advanced github search syntax. +Returns an array of closed issues matching the "bug" term. For more complex searches, use the [search api](search.md) which supports the advanced GitHub search syntax. ### Get information about an issue From 3bff763ed3eb6ae9c7716e47df41592f219cd171 Mon Sep 17 00:00:00 2001 From: Karin van den Berg Date: Thu, 6 Aug 2015 11:06:33 +0200 Subject: [PATCH 304/951] Add functionality for Organization:Issues --- lib/Github/Api/Organization.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index a506702dae3..017b514ec5f 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -74,4 +74,18 @@ public function teams() { return new Teams($this->client); } + + /** + * @link http://developer.github.com/v3/issues/#list-issues + * + * @param $organization + * @param array $params + * @param int $page + * + * @return array + */ + public function issues($organization, array $params = array(), $page = 1) + { + return $this->get('orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => $page), $params)); + } } From d092f10b5c8d63685f470dbedda26730f089a086 Mon Sep 17 00:00:00 2001 From: Karin van den Berg Date: Thu, 6 Aug 2015 11:32:05 +0200 Subject: [PATCH 305/951] Update docs --- doc/organization.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/organization.md b/doc/organization.md index 3a1ee9434e7..5fdbb820888 100644 --- a/doc/organization.md +++ b/doc/organization.md @@ -7,4 +7,22 @@ Additional APIs: * [Members API](organization/members.md) * [Teams API](organization/teams.md) + +Wraps [GitHub Issues API](https://developer.github.com/v3/issues/). + +### List issues in an organization + +```php +$issues = $client->api('orgs')->issues('KnpLabs', 'php-github-api', array('state' => 'open')); +``` +You can specify the page number: + +```php +$issues = $client->api('orgs')->issues('KnpLabs', 'php-github-api', array('state' => 'open'), 2); +``` + +Returns an array of issues. + + + To be written... From 059603df2131f2a8ec5aad14694dd94cff5a491e Mon Sep 17 00:00:00 2001 From: Karin van den Berg Date: Thu, 6 Aug 2015 11:33:28 +0200 Subject: [PATCH 306/951] Doc improvement --- doc/organization.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/organization.md b/doc/organization.md index 5fdbb820888..1ae32e69f0d 100644 --- a/doc/organization.md +++ b/doc/organization.md @@ -7,10 +7,8 @@ Additional APIs: * [Members API](organization/members.md) * [Teams API](organization/teams.md) - -Wraps [GitHub Issues API](https://developer.github.com/v3/issues/). - ### List issues in an organization +[GitHub Issues API](https://developer.github.com/v3/issues/). ```php $issues = $client->api('orgs')->issues('KnpLabs', 'php-github-api', array('state' => 'open')); From 859b6e6286f3659d2618c40b0e660294b06352ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lecerf?= Date: Thu, 20 Aug 2015 01:36:50 +0200 Subject: [PATCH 307/951] [fix] Copy-paste mistake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doc is about the ‘Meta’ API, not the ‘User’ one. --- doc/meta.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/meta.md b/doc/meta.md index 06cb7b8681f..fb3d579f1d9 100644 --- a/doc/meta.md +++ b/doc/meta.md @@ -1,8 +1,8 @@ -## Users API +## Meta API [Back to the navigation](README.md) -Wrap [GitHub User API](http://developer.github.com/v3/meta/). +Wrap [GitHub Meta API](http://developer.github.com/v3/meta/). ### Get information about GitHub services From 7a8417b4891ef63e2912a0c6cb306fb84c8f56d0 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Jul 2015 19:28:03 +0200 Subject: [PATCH 308/951] Work on milestones --- lib/Github/Api/Issue/Comments.php | 60 +++++++++++++++++-- lib/Github/Api/Issue/Events.php | 25 ++++++-- lib/Github/Api/Issue/Labels.php | 89 ++++++++++++++++++++++++++++- lib/Github/Api/Issue/Milestones.php | 64 ++++++++++++++++++++- 4 files changed, 225 insertions(+), 13 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index ae6370fc660..cf6b7ac32f6 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -11,28 +11,42 @@ */ class Comments extends AbstractApi { + /** + * Configure the body type. + * + * @param string $bodyType + */ public function configure($bodyType = null) { switch ($bodyType) { case 'raw': - $header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.raw+json';; break; case 'text': - $header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.text+json'; break; case 'html': - $header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.html+json'; break; default: - $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.full+json'; } - $this->client->setHeaders(array($header)); + $this->client->setHeaders(array(sprintf($header, $this->client->getOption('api_version')))); } + /** + * Get all comments for an issue. + * + * @param string g$username + * @param string $repository + * @param int $issue + * @param int $page + * @return array + */ public function all($username, $repository, $issue, $page = 1) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array( @@ -40,11 +54,29 @@ public function all($username, $repository, $issue, $page = 1) )); } + /** + * Get a comment for an issue. + * + * @param string $username + * @param string $repository + * @param int $comment + * @return array + */ public function show($username, $repository, $comment) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); } + /** + * Create a comment for an issue. + * + * @param string $username + * @param string $repository + * @param int $issue + * @param array $params + * @return array + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, $issue, array $params) { if (!isset($params['body'])) { @@ -54,6 +86,16 @@ public function create($username, $repository, $issue, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params); } + /** + * Update a comment for an issue. + * + * @param string $username + * @param string $repository + * @param int $comment + * @param array $params + * @return array + * @throws \Github\Exception\MissingArgumentException + */ public function update($username, $repository, $comment, array $params) { if (!isset($params['body'])) { @@ -63,6 +105,14 @@ public function update($username, $repository, $comment, array $params) return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params); } + /** + * Delete a comment for an issue. + * + * @param string $username + * @param string $repository + * @param int $comment + * @return array + */ public function remove($username, $repository, $comment) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 17bcef83921..33387908759 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -10,19 +10,36 @@ */ class Events extends AbstractApi { + /** + * Get all events for an issue. + * + * @param string $username + * @param string $repository + * @param int|null $issue + * @param int $page + * @return array + */ public function all($username, $repository, $issue = null, $page = 1) { if (null !== $issue) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events', array( - 'page' => $page - )); + $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events'; + } else { + $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events', array( + return $this->get($path, array( 'page' => $page )); } + /** + * Display an event for an issue. + * + * @param $username + * @param $repository + * @param $event + * @return array + */ public function show($username, $repository, $event) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event)); diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index bdce1437186..d65e2fb97f0 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -12,15 +12,37 @@ */ class Labels extends AbstractApi { + /** + * Get all labels for a repository or the labels for a specific issue. + * + * @param string $username + * @param string $repository + * @param int|null $issue + * + * @return array + */ public function all($username, $repository, $issue = null) { if ($issue === null) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'); + $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'; + } else { + $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); + return $this->get($path); } + /** + * Create a label for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['name'])) { @@ -33,21 +55,53 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } + /** + * Delete a label for a repository. + * + * @param string $username + * @param string $repository + * @param string $label + * + * @return array + */ public function deleteLabel($username, $repository, $label) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } + /** + * Edit a label for a repository + * + * @param string $username + * @param string $repository + * @param string $label + * @param string $newName + * @param string $color + * + * @return array + */ public function update($username, $repository, $label, $newName, $color) { $params = array( - 'name' => $newName, + 'name' => $newName, 'color' => $color, ); return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); } + /** + * Add a label to an issue. + * + * @param string $username + * @param string $repository + * @param int $issue + * @param string $labels + * + * @return array + * + * @thorws \Github\Exception\InvalidArgumentException + */ public function add($username, $repository, $issue, $labels) { if (is_string($labels)) { @@ -59,16 +113,45 @@ public function add($username, $repository, $issue, $labels) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels); } + /** + * Replace labels for an issue. + * + * @param string $username + * @param string $repository + * @param int $issue + * @param array $params + * + * @return array + */ public function replace($username, $repository, $issue, array $params) { return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params); } + /** + * Remove a label for an issue + * + * @param string $username + * @param string $repository + * @param string $issue + * @param string $label + * + * @return null + */ public function remove($username, $repository, $issue, $label) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label)); } + /** + * Remove all labels from an issue. + * + * @param string $username + * @param string $repository + * @param string $issue + * + * @return null + */ public function clear($username, $repository, $issue) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 049e2b35a33..87a2df52eb8 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -11,6 +11,15 @@ */ class Milestones extends AbstractApi { + /** + * Get all milestones for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + */ public function all($username, $repository, array $params = array()) { if (isset($params['state']) && !in_array($params['state'], array('open', 'closed', 'all'))) { @@ -23,14 +32,39 @@ public function all($username, $repository, array $params = array()) $params['direction'] = 'desc'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc'), $params)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array( + 'page' => 1, + 'state' => 'open', + 'sort' => 'due_date', + 'direction' => 'desc' + ), $params)); } + /** + * Get a milestone for a repository. + * + * @param string $username + * @param string $repository + * @param int $id + * + * @return array + */ public function show($username, $repository, $id) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } + /** + * Create a milestone for a repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + * + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, array $params) { if (!isset($params['title'])) { @@ -43,6 +77,16 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); } + /** + * Update a milestone for a repository. + * + * @param string $username + * @param string $repository + * @param int $id + * @param array $params + * + * @return array + */ public function update($username, $repository, $id, array $params) { if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { @@ -52,11 +96,29 @@ public function update($username, $repository, $id, array $params) return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params); } + /** + * Delete a milestone for a repository. + * + * @param string $username + * @param string $repository + * @param int $id + * + * @return null + */ public function remove($username, $repository, $id) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } + /** + * Get the labels of a milestone + * + * @param string $username + * @param string $repository + * @param int $id + * + * @return array + */ public function labels($username, $repository, $id) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels'); From 0dbf9e792551507fa8afdf9c573ad9d62bf5d526 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 09:14:55 +0200 Subject: [PATCH 309/951] Some fixes --- lib/Github/Api/Issue/Comments.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index cf6b7ac32f6..87ce579f970 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -14,13 +14,13 @@ class Comments extends AbstractApi /** * Configure the body type. * - * @param string $bodyType + * @param string|null $bodyType */ public function configure($bodyType = null) { switch ($bodyType) { case 'raw': - $header = 'Accept: application/vnd.github.%s.raw+json';; + $header = 'Accept: application/vnd.github.%s.raw+json'; break; case 'text': @@ -41,10 +41,11 @@ public function configure($bodyType = null) /** * Get all comments for an issue. * - * @param string g$username + * @param string $username * @param string $repository * @param int $issue * @param int $page + * * @return array */ public function all($username, $repository, $issue, $page = 1) @@ -60,6 +61,7 @@ public function all($username, $repository, $issue, $page = 1) * @param string $username * @param string $repository * @param int $comment + * * @return array */ public function show($username, $repository, $comment) @@ -74,8 +76,9 @@ public function show($username, $repository, $comment) * @param string $repository * @param int $issue * @param array $params - * @return array + * * @throws \Github\Exception\MissingArgumentException + * @return array */ public function create($username, $repository, $issue, array $params) { @@ -93,8 +96,9 @@ public function create($username, $repository, $issue, array $params) * @param string $repository * @param int $comment * @param array $params - * @return array + * * @throws \Github\Exception\MissingArgumentException + * @return array */ public function update($username, $repository, $comment, array $params) { @@ -111,6 +115,7 @@ public function update($username, $repository, $comment, array $params) * @param string $username * @param string $repository * @param int $comment + * * @return array */ public function remove($username, $repository, $comment) From d6690ee93b50a417f6dc76cda29e9b608d93b517 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 09:28:25 +0200 Subject: [PATCH 310/951] Refactor setHeaders --- lib/Github/Api/Issue/Comments.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 87ce579f970..8789bec439a 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -18,24 +18,13 @@ class Comments extends AbstractApi */ public function configure($bodyType = null) { - switch ($bodyType) { - case 'raw': - $header = 'Accept: application/vnd.github.%s.raw+json'; - break; - - case 'text': - $header = 'Accept: application/vnd.github.%s.text+json'; - break; - - case 'html': - $header = 'Accept: application/vnd.github.%s.html+json'; - break; - - default: - $header = 'Accept: application/vnd.github.%s.full+json'; + if (!in_array($bodyType, array('raw', 'text', 'html'))) { + $bodyType = 'full'; } - $this->client->setHeaders(array(sprintf($header, $this->client->getOption('api_version')))); + $this->client->setHeaders(array( + sprintf('Accept: application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType) + )); } /** From 26b738ce67e4cb891ea4fc069a2e894835c4b38d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 10:00:31 +0200 Subject: [PATCH 311/951] Add API @link --- lib/Github/Api/Issue/Comments.php | 6 ++++++ lib/Github/Api/Issue/Events.php | 2 ++ lib/Github/Api/Issue/Labels.php | 6 ++++++ lib/Github/Api/Issue/Milestones.php | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 8789bec439a..ad6a95d633b 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -14,6 +14,7 @@ class Comments extends AbstractApi /** * Configure the body type. * + * @link https://developer.github.com/v3/issues/comments/#custom-media-types * @param string|null $bodyType */ public function configure($bodyType = null) @@ -30,6 +31,7 @@ public function configure($bodyType = null) /** * Get all comments for an issue. * + * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue * @param string $username * @param string $repository * @param int $issue @@ -47,6 +49,7 @@ public function all($username, $repository, $issue, $page = 1) /** * Get a comment for an issue. * + * @link https://developer.github.com/v3/issues/comments/#get-a-single-comment * @param string $username * @param string $repository * @param int $comment @@ -61,6 +64,7 @@ public function show($username, $repository, $comment) /** * Create a comment for an issue. * + * @link https://developer.github.com/v3/issues/comments/#create-a-comment * @param string $username * @param string $repository * @param int $issue @@ -81,6 +85,7 @@ public function create($username, $repository, $issue, array $params) /** * Update a comment for an issue. * + * @link https://developer.github.com/v3/issues/comments/#edit-a-comment * @param string $username * @param string $repository * @param int $comment @@ -101,6 +106,7 @@ public function update($username, $repository, $comment, array $params) /** * Delete a comment for an issue. * + * @link https://developer.github.com/v3/issues/comments/#delete-a-comment * @param string $username * @param string $repository * @param int $comment diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 33387908759..1fa5dc502e3 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -13,6 +13,7 @@ class Events extends AbstractApi /** * Get all events for an issue. * + * @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue * @param string $username * @param string $repository * @param int|null $issue @@ -35,6 +36,7 @@ public function all($username, $repository, $issue = null, $page = 1) /** * Display an event for an issue. * + * @link https://developer.github.com/v3/issues/events/#get-a-single-event * @param $username * @param $repository * @param $event diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index d65e2fb97f0..075597ed50f 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -15,6 +15,7 @@ class Labels extends AbstractApi /** * Get all labels for a repository or the labels for a specific issue. * + * @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue * @param string $username * @param string $repository * @param int|null $issue @@ -58,6 +59,7 @@ public function create($username, $repository, array $params) /** * Delete a label for a repository. * + * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue * @param string $username * @param string $repository * @param string $label @@ -93,6 +95,7 @@ public function update($username, $repository, $label, $newName, $color) /** * Add a label to an issue. * + * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue * @param string $username * @param string $repository * @param int $issue @@ -116,6 +119,7 @@ public function add($username, $repository, $issue, $labels) /** * Replace labels for an issue. * + * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue * @param string $username * @param string $repository * @param int $issue @@ -131,6 +135,7 @@ public function replace($username, $repository, $issue, array $params) /** * Remove a label for an issue * + * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue * @param string $username * @param string $repository * @param string $issue @@ -146,6 +151,7 @@ public function remove($username, $repository, $issue, $label) /** * Remove all labels from an issue. * + * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue * @param string $username * @param string $repository * @param string $issue diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 87a2df52eb8..55ba6fed998 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -14,6 +14,7 @@ class Milestones extends AbstractApi /** * Get all milestones for a repository. * + * @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository * @param string $username * @param string $repository * @param array $params @@ -43,6 +44,7 @@ public function all($username, $repository, array $params = array()) /** * Get a milestone for a repository. * + * @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone * @param string $username * @param string $repository * @param int $id @@ -57,6 +59,7 @@ public function show($username, $repository, $id) /** * Create a milestone for a repository. * + * @link https://developer.github.com/v3/issues/milestones/#create-a-milestone * @param string $username * @param string $repository * @param array $params @@ -80,6 +83,7 @@ public function create($username, $repository, array $params) /** * Update a milestone for a repository. * + * @link https://developer.github.com/v3/issues/milestones/#update-a-milestone * @param string $username * @param string $repository * @param int $id @@ -99,6 +103,7 @@ public function update($username, $repository, $id, array $params) /** * Delete a milestone for a repository. * + * @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone * @param string $username * @param string $repository * @param int $id @@ -113,6 +118,7 @@ public function remove($username, $repository, $id) /** * Get the labels of a milestone * + * @link https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone * @param string $username * @param string $repository * @param int $id From a623cb15ce677e322318b6f86397c284e054dd4b Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 11:33:27 +0200 Subject: [PATCH 312/951] Add missing API @link --- lib/Github/Api/Issue/Labels.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 075597ed50f..0a67445d4e3 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -36,6 +36,7 @@ public function all($username, $repository, $issue = null) /** * Create a label for a repository. * + * @link https://developer.github.com/v3/issues/labels/#create-a-label * @param string $username * @param string $repository * @param array $params @@ -74,6 +75,7 @@ public function deleteLabel($username, $repository, $label) /** * Edit a label for a repository * + * @link https://developer.github.com/v3/issues/labels/#update-a-label * @param string $username * @param string $repository * @param string $label From 9ee0672fdcf4bfe16c152ddad2b59a685c6f890b Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Sat, 26 Sep 2015 11:50:40 -0700 Subject: [PATCH 313/951] Added rate limit endpoint and tests --- lib/Github/Api/RateLimit.php | 46 +++++++++++++++++++ lib/Github/Client.php | 6 +++ test/Github/Tests/Api/RateLimitTest.php | 41 +++++++++++++++++ .../Github/Tests/Functional/RateLimitTest.php | 22 +++++++++ 4 files changed, 115 insertions(+) create mode 100644 lib/Github/Api/RateLimit.php create mode 100644 test/Github/Tests/Api/RateLimitTest.php create mode 100644 test/Github/Tests/Functional/RateLimitTest.php diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php new file mode 100644 index 00000000000..13f3a156725 --- /dev/null +++ b/lib/Github/Api/RateLimit.php @@ -0,0 +1,46 @@ + + */ +class RateLimit extends AbstractApi +{ + + /** + * Get rate limits + * + * @return \Guzzle\Http\EntityBodyInterface|mixed|string + */ + public function getRateLimits() + { + return $this->get('rate_limit'); + } + + /** + * Get core rate limit + * + * @return integer + */ + public function getCoreLimit() + { + $response = $this->getRateLimits(); + return $response['resources']['core']['limit']; + } + + /** + * Get search rate limit + * + * @return integer + */ + public function getSearchLimit() + { + $response = $this->getRateLimits(); + return $response['resources']['search']['limit']; + } + +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index fd3be2e088e..c1a17169dc6 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -29,6 +29,7 @@ * @method Api\PullRequest pr() * @method Api\PullRequest pullRequest() * @method Api\PullRequest pullRequests() + * @method Api\RateLimit ratelimit() * @method Api\Repo repo() * @method Api\Repo repos() * @method Api\Repo repository() @@ -168,6 +169,11 @@ public function api($name) $api = new Api\PullRequest($this); break; + case 'rateLimit': + case 'rate_limit': + $api = new Api\RateLimit($this); + break; + case 'repo': case 'repos': case 'repository': diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php new file mode 100644 index 00000000000..f3b2b4dba5b --- /dev/null +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -0,0 +1,41 @@ + [ + 'core' => [ + 'limit' => 5000, + 'remaining' => 4999, + 'reset' => 1372700873 + ], + 'search' => [ + 'limit' => 30, + 'remaining' => 18, + 'reset' => 1372697452 + ] + ] + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('rate_limit') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->getRateLimits()); + } + + protected function getApiClass() + { + return 'Github\Api\RateLimit'; + } +} \ No newline at end of file diff --git a/test/Github/Tests/Functional/RateLimitTest.php b/test/Github/Tests/Functional/RateLimitTest.php new file mode 100644 index 00000000000..3447db3ff8d --- /dev/null +++ b/test/Github/Tests/Functional/RateLimitTest.php @@ -0,0 +1,22 @@ +client->api('rate_limit')->getRateLimits(); + + $this->assertArrayHasKey('resources', $response); + $this->assertArraySubset(['resources' => ['core' => ['limit' => 60]]], $response); + + } + +} From cf0a6d4aa84118bc847fd2a1f8d0b94594b6f6c4 Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Sat, 26 Sep 2015 12:03:14 -0700 Subject: [PATCH 314/951] added documentation --- doc/rate_limits.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 doc/rate_limits.md diff --git a/doc/rate_limits.md b/doc/rate_limits.md new file mode 100644 index 00000000000..123e403abf8 --- /dev/null +++ b/doc/rate_limits.md @@ -0,0 +1,23 @@ +## Rate Limit API +[Back to the navigation](README.md) + +Get Rate Limit +Wraps [GitHub Rate Limit API](http://developer.github.com/v3/rate_limit/). + +#### Get All Rate Limits. + +```php +$rateLimits = $github->api('rate_limit')->getRateLimits(); +``` + +#### Get Core Rate Limit + +```php +$coreLimit = $github->api('rate_limit')->getCoreLimit(); +``` + +#### Get Search Rate Limit + +```php +$searchLimit = $github->api('rate_limit)->getSearchLimit'); +``` From 8733443f02d3375340eb14cb3f22cb344c4e9492 Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Sat, 26 Sep 2015 12:10:37 -0700 Subject: [PATCH 315/951] style updates from styleci check --- lib/Github/Api/RateLimit.php | 2 -- test/Github/Tests/Api/RateLimitTest.php | 16 ++++++++-------- test/Github/Tests/Functional/RateLimitTest.php | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index 13f3a156725..e66724788ca 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -10,7 +10,6 @@ */ class RateLimit extends AbstractApi { - /** * Get rate limits * @@ -42,5 +41,4 @@ public function getSearchLimit() $response = $this->getRateLimits(); return $response['resources']['search']['limit']; } - } diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index f3b2b4dba5b..d5632d35c65 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -10,20 +10,20 @@ class RateLimitTest extends TestCase */ public function shouldReturnRateLimitArray() { - $expectedArray = [ - 'resources' => [ - 'core' => [ + $expectedArray = array( + 'resources' => array( + 'core' => array( 'limit' => 5000, 'remaining' => 4999, 'reset' => 1372700873 - ], - 'search' => [ + ), + 'search' => array( 'limit' => 30, 'remaining' => 18, 'reset' => 1372697452 - ] - ] - ]; + ) + ) + ); $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Functional/RateLimitTest.php b/test/Github/Tests/Functional/RateLimitTest.php index 3447db3ff8d..6bc0eb2f053 100644 --- a/test/Github/Tests/Functional/RateLimitTest.php +++ b/test/Github/Tests/Functional/RateLimitTest.php @@ -15,7 +15,7 @@ public function shouldRetrievedRateLimits() $response = $this->client->api('rate_limit')->getRateLimits(); $this->assertArrayHasKey('resources', $response); - $this->assertArraySubset(['resources' => ['core' => ['limit' => 60]]], $response); + $this->assertArraySubset(array('resources' => array('core' => array('limit' => 60))), $response); } From 177e5f9bc09de18939a36e9121f54209eb2ffcaf Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Sat, 26 Sep 2015 12:10:37 -0700 Subject: [PATCH 316/951] Style updates from Styleci check --- lib/Github/Api/RateLimit.php | 2 -- test/Github/Tests/Api/RateLimitTest.php | 18 +++++++++--------- test/Github/Tests/Functional/RateLimitTest.php | 4 +--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index 13f3a156725..e66724788ca 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -10,7 +10,6 @@ */ class RateLimit extends AbstractApi { - /** * Get rate limits * @@ -42,5 +41,4 @@ public function getSearchLimit() $response = $this->getRateLimits(); return $response['resources']['search']['limit']; } - } diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index f3b2b4dba5b..bd917c651b6 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -4,26 +4,25 @@ class RateLimitTest extends TestCase { - /** * @test */ public function shouldReturnRateLimitArray() { - $expectedArray = [ - 'resources' => [ - 'core' => [ + $expectedArray = array( + 'resources' => array( + 'core' => array( 'limit' => 5000, 'remaining' => 4999, 'reset' => 1372700873 - ], - 'search' => [ + ), + 'search' => array( 'limit' => 30, 'remaining' => 18, 'reset' => 1372697452 - ] - ] - ]; + ) + ) + ); $api = $this->getApiMock(); $api->expects($this->once()) @@ -38,4 +37,5 @@ protected function getApiClass() { return 'Github\Api\RateLimit'; } + } \ No newline at end of file diff --git a/test/Github/Tests/Functional/RateLimitTest.php b/test/Github/Tests/Functional/RateLimitTest.php index 3447db3ff8d..b0b63704d63 100644 --- a/test/Github/Tests/Functional/RateLimitTest.php +++ b/test/Github/Tests/Functional/RateLimitTest.php @@ -15,8 +15,6 @@ public function shouldRetrievedRateLimits() $response = $this->client->api('rate_limit')->getRateLimits(); $this->assertArrayHasKey('resources', $response); - $this->assertArraySubset(['resources' => ['core' => ['limit' => 60]]], $response); - + $this->assertArraySubset(array('resources' => array('core' => array('limit' => 60))), $response); } - } From fd76633e96dd8a150dc87a9683a67ad22f4c902f Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Sat, 26 Sep 2015 12:27:26 -0700 Subject: [PATCH 317/951] updated docblock --- lib/Github/Api/RateLimit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index e66724788ca..08ff9256701 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -13,7 +13,7 @@ class RateLimit extends AbstractApi /** * Get rate limits * - * @return \Guzzle\Http\EntityBodyInterface|mixed|string + * @return array */ public function getRateLimits() { From a07bce5ff160febaeed043bd551bb15e1f280fde Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Sat, 26 Sep 2015 12:29:15 -0700 Subject: [PATCH 318/951] remove extra line --- test/Github/Tests/Api/RateLimitTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index bd917c651b6..4f1b8c467d3 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -37,5 +37,4 @@ protected function getApiClass() { return 'Github\Api\RateLimit'; } - -} \ No newline at end of file +} From 34dc5750fdb51fc2957d5d1eb4fdb91312561817 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Sun, 4 Oct 2015 16:49:30 +0200 Subject: [PATCH 319/951] Show error message if exists --- lib/Github/HttpClient/Listener/ErrorListener.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Listener/ErrorListener.php index 1f6cd5187b5..3772fbbb27a 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Listener/ErrorListener.php @@ -70,7 +70,11 @@ public function onRequestError(Event $event) break; case 'invalid': - $errors[] = sprintf('Field "%s" is invalid, for resource "%s"', $error['field'], $error['resource']); + if (isset($error['message'])) { + $errors[] = sprintf('Field "%s" is invalid, for resource "%s": "%s"', $error['field'], $error['resource'], $error['message']); + } else { + $errors[] = sprintf('Field "%s" is invalid, for resource "%s"', $error['field'], $error['resource']); + } break; case 'already_exists': From 130f962de8881379663f03e773d03ccd78dd8cb2 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Sun, 4 Oct 2015 18:44:29 +0200 Subject: [PATCH 320/951] Repo::all method --- doc/repos.md | 14 ++++++++++ lib/Github/Api/Repo.php | 17 ++++++++++++ test/Github/Tests/Api/RepoTest.php | 42 ++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index ca8a8b4da74..95cc76a310a 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -4,6 +4,20 @@ Searching repositories, getting repository information and managing repository information for authenticated users. Wrap [GitHub Repo API](http://developer.github.com/v3/repos/). All methods are described on that page. +### List all repositories + +#### Simple call + +```php +$repos = $client->api('repo')->all(); +``` + +#### Start from a specific repository id + +```php +$repos = $client->api('repo')->all(1337); +``` + ### Search repos by keyword #### Simple search diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 34d9dcbb25e..3e398fe1c98 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -39,6 +39,23 @@ public function find($keyword, array $params = array()) return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); } + /** + * List all public repositories. + * + * @link https://developer.github.com/v3/repos/#list-all-public-repositories + * + * @param int|null $id The integer ID of the last Repository that you’ve seen. + * + * @return array list of users found + */ + public function all($id = null) + { + if (!is_int($id)) { + return $this->get('repositories'); + } + return $this->get('repositories?since=' . rawurldecode($id)); + } + /** * Get the last year of commit activity for a repository grouped by week. * diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 200b9cbf447..849bfe35d10 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -58,6 +58,48 @@ public function shouldPaginateFoundRepositories() $this->assertEquals($expectedArray, $api->find('php', array('start_page' => 2))); } + /** + * @test + */ + public function shouldGetAllRepositories() + { + $expectedArray = array( + array('id' => 1, 'name' => 'dummy project'), + array('id' => 2, 'name' => 'awesome another project'), + array('id' => 3, 'name' => 'fork of php'), + array('id' => 4, 'name' => 'fork of php-cs'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetAllRepositoriesStartingIndex() + { + $expectedArray = array( + array('id' => 1, 'name' => 'dummy project'), + array('id' => 2, 'name' => 'awesome another project'), + array('id' => 3, 'name' => 'fork of php'), + array('id' => 4, 'name' => 'fork of php-cs'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repositories?since=2') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all(2)); + } + /** * @test */ From f25f066394401e7a37a14b74b37fbb0f95d4fe5d Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Sun, 4 Oct 2015 14:32:02 +0200 Subject: [PATCH 321/951] Use StyleCI Bridge --- .php_cs | 24 ++++++++++++------------ composer.json | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.php_cs b/.php_cs index 28ec2062129..49ee926957e 100644 --- a/.php_cs +++ b/.php_cs @@ -1,14 +1,14 @@ in(__DIR__); - -$fixers = array( - 'long_array_syntax', -); - -return Symfony\CS\Config\Config::create() - ->setUsingCache(true) - ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) - ->fixers($fixers) - ->finder($finder); +require __DIR__.'/vendor/autoload.php'; + +use SLLH\StyleCIBridge\ConfigBridge; + +$config = ConfigBridge::create(); +$config->setUsingCache(true); + +if (method_exists($config, 'setRiskyAllowed')) { + $config->setRiskyAllowed(true); +} + +return $config; diff --git a/composer.json b/composer.json index f44e75bcd0a..8bf4461d93d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "guzzle/guzzle": "~3.7" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.0", + "sllh/php-cs-fixer-styleci-bridge": "~1.3" }, "suggest": { "knplabs/gaufrette": "Needed for optional Gaufrette cache" From 76e10403a8f6de5b8dd6f10dda4d22f6c891e10f Mon Sep 17 00:00:00 2001 From: Einenlum Date: Wed, 7 Oct 2015 11:20:58 +0200 Subject: [PATCH 322/951] Remove the warning about releases methods --- doc/repo/releases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index de7ab130082..31f5fa5e10d 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -1,7 +1,7 @@ ## Repo / Releases API [Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) -This Github API Endpoint is currently undocumented because it's new, but works just fine. +Provides information about releases for a repository. Wraps [GitHub Releases API](https://developer.github.com/v3/repos/releases/). ### Get latest actual release From f4b35ac99aeafa1476bee8b009ee7e0f1c942568 Mon Sep 17 00:00:00 2001 From: Einenlum Date: Wed, 7 Oct 2015 11:19:15 +0200 Subject: [PATCH 323/951] Add documentation for tags methods --- doc/README.md | 1 + doc/repo/tags.md | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 doc/repo/tags.md diff --git a/doc/README.md b/doc/README.md index 890ac85e7f2..0c52de0f8b5 100644 --- a/doc/README.md +++ b/doc/README.md @@ -19,6 +19,7 @@ APIs: * [Contents](repo/contents.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) + * [Tags](repo/tags.md) * [Deployments](repo/deployments.md) * [Users](users.md) * [Meta](meta.md) diff --git a/doc/repo/tags.md b/doc/repo/tags.md new file mode 100644 index 00000000000..95e35bb0665 --- /dev/null +++ b/doc/repo/tags.md @@ -0,0 +1,8 @@ +## Repo / Tags API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List all tags + +```php +$tags = $client->api('repo')->tags('twbs', 'bootstrap'); +``` From 8775cb21c91aef2ffe350682c216c8e69c54321a Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Wed, 7 Oct 2015 08:07:32 -0700 Subject: [PATCH 324/951] Added link to rate_limits.md --- doc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/README.md b/doc/README.md index 890ac85e7f2..a1cb1291ef6 100644 --- a/doc/README.md +++ b/doc/README.md @@ -15,6 +15,7 @@ APIs: * [Teams](organization/teams.md) * [Pull Requests](pull_requests.md) * [Comments](pull_request/comments.md) +* [Rate Limits](rate_limits.md) * [Repositories](repos.md) * [Contents](repo/contents.md) * [Releases](repo/releases.md) From eca9e8c3481972ba3b992f732cccd4e56c94d260 Mon Sep 17 00:00:00 2001 From: Jeff Finley Date: Thu, 8 Oct 2015 13:48:18 -0700 Subject: [PATCH 325/951] Add blank line before return statements. --- lib/Github/Api/RateLimit.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index 08ff9256701..a07eb781a6e 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -28,6 +28,7 @@ public function getRateLimits() public function getCoreLimit() { $response = $this->getRateLimits(); + return $response['resources']['core']['limit']; } @@ -39,6 +40,7 @@ public function getCoreLimit() public function getSearchLimit() { $response = $this->getRateLimits(); + return $response['resources']['search']['limit']; } } From 5d09f4c3e75a5cca069b375815d7aa5108a4be9a Mon Sep 17 00:00:00 2001 From: Dusan Lukic Date: Fri, 9 Oct 2015 23:15:41 +0200 Subject: [PATCH 326/951] Documentation fix --- doc/organization.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/organization.md b/doc/organization.md index 1ae32e69f0d..e44c436dff3 100644 --- a/doc/organization.md +++ b/doc/organization.md @@ -11,12 +11,12 @@ Additional APIs: [GitHub Issues API](https://developer.github.com/v3/issues/). ```php -$issues = $client->api('orgs')->issues('KnpLabs', 'php-github-api', array('state' => 'open')); +$issues = $client->api('organizations')->issues('KnpLabs', 'php-github-api', array('state' => 'open')); ``` You can specify the page number: ```php -$issues = $client->api('orgs')->issues('KnpLabs', 'php-github-api', array('state' => 'open'), 2); +$issues = $client->api('organizations')->issues('KnpLabs', 'php-github-api', array('state' => 'open'), 2); ``` Returns an array of issues. From dc2c8f60ec76b9a4673b89ca463dc4bb2b64fbbc Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 8 Oct 2015 10:02:40 +0200 Subject: [PATCH 327/951] Add return fixer --- .styleci.yml | 1 + lib/Github/Api/Deployment.php | 1 + lib/Github/Api/Repository/Commits.php | 1 + lib/Github/Api/User.php | 1 + 4 files changed, 4 insertions(+) diff --git a/.styleci.yml b/.styleci.yml index e92503292bf..418a93eb0f1 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -2,3 +2,4 @@ preset: psr2 enabled: - long_array_syntax + - return diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index c86e7a073ab..eecee8d115b 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -67,6 +67,7 @@ public function updateStatus($username, $repository, $id, array $params) if (!isset($params['state'])) { throw new MissingArgumentException(array('state')); } + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); } diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 9098498684a..d8d45c73cd3 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -21,6 +21,7 @@ public function compare($username, $repository, $base, $head, $mediaType = null) if (null !== $mediaType) { $headers['Accept'] = $mediaType; } + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), array(), $headers); } diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 0cc707b0bd7..888eb9dfed4 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -39,6 +39,7 @@ public function all($id = null) if (!is_int($id)) { return $this->get('users'); } + return $this->get('users?since=' . rawurldecode($id)); } From 3f770dee69a41ad33abafd5f6ab141739705ffe8 Mon Sep 17 00:00:00 2001 From: Daniel Fahlke Date: Sun, 11 Oct 2015 22:07:38 +0200 Subject: [PATCH 328/951] use correct case for rateLimit method annotation --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c1a17169dc6..b3c9f63e266 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -29,7 +29,7 @@ * @method Api\PullRequest pr() * @method Api\PullRequest pullRequest() * @method Api\PullRequest pullRequests() - * @method Api\RateLimit ratelimit() + * @method Api\RateLimit rateLimit() * @method Api\Repo repo() * @method Api\Repo repos() * @method Api\Repo repository() From 569d4694b500ec0da676eeb544511d8509c3c5fb Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Tue, 20 Oct 2015 14:59:32 -0500 Subject: [PATCH 329/951] Removes exec bit from various random files --- LICENSE | 0 README.md | 0 lib/Github/Api/PullRequest.php | 0 test/Github/Tests/Api/PullRequestTest.php | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 LICENSE mode change 100755 => 100644 README.md mode change 100755 => 100644 lib/Github/Api/PullRequest.php mode change 100755 => 100644 test/Github/Tests/Api/PullRequestTest.php diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php old mode 100755 new mode 100644 diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php old mode 100755 new mode 100644 From 56e900b732c049611e8d7804a696b81768ffee02 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 20 Oct 2015 21:02:54 +0100 Subject: [PATCH 330/951] CS fix --- lib/Github/Api/Repo.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 3e398fe1c98..772e0d55792 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -53,6 +53,7 @@ public function all($id = null) if (!is_int($id)) { return $this->get('repositories'); } + return $this->get('repositories?since=' . rawurldecode($id)); } From 6381a8cc2839ca29b5101ff4d879a02c6bf7eb3a Mon Sep 17 00:00:00 2001 From: Giancarlo Date: Thu, 22 Oct 2015 22:18:29 -0500 Subject: [PATCH 331/951] Update rate_limits.md Change $client instead $github to match the rest of the docs --- doc/rate_limits.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/rate_limits.md b/doc/rate_limits.md index 123e403abf8..24b3894b611 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -7,17 +7,17 @@ Wraps [GitHub Rate Limit API](http://developer.github.com/v3/rate_limit/). #### Get All Rate Limits. ```php -$rateLimits = $github->api('rate_limit')->getRateLimits(); +$rateLimits = $client->api('rate_limit')->getRateLimits(); ``` #### Get Core Rate Limit ```php -$coreLimit = $github->api('rate_limit')->getCoreLimit(); +$coreLimit = $client->api('rate_limit')->getCoreLimit(); ``` #### Get Search Rate Limit ```php -$searchLimit = $github->api('rate_limit)->getSearchLimit'); +$searchLimit = $client->api('rate_limit)->getSearchLimit'); ``` From 98d402e791d3c235f24d653670d18682a63920d6 Mon Sep 17 00:00:00 2001 From: Amaury Leroux de Lens Date: Tue, 17 Nov 2015 15:29:22 +0100 Subject: [PATCH 332/951] Fix typo in searchLimit call example --- doc/rate_limits.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/rate_limits.md b/doc/rate_limits.md index 24b3894b611..d64e91be39c 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -19,5 +19,5 @@ $coreLimit = $client->api('rate_limit')->getCoreLimit(); #### Get Search Rate Limit ```php -$searchLimit = $client->api('rate_limit)->getSearchLimit'); +$searchLimit = $client->api('rate_limit')->getSearchLimit(); ``` From af12ef9dbfe69121da286f6d7e7918dd9a8d5e2a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 4 Dec 2015 18:58:43 +0000 Subject: [PATCH 333/951] Fixed broken merge function --- lib/Github/Api/PullRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 14db3bc7a60..e0bb27bfee0 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -115,10 +115,10 @@ public function merged($username, $repository, $id) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); } - public function merge($username, $repository, $id, $message = '') + public function merge($username, $repository, $id, $message, $sha) { return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', array( - 'commit_message' => $message + 'commit_message' => $message, 'sha' => $sha )); } } From 2db76fa2fce2c80b95bb0b688c6d3daff8aa5c34 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 12 Dec 2015 10:38:30 +0000 Subject: [PATCH 334/951] Updated related tests --- test/Github/Tests/Api/PullRequestTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index e35599e4448..e9b8f2dba2f 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -143,10 +143,10 @@ public function shouldMergePullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something')) + ->with('repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40))) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something')); + $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40))); } /** From 0fd7fbb44bea56a4d9a64d3214aa6c8a4436f50b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 12 Dec 2015 10:44:17 +0000 Subject: [PATCH 335/951] Run on new travis infrastructure, and on php 7.0 too --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1f4b972c7a..9dbd08d8147 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,13 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm -before_script: - - travis_retry composer self-update - - travis_retry composer install --no-interaction --prefer-source --dev +sudo: false + +install: + - travis_retry composer install --no-interaction --prefer-source script: - vendor/bin/phpunit --verbose --coverage-text From abc7a6fd5bbe0d4e555b2c890ccd187e63af0ab1 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 12 Dec 2015 10:49:43 +0000 Subject: [PATCH 336/951] Updated badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc569524322..cfac351015f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PHP GitHub API -[![Build Status](https://secure.travis-ci.org/KnpLabs/php-github-api.png)](http://travis-ci.org/KnpLabs/php-github-api) -[![StyleCI](https://styleci.io/repos/3948501/shield)](https://styleci.io/repos/3948501) +[![Build Status](https://travis-ci.org/KnpLabs/php-github-api.svg?branch=master)](https://travis-ci.org/KnpLabs/php-github-api) +[![StyleCI](https://styleci.io/repos/3948501/shield?style=flat)](https://styleci.io/repos/3948501) A simple Object Oriented wrapper for GitHub API, written with PHP5. From 0b93487445fe898b62f7eddbf4f80e87d12f4514 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 17 Dec 2015 12:25:07 +0000 Subject: [PATCH 337/951] Fixed branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8bf4461d93d..ca541c41c3b 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "1.5.x-dev" } } } From 3c435efe4fba6879eb455cb0f7ab0d85b7014d57 Mon Sep 17 00:00:00 2001 From: dantleech Date: Mon, 21 Dec 2015 18:05:28 +0100 Subject: [PATCH 338/951] Fixed link to security --- doc/organization/webhooks.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/organization/webhooks.md b/doc/organization/webhooks.md index 4844748fa20..842ebe432b4 100644 --- a/doc/organization/webhooks.md +++ b/doc/organization/webhooks.md @@ -9,7 +9,7 @@ Additional APIs: ### List webhooks for an organization -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $webhooks = $client->organization()->all('KnpLabs'); @@ -19,7 +19,7 @@ Returns an array of webhooks for the organization. ### Get a webhook for an organization -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $webhook = $client->organization()->show('KnpLabs', 123); @@ -29,7 +29,7 @@ Returns the webhook with the ID 123 as an array for the organization. ### Create a new webhook for an organization -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $webhook = $client->organization()->create('KnpLabs', array( @@ -53,7 +53,7 @@ The create webhook will be returned as an array. ### Update an existing webhook for an organization -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $success = $client->organization()->update('KnpLabs', 123, array( @@ -76,7 +76,7 @@ In case of success, an array of informations about the webhook will be returned. ### Ping a webhook for an organization -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $client->organization()->pings('KnpLabs', 123); @@ -86,10 +86,10 @@ No content is returned. ### Delete a webhook for an organization -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $client->organization()->delete('KnpLabs', 123); ``` -No content is returned. \ No newline at end of file +No content is returned. From f616334dbb2acc60056a7f2b2b149d76e9094515 Mon Sep 17 00:00:00 2001 From: Giancarlo Date: Tue, 22 Dec 2015 15:49:15 -0500 Subject: [PATCH 339/951] Missing ")" in issues.md --- doc/issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issues.md b/doc/issues.md index 67ff9556a4b..e2804277d35 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -38,7 +38,7 @@ Returns an array of information about the issue. > Requires [authentication](security.md). ```php -$client->api('issue')->create('KnpLabs', 'php-github-api', array('title' => 'The issue title', 'body' => 'The issue body'); +$client->api('issue')->create('KnpLabs', 'php-github-api', array('title' => 'The issue title', 'body' => 'The issue body')); ``` Creates a new issue in the repo "php-github-api" of the user "KnpLabs". The issue is assigned to the authenticated user. From 80897c80905e354cdab3f093e54c51c85afdcb0d Mon Sep 17 00:00:00 2001 From: Mark Biek Date: Wed, 23 Dec 2015 14:40:45 -0500 Subject: [PATCH 340/951] Added examples for manipulating repository hooks --- doc/repos.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 95cc76a310a..df504465804 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -136,6 +136,30 @@ $client->api('repo')->keys()->remove('username', 'reponame', 12345); Removes the key with id 12345 from the 'reponame' repository and returns a list of the deploy keys for the repository. +### Add a hook to a repository + +> Requires [authentication](security.md). + +```php +$client->api('repo')->hooks()->create('username', 'reponame', $params); +``` + +### Remove a hook from a repository + +> Requires [authentication](security.md). + +```php +$client->api('repo')->hooks()->remove('username', 'reponame', $id); +``` + +### Return a list of all hooks for the 'reponame' repository + +> Requires [authentication](security.md). + +```php +$client->api('repo')->hooks()->show('username', 'reponame'); +``` + ### Get the collaborators for a repository ```php From 1fd0bd30f2c4b37bdaca95e0eb781a673787066c Mon Sep 17 00:00:00 2001 From: Bill Wheeler Date: Sat, 2 Jan 2016 04:50:12 -0600 Subject: [PATCH 341/951] Add in ability to restrict Member list by role. --- lib/Github/Api/Organization/Members.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 7358ed27689..ed2f997cc86 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -10,7 +10,7 @@ */ class Members extends AbstractApi { - public function all($organization, $type = null, $filter = 'all') + public function all($organization, $type = null, $filter = 'all', $role = null) { $parameters = array(); $path = 'orgs/'.rawurlencode($organization).'/'; @@ -19,6 +19,9 @@ public function all($organization, $type = null, $filter = 'all') if (null !== $filter) { $parameters['filter'] = $filter; } + if (null !== $role) { + $parameters['role'] = $role; + } } else { $path .= 'public_members'; } From 8080a1c220885a158e73a7d86aa93ef31e7245d9 Mon Sep 17 00:00:00 2001 From: Bill Wheeler Date: Sat, 2 Jan 2016 04:54:14 -0600 Subject: [PATCH 342/951] Add in ability to get a user's membership status within an organization. --- lib/Github/Api/Organization/Members.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index ed2f997cc86..f8afeedce2c 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -34,6 +34,11 @@ public function show($organization, $username) return $this->get('orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); } + public function member($organization, $username) + { + return $this->get('orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); + } + public function check($organization, $username) { return $this->get('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); From 806455cf3b1e5d24df79ecc09ac2916b78698862 Mon Sep 17 00:00:00 2001 From: Bill Wheeler Date: Sun, 3 Jan 2016 12:13:17 -0600 Subject: [PATCH 343/951] Add method to add Member to an organization --- lib/Github/Api/Organization/Members.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index f8afeedce2c..2d11f0a426a 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -44,6 +44,11 @@ public function check($organization, $username) return $this->get('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } + public function addMember($team, $username) + { + return $this->put('orgs/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + } + public function publicize($organization, $username) { return $this->put('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); From d78c57fc5be46d3d72b113e6926b210eb5a07809 Mon Sep 17 00:00:00 2001 From: Bill Wheeler Date: Sun, 3 Jan 2016 12:21:18 -0600 Subject: [PATCH 344/951] Fix variable name --- lib/Github/Api/Organization/Members.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 2d11f0a426a..10e0fa5bb66 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -44,9 +44,9 @@ public function check($organization, $username) return $this->get('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } - public function addMember($team, $username) + public function addMember($organization, $username) { - return $this->put('orgs/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->put('orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); } public function publicize($organization, $username) From 3e66a16ae6fcd2eaffe8e9620f86e2cfe1198121 Mon Sep 17 00:00:00 2001 From: Bill Wheeler Date: Sun, 3 Jan 2016 17:42:42 -0600 Subject: [PATCH 345/951] Limit caching to GET requests only --- lib/Github/HttpClient/CachedHttpClient.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index c753fe4ab07..3a0bfdc00b2 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -68,7 +68,9 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers return $cacheResponse; } - $this->getCache()->set($this->id, $response); + if ($httpMethod == 'GET') { + $this->getCache()->set($this->id, $response); + } return $response; } From 6c27bd4b9060f8d2eb494320c00ed1c069750a69 Mon Sep 17 00:00:00 2001 From: Bill Wheeler Date: Sat, 16 Jan 2016 11:41:32 -0600 Subject: [PATCH 346/951] Add HEAD to allowed cacheable request types -- Thanks GrahamCampbell! --- lib/Github/HttpClient/CachedHttpClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index 3a0bfdc00b2..f7d363b131d 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -68,7 +68,7 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers return $cacheResponse; } - if ($httpMethod == 'GET') { + if (in_array($httpMethod, array('GET', 'HEAD'), true)) { $this->getCache()->set($this->id, $response); } From e964637654dcb0dd55c83f36cb9e19001ae9710b Mon Sep 17 00:00:00 2001 From: corbosman Date: Fri, 29 Jan 2016 16:56:31 -0400 Subject: [PATCH 347/951] list all organizations --- lib/Github/Api/Organization.php | 10 ++++++++++ test/Github/Tests/Api/OrganizationTest.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 017b514ec5f..32b5ff9e058 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -15,6 +15,16 @@ */ class Organization extends AbstractApi { + /** + * @link https://developer.github.com/v3/orgs/#list-all-organizations + * + * @return array the organizations + */ + public function all() + { + return $this->get('organizations'); + } + /** * Get extended information about an organization by its name. * diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index b1497c2f4c4..c8eed20a6f5 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -4,6 +4,22 @@ class OrganizationTest extends TestCase { + /** + * @test + */ + public function shouldGetAllOrganizations() + { + $expectedValue = array(array('login' => 'KnpLabs')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('organizations') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all()); + } + /** * @test */ From b9e639cfdb534432afa64a10fc08c1b83bc933ee Mon Sep 17 00:00:00 2001 From: corbosman Date: Sat, 30 Jan 2016 08:32:40 -0400 Subject: [PATCH 348/951] add since to organizations --- lib/Github/Api/Organization.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 32b5ff9e058..536a73c8c2e 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -20,9 +20,9 @@ class Organization extends AbstractApi * * @return array the organizations */ - public function all() + public function all($since = '') { - return $this->get('organizations'); + return $this->get('organizations?since='.rawurlencode($since)); } /** From 6e896d4300effdff1b76181c69a896e65f52fe34 Mon Sep 17 00:00:00 2001 From: corbosman Date: Sat, 30 Jan 2016 08:37:53 -0400 Subject: [PATCH 349/951] fix shouldGetAllOrganizations test --- test/Github/Tests/Api/OrganizationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index c8eed20a6f5..0a673dbb065 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -14,10 +14,10 @@ public function shouldGetAllOrganizations() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('organizations') + ->with('organizations?since=1') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all()); + $this->assertEquals($expectedValue, $api->all(1)); } /** From 15b41f46158c153e0bab852e64612b3f6b465fdc Mon Sep 17 00:00:00 2001 From: Dorell James Galang Date: Wed, 10 Feb 2016 08:04:25 +0000 Subject: [PATCH 350/951] Incorrect use of show method. Use all method instead to get all hooks in a given repo. --- doc/repos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index df504465804..df416b2aa85 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -157,7 +157,7 @@ $client->api('repo')->hooks()->remove('username', 'reponame', $id); > Requires [authentication](security.md). ```php -$client->api('repo')->hooks()->show('username', 'reponame'); +$client->api('repo')->hooks()->all('username', 'reponame'); ``` ### Get the collaborators for a repository From 07cb4c14eb451688de7acdc39d34ac7ba320773c Mon Sep 17 00:00:00 2001 From: David Corbin Date: Wed, 10 Feb 2016 13:58:02 -0500 Subject: [PATCH 351/951] Created method to add user to organization --- lib/Github/Api/Organization/Members.php | 8 ++++++++ .../Tests/Api/Organization/MembersTest.php | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 7358ed27689..b1c0563c590 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -46,6 +46,14 @@ public function conceal($organization, $username) return $this->delete('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } + /* + * Add user to organization + */ + public function add($organization, $username) + { + return $this->put('orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); + } + public function remove($organization, $username) { return $this->delete('orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); diff --git a/test/Github/Tests/Api/Organization/MembersTest.php b/test/Github/Tests/Api/Organization/MembersTest.php index 7111766b82e..8a6a252e0c8 100644 --- a/test/Github/Tests/Api/Organization/MembersTest.php +++ b/test/Github/Tests/Api/Organization/MembersTest.php @@ -54,6 +54,22 @@ public function shouldCheckIfOrganizationMember() $this->assertEquals($expectedValue, $api->check('KnpLabs', 'l3l0')); } + /** + * @test + */ + public function shouldAddOrganizationMember() + { + $expectedValue = 'response'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('orgs/KnpLabs/memberships/l3l0') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->add('KnpLabs', 'l3l0')); + } + /** * @test */ From 749f069b19f7fd6dbd8eadcef1a06325f3a9a1e8 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 23 Feb 2016 14:14:36 -0800 Subject: [PATCH 352/951] Made response mediator content type aware --- .../HttpClient/Message/ResponseMediator.php | 13 +++++++------ test/Github/Tests/Functional/RepoTest.php | 18 ++++++++++++++++++ .../HttpClient/Listener/ErrorListenerTest.php | 6 ++++++ test/Github/Tests/Mock/TestResponse.php | 5 +++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 23982ae3144..5394d80cccb 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -9,14 +9,15 @@ class ResponseMediator { public static function getContent(Response $response) { - $body = $response->getBody(true); - $content = json_decode($body, true); - - if (JSON_ERROR_NONE !== json_last_error()) { - return $body; + $body = $response->getBody(true); + if (strpos($response->getContentType(), 'application/json') === 0) { + $content = json_decode($body, true); + if (JSON_ERROR_NONE === json_last_error()) { + return $content; + } } - return $content; + return $body; } public static function getPagination(Response $response) diff --git a/test/Github/Tests/Functional/RepoTest.php b/test/Github/Tests/Functional/RepoTest.php index ce25d545ee6..b45c27c832a 100644 --- a/test/Github/Tests/Functional/RepoTest.php +++ b/test/Github/Tests/Functional/RepoTest.php @@ -42,6 +42,24 @@ public function shouldRetrieveRawBlob() $this->assertStringStartsWith('client->api('git_data')->blobs(); + $api->configure('raw'); + + $contents = $api->show( + 'KnpLabs', + 'php-github-api', + 'dc16d3e77fd4e40638cb722927ffe15fa85b1434' + ); + + $this->assertInternalType('string', $contents); + $this->assertStringStartsWith('{', $contents); + } + /** * @test */ diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php index ee783a888b6..b491d3d58c5 100644 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php @@ -120,6 +120,9 @@ public function shouldNotPassWhen400IsSent() $response->expects($this->once()) ->method('getBody') ->will($this->returnValue(json_encode(array('message' => 'test')))); + $response->expects($this->once()) + ->method('getContentType') + ->will($this->returnValue('application/json')); $response->expects($this->any()) ->method('getStatusCode') ->will($this->returnValue(400)); @@ -159,6 +162,9 @@ public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) ->method('getHeader') ->with('X-RateLimit-Limit') ->will($this->returnValue(5000)); + $response->expects($this->once()) + ->method('getContentType') + ->will($this->returnValue('application/json')); $response->expects($this->once()) ->method('getBody') ->will($this->returnValue($content)); diff --git a/test/Github/Tests/Mock/TestResponse.php b/test/Github/Tests/Mock/TestResponse.php index 9d102844138..0ca86483439 100644 --- a/test/Github/Tests/Mock/TestResponse.php +++ b/test/Github/Tests/Mock/TestResponse.php @@ -36,4 +36,9 @@ public function getHeader($header = null) return $header; } + + public function getContentType() + { + return 'application/json'; + } } From e6f043146ed7283a396e146ec467d926cdae5ffe Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Sun, 20 Mar 2016 17:17:06 +0100 Subject: [PATCH 353/951] Add repository stargazers support --- lib/Github/Api/Repo.php | 13 ++++++ lib/Github/Api/Repository/Stargazers.php | 35 ++++++++++++++ test/Github/Tests/Api/RepoTest.php | 10 ++++ .../Tests/Api/Repository/StargazersTest.php | 46 +++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 lib/Github/Api/Repository/Stargazers.php create mode 100644 test/Github/Tests/Api/Repository/StargazersTest.php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 772e0d55792..4a3e47a62a6 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\Stargazers; use Github\Api\Repository\Statuses; /** @@ -309,6 +310,18 @@ public function forks() return new Forks($this->client); } + /** + * Manage the stargazers of a repository. + * + * @link https://developer.github.com/v3/activity/starring/#list-stargazers + * + * @return Stargazers + */ + public function stargazers() + { + return new Stargazers($this->client); + } + /** * Manage the hooks of a repository. * diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php new file mode 100644 index 00000000000..f8d2ec17e14 --- /dev/null +++ b/lib/Github/Api/Repository/Stargazers.php @@ -0,0 +1,35 @@ + + */ +class Stargazers extends AbstractApi +{ + /** + * Configure the body type + * + * @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps + * + * @param string $bodyType + */ + public function configure($bodyType = null) + { + if ('star' === $bodyType) { + $this->client->setHeaders( + array( + 'Accept' => sprintf('application/vnd.github.%s.star+json', $this->client->getOption('api_version')) + ) + ); + } + } + + public function all($username, $repository) + { + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stargazers'); + } +} diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 849bfe35d10..3ada7d440fb 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -465,6 +465,16 @@ public function shouldGetStatusesApiObject() $this->assertInstanceOf('Github\Api\Repository\Statuses', $api->statuses()); } + /** + * @test + */ + public function shouldGetStargazersApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Stargazers', $api->stargazers()); + } + /** * @test */ diff --git a/test/Github/Tests/Api/Repository/StargazersTest.php b/test/Github/Tests/Api/Repository/StargazersTest.php new file mode 100644 index 00000000000..e9c2dbbb50c --- /dev/null +++ b/test/Github/Tests/Api/Repository/StargazersTest.php @@ -0,0 +1,46 @@ + 'nidup')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/stargazers') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetAllRepositoryStargazersWithAlternativeResponse() + { + $expectedValue = array(array('starred_at' => '2013-10-01T13:22:01Z', 'user' => array('login' => 'nidup'))); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('repos/KnpLabs/php-github-api/stargazers') + ->will($this->returnValue($expectedValue)); + $api->configure('star'); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Stargazers'; + } +} From 13c8c88c59c829c59ac882e27c5bc399259097b3 Mon Sep 17 00:00:00 2001 From: Niels van der Veer Date: Wed, 30 Mar 2016 23:08:53 +0200 Subject: [PATCH 354/951] Add documentation for repository archive This PR adds a documentation for the usage of the Get repository Archive --- doc/repo/contents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/contents.md b/doc/repo/contents.md index 56947c5e318..ccc6c12d509 100644 --- a/doc/repo/contents.md +++ b/doc/repo/contents.md @@ -46,7 +46,7 @@ $fileInfo = $client->api('repo')->contents()->rm('knp-labs', 'php-github-api', $ ### Get repository archive ```php -// @todo Document +$archive = $client->api('repo')->contents()->archive('knp-labs', 'php-github-api', $format, $reference); ``` ### Download a file From 378ff4d8f65bda8ffada208386a73c5f96075942 Mon Sep 17 00:00:00 2001 From: Ashley Clarke Date: Fri, 15 Apr 2016 01:21:13 +0100 Subject: [PATCH 355/951] fix typo --- doc/repos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index df416b2aa85..55ebe1326cd 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -291,7 +291,7 @@ $repo = ResponseMediator::getContent($data); ### Get the milestones of a repository ```php -milestones = $client->api('repo')->milestones('ornicar', 'php-github-api'); +$milestones = $client->api('repo')->milestones('ornicar', 'php-github-api'); ``` Returns a list of milestones. From b6535b2bca4fa4a30f3e1a02271ef757149c19c1 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Fri, 15 Apr 2016 08:42:46 +0200 Subject: [PATCH 356/951] Try to fix build in PHP 5.3 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9dbd08d8147..936fc3d9441 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3.3 - 5.3 - 5.4 - 5.5 From ef2672eab87029d4661427c013ad1b0f1f73fb0e Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Thu, 19 May 2016 00:17:03 +0200 Subject: [PATCH 357/951] Add Hooks::ping Ref: https://developer.github.com/v3/repos/hooks/#ping-a-hook --- lib/Github/Api/Repository/Hooks.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index f4866ad0af9..55940ea5009 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -39,6 +39,11 @@ public function update($username, $repository, $id, array $params) return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params); } + public function ping($username, $repository, $id) + { + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/pings'); + } + public function test($username, $repository, $id) { return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/test'); From 10b6402fc2ab65e2027204bc4422702490426b9b Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 19 May 2016 21:53:42 +0200 Subject: [PATCH 358/951] Create statuses.md --- .../statuses.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 doc/repo/statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-../statuses.md diff --git a/doc/repo/statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-../statuses.md b/doc/repo/statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-../statuses.md new file mode 100644 index 00000000000..4f4378c2b54 --- /dev/null +++ b/doc/repo/statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-../statuses.md @@ -0,0 +1,28 @@ +## Repo / Statuses API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List all statuses for a commit + +```php +$statuses = $client->api('repo')->statuses()->show('NimbleCI', 'docker-web-tester-behat', $commitSha); +``` + +### Get the combined statuses for a commit + +```php +$statuses = $client->api('repo')->statuses()->combined('NimbleCI', 'docker-web-tester-behat', $commitSha); +``` + +### Create a status for a commit + +For the full list of parameters see https://developer.github.com/v3/repos/statuses/#parameters + +```php +$params = [ + 'state' => 'pending', # The 'state' element is required + 'target_url' => 'https://nimbleci.com/...', + 'description' => 'A great description...', + 'context' => 'my-context', +]; +$statuses = $client->api('repo')->statuses()->create('NimbleCI', 'docker-web-tester-behat', $commitSha, $params); +``` From 6975ba7660812ab5b8c18196a62c8a03c3e00910 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 19 May 2016 21:58:47 +0200 Subject: [PATCH 359/951] Fix strange directory structure --- .../repos.md-Back-to-the-navigation-.. => }/statuses.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/repo/{statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-.. => }/statuses.md (100%) diff --git a/doc/repo/statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-../statuses.md b/doc/repo/statuses.md similarity index 100% rename from doc/repo/statuses.md-Repo/Releases-API-Back-to-the-Repos-API-../repos.md-Back-to-the-navigation-../statuses.md rename to doc/repo/statuses.md From 3acf131628c6c4d21bf9cc993d86a475ec0f7116 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Mon, 23 May 2016 02:11:38 +0200 Subject: [PATCH 360/951] Add commit_message parameter on Repo::merge only if given If you add the commit_message with null value, you will get this error: For 'properties/commit_message', nil is not a string. So the commit_message parameter has to be added only if $message is valid. --- lib/Github/Api/Repo.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 4a3e47a62a6..09784358831 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -488,11 +488,16 @@ public function subscribers($username, $repository, $page = 1) */ public function merge($username, $repository, $base, $head, $message = null) { - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', array( - 'base' => $base, - 'head' => $head, - 'commit_message' => $message - )); + $parameters = array( + 'base' => $base, + 'head' => $head, + ); + + if (is_string($message)) { + $parameters['commit_message'] = $message; + } + + return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', $parameters); } /** From 021d9242aad023869af9f242dc076e9967f9df70 Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Sat, 28 May 2016 14:10:13 +0200 Subject: [PATCH 361/951] Add merge by squash option Refs: - https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button - https://developer.github.com/changes/2016-04-01-squash-api-preview/ --- lib/Github/Api/PullRequest.php | 16 ++++++++++++---- test/Github/Tests/Api/PullRequestTest.php | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index e0bb27bfee0..6e3028faf53 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -115,10 +115,18 @@ public function merged($username, $repository, $id) return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); } - public function merge($username, $repository, $id, $message, $sha) + public function merge($username, $repository, $id, $message, $sha, $squash = false, $title = null) { - return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', array( - 'commit_message' => $message, 'sha' => $sha - )); + $params = array( + 'commit_message' => $message, + 'sha' => $sha, + 'squash' => $squash, + ); + + if (is_string($title)) { + $params['commit_title'] = $title; + } + + return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', $params); } } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index e9b8f2dba2f..cf18f9e3b82 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -143,7 +143,7 @@ public function shouldMergePullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40))) + ->with('repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'squash' => false)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40))); From ea29a747f2779fee09299f964fb5a88b6c21e736 Mon Sep 17 00:00:00 2001 From: Frank Gambino Date: Sun, 5 Jun 2016 03:07:05 -0400 Subject: [PATCH 362/951] Update TreesTest.php --- test/Github/Tests/Api/GitData/TreesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index 2281331542b..1313f282f41 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -14,7 +14,7 @@ public function shouldShowTreeUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/git/trees/123', array('recursive' => null)) + ->with('repos/KnpLabs/php-github-api/git/trees/123', array()) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); From 000cbbf771efea4c63505d91dba1e7f4bb02a381 Mon Sep 17 00:00:00 2001 From: Frank Gambino Date: Sun, 5 Jun 2016 03:10:49 -0400 Subject: [PATCH 363/951] Update Trees.php --- lib/Github/Api/GitData/Trees.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GitData/Trees.php b/lib/Github/Api/GitData/Trees.php index 3ce35a476ac..3fe61cdb236 100644 --- a/lib/Github/Api/GitData/Trees.php +++ b/lib/Github/Api/GitData/Trees.php @@ -23,7 +23,7 @@ class Trees extends AbstractApi */ public function show($username, $repository, $sha, $recursive = false) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), array('recursive' => $recursive ? 1 : null)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), $recursive ? array('recursive' => 1) : array()); } /** From dc836bafda9d05b0bb6bc01826dccd1ded58c915 Mon Sep 17 00:00:00 2001 From: Chase Coney Date: Fri, 10 Jun 2016 14:39:10 -0500 Subject: [PATCH 364/951] Allow Adding Repo With Permissions --- lib/Github/Api/Organization/Teams.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 6acca32a054..aa9b9c22302 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -83,8 +83,12 @@ public function repository($team, $username, $repository) return $this->get('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } - public function addRepository($team, $username, $repository) + public function addRepository($team, $username, $repository, array $params) { + if (isset($params['permission']) && !in_array($params['permission'], array('pull', 'push', 'admin'))) { + $params['permission'] = 'pull'; + } + return $this->put('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } From 6e96cf6026f25794e58b8f68d109526ffcda03df Mon Sep 17 00:00:00 2001 From: Chase Coney Date: Fri, 10 Jun 2016 15:11:41 -0500 Subject: [PATCH 365/951] Fix test. Whoops. --- lib/Github/Api/Organization/Teams.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index aa9b9c22302..c90ee12af6e 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -83,7 +83,7 @@ public function repository($team, $username, $repository) return $this->get('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } - public function addRepository($team, $username, $repository, array $params) + public function addRepository($team, $username, $repository, $params = array()) { if (isset($params['permission']) && !in_array($params['permission'], array('pull', 'push', 'admin'))) { $params['permission'] = 'pull'; From 7eb2c8fbbd166fd309a17315df55064674b63d7e Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 27 Jun 2016 00:53:29 +0300 Subject: [PATCH 366/951] Fixed Github\HttpClient\CachedHttpClient PHPDoc --- lib/Github/HttpClient/CachedHttpClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index f7d363b131d..224ebd11235 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -22,7 +22,7 @@ class CachedHttpClient extends HttpClient /** * Contains the lastResponse fetched from cache. * - * @var Guzzle\Http\Message\Response + * @var \Guzzle\Http\Message\Response */ private $lastCachedResponse; @@ -110,7 +110,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header } /** - * @return Guzzle\Http\Message\Response + * @return \Guzzle\Http\Message\Response */ public function getLastResponse($force = false) { From 4d5828859474f1b48d8eaa399643ab6b99883a14 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 27 Jun 2016 00:57:21 +0300 Subject: [PATCH 367/951] Added Github\HttpClient\HttpClient::$client --- lib/Github/HttpClient/HttpClient.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index 84b2b09bc46..11f65f7bbc2 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -20,6 +20,11 @@ */ class HttpClient implements HttpClientInterface { + /** + * @var ClientInterface + */ + public $client; + protected $options = array( 'base_url' => 'https://api.github.com/', From b6772b8a7e48a766fde97cf726ab293ff8e8e488 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 27 Jun 2016 02:19:58 +0300 Subject: [PATCH 368/951] Create Stargazers docs --- doc/repo/stargazers.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 doc/repo/stargazers.md diff --git a/doc/repo/stargazers.md b/doc/repo/stargazers.md new file mode 100644 index 00000000000..003f2ad8d71 --- /dev/null +++ b/doc/repo/stargazers.md @@ -0,0 +1,10 @@ +## Repo / Stargazers API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List all stargazers + +```php +$stargazers = $client->api('repo')->stargazers(); + +$stargazers->all('twbs', 'bootstrap'); +``` From 0c66a59ff37449d011e603c1df2b1220602e6ef1 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 27 Jun 2016 02:23:03 +0300 Subject: [PATCH 369/951] Updated docs index page --- doc/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/README.md b/doc/README.md index 04d7cb94b62..da189b1f86f 100644 --- a/doc/README.md +++ b/doc/README.md @@ -18,10 +18,12 @@ APIs: * [Rate Limits](rate_limits.md) * [Repositories](repos.md) * [Contents](repo/contents.md) + * [Deployments](repo/deployments.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) + * [Stargazers](repo/stargazers.md) + * [Statuses](repo/statuses.md) * [Tags](repo/tags.md) - * [Deployments](repo/deployments.md) * [Users](users.md) * [Meta](meta.md) * [Activity](activity.md) From 60eae62d1ca8272005b91662d6e008b3a0850fce Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 14 Jul 2016 18:48:40 -0700 Subject: [PATCH 370/951] We actually use PSR-4 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cfac351015f..fec2f0fd9f6 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Now we can use autoloader from Composer by: } ``` -> `php-github-api` follows the PSR-0 convention names for its classes, which means you can easily integrate `php-github-api` classes loading in your own autoloader. +> `php-github-api` follows the PSR-4 convention names for its classes, which means you can easily integrate `php-github-api` classes loading in your own autoloader. ## Using Laravel? From 07cb2c6ce3c2bdde7792c2dc61747b16dc0f27d3 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 14 Jul 2016 19:16:30 -0700 Subject: [PATCH 371/951] Fixed the branch alias again --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ca541c41c3b..8e57dd236cb 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "1.8.x-dev" } } } From e672cdd971fa405edcf2e31603a2b38a2e20e50d Mon Sep 17 00:00:00 2001 From: klemens Date: Mon, 18 Jul 2016 20:14:30 +0200 Subject: [PATCH 372/951] trivial spelling fixes --- doc/activity.md | 2 +- doc/organization/webhooks.md | 2 +- doc/users.md | 2 +- lib/Github/Api/GitData/Blobs.php | 2 +- lib/Github/Api/Meta.php | 2 +- lib/Github/Api/Organization.php | 2 +- lib/Github/Api/Repo.php | 4 ++-- lib/Github/Api/User.php | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/activity.md b/doc/activity.md index 6f1429e157d..81b35d47973 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -73,7 +73,7 @@ $owner = "KnpLabs"; $repo = "php-github-api"; $activity = $client->api('current_user')->watchers()->check($owner, $repo); ``` -Throws an Exception with code 404 in case that the repo is not beeing watched by the authenticated user or NULL in case that it is beeing watched by the authenticated user. +Throws an Exception with code 404 in case that the repo is not being watched by the authenticated user or NULL in case that it is being watched by the authenticated user. ### Watch a specific repo for authenticated user diff --git a/doc/organization/webhooks.md b/doc/organization/webhooks.md index 842ebe432b4..83898603c16 100644 --- a/doc/organization/webhooks.md +++ b/doc/organization/webhooks.md @@ -72,7 +72,7 @@ $success = $client->organization()->update('KnpLabs', 123, array( Update an existing webhook with ID 123 for the organization. *url* parameter is required. -In case of success, an array of informations about the webhook will be returned. +In case of success, an array of information about the webhook will be returned. ### Ping a webhook for an organization diff --git a/doc/users.md b/doc/users.md index 4aa3d864673..b6c36309d70 100644 --- a/doc/users.md +++ b/doc/users.md @@ -36,7 +36,7 @@ $user = $client->api('user')->show('KnpLabs'); Returns an array of information about the user. -### Update user informations +### Update user information > Requires [authentication](security.md). diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index fe9cfc6123a..2819713fb99 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -12,7 +12,7 @@ class Blobs extends AbstractApi { /** - * Configure the Acccept header depending on the blob type. + * Configure the Accept header depending on the blob type. * * @param string|null $bodyType */ diff --git a/lib/Github/Api/Meta.php b/lib/Github/Api/Meta.php index 73a43301f9e..fa3668af98a 100644 --- a/lib/Github/Api/Meta.php +++ b/lib/Github/Api/Meta.php @@ -13,7 +13,7 @@ class Meta extends AbstractApi /** * Get the ip address of the hook and git servers for the GitHub.com service. * - * @return array Informations about the service of GitHub.com + * @return array Information about the service of GitHub.com */ public function service() { diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 536a73c8c2e..3f0321aefe5 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -32,7 +32,7 @@ public function all($since = '') * * @param string $organization the organization to show * - * @return array informations about the organization + * @return array information about the organization */ public function show($organization) { diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 09784358831..9d98c3f1fe5 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -111,7 +111,7 @@ public function org($organization, array $params = array()) * @param string $username the user who owns the repository * @param string $repository the name of the repository * - * @return array informations about the repository + * @return array information about the repository */ public function show($username, $repository) { @@ -177,7 +177,7 @@ public function create( * @param string $repository the name of the repository * @param array $values the key => value pairs to post * - * @return array informations about the repository + * @return array information about the repository */ public function update($username, $repository, array $values) { diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 888eb9dfed4..dd5ee1b2737 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -50,7 +50,7 @@ public function all($id = null) * * @param string $username the username to show * - * @return array informations about the user + * @return array information about the user */ public function show($username) { From fcfc29c4def64ae52dede07660cb39a34b28037c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 12 Jun 2016 14:00:16 +0200 Subject: [PATCH 373/951] Decouple from Guzzle by using HTTPlug --- .styleci.yml | 1 - .travis.yml | 2 - README.md | 29 +- composer.json | 10 +- doc/customize.md | 59 ++-- lib/Github/Api/AbstractApi.php | 35 +- lib/Github/Api/AcceptHeaderTrait.php | 62 ++++ .../Api/Enterprise/ManagementConsole.php | 2 +- lib/Github/Api/GitData/Blobs.php | 10 +- lib/Github/Api/Issue/Comments.php | 8 +- lib/Github/Api/Repository/Assets.php | 8 +- lib/Github/Api/Repository/Comments.php | 6 +- lib/Github/Api/Repository/Stargazers.php | 10 +- lib/Github/Client.php | 166 ++++++++-- .../HttpClient/Cache/CacheInterface.php | 8 +- .../HttpClient/Cache/FilesystemCache.php | 8 +- .../HttpClient/Cache/GaufretteCache.php | 8 +- .../HttpClient/Cache/ResponseSerializer.php | 61 ++++ lib/Github/HttpClient/CachedHttpClient.php | 124 -------- lib/Github/HttpClient/HttpClient.php | 195 ------------ lib/Github/HttpClient/HttpClientInterface.php | 112 ------- .../HttpClient/Listener/AuthListener.php | 68 ---- .../HttpClient/Message/ResponseMediator.php | 48 ++- .../HttpClient/Plugin/Authentication.php | 81 +++++ lib/Github/HttpClient/Plugin/Cache.php | 87 +++++ .../GithubExceptionThrower.php} | 49 ++- lib/Github/HttpClient/Plugin/History.php | 38 +++ lib/Github/HttpClient/Plugin/PathPrepend.php | 37 +++ lib/Github/ResultPager.php | 19 +- test/Github/Tests/Api/AbstractApiTest.php | 137 +++++--- .../Tests/Api/Repository/AssetsTest.php | 2 +- .../Tests/Api/Repository/ContentsTest.php | 28 +- test/Github/Tests/Api/TestCase.php | 9 +- test/Github/Tests/ClientTest.php | 76 +++-- test/Github/Tests/Functional/MarkdownTest.php | 3 + test/Github/Tests/Functional/RepoTest.php | 2 +- test/Github/Tests/Functional/TestCase.php | 3 + .../HttpClient/Cache/FilesystemCacheTest.php | 2 +- .../HttpClient/Cache/GaufretteCacheTest.php | 2 +- .../Tests/HttpClient/CachedHttpClientTest.php | 78 ----- .../Tests/HttpClient/HttpClientTest.php | 299 ------------------ .../HttpClient/Listener/AuthListenerTest.php | 137 -------- .../HttpClient/Listener/ErrorListenerTest.php | 239 -------------- .../Message/ResponseMediatorTest.php | 88 ++++++ test/Github/Tests/Mock/PaginatedResponse.php | 49 +++ test/Github/Tests/Mock/TestHttpClient.php | 65 ---- test/Github/Tests/Mock/TestResponse.php | 44 --- test/Github/Tests/ResultPagerTest.php | 269 +++------------- 48 files changed, 1001 insertions(+), 1882 deletions(-) create mode 100644 lib/Github/Api/AcceptHeaderTrait.php create mode 100644 lib/Github/HttpClient/Cache/ResponseSerializer.php delete mode 100644 lib/Github/HttpClient/CachedHttpClient.php delete mode 100644 lib/Github/HttpClient/HttpClient.php delete mode 100644 lib/Github/HttpClient/HttpClientInterface.php delete mode 100644 lib/Github/HttpClient/Listener/AuthListener.php create mode 100644 lib/Github/HttpClient/Plugin/Authentication.php create mode 100644 lib/Github/HttpClient/Plugin/Cache.php rename lib/Github/HttpClient/{Listener/ErrorListener.php => Plugin/GithubExceptionThrower.php} (72%) create mode 100644 lib/Github/HttpClient/Plugin/History.php create mode 100644 lib/Github/HttpClient/Plugin/PathPrepend.php delete mode 100644 test/Github/Tests/HttpClient/CachedHttpClientTest.php delete mode 100644 test/Github/Tests/HttpClient/HttpClientTest.php delete mode 100644 test/Github/Tests/HttpClient/Listener/AuthListenerTest.php delete mode 100644 test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php create mode 100644 test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php create mode 100644 test/Github/Tests/Mock/PaginatedResponse.php delete mode 100644 test/Github/Tests/Mock/TestHttpClient.php delete mode 100644 test/Github/Tests/Mock/TestResponse.php diff --git a/.styleci.yml b/.styleci.yml index 418a93eb0f1..731de4d858d 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,5 +1,4 @@ preset: psr2 enabled: - - long_array_syntax - return diff --git a/.travis.yml b/.travis.yml index 936fc3d9441..30c91afd2f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php php: - - 5.3 - - 5.4 - 5.5 - 5.6 - 7.0 diff --git a/README.md b/README.md index fec2f0fd9f6..0d8e23466b1 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ Uses [GitHub API v3](http://developer.github.com/v3/). The object API is very si ## Features -* Follows PSR-0 conventions and coding standard: autoload friendly +* Follows PSR-4 conventions and coding standard: autoload friendly * Light and fast thanks to lazy loading of API classes * Extensively tested and documented ## Requirements -* PHP >= 5.3.2 with [cURL](http://php.net/manual/en/book.curl.php) extension, +* PHP >= 5.5 * [Guzzle](https://github.com/guzzle/guzzle) library, * (optional) PHPUnit to run tests. @@ -28,21 +28,12 @@ The first step to use `php-github-api` is to download composer: $ curl -s http://getcomposer.org/installer | php ``` -Then we have to install our dependencies using: +Then run the following command to require the library: ```bash -$ php composer.phar install -``` -Now we can use autoloader from Composer by: - -```json -{ - "require": { - "knplabs/github-api": "~1.4" - } -} +$ php composer.phar require knplabs/github-api php-http/guzzle6-adapter ``` -> `php-github-api` follows the PSR-4 convention names for its classes, which means you can easily integrate `php-github-api` classes loading in your own autoloader. +Why `php-http/guzzle6-adapter`? We are decoupled form any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md). ## Using Laravel? @@ -70,19 +61,15 @@ From `$client` object, you can access to all GitHub. // This file is generated by Composer require_once 'vendor/autoload.php'; -$client = new \Github\Client( - new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache')) -); +$client = new \Github\Client(); +$client->useCache(); // Or select directly which cache you want to use -$client = new \Github\HttpClient\CachedHttpClient(); -$client->setCache( +$client->useCache( // Built in one, or any cache implementing this interface: // Github\HttpClient\Cache\CacheInterface new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache') ); - -$client = new \Github\Client($client); ``` Using cache, the client will get cached responses if resources haven't changed since last time, diff --git a/composer.json b/composer.json index 8e57dd236cb..a905ca9500b 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,16 @@ } ], "require": { - "php": ">=5.3.2", - "ext-curl": "*", - "guzzle/guzzle": "~3.7" + "php": "^5.5|^7.0", + "php-http/httplug": "^1.0", + "php-http/discovery": "^1.0", + "php-http/client-implementation": "^1.0", + "php-http/client-common": "^1.1" }, "require-dev": { "phpunit/phpunit": "~4.0", + "php-http/guzzle6-adapter": "~1.0", + "guzzlehttp/psr7": "^1.2", "sllh/php-cs-fixer-styleci-bridge": "~1.3" }, "suggest": { diff --git a/doc/customize.md b/doc/customize.md index 82274dc5e4a..9327afb4858 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -1,60 +1,43 @@ ## Customize `php-github-api` and testing [Back to the navigation](README.md) -### Configure the http client -Wanna change, let's say, the http client User Agent? +### Inject a new HTTP client instance -```php -$client->getHttpClient()->setOption('user_agent', 'My new User Agent'); -``` - -See all available options in `Github/HttpClient/HttpClient.php` - -### Guzzle events +`php-github-api` relies on `php-http/discovery` to find an installed HTTP client. You may specify a HTTP client +yourself by calling `\Github\Client::setHttpClient`. A HTTP client must implement `Http\Client\HttpClient`. A list of +community provided clients is found here: https://packagist.org/providers/php-http/client-implementation -If you need to perform any special action on request/response use guzzle events: +You can inject a HTTP client through `Github\Client#setHttpClient()` method: ```php -use Guzzle\Common\Event; -use Github\HttpClient\Message\ResponseMediator; - -$client->getHttpClient()->addListener('request.success', function(Event $event) { - $remaining = ResponseMediator::getApiLimit($event['response']); - - var_dump($remaining); -}); - -$client->user()->show('cursedcoder'); +$client = new Github\Client(); +$client->setHttpClient(new Http\Adapter\Guzzle6\Client()); ``` -see list of events http://guzzle3.readthedocs.org/http-client/request.html#plugins-and-events +### Configure the HTTP client -### Inject a new http client instance - -`php-github-api` provides a curl-based implementation of a http client. -If you want to use your own http client implementation, inject it to the `Github\Client` instance: +Wanna change, let's say, the HTTP client User Agent? You need to create a Plugin that modifies the +request. Read more about [HTTPlug plugins here](http://docs.php-http.org/en/latest/plugins/introduction.html#how-it-works). ```php -use Github\HttpClient\HttpClient; +use Http\Client\Common\Plugin; +use Psr\Http\Message\RequestInterface; -// create a custom http client -class MyHttpClient extends HttpClient +class CustomUserAgentPlugin implements Plugin { - public function request($url, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) + /** + * {@inheritdoc} + */ + public function handleRequest(RequestInterface $request, callable $next, callable $first) { - // send the request and return the raw response + $request->withHeader('user-agent', 'Foobar'); + + return $next($request); } } -``` - -> Your http client implementation may not extend `Github\HttpClient\HttpClient`, but only implement `Github\HttpClient\HttpClientInterface`. -You can now inject your http client through `Github\Client#setHttpClient()` method: - -```php -$client = new Github\Client(); -$client->setHttpClient(new MyHttpClient()); +$githubClient->addPlugin(new CustomUserAgentPlugin()); ``` ### Run Test Suite diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index e7209936ea5..bb2e1c7855b 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -63,7 +63,7 @@ public function setPerPage($perPage) * @param array $parameters GET parameters. * @param array $requestHeaders Request Headers. * - * @return \Guzzle\Http\EntityBodyInterface|mixed|string + * @return array|string */ protected function get($path, array $parameters = array(), $requestHeaders = array()) { @@ -73,7 +73,12 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { unset($parameters['ref']); } - $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); + + if (count($parameters) > 0) { + $path .= '?'.http_build_query($parameters); + } + + $response = $this->client->getHttpClient()->get($path, $requestHeaders); return ResponseMediator::getContent($response); } @@ -85,7 +90,7 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr * @param array $parameters HEAD parameters. * @param array $requestHeaders Request headers. * - * @return \Guzzle\Http\Message\Response + * @return \Psr\Http\Message\ResponseInterface */ protected function head($path, array $parameters = array(), $requestHeaders = array()) { @@ -93,9 +98,7 @@ protected function head($path, array $parameters = array(), $requestHeaders = ar unset($parameters['ref']); } - $response = $this->client->getHttpClient()->request($path, null, 'HEAD', $requestHeaders, array( - 'query' => $parameters - )); + $response = $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders); return $response; } @@ -120,17 +123,17 @@ protected function post($path, array $parameters = array(), $requestHeaders = ar * Send a POST request with raw data. * * @param string $path Request path. - * @param $body Request body. + * @param string $body Request body. * @param array $requestHeaders Request headers. * - * @return \Guzzle\Http\EntityBodyInterface|mixed|string + * @return array|string */ protected function postRaw($path, $body, $requestHeaders = array()) { $response = $this->client->getHttpClient()->post( $path, - $body, - $requestHeaders + $requestHeaders, + $body ); return ResponseMediator::getContent($response); @@ -147,8 +150,8 @@ protected function patch($path, array $parameters = array(), $requestHeaders = a { $response = $this->client->getHttpClient()->patch( $path, - $this->createJsonBody($parameters), - $requestHeaders + $requestHeaders, + $this->createJsonBody($parameters) ); return ResponseMediator::getContent($response); @@ -165,8 +168,8 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr { $response = $this->client->getHttpClient()->put( $path, - $this->createJsonBody($parameters), - $requestHeaders + $requestHeaders, + $this->createJsonBody($parameters) ); return ResponseMediator::getContent($response); @@ -183,8 +186,8 @@ protected function delete($path, array $parameters = array(), $requestHeaders = { $response = $this->client->getHttpClient()->delete( $path, - $this->createJsonBody($parameters), - $requestHeaders + $requestHeaders, + $this->createJsonBody($parameters) ); return ResponseMediator::getContent($response); diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php new file mode 100644 index 00000000000..039f3f4c4f6 --- /dev/null +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -0,0 +1,62 @@ + + */ +trait AcceptHeaderTrait +{ + protected $acceptHeaderValue = null; + + protected function get($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders)); + } + + protected function head($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders)); + } + + protected function post($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders)); + } + + protected function postRaw($path, $body, $requestHeaders = array()) + { + return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders)); + } + + protected function patch($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders)); + } + + protected function put($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders)); + } + + protected function delete($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders)); + } + + /** + * Append a new accept header on all requests + * @return array + */ + private function mergeHeaders(array $headers = array()) + { + $default = array(); + if ($this->acceptHeaderValue) { + $default = array('Accept' => $this->acceptHeaderValue); + } + + return array_merge($default, $headers); + } +} diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 8554425f365..bc25e53466f 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -68,7 +68,7 @@ public function keys($hash) * @param string $uri the request URI * @param string $hash md5 hash of your license * - * @return \Guzzle\Http\EntityBodyInterface|mixed|string + * @return array|string */ protected function getWithLicenseHash($uri, $hash) { diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index fe9cfc6123a..7ce05b31fab 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -3,14 +3,18 @@ namespace Github\Api\GitData; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** * @link http://developer.github.com/v3/git/blobs/ * @author Joseph Bielawski + * @author Tobias Nyholm */ class Blobs extends AbstractApi { + use AcceptHeaderTrait; + /** * Configure the Acccept header depending on the blob type. * @@ -18,10 +22,8 @@ class Blobs extends AbstractApi */ public function configure($bodyType = null) { - if ('raw' == $bodyType) { - $this->client->setHeaders(array( - 'Accept' => sprintf('application/vnd.github.%s.raw', $this->client->getOption('api_version')) - )); + if ('raw' === $bodyType) { + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getOption('api_version')); } } diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index ad6a95d633b..a8e6825d892 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -3,14 +3,18 @@ namespace Github\Api\Issue; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** * @link http://developer.github.com/v3/issues/comments/ * @author Joseph Bielawski + * @author Tobias Nyholm */ class Comments extends AbstractApi { + use AcceptHeaderTrait; + /** * Configure the body type. * @@ -23,9 +27,7 @@ public function configure($bodyType = null) $bodyType = 'full'; } - $this->client->setHeaders(array( - sprintf('Accept: application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType) - )); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType); } /** diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index b386561796e..7fa7a1dddfc 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -73,13 +73,7 @@ public function create($username, $repository, $id, $name, $contentType, $conten // Asset creation requires a separate endpoint, uploads.github.com. // Change the base url for the HTTP client temporarily while we execute // this request. - $baseUrl = $this->client->getHttpClient()->client->getBaseUrl(); - $this->client->getHttpClient()->client->setBaseUrl('https://uploads.github.com/'); - - $response = $this->postRaw('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, array('Content-Type' => $contentType)); - - // Reset the base url. - $this->client->getHttpClient()->client->setBaseUrl($baseUrl); + $response = $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, array('Content-Type' => $contentType)); return $response; } diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index cce0e5059d6..d3fe8a09381 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -3,14 +3,18 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** * @link http://developer.github.com/v3/repos/comments/ * @author Joseph Bielawski + * @author Tobias Nyholm */ class Comments extends AbstractApi { + use AcceptHeaderTrait; + public function configure($bodyType = null) { switch ($bodyType) { @@ -30,7 +34,7 @@ public function configure($bodyType = null) $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version')); } - $this->client->setHeaders(array($header)); + $this->acceptHeaderValue = $header; } public function all($username, $repository, $sha = null) diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index f8d2ec17e14..f1d54db8fc2 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -3,13 +3,17 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://developer.github.com/v3/activity/starring/#list-stargazers * @author Nicolas Dupont + * @author Tobias Nyholm */ class Stargazers extends AbstractApi { + use AcceptHeaderTrait; + /** * Configure the body type * @@ -20,11 +24,7 @@ class Stargazers extends AbstractApi public function configure($bodyType = null) { if ('star' === $bodyType) { - $this->client->setHeaders( - array( - 'Accept' => sprintf('application/vnd.github.%s.star+json', $this->client->getOption('api_version')) - ) - ); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getOption('api_version')); } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index b3c9f63e266..9279ce5c4fd 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -5,8 +5,20 @@ use Github\Api\ApiInterface; use Github\Exception\InvalidArgumentException; use Github\Exception\BadMethodCallException; -use Github\HttpClient\HttpClient; -use Github\HttpClient\HttpClientInterface; +use Github\HttpClient\Cache\CacheInterface; +use Github\HttpClient\Plugin\Authentication; +use Github\HttpClient\Plugin\Cache; +use Github\HttpClient\Plugin\GithubExceptionThrower; +use Github\HttpClient\Plugin\History; +use Github\HttpClient\Plugin\PathPrepend; +use Http\Client\Common\HttpMethodsClient; +use Http\Client\Common\Plugin; +use Http\Client\Common\PluginClient; +use Http\Client\HttpClient; +use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\UriFactoryDiscovery; +use Http\Message\MessageFactory; /** * Simple yet very cool PHP GitHub client. @@ -77,32 +89,67 @@ class Client * @var array */ private $options = array( - 'base_url' => 'https://api.github.com/', - - 'user_agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', - 'timeout' => 10, - - 'api_limit' => 5000, 'api_version' => 'v3', - - 'cache_dir' => null ); /** - * The Buzz instance used to communicate with GitHub. + * The object that sends HTTP messages * * @var HttpClient */ private $httpClient; + /** + * A HTTP client with all our plugins + * + * @var PluginClient + */ + private $pluginClient; + + /** + * @var MessageFactory + */ + private $messageFactory; + + /** + * @var Plugin[] + */ + private $plugins = []; + + /** + * True if we should create a new Plugin client at next request. + * @var bool + */ + private $httpClientModified = true; + + /** + * Http headers + * @var array + */ + private $headers = []; + + /** + * @var History + */ + private $responseHistory; + /** * Instantiate a new GitHub client. * - * @param null|HttpClientInterface $httpClient Github http client + * @param HttpClient|null $httpClient */ - public function __construct(HttpClientInterface $httpClient = null) + public function __construct(HttpClient $httpClient = null) { - $this->httpClient = $httpClient; + $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); + $this->messageFactory = MessageFactoryDiscovery::find(); + + $this->responseHistory = new History(); + $this->addPlugin(new GithubExceptionThrower()); + $this->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); + $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com/'))); + $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( + 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', + ))); } /** @@ -235,7 +282,8 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null $authMethod = self::AUTH_HTTP_PASSWORD; } - $this->getHttpClient()->authenticate($tokenOrLogin, $password, $authMethod); + $this->removePlugin(Authentication::class); + $this->addPlugin(new Authentication($tokenOrLogin, $password, $authMethod)); } /** @@ -245,27 +293,60 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null */ public function setEnterpriseUrl($enterpriseUrl) { - $baseUrl = (substr($enterpriseUrl, -1) == '/') ? substr($enterpriseUrl, 0, -1) : $enterpriseUrl; - $this->getHttpClient()->client->setBaseUrl($baseUrl . '/api/v3'); + $this->removePlugin(Plugin\AddHostPlugin::class); + $this->removePlugin(PathPrepend::class); + + $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); + $this->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getOption('api_version')))); + } + + /** + * Add a new plugin to the chain + * + * @param Plugin $plugin + */ + protected function addPlugin(Plugin $plugin) + { + $this->plugins[] = $plugin; + $this->httpClientModified = true; } /** - * @return HttpClient + * Remove a plugin by its fqn. + * + * @param string $fqn + */ + protected function removePlugin($fqn) + { + foreach ($this->plugins as $idx => $plugin) { + if ($plugin instanceof $fqn) { + unset($this->plugins[$idx]); + } + } + } + + /** + * @return HttpMethodsClient */ public function getHttpClient() { - if (null === $this->httpClient) { - $this->httpClient = new HttpClient($this->options); + if ($this->httpClientModified) { + $this->httpClientModified = false; + $this->pluginClient = new HttpMethodsClient( + new PluginClient($this->httpClient, $this->plugins), + $this->messageFactory + ); } - return $this->httpClient; + return $this->pluginClient; } /** - * @param HttpClientInterface $httpClient + * @param HttpClient $httpClient */ - public function setHttpClient(HttpClientInterface $httpClient) + public function setHttpClient(HttpClient $httpClient) { + $this->httpClientModified = true; $this->httpClient = $httpClient; } @@ -274,15 +355,39 @@ public function setHttpClient(HttpClientInterface $httpClient) */ public function clearHeaders() { - $this->getHttpClient()->clearHeaders(); + $this->headers = array( + 'Accept' => sprintf('application/vnd.github.%s+json', $this->options['api_version']), + ); + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); } /** * @param array $headers */ - public function setHeaders(array $headers) + public function addHeaders(array $headers) { - $this->getHttpClient()->setHeaders($headers); + $this->headers = array_merge($this->headers, $headers); + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); + } + + /** + * @param bool|CacheInterface $cache + */ + public function useCache($cache = true) + { + $this->removePlugin(Cache::class); + if ($cache !== false) { + if ($cache instanceof CacheInterface) { + $plugin = new Cache($cache); + } else { + $plugin = new Cache(); + } + $this->addPlugin($plugin); + } } /** @@ -332,4 +437,13 @@ public function __call($name, $args) throw new BadMethodCallException(sprintf('Undefined method called: "%s"', $name)); } } + + /** + * + * @return null|\Psr\Http\Message\ResponseInterface + */ + public function getLastResponse() + { + return $this->responseHistory->getLastResponse(); + } } diff --git a/lib/Github/HttpClient/Cache/CacheInterface.php b/lib/Github/HttpClient/Cache/CacheInterface.php index 77bb4f89ec9..014e0d20626 100644 --- a/lib/Github/HttpClient/Cache/CacheInterface.php +++ b/lib/Github/HttpClient/Cache/CacheInterface.php @@ -2,7 +2,7 @@ namespace Github\HttpClient\Cache; -use Guzzle\Http\Message\Response; +use Psr\Http\Message\ResponseInterface; /** * Caches github api responses. @@ -37,15 +37,15 @@ public function getETag($id); * * @throws \InvalidArgumentException If cache data don't exists * - * @return Response The cached response object + * @return ResponseInterface The cached response object */ public function get($id); /** * @param string $id The id of the cached resource - * @param Response $response The response to cache + * @param ResponseInterface $response The response to cache * * @throws \InvalidArgumentException If cache data cannot be saved */ - public function set($id, Response $response); + public function set($id, ResponseInterface $response); } diff --git a/lib/Github/HttpClient/Cache/FilesystemCache.php b/lib/Github/HttpClient/Cache/FilesystemCache.php index ff332b57075..82581b62a75 100644 --- a/lib/Github/HttpClient/Cache/FilesystemCache.php +++ b/lib/Github/HttpClient/Cache/FilesystemCache.php @@ -2,7 +2,7 @@ namespace Github\HttpClient\Cache; -use Guzzle\Http\Message\Response; +use Psr\Http\Message\ResponseInterface; class FilesystemCache implements CacheInterface { @@ -25,7 +25,7 @@ public function __construct($path) public function get($id) { if (false !== $content = @file_get_contents($this->getPath($id))) { - return unserialize($content); + return ResponseSerializer::unserialize($content); } throw new \InvalidArgumentException(sprintf('File "%s" not found', $this->getPath($id))); @@ -34,13 +34,13 @@ public function get($id) /** * {@inheritdoc} */ - public function set($id, Response $response) + public function set($id, ResponseInterface $response) { if (!is_dir($this->path)) { @mkdir($this->path, 0777, true); } - if (false === @file_put_contents($this->getPath($id), serialize($response))) { + if (false === @file_put_contents($this->getPath($id), ResponseSerializer::serialize($response))) { throw new \InvalidArgumentException(sprintf('Cannot put content in file "%s"', $this->getPath($id))); } if (false === @file_put_contents($this->getPath($id).'.etag', $response->getHeader('ETag'))) { diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php index b72a104c9af..812be7cbbb2 100644 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ b/lib/Github/HttpClient/Cache/GaufretteCache.php @@ -2,8 +2,8 @@ namespace Github\HttpClient\Cache; -use Guzzle\Http\Message\Response; use Gaufrette\Filesystem; +use Psr\Http\Message\ResponseInterface; /** * Gaufrette Cache. @@ -32,15 +32,15 @@ public function get($id) { $content = $this->filesystem->read($id); - return unserialize($content); + return ResponseSerializer::unserialize($content); } /** * {@inheritdoc} */ - public function set($id, Response $response) + public function set($id, ResponseInterface $response) { - $this->filesystem->write($id, serialize($response), true); + $this->filesystem->write($id, ResponseSerializer::serialize($response), true); $this->filesystem->write($id.'.etag', $response->getHeader('ETag'), true); } diff --git a/lib/Github/HttpClient/Cache/ResponseSerializer.php b/lib/Github/HttpClient/Cache/ResponseSerializer.php new file mode 100644 index 00000000000..43b8d95fa05 --- /dev/null +++ b/lib/Github/HttpClient/Cache/ResponseSerializer.php @@ -0,0 +1,61 @@ + + */ +class ResponseSerializer +{ + /** + * @param ResponseInterface $response + * @param StreamFactory|null $streamFactory + * + * @return array + */ + public static function serialize(ResponseInterface $response, StreamFactory $streamFactory = null) + { + $streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); + + $bodyStream = $response->getBody(); + $body = $bodyStream->__toString(); + if ($bodyStream->isSeekable()) { + $bodyStream->rewind(); + } else { + /* + * If the body is not seekbable we can not rewind it. The stream could be a type of stream + * that you only can read once. That is why we have to replace the old stream with a new one. + */ + $response = $response->withBody($streamFactory->createStream($body)); + } + + return serialize(array('response' => serialize($response), 'body' => $body)); + } + + /** + * @param $data + * @param StreamFactory|null $streamFactory + * + * @return ResponseInterface|null + */ + public static function unserialize($serializedData, StreamFactory $streamFactory = null) + { + $data = unserialize($serializedData); + if (!isset($data['response']) || !isset($data['body'])) { + return null; + } + + $streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); + + $response = unserialize($data['response']); + $response = $response->withBody($streamFactory->createStream($data['body'])); + + return $response; + } +} diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php deleted file mode 100644 index 224ebd11235..00000000000 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ /dev/null @@ -1,124 +0,0 @@ - - */ -class CachedHttpClient extends HttpClient -{ - /** - * @var CacheInterface - */ - protected $cache; - - /** - * Contains the lastResponse fetched from cache. - * - * @var \Guzzle\Http\Message\Response - */ - private $lastCachedResponse; - - /** - * Identifier used for the cache file(s). - * $path + encoded query parameter(s) if they exist. - * - * @var string - */ - private $id; - - /** - * @return CacheInterface - */ - public function getCache() - { - if (null === $this->cache) { - $this->cache = new FilesystemCache($this->options['cache_dir'] ?: sys_get_temp_dir().DIRECTORY_SEPARATOR.'php-github-api-cache'); - } - - return $this->cache; - } - - /** - * @param $cache CacheInterface - */ - public function setCache(CacheInterface $cache) - { - $this->cache = $cache; - } - - /** - * {@inheritdoc} - */ - public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) - { - $response = parent::request($path, $body, $httpMethod, $headers, $options); - - if (304 == $response->getStatusCode()) { - $cacheResponse = $this->getCache()->get($this->id); - $this->lastCachedResponse = $cacheResponse; - - return $cacheResponse; - } - - if (in_array($httpMethod, array('GET', 'HEAD'), true)) { - $this->getCache()->set($this->id, $response); - } - - return $response; - } - - /** - * Create requests with If-Modified-Since headers. - * - * {@inheritdoc} - */ - protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) - { - $request = parent::createRequest($httpMethod, $path, $body, $headers, $options); - - $this->id = $path; - - if (array_key_exists('query', $options) && !empty($options['query'])) { - $this->id .= '?' . $request->getQuery(); - } - - if ($modifiedAt = $this->getCache()->getModifiedSince($this->id)) { - $modifiedAt = new \DateTime('@'.$modifiedAt); - $modifiedAt->setTimezone(new \DateTimeZone('GMT')); - - $request->addHeader( - 'If-Modified-Since', - sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) - ); - } - if ($etag = $this->getCache()->getETag($this->id)) { - $request->addHeader( - 'If-None-Match', - $etag - ); - } - - return $request; - } - - /** - * @return \Guzzle\Http\Message\Response - */ - public function getLastResponse($force = false) - { - $lastResponse = parent::getLastResponse(); - if (304 != $lastResponse->getStatusCode()) { - $force = true; - } - - return ($force) ? $lastResponse : $this->lastCachedResponse; - } -} diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php deleted file mode 100644 index 11f65f7bbc2..00000000000 --- a/lib/Github/HttpClient/HttpClient.php +++ /dev/null @@ -1,195 +0,0 @@ - - */ -class HttpClient implements HttpClientInterface -{ - /** - * @var ClientInterface - */ - public $client; - - protected $options = array( - 'base_url' => 'https://api.github.com/', - - 'user_agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', - 'timeout' => 10, - - 'api_limit' => 5000, - 'api_version' => 'v3', - - 'cache_dir' => null - ); - - protected $headers = array(); - - private $lastResponse; - private $lastRequest; - - /** - * @param array $options - * @param ClientInterface $client - */ - public function __construct(array $options = array(), ClientInterface $client = null) - { - $this->options = array_merge($this->options, $options); - $client = $client ?: new GuzzleClient($this->options['base_url'], $this->options); - $this->client = $client; - - $this->addListener('request.error', array(new ErrorListener($this->options), 'onRequestError')); - $this->clearHeaders(); - } - - /** - * {@inheritDoc} - */ - public function setOption($name, $value) - { - $this->options[$name] = $value; - } - - /** - * {@inheritDoc} - */ - public function setHeaders(array $headers) - { - $this->headers = array_merge($this->headers, $headers); - } - - /** - * Clears used headers. - */ - public function clearHeaders() - { - $this->headers = array( - 'Accept' => sprintf('application/vnd.github.%s+json', $this->options['api_version']), - 'User-Agent' => sprintf('%s', $this->options['user_agent']), - ); - } - - public function addListener($eventName, $listener) - { - $this->client->getEventDispatcher()->addListener($eventName, $listener); - } - - public function addSubscriber(EventSubscriberInterface $subscriber) - { - $this->client->addSubscriber($subscriber); - } - - /** - * {@inheritDoc} - */ - public function get($path, array $parameters = array(), array $headers = array()) - { - return $this->request($path, null, 'GET', $headers, array('query' => $parameters)); - } - - /** - * {@inheritDoc} - */ - public function post($path, $body = null, array $headers = array()) - { - return $this->request($path, $body, 'POST', $headers); - } - - /** - * {@inheritDoc} - */ - public function patch($path, $body = null, array $headers = array()) - { - return $this->request($path, $body, 'PATCH', $headers); - } - - /** - * {@inheritDoc} - */ - public function delete($path, $body = null, array $headers = array()) - { - return $this->request($path, $body, 'DELETE', $headers); - } - - /** - * {@inheritDoc} - */ - public function put($path, $body, array $headers = array()) - { - return $this->request($path, $body, 'PUT', $headers); - } - - /** - * {@inheritDoc} - */ - public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) - { - $request = $this->createRequest($httpMethod, $path, $body, $headers, $options); - - try { - $response = $this->client->send($request); - } catch (\LogicException $e) { - throw new ErrorException($e->getMessage(), $e->getCode(), $e); - } catch (TwoFactorAuthenticationRequiredException $e) { - throw $e; - } catch (\RuntimeException $e) { - throw new RuntimeException($e->getMessage(), $e->getCode(), $e); - } - - $this->lastRequest = $request; - $this->lastResponse = $response; - - return $response; - } - - /** - * {@inheritDoc} - */ - public function authenticate($tokenOrLogin, $password = null, $method) - { - $this->addListener('request.before_send', array( - new AuthListener($tokenOrLogin, $password, $method), 'onRequestBeforeSend' - )); - } - - /** - * @return Request - */ - public function getLastRequest() - { - return $this->lastRequest; - } - - /** - * @return Response - */ - public function getLastResponse() - { - return $this->lastResponse; - } - - protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) - { - return $this->client->createRequest( - $httpMethod, - $path, - array_merge($this->headers, $headers), - $body, - $options - ); - } -} diff --git a/lib/Github/HttpClient/HttpClientInterface.php b/lib/Github/HttpClient/HttpClientInterface.php deleted file mode 100644 index 5ed0a9e34e5..00000000000 --- a/lib/Github/HttpClient/HttpClientInterface.php +++ /dev/null @@ -1,112 +0,0 @@ - - */ -interface HttpClientInterface -{ - /** - * Send a GET request. - * - * @param string $path Request path - * @param array $parameters GET Parameters - * @param array $headers Reconfigure the request headers for this call only - * - * @return Response - */ - public function get($path, array $parameters = array(), array $headers = array()); - - /** - * Send a POST request. - * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only - * - * @return Response - */ - public function post($path, $body = null, array $headers = array()); - - /** - * Send a PATCH request. - * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only - * - * @internal param array $parameters Request body - * - * @return Response - */ - public function patch($path, $body = null, array $headers = array()); - - /** - * Send a PUT request. - * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only - * - * @return Response - */ - public function put($path, $body, array $headers = array()); - - /** - * Send a DELETE request. - * - * @param string $path Request path - * @param mixed $body Request body - * @param array $headers Reconfigure the request headers for this call only - * - * @return Response - */ - public function delete($path, $body = null, array $headers = array()); - - /** - * Send a request to the server, receive a response, - * decode the response and returns an associative array. - * - * @param string $path Request path - * @param mixed $body Request body - * @param string $httpMethod HTTP method to use - * @param array $headers Request headers - * - * @return Response - */ - public function request($path, $body, $httpMethod = 'GET', array $headers = array()); - - /** - * Change an option value. - * - * @param string $name The option name - * @param mixed $value The value - * - * @throws InvalidArgumentException - */ - public function setOption($name, $value); - - /** - * Set HTTP headers. - * - * @param array $headers - */ - public function setHeaders(array $headers); - - /** - * Authenticate a user for all next requests. - * - * @param string $tokenOrLogin GitHub private token/username/client ID - * @param null|string $password GitHub password/secret (optionally can contain $authMethod) - * @param null|string $authMethod One of the AUTH_* class constants - * - * @throws InvalidArgumentException If no authentication method was given - */ - public function authenticate($tokenOrLogin, $password, $authMethod); -} diff --git a/lib/Github/HttpClient/Listener/AuthListener.php b/lib/Github/HttpClient/Listener/AuthListener.php deleted file mode 100644 index 41ad42e4642..00000000000 --- a/lib/Github/HttpClient/Listener/AuthListener.php +++ /dev/null @@ -1,68 +0,0 @@ -tokenOrLogin = $tokenOrLogin; - $this->password = $password; - $this->method = $method; - } - - public function onRequestBeforeSend(Event $event) - { - // Skip by default - if (null === $this->method) { - return; - } - - switch ($this->method) { - case Client::AUTH_HTTP_PASSWORD: - $event['request']->setHeader( - 'Authorization', - sprintf('Basic %s', base64_encode($this->tokenOrLogin . ':' . $this->password)) - ); - break; - - case Client::AUTH_HTTP_TOKEN: - $event['request']->setHeader('Authorization', sprintf('token %s', $this->tokenOrLogin)); - break; - - case Client::AUTH_URL_CLIENT_ID: - $url = $event['request']->getUrl(); - - $parameters = array( - 'client_id' => $this->tokenOrLogin, - 'client_secret' => $this->password, - ); - - $url .= (false === strpos($url, '?') ? '?' : '&'); - $url .= utf8_encode(http_build_query($parameters, '', '&')); - - $event['request']->setUrl($url); - break; - - case Client::AUTH_URL_TOKEN: - $url = $event['request']->getUrl(); - $url .= (false === strpos($url, '?') ? '?' : '&'); - $url .= utf8_encode(http_build_query(array('access_token' => $this->tokenOrLogin), '', '&')); - - $event['request']->setUrl($url); - break; - - default: - throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); - break; - } - } -} diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 5394d80cccb..c841d21269d 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -2,15 +2,20 @@ namespace Github\HttpClient\Message; -use Guzzle\Http\Message\Response; use Github\Exception\ApiLimitExceedException; +use Psr\Http\Message\ResponseInterface; class ResponseMediator { - public static function getContent(Response $response) + /** + * @param ResponseInterface $response + * + * @return array|string + */ + public static function getContent(ResponseInterface $response) { - $body = $response->getBody(true); - if (strpos($response->getContentType(), 'application/json') === 0) { + $body = $response->getBody()->__toString(); + if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) { $content = json_decode($body, true); if (JSON_ERROR_NONE === json_last_error()) { return $content; @@ -20,14 +25,18 @@ public static function getContent(Response $response) return $body; } - public static function getPagination(Response $response) + /** + * @param ResponseInterface $response + * + * @return array|null + */ + public static function getPagination(ResponseInterface $response) { - $header = (string) $response->getHeader('Link'); - - if (empty($header)) { + if (!$response->hasHeader('Link')) { return null; } + $header = self::getHeader($response, 'Link'); $pagination = array(); foreach (explode(',', $header) as $link) { preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match); @@ -40,9 +49,14 @@ public static function getPagination(Response $response) return $pagination; } - public static function getApiLimit(Response $response) + /** + * @param ResponseInterface $response + * + * @return null|string + */ + public static function getApiLimit(ResponseInterface $response) { - $remainingCalls = (string) $response->getHeader('X-RateLimit-Remaining'); + $remainingCalls = self::getHeader($response, 'X-RateLimit-Remaining'); if (null !== $remainingCalls && 1 > $remainingCalls) { throw new ApiLimitExceedException($remainingCalls); @@ -50,4 +64,18 @@ public static function getApiLimit(Response $response) return $remainingCalls; } + + /** + * Get the value for a single header + * @param ResponseInterface $response + * @param string $name + * + * @return string|null + */ + public static function getHeader(ResponseInterface $response, $name) + { + $headers = $response->getHeader($name); + + return array_shift($headers); + } } diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php new file mode 100644 index 00000000000..4651e6bf302 --- /dev/null +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -0,0 +1,81 @@ + + */ +class Authentication implements Plugin +{ + private $tokenOrLogin; + private $password; + private $method; + + public function __construct($tokenOrLogin, $password = null, $method) + { + $this->tokenOrLogin = $tokenOrLogin; + $this->password = $password; + $this->method = $method; + } + + /** + * {@inheritdoc} + */ + public function handleRequest(RequestInterface $request, callable $next, callable $first) + { + switch ($this->method) { + case Client::AUTH_HTTP_PASSWORD: + $request = $request->withHeader( + 'Authorization', + sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)) + ); + break; + + case Client::AUTH_HTTP_TOKEN: + $request = $request->withHeader('Authorization', sprintf('token %s', $this->tokenOrLogin)); + break; + + case Client::AUTH_URL_CLIENT_ID: + $uri = $request->getUri(); + $query = $uri->getQuery(); + + $parameters = array( + 'client_id' => $this->tokenOrLogin, + 'client_secret' => $this->password, + ); + + $query .= empty($query) ? '' : '&'; + $query .= utf8_encode(http_build_query($parameters, '', '&')); + + $uri = $uri->withQuery($query); + $request = $request->withUri($uri); + break; + + case Client::AUTH_URL_TOKEN: + $uri = $request->getUri(); + $query = $uri->getQuery(); + + $parameters = array('access_token' => $this->tokenOrLogin); + + $query .= empty($query) ? '' : '&'; + $query .= utf8_encode(http_build_query($parameters, '', '&')); + + $uri = $uri->withQuery($query); + $request = $request->withUri($uri); + break; + + default: + throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); + break; + } + + return $next($request); + } +} diff --git a/lib/Github/HttpClient/Plugin/Cache.php b/lib/Github/HttpClient/Plugin/Cache.php new file mode 100644 index 00000000000..cc4397dd59e --- /dev/null +++ b/lib/Github/HttpClient/Plugin/Cache.php @@ -0,0 +1,87 @@ + + * @author Tobias Nyholm + */ +class Cache implements Plugin +{ + /** + * @var CacheInterface + */ + protected $cache; + + /** + * + * @param CacheInterface $cache + */ + public function __construct(CacheInterface $cache = null) + { + $this->cache = $cache; + } + + /** + * {@inheritdoc} + */ + public function handleRequest(RequestInterface $request, callable $next, callable $first) + { + $cacheKey = sha1($request->getUri()->__toString()); + + if ($modifiedAt = $this->getCache()->getModifiedSince($cacheKey)) { + $modifiedAt = new \DateTime('@'.$modifiedAt); + $modifiedAt->setTimezone(new \DateTimeZone('GMT')); + + $request = $request->withHeader( + 'If-Modified-Since', + sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) + ); + } + if ($etag = $this->getCache()->getETag($cacheKey)) { + $request = $request->withHeader( + 'If-None-Match', + $etag + ); + } + + return $next($request)->then(function (ResponseInterface $response) use ($request, $cacheKey) { + if (304 === $response->getStatusCode()) { + $cacheResponse = $this->getCache()->get($cacheKey); + $this->lastCachedResponse = $cacheResponse; + + return $cacheResponse; + } + + if (in_array($request->getMethod(), array('GET', 'HEAD'), true)) { + $this->getCache()->set($cacheKey, $response); + } + + return $response; + }); + } + + + /** + * @return CacheInterface + */ + public function getCache() + { + if (null === $this->cache) { + $this->cache = new FilesystemCache(sys_get_temp_dir().DIRECTORY_SEPARATOR.'php-github-api-cache'); + } + + return $this->cache; + } +} diff --git a/lib/Github/HttpClient/Listener/ErrorListener.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php similarity index 72% rename from lib/Github/HttpClient/Listener/ErrorListener.php rename to lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 3772fbbb27a..d3042bc6dc0 100644 --- a/lib/Github/HttpClient/Listener/ErrorListener.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -1,53 +1,44 @@ + * @author Tobias Nyholm */ -class ErrorListener +class GithubExceptionThrower implements Plugin { /** - * @var array + * {@inheritdoc} */ - private $options; - - /** - * @param array $options - */ - public function __construct(array $options) + public function handleRequest(RequestInterface $request, callable $next, callable $first) { - $this->options = $options; - } - - /** - * {@inheritDoc} - */ - public function onRequestError(Event $event) - { - /** @var $request \Guzzle\Http\Message\Request */ - $request = $event['request']; - $response = $request->getResponse(); + return $next($request)->then(function (ResponseInterface $response) use ($request) { + if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) { + return $response; + } - if ($response->isClientError() || $response->isServerError()) { - $remaining = (string) $response->getHeader('X-RateLimit-Remaining'); - $limit = $response->getHeader('X-RateLimit-Limit'); + // If error: + $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); + $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); - if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getResource(), 1, 10)) { + if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { throw new ApiLimitExceedException($limit); } if (401 === $response->getStatusCode()) { - if ($response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) $response->getHeader('X-GitHub-OTP'), 'required;')) { - $type = substr((string) $response->getHeader('X-GitHub-OTP'), 9); + if ($response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 'required;')) { + $type = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 9); throw new TwoFactorAuthenticationRequiredException($type); } @@ -88,11 +79,11 @@ public function onRequestError(Event $event) } } - throw new ValidationFailedException('Validation Failed: ' . implode(', ', $errors), 422); + throw new ValidationFailedException('Validation Failed: '.implode(', ', $errors), 422); } } throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); - }; + }); } } diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php new file mode 100644 index 00000000000..303d81404dc --- /dev/null +++ b/lib/Github/HttpClient/Plugin/History.php @@ -0,0 +1,38 @@ + + */ +class History implements Journal +{ + /** + * @var ResponseInterface + */ + private $lastResponse; + + /** + * @return ResponseInterface|null + */ + public function getLastResponse() + { + return $this->lastResponse; + } + + public function addSuccess(RequestInterface $request, ResponseInterface $response) + { + $this->lastResponse = $response; + } + + public function addFailure(RequestInterface $request, Exception $exception) + { + } +} diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php new file mode 100644 index 00000000000..b3b840e1487 --- /dev/null +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -0,0 +1,37 @@ + + */ +class PathPrepend implements Plugin +{ + private $path; + + /** + * @param string $path + */ + public function __construct($path) + { + $this->path = $path; + } + + /** + * {@inheritdoc} + */ + public function handleRequest(RequestInterface $request, callable $next, callable $first) + { + $currentPath = $request->getUri()->getPath(); + $uri = $request->getUri()->withPath($this->path.$currentPath); + + $request = $request->withUri($uri); + + return $next($request); + } +} diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 21bc08ec3f4..b63ffd676ec 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -59,7 +59,7 @@ public function getPagination() */ public function fetch(ApiInterface $api, $method, array $parameters = array()) { - $result = call_user_func_array(array($api, $method), $parameters); + $result = $this->callApi($api, $method, $parameters); $this->postFetch(); return $result; @@ -78,8 +78,7 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = array() // set parameters per_page to GitHub max to minimize number of requests $api->setPerPage(100); - $result = array(); - $result = call_user_func_array(array($api, $method), $parameters); + $result = $this->callApi($api, $method, $parameters); $this->postFetch(); if ($isSearch) { @@ -107,7 +106,7 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = array() */ public function postFetch() { - $this->pagination = ResponseMediator::getPagination($this->client->getHttpClient()->getLastResponse()); + $this->pagination = ResponseMediator::getPagination($this->client->getLastResponse()); } /** @@ -178,4 +177,16 @@ protected function get($key) return ResponseMediator::getContent($result); } } + + /** + * @param ApiInterface $api + * @param $method + * @param array $parameters + * + * @return mixed + */ + protected function callApi(ApiInterface $api, $method, array $parameters) + { + return call_user_func_array(array($api, $method), $parameters); + } } diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index f3982e398e6..0edd5daf7b7 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -3,7 +3,7 @@ namespace Github\Tests\Api; use Github\Api\AbstractApi; -use Guzzle\Http\Message\Response; +use GuzzleHttp\Psr7\Response; class AbstractApiTest extends \PHPUnit_Framework_TestCase { @@ -14,15 +14,17 @@ public function shouldPassGETRequestToClient() { $expectedArray = array('value'); - $httpClient = $this->getHttpMock(); + $httpClient = $this->getHttpMethodsMock(array('get')); $httpClient ->expects($this->any()) ->method('get') - ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) - ->will($this->returnValue($expectedArray)); - $client = $this->getClientMock(); - $client->setHttpClient($httpClient); - + ->with('/path?param1=param1value', array('header1' => 'header1value')) + ->will($this->returnValue($this->getPSR7Response($expectedArray))); + $client = $this->getMock('Github\Client', array('getHttpClient')); + $client->expects($this->any()) + ->method('getHttpClient') + ->willReturn($httpClient); + $api = $this->getAbstractApiObject($client); $this->assertEquals($expectedArray, $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); @@ -35,14 +37,17 @@ public function shouldPassPOSTRequestToClient() { $expectedArray = array('value'); - $httpClient = $this->getHttpMock(); + $httpClient = $this->getHttpMethodsMock(array('post')); $httpClient ->expects($this->once()) ->method('post') - ->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value')) - ->will($this->returnValue($expectedArray)); - $client = $this->getClientMock(); - $client->setHttpClient($httpClient); + ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->will($this->returnValue($this->getPSR7Response($expectedArray))); + + $client = $this->getMock('Github\Client', array('getHttpClient')); + $client->expects($this->any()) + ->method('getHttpClient') + ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); @@ -56,14 +61,17 @@ public function shouldPassPATCHRequestToClient() { $expectedArray = array('value'); - $httpClient = $this->getHttpMock(); + $httpClient = $this->getHttpMethodsMock(array('patch')); $httpClient ->expects($this->once()) ->method('patch') - ->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value')) - ->will($this->returnValue($expectedArray)); - $client = $this->getClientMock(); - $client->setHttpClient($httpClient); + ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->will($this->returnValue($this->getPSR7Response($expectedArray))); + + $client = $this->getMock('Github\Client', array('getHttpClient')); + $client->expects($this->any()) + ->method('getHttpClient') + ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); @@ -77,14 +85,17 @@ public function shouldPassPUTRequestToClient() { $expectedArray = array('value'); - $httpClient = $this->getHttpMock(); + $httpClient = $this->getHttpMethodsMock(array('put')); $httpClient ->expects($this->once()) ->method('put') - ->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value')) - ->will($this->returnValue($expectedArray)); - $client = $this->getClientMock(); - $client->setHttpClient($httpClient); + ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->will($this->returnValue($this->getPSR7Response($expectedArray))); + + $client = $this->getMock('Github\Client', array('getHttpClient')); + $client->expects($this->any()) + ->method('getHttpClient') + ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); @@ -98,14 +109,18 @@ public function shouldPassDELETERequestToClient() { $expectedArray = array('value'); - $httpClient = $this->getHttpMock(); + $httpClient = $this->getHttpMethodsMock(array('delete')); $httpClient ->expects($this->once()) ->method('delete') - ->with('/path', array('param1' => 'param1value'), array('option1' => 'option1value')) - ->will($this->returnValue($expectedArray)); - $client = $this->getClientMock(); - $client->setHttpClient($httpClient); + ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->will($this->returnValue($this->getPSR7Response($expectedArray))); + + $client = $this->getMock('Github\Client', array('getHttpClient')); + $client->expects($this->any()) + ->method('getHttpClient') + ->willReturn($httpClient); + $api = $this->getAbstractApiObject($client); @@ -117,18 +132,21 @@ public function shouldPassDELETERequestToClient() */ public function shouldNotPassEmptyRefToClient() { - $expectedResponse = new Response('value'); + $expectedArray = array('value'); - $httpClient = $this->getHttpMock(); + $httpClient = $this->getHttpMethodsMock(array('get')); $httpClient ->expects($this->any()) ->method('get') ->with('/path', array()) - ->will($this->returnValue($expectedResponse)); - $client = $this->getClientMock(); - $client->setHttpClient($httpClient); + ->will($this->returnValue($this->getPSR7Response($expectedArray))); + + $client = $this->getMock('Github\Client', array('getHttpClient')); + $client->expects($this->any()) + ->method('getHttpClient') + ->willReturn($httpClient); - $api = new ExposedAbstractApiTestInstance($client); + $api = $this->getAbstractApiObject($client); $api->get('/path', array('ref' => null)); } @@ -142,26 +160,50 @@ protected function getAbstractApiObject($client) */ protected function getClientMock() { - return new \Github\Client($this->getHttpMock()); + return new \Github\Client($this->getHttpMethodsMock()); } /** - * @return \Github\HttpClient\HttpClientInterface + * Return a HttpMethods client mock + * + * @return \Http\Client\Common\HttpMethodsClient */ - protected function getHttpMock() + protected function getHttpMethodsMock(array $methods = array()) { - return $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $this->getHttpClientMock())); - } + $methods = array_merge(array('sendRequest'), $methods); + $mock = $this->getMock('Http\Client\Common\HttpMethodsClient', $methods, array(), '', false); + $mock + ->expects($this->any()) + ->method('sendRequest'); + return $mock; + } + /** + * @return \Http\Client\HttpClient + */ protected function getHttpClientMock() { - $mock = $this->getMock('Guzzle\Http\Client', array('send')); + $mock = $this->getMock('Http\Client\HttpClient', array('sendRequest')); $mock ->expects($this->any()) - ->method('send'); + ->method('sendRequest'); return $mock; } + + /** + * @param $expectedArray + * + * @return Response + */ + private function getPSR7Response($expectedArray) + { + return new Response( + 200, + array('Content-Type' => 'application/json'), + \GuzzleHttp\Psr7\stream_for(json_encode($expectedArray)) + ); + } } class AbstractApiTestInstance extends AbstractApi @@ -171,7 +213,7 @@ class AbstractApiTestInstance extends AbstractApi */ public function get($path, array $parameters = array(), $requestHeaders = array()) { - return $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); + return parent::get($path, $parameters, $requestHeaders); } /** @@ -179,7 +221,7 @@ public function get($path, array $parameters = array(), $requestHeaders = array( */ public function post($path, array $parameters = array(), $requestHeaders = array()) { - return $this->client->getHttpClient()->post($path, $parameters, $requestHeaders); + return parent::post($path, $parameters, $requestHeaders); } /** @@ -187,7 +229,7 @@ public function post($path, array $parameters = array(), $requestHeaders = array */ public function postRaw($path, $body, $requestHeaders = array()) { - return $this->client->getHttpClient()->post($path, $body, $requestHeaders); + return parent::postRaw($path, $body, $requestHeaders); } /** @@ -195,7 +237,7 @@ public function postRaw($path, $body, $requestHeaders = array()) */ public function patch($path, array $parameters = array(), $requestHeaders = array()) { - return $this->client->getHttpClient()->patch($path, $parameters, $requestHeaders); + return parent::patch($path, $parameters, $requestHeaders); } /** @@ -203,7 +245,7 @@ public function patch($path, array $parameters = array(), $requestHeaders = arra */ public function put($path, array $parameters = array(), $requestHeaders = array()) { - return $this->client->getHttpClient()->put($path, $parameters, $requestHeaders); + return parent::put($path, $parameters, $requestHeaders); } /** @@ -211,10 +253,13 @@ public function put($path, array $parameters = array(), $requestHeaders = array( */ public function delete($path, array $parameters = array(), $requestHeaders = array()) { - return $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); + return parent::delete($path, $parameters, $requestHeaders); } } +/** + * @deprecated + */ class ExposedAbstractApiTestInstance extends AbstractApi { /** diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index dc6e6146b0b..174268468ca 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -60,7 +60,7 @@ public function shouldCreateReleaseAsset() $api = $this->getApiMock(); $api->expects($this->once()) ->method('postRaw') - ->with('repos/KnpLabs/php-github-api/releases/'. $releaseId .'/assets?name='.$name) + ->with('https://uploads.github.com/repos/KnpLabs/php-github-api/releases/'. $releaseId .'/assets?name='.$name) ->will($this->returnValue($body)); $this->assertEquals($body, $api->create('KnpLabs', 'php-github-api', $releaseId, $name, $contentType, $body)); diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index ddce2c9e905..cc9bb693940 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -4,6 +4,7 @@ use Github\Tests\Api\TestCase; use Github\Exception\TwoFactorAuthenticationRequiredException; +use GuzzleHttp\Psr7\Response; class ContentsTest extends TestCase { @@ -44,34 +45,24 @@ public function shouldShowReadme() */ public function shouldReturnTrueWhenFileExists() { - $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') - ->disableOriginalConstructor() - ->getMock(); - - $responseMock->expects($this->any()) - ->method('getStatusCode') - ->willReturn(200); + $response = new Response(200); $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) - ->will($this->returnValue($responseMock)); + ->will($this->returnValue($response)); $this->assertEquals(true, $api->exists('KnpLabs', 'php-github-api', 'composer.json')); } public function getFailureStubsForExistsTest() { - $nonOkResponseMock =$this->getGuzzleResponseMock(); - - $nonOkResponseMock->expects($this->any()) - ->method('getStatusCode') - ->willReturn(403); + $response = new Response(403); return array( array($this->throwException(new \ErrorException())), - array($this->returnValue($nonOkResponseMock)) + array($this->returnValue($response)) ); } @@ -331,13 +322,4 @@ protected function getApiClass() { return 'Github\Api\Repository\Contents'; } - - private function getGuzzleResponseMock() - { - $responseMock = $this->getMockBuilder('\Guzzle\Http\Message\Response') - ->disableOriginalConstructor() - ->getMock(); - - return $responseMock; - } } diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index a8f322e31e7..965781cd9d7 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -8,15 +8,12 @@ abstract protected function getApiClass(); protected function getApiMock() { - $httpClient = $this->getMock('Guzzle\Http\Client', array('send')); + $httpClient = $this->getMock('Http\Client\HttpClient', array('sendRequest')); $httpClient ->expects($this->any()) - ->method('send'); + ->method('sendRequest'); - $mock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $httpClient)); - - $client = new \Github\Client($mock); - $client->setHttpClient($mock); + $client = new \Github\Client($httpClient); return $this->getMockBuilder($this->getApiClass()) ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index a51996319d7..0a9983eb20b 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -4,6 +4,8 @@ use Github\Client; use Github\Exception\BadMethodCallException; +use Github\HttpClient\Plugin\Authentication; +use Http\Client\Common\Plugin; class ClientTest extends \PHPUnit_Framework_TestCase { @@ -14,7 +16,7 @@ public function shouldNotHaveToPassHttpClientToConstructor() { $client = new Client(); - $this->assertInstanceOf('Github\HttpClient\HttpClient', $client->getHttpClient()); + $this->assertInstanceOf('\Http\Client\HttpClient', $client->getHttpClient()); } /** @@ -22,9 +24,9 @@ public function shouldNotHaveToPassHttpClientToConstructor() */ public function shouldPassHttpClientInterfaceToConstructor() { - $client = new Client($this->getHttpClientMock()); + $client = new Client($this->getMock('Http\Client\HttpClient')); - $this->assertInstanceOf('Github\HttpClient\HttpClientInterface', $client->getHttpClient()); + $this->assertInstanceOf('Http\Client\HttpClient', $client->getHttpClient()); } /** @@ -33,12 +35,15 @@ public function shouldPassHttpClientInterfaceToConstructor() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $httpClient = $this->getHttpClientMock(); - $httpClient->expects($this->once()) - ->method('authenticate') - ->with($login, $password, $method); + $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client->expects($this->once()) + ->method('addPlugin') + ->with($this->equalTo(new Authentication($login, $password, $method))); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Authentication::class); - $client = new Client($httpClient); $client->authenticate($login, $password, $method); } @@ -58,12 +63,15 @@ public function getAuthenticationFullData() */ public function shouldAuthenticateUsingGivenParameters($token, $method) { - $httpClient = $this->getHttpClientMock(); - $httpClient->expects($this->once()) - ->method('authenticate') - ->with($token, null, $method); + $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client->expects($this->once()) + ->method('addPlugin') + ->with($this->equalTo(new Authentication($token, null, $method))); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Authentication::class); - $client = new Client($httpClient); $client->authenticate($token, $method); } @@ -81,36 +89,46 @@ public function getAuthenticationPartialData() */ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet() { - $httpClient = $this->getHttpClientMock(array('addListener')); + $client = new Client(); - $client = new Client($httpClient); $client->authenticate('login', null, null); } /** * @test */ - public function shouldClearHeadersLazy() + public function shouldClearHeaders() { - $httpClient = $this->getHttpClientMock(array('clearHeaders')); - $httpClient->expects($this->once())->method('clearHeaders'); + $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client->expects($this->once()) + ->method('addPlugin') + ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); - $client = new Client($httpClient); $client->clearHeaders(); } /** * @test */ - public function shouldSetHeadersLaizly() + public function shouldAddHeaders() { $headers = array('header1', 'header2'); - $httpClient = $this->getHttpClientMock(); - $httpClient->expects($this->once())->method('setHeaders')->with($headers); + $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client->expects($this->once()) + ->method('addPlugin') + // TODO verify that headers exists + ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); - $client = new Client($httpClient); - $client->setHeaders($headers); + $client->addHeaders($headers); } /** @@ -199,14 +217,4 @@ public function getApiClassesProvider() array('meta', 'Github\Api\Meta') ); } - - public function getHttpClientMock(array $methods = array()) - { - $methods = array_merge( - array('get', 'post', 'patch', 'put', 'delete', 'request', 'setOption', 'setHeaders', 'authenticate'), - $methods - ); - - return $this->getMock('Github\HttpClient\HttpClientInterface', $methods); - } } diff --git a/test/Github/Tests/Functional/MarkdownTest.php b/test/Github/Tests/Functional/MarkdownTest.php index 0e7e2b033ba..34c967cbbef 100644 --- a/test/Github/Tests/Functional/MarkdownTest.php +++ b/test/Github/Tests/Functional/MarkdownTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Functional; +use Github\Api\Markdown; + /** * @group functional */ @@ -12,6 +14,7 @@ class MarkdownTest extends TestCase */ public function shouldRetrieveParsedMarkdownContent() { + /** @var Markdown $api */ $api = $this->client->api('markdown'); $input = 'Hello world github/linguist#1 **cool**, and #1!'; diff --git a/test/Github/Tests/Functional/RepoTest.php b/test/Github/Tests/Functional/RepoTest.php index b45c27c832a..7416a3384d8 100644 --- a/test/Github/Tests/Functional/RepoTest.php +++ b/test/Github/Tests/Functional/RepoTest.php @@ -12,7 +12,7 @@ class RepoTest extends TestCase */ public function shouldShowPRDiffIfHeaderIsPresent() { - $this->client->setHeaders( + $this->client->addHeaders( array('Accept' => sprintf( 'application/vnd.github.%s.diff', $this->client->getOption('api_version') diff --git a/test/Github/Tests/Functional/TestCase.php b/test/Github/Tests/Functional/TestCase.php index ef51c1a52c9..17c76cdc15e 100644 --- a/test/Github/Tests/Functional/TestCase.php +++ b/test/Github/Tests/Functional/TestCase.php @@ -11,6 +11,9 @@ */ class TestCase extends \PHPUnit_Framework_TestCase { + /** + * @var Client + */ protected $client; public function setUp() diff --git a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php index 54efdd49ba4..6383fecad5a 100644 --- a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php +++ b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php @@ -2,8 +2,8 @@ namespace Github\Tests\HttpClient\Cache; -use Guzzle\Http\Message\Response; use Github\HttpClient\Cache\FilesystemCache; +use GuzzleHttp\Psr7\Response; class FilesystemCacheTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php b/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php index 2a84f14ad54..2e033f53b46 100644 --- a/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php +++ b/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php @@ -2,8 +2,8 @@ namespace Github\Tests\HttpClient\Cache; -use Guzzle\Http\Message\Response; use Github\HttpClient\Cache\GaufretteCache; +use GuzzleHttp\Psr7\Response; class GaufretteCacheTest extends \PHPUnit_Framework_TestCase { diff --git a/test/Github/Tests/HttpClient/CachedHttpClientTest.php b/test/Github/Tests/HttpClient/CachedHttpClientTest.php deleted file mode 100644 index 477b3e2eab3..00000000000 --- a/test/Github/Tests/HttpClient/CachedHttpClientTest.php +++ /dev/null @@ -1,78 +0,0 @@ -getCacheMock(); - $response = new Response(200); - - $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('send') - ->will($this->returnValue($response)); - - $httpClient = new CachedHttpClient(array('base_url' => ''), $client); - $httpClient->setCache($cache); - - $cache->expects($this->once())->method('set')->with('test', $response); - $httpClient->get('test'); - } - - /** - * @test - */ - public function shouldGetCachedResponseWhileResourceNotModified() - { - $cache = $this->getCacheMock(); - $response = new Response(304); - - $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('send') - ->will($this->returnValue($response)); - - $httpClient = new CachedHttpClient(array('base_url' => ''), $client); - $httpClient->setCache($cache); - $httpClient->fakeResponse = $response; - - $cache->expects($this->once())->method('get')->with('test'); - - $httpClient->get('test'); - } - - /** - * @test - */ - public function shouldRenewCacheWhenResourceHasChanged() - { - $cache = $this->getCacheMock(); - $response = new Response(200); - - $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('send') - ->will($this->returnValue($response)); - - $httpClient = new CachedHttpClient(array('base_url' => ''), $client); - $httpClient->setCache($cache); - - $cache->expects($this->once())->method('set')->with('test', $response); - $cache->expects($this->once())->method('getModifiedSince')->with('test')->will($this->returnValue(1256953732)); - - $httpClient->get('test'); - } - - public function getCacheMock() - { - return $this->getMock('Github\HttpClient\Cache\CacheInterface'); - } -} diff --git a/test/Github/Tests/HttpClient/HttpClientTest.php b/test/Github/Tests/HttpClient/HttpClientTest.php deleted file mode 100644 index c6a645a214f..00000000000 --- a/test/Github/Tests/HttpClient/HttpClientTest.php +++ /dev/null @@ -1,299 +0,0 @@ - 33 - ), $this->getBrowserMock()); - - $this->assertEquals(33, $httpClient->getOption('timeout')); - $this->assertEquals(5000, $httpClient->getOption('api_limit')); - } - - /** - * @test - */ - public function shouldBeAbleToSetOption() - { - $httpClient = new TestHttpClient(array(), $this->getBrowserMock()); - $httpClient->setOption('timeout', 666); - - $this->assertEquals(666, $httpClient->getOption('timeout')); - } - - /** - * @test - * @dataProvider getAuthenticationFullData - */ - public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) - { - $client = new GuzzleClient(); - $listeners = $client->getEventDispatcher()->getListeners('request.before_send'); - $this->assertCount(1, $listeners); - - $httpClient = new TestHttpClient(array(), $client); - $httpClient->authenticate($login, $password, $method); - - $listeners = $client->getEventDispatcher()->getListeners('request.before_send'); - $this->assertCount(2, $listeners); - - $authListener = $listeners[1][0]; - $this->assertInstanceOf('Github\HttpClient\Listener\AuthListener', $authListener); - } - - public function getAuthenticationFullData() - { - return array( - array('login', 'password', Client::AUTH_HTTP_PASSWORD), - array('token', null, Client::AUTH_HTTP_TOKEN), - array('token', null, Client::AUTH_URL_TOKEN), - array('client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID), - ); - } - - /** - * @test - */ - public function shouldDoGETRequest() - { - $path = '/some/path'; - $parameters = array('a' => 'b'); - $headers = array('c' => 'd'); - - $client = $this->getBrowserMock(); - - $httpClient = new HttpClient(array(), $client); - $httpClient->get($path, $parameters, $headers); - } - - /** - * @test - */ - public function shouldDoPOSTRequest() - { - $path = '/some/path'; - $body = 'a = b'; - $headers = array('c' => 'd'); - - $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('createRequest') - ->with('POST', $path, $this->isType('array'), $body); - - $httpClient = new HttpClient(array(), $client); - $httpClient->post($path, $body, $headers); - } - - /** - * @test - */ - public function shouldDoPOSTRequestWithoutContent() - { - $path = '/some/path'; - - $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('createRequest') - ->with('POST', $path, $this->isType('array')); - - $httpClient = new HttpClient(array(), $client); - $httpClient->post($path); - } - - /** - * @test - */ - public function shouldDoPATCHRequest() - { - $path = '/some/path'; - $body = 'a = b'; - $headers = array('c' => 'd'); - - $client = $this->getBrowserMock(); - - $httpClient = new HttpClient(array(), $client); - $httpClient->patch($path, $body, $headers); - } - - /** - * @test - */ - public function shouldDoDELETERequest() - { - $path = '/some/path'; - $body = 'a = b'; - $headers = array('c' => 'd'); - - $client = $this->getBrowserMock(); - - $httpClient = new HttpClient(array(), $client); - $httpClient->delete($path, $body, $headers); - } - - /** - * @test - */ - public function shouldDoPUTRequest() - { - $path = '/some/path'; - $headers = array('c' => 'd'); - - $client = $this->getBrowserMock(); - - $httpClient = new HttpClient(array(), $client); - $httpClient->put($path, $headers); - } - - /** - * @test - */ - public function shouldDoCustomRequest() - { - $path = '/some/path'; - $body = 'a = b'; - $options = array('c' => 'd'); - - $client = $this->getBrowserMock(); - - $httpClient = new HttpClient(array(), $client); - $httpClient->request($path, $body, 'HEAD', $options); - } - - /** - * @test - */ - public function shouldHandlePagination() - { - $path = '/some/path'; - $body = 'a = b'; - $headers = array('c' => 'd'); - - $response = new Response(200); - $response->addHeader('Link', "; rel=\"page2\", \n; rel=\"page4\""); - - $client = $this->getBrowserMock(); - - $httpClient = new HttpClient(array(), $client); - $httpClient->request($path, $body, 'HEAD', $headers); - - $this->assertEquals(array('page2' => 'page1', 'page4' => 'page3'), ResponseMediator::getPagination($response)); - } - - /** - * @test - */ - public function shouldAllowToReturnRawContent() - { - $path = '/some/path'; - $parameters = array('a = b'); - $headers = array('c' => 'd'); - - $message = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); - $message->expects($this->once()) - ->method('getBody') - ->will($this->returnValue('Just raw context')); - - $client = $this->getBrowserMock(); - $client->expects($this->once()) - ->method('send') - ->will($this->returnValue($message)); - - $httpClient = new TestHttpClient(array(), $client); - $response = $httpClient->get($path, $parameters, $headers); - - $this->assertEquals("Just raw context", $response->getBody()); - $this->assertInstanceOf('Guzzle\Http\Message\MessageInterface', $response); - } - - /** - * @test - * @expectedException \Github\Exception\ApiLimitExceedException - */ - public function shouldThrowExceptionWhenApiIsExceeded() - { - $path = '/some/path'; - $parameters = array('a = b'); - $headers = array('c' => 'd'); - - $response = new Response(403); - $response->addHeader('X-RateLimit-Remaining', 0); - - $mockPlugin = new MockPlugin(); - $mockPlugin->addResponse($response); - - $client = new GuzzleClient('http://123.com/'); - $client->addSubscriber($mockPlugin); - - $httpClient = new TestHttpClient(array(), $client); - $httpClient->get($path, $parameters, $headers); - } - - /** - * @test - * @expectedException \Github\Exception\TwoFactorAuthenticationRequiredException - */ - public function shouldForwardTwoFactorAuthenticationExceptionWhenItHappens() - { - $path = '/some/path'; - $parameters = array('a = b'); - $headers = array('c' => 'd'); - - $response = new Response(401); - $response->addHeader('X-GitHub-OTP', 'required; sms'); - - $mockPlugin = new MockPlugin(); - $mockPlugin->addResponse($response); - - $client = new GuzzleClient('http://123.com/'); - $client->addSubscriber($mockPlugin); - - $httpClient = new TestHttpClient(array(), $client); - $httpClient->get($path, $parameters, $headers); - } - - protected function getBrowserMock(array $methods = array()) - { - $mock = $this->getMock( - 'Guzzle\Http\Client', - array_merge( - array('send', 'createRequest'), - $methods - ) - ); - - $mock->expects($this->any()) - ->method('createRequest') - ->will($this->returnValue($this->getMock('Guzzle\Http\Message\Request', array(), array('GET', 'some')))); - - return $mock; - } -} - -class TestHttpClient extends HttpClient -{ - public function getOption($name, $default = null) - { - return isset($this->options[$name]) ? $this->options[$name] : $default; - } - - public function request($path, $body, $httpMethod = 'GET', array $headers = array(), array $options = array()) - { - $request = $this->client->createRequest($httpMethod, $path); - - return $this->client->send($request); - } -} diff --git a/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php b/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php deleted file mode 100644 index 68fd4387401..00000000000 --- a/test/Github/Tests/HttpClient/Listener/AuthListenerTest.php +++ /dev/null @@ -1,137 +0,0 @@ -onRequestBeforeSend($this->getEventMock()); - } - - /** - * @test - */ - public function shouldDoNothingForHaveNullMethod() - { - $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); - $request->expects($this->never()) - ->method('addHeader'); - $request->expects($this->never()) - ->method('fromUrl'); - $request->expects($this->never()) - ->method('getUrl'); - - $listener = new AuthListener('test', 'pass', null); - $listener->onRequestBeforeSend($this->getEventMock($request)); - } - - /** - * @test - */ - public function shouldDoNothingForPostSend() - { - $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); - $request->expects($this->never()) - ->method('addHeader'); - $request->expects($this->never()) - ->method('fromUrl'); - $request->expects($this->never()) - ->method('getUrl'); - - $listener = new AuthListener('login', 'somepassphrase', Client::AUTH_HTTP_PASSWORD); - $listener->onRequestBeforeSend($this->getEventMock($request)); - } - - /** - * @test - */ - public function shouldSetAuthBasicHeaderForAuthPassMethod() - { - $expected = 'Basic '.base64_encode('login2:pass42323'); - - $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); - $request->expects($this->once()) - ->method('setHeader') - ->with('Authorization', $expected); - $request->expects($this->once()) - ->method('getHeader') - ->with('Authorization') - ->will($this->returnValue($expected)); - - $listener = new AuthListener('login2', 'pass42323', Client::AUTH_HTTP_PASSWORD); - $listener->onRequestBeforeSend($this->getEventMock($request)); - - $this->assertEquals($expected, $request->getHeader('Authorization')); - } - - /** - * @test - */ - public function shouldSetAuthTokenHeaderForAuthPassMethod() - { - $expected = 'token test'; - - $request = $this->getMock('Guzzle\Http\Message\RequestInterface'); - $request->expects($this->once()) - ->method('setHeader') - ->with('Authorization', $expected); - $request->expects($this->once()) - ->method('getHeader') - ->with('Authorization') - ->will($this->returnValue($expected)); - - $listener = new AuthListener('test', null, Client::AUTH_HTTP_TOKEN); - $listener->onRequestBeforeSend($this->getEventMock($request)); - - $this->assertEquals($expected, $request->getHeader('Authorization')); - } - - /** - * @test - */ - public function shouldSetTokenInUrlForAuthUrlMethod() - { - $request = new Request('GET', '/res'); - - $listener = new AuthListener('test', null, Client::AUTH_URL_TOKEN); - $listener->onRequestBeforeSend($this->getEventMock($request)); - - $this->assertEquals('/res?access_token=test', $request->getUrl()); - } - - /** - * @test - */ - public function shouldSetClientDetailsInUrlForAuthUrlMethod() - { - $request = new Request('GET', '/res'); - - $listener = new AuthListener('clientId', 'clientSecret', Client::AUTH_URL_CLIENT_ID); - $listener->onRequestBeforeSend($this->getEventMock($request)); - - $this->assertEquals('/res?client_id=clientId&client_secret=clientSecret', $request->getUrl()); - } - - private function getEventMock($request = null) - { - $mock = $this->getMockBuilder('Guzzle\Common\Event')->getMock(); - - if ($request) { - $mock->expects($this->any()) - ->method('offsetGet') - ->will($this->returnValue($request)); - } - - return $mock; - } -} diff --git a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php b/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php deleted file mode 100644 index b491d3d58c5..00000000000 --- a/test/Github/Tests/HttpClient/Listener/ErrorListenerTest.php +++ /dev/null @@ -1,239 +0,0 @@ -getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(false)); - - $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->onRequestError($this->getEventMock($response)); - } - - /** - * @test - * @expectedException \Github\Exception\ApiLimitExceedException - */ - public function shouldFailWhenApiLimitWasExceed() - { - $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(true)); - $response->expects($this->at(1)) - ->method('getHeader') - ->with('X-RateLimit-Remaining') - ->will($this->returnValue(0)); - $response->expects($this->at(2)) - ->method('getHeader') - ->with('X-RateLimit-Limit') - ->will($this->returnValue(5000)); - - $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->onRequestError($this->getEventMock($response)); - } - - /** - * @test - * @expectedException \Github\Exception\RuntimeException - */ - public function shouldNotPassWhenContentWasNotValidJson() - { - $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(true)); - $response->expects($this->at(1)) - ->method('getHeader') - ->with('X-RateLimit-Remaining') - ->will($this->returnValue(5000)); - $response->expects($this->at(2)) - ->method('getHeader') - ->with('X-RateLimit-Limit') - ->will($this->returnValue(5000)); - - $response->expects($this->once()) - ->method('getBody') - ->will($this->returnValue('fail')); - - $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->onRequestError($this->getEventMock($response)); - } - - /** - * @test - * @expectedException \Github\Exception\RuntimeException - */ - public function shouldNotPassWhenContentWasValidJsonButStatusIsNotCovered() - { - $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(true)); - $response->expects($this->at(1)) - ->method('getHeader') - ->with('X-RateLimit-Remaining') - ->will($this->returnValue(5000)); - $response->expects($this->at(2)) - ->method('getHeader') - ->with('X-RateLimit-Limit') - ->will($this->returnValue(5000)); - $response->expects($this->once()) - ->method('getBody') - ->will($this->returnValue(json_encode(array('message' => 'test')))); - $response->expects($this->any()) - ->method('getStatusCode') - ->will($this->returnValue(404)); - - $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->onRequestError($this->getEventMock($response)); - } - - /** - * @test - * @expectedException \Github\Exception\ErrorException - */ - public function shouldNotPassWhen400IsSent() - { - $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(true)); - $response->expects($this->at(1)) - ->method('getHeader') - ->with('X-RateLimit-Remaining') - ->will($this->returnValue(5000)); - $response->expects($this->at(2)) - ->method('getHeader') - ->with('X-RateLimit-Limit') - ->will($this->returnValue(5000)); - $response->expects($this->once()) - ->method('getBody') - ->will($this->returnValue(json_encode(array('message' => 'test')))); - $response->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('application/json')); - $response->expects($this->any()) - ->method('getStatusCode') - ->will($this->returnValue(400)); - - $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->onRequestError($this->getEventMock($response)); - } - - /** - * @test - * @dataProvider getErrorCodesProvider - * @expectedException \Github\Exception\ValidationFailedException - */ - public function shouldNotPassWhen422IsSentWithErrorCode($errorCode) - { - $content = json_encode(array( - 'message' => 'Validation Failed', - 'errors' => array( - array( - 'code' => $errorCode, - 'field' => 'test', - 'value' => 'wrong', - 'resource' => 'fake' - ) - ) - )); - - $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(true)); - $response->expects($this->at(1)) - ->method('getHeader') - ->with('X-RateLimit-Remaining') - ->will($this->returnValue(5000)); - $response->expects($this->at(2)) - ->method('getHeader') - ->with('X-RateLimit-Limit') - ->will($this->returnValue(5000)); - $response->expects($this->once()) - ->method('getContentType') - ->will($this->returnValue('application/json')); - $response->expects($this->once()) - ->method('getBody') - ->will($this->returnValue($content)); - $response->expects($this->any()) - ->method('getStatusCode') - ->will($this->returnValue(422)); - - $listener = new ErrorListener(array('api_limit' => 5000)); - $listener->onRequestError($this->getEventMock($response)); - } - - /** - * @test - * @expectedException \Github\Exception\TwoFactorAuthenticationRequiredException - */ - public function shouldThrowTwoFactorAuthenticationRequiredException() - { - $response = $this->getMockBuilder('Guzzle\Http\Message\Response')->disableOriginalConstructor()->getMock(); - $response->expects($this->once()) - ->method('isClientError') - ->will($this->returnValue(true)); - $response->expects($this->any()) - ->method('getStatusCode') - ->will($this->returnValue(401)); - $response->expects($this->any()) - ->method('getHeader') - ->will($this->returnCallback(function ($name) { - switch ($name) { - case 'X-RateLimit-Remaining': - return 5000; - case 'X-GitHub-OTP': - return 'required; sms'; - case 'X-RateLimit-Limit': - return 5000; - } - })); - $response->expects($this->any()) - ->method('hasHeader') - ->with('X-GitHub-OTP') - ->will($this->returnValue(true)); - - $listener = new ErrorListener(array()); - $listener->onRequestError($this->getEventMock($response)); - } - - public function getErrorCodesProvider() - { - return array( - array('missing'), - array('missing_field'), - array('invalid'), - array('already_exists'), - ); - } - - private function getEventMock($response) - { - $mock = $this->getMockBuilder('Guzzle\Common\Event')->getMock(); - - $request = $this->getMockBuilder('Guzzle\Http\Message\Request')->disableOriginalConstructor()->getMock(); - - $request->expects($this->any()) - ->method('getResponse') - ->will($this->returnValue($response)); - - $mock->expects($this->any()) - ->method('offsetGet') - ->will($this->returnValue($request)); - - return $mock; - } -} diff --git a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php new file mode 100644 index 00000000000..2880f95fd28 --- /dev/null +++ b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php @@ -0,0 +1,88 @@ + + */ +class ResponseMediatorTest extends \PHPUnit_Framework_TestCase +{ + public function testGetContent() + { + $body = array('foo' => 'bar'); + $response = new Response( + 200, + array('Content-Type'=>'application/json'), + \GuzzleHttp\Psr7\stream_for(json_encode($body)) + ); + + $this->assertEquals($body, ResponseMediator::getContent($response)); + } + + /** + * If content-type is not json we should get the raw body. + */ + public function testGetContentNotJson() + { + $body = 'foobar'; + $response = new Response( + 200, + array(), + \GuzzleHttp\Psr7\stream_for($body) + ); + + $this->assertEquals($body, ResponseMediator::getContent($response)); + } + + /** + * Make sure we return the body if we have invalid json + */ + public function testGetContentInvalidJson() + { + $body = 'foobar'; + $response = new Response( + 200, + array('Content-Type'=>'application/json'), + \GuzzleHttp\Psr7\stream_for($body) + ); + + $this->assertEquals($body, ResponseMediator::getContent($response)); + } + + public function testGetPagination() + { + $header = <<; rel="first", +; rel="next", +; rel="prev", +; rel="last", +TEXT; + + $pagination = array( + 'first' => 'http://github.com', + 'next' => 'http://github.com', + 'prev' => 'http://github.com', + 'last' => 'http://github.com' + ); + + // response mock + $response = new Response(200, array('link'=>$header)); + $result = ResponseMediator::getPagination($response); + + $this->assertEquals($pagination, $result); + } + + public function testGetHeader() + { + $header = 'application/json'; + $response = new Response( + 200, + array('Content-Type'=> $header) + ); + + $this->assertEquals($header, ResponseMediator::getHeader($response, 'content-type')); + } +} diff --git a/test/Github/Tests/Mock/PaginatedResponse.php b/test/Github/Tests/Mock/PaginatedResponse.php new file mode 100644 index 00000000000..13d2e815fc0 --- /dev/null +++ b/test/Github/Tests/Mock/PaginatedResponse.php @@ -0,0 +1,49 @@ + + */ +class PaginatedResponse extends Response +{ + protected $loopCount; + + protected $content; + + public function __construct($loopCount, array $content = []) + { + $this->loopCount = $loopCount; + $this->content = $content; + + parent::__construct(200, array('Content-Type'=>'application/json'), \GuzzleHttp\Psr7\stream_for(json_encode($content))); + } + + public function getHeader($header) + { + if ($header === 'Link') { + if ($this->loopCount > 1) { + $header = array(sprintf('; rel="next"', $this->loopCount)); + } else { + $header = array('; rel="prev"'); + } + + $this->loopCount--; + + return $header; + } + + return parent::getHeader($header); + } + + public function hasHeader($header) + { + if ($header === 'Link') { + return true; + } + + return parent::hasHeader($header); + } +} diff --git a/test/Github/Tests/Mock/TestHttpClient.php b/test/Github/Tests/Mock/TestHttpClient.php deleted file mode 100644 index 7b52d8807cc..00000000000 --- a/test/Github/Tests/Mock/TestHttpClient.php +++ /dev/null @@ -1,65 +0,0 @@ - array(), - 'post' => array(), - 'patch' => array(), - 'put' => array(), - 'delete' => array(), - ); - public $options = array(); - public $headers = array(); - - public function authenticate($tokenOrLogin, $password, $authMethod) - { - $this->authenticated = true; - } - - public function setOption($key, $value) - { - $this->options[$key] = $value; - } - - public function setHeaders(array $headers) - { - $this->headers = $headers; - } - - public function get($path, array $parameters = array(), array $headers = array()) - { - $this->requests['get'][] = $path; - } - - public function post($path, $body = null, array $headers = array()) - { - $this->requests['post'][] = $path; - } - - public function patch($path, $body = null, array $headers = array()) - { - $this->requests['patch'][] = $path; - } - - public function put($path, array $options = array(), array $headers = array()) - { - $this->requests['put'][] = $path; - } - - public function delete($path, $body = null, array $headers = array()) - { - $this->requests['delete'][] = $path; - } - - public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) - { - $this->requests[$httpMethod][] = $path; - } -} diff --git a/test/Github/Tests/Mock/TestResponse.php b/test/Github/Tests/Mock/TestResponse.php deleted file mode 100644 index 0ca86483439..00000000000 --- a/test/Github/Tests/Mock/TestResponse.php +++ /dev/null @@ -1,44 +0,0 @@ -loopCount = $loopCount; - $this->content = $content; - } - - /** - * {@inheritDoc} - */ - public function getBody($asString = false) - { - return json_encode($this->content); - } - - public function getHeader($header = null) - { - if ($this->loopCount) { - $header = sprintf('; rel="next"', $this->loopCount); - } else { - $header = '; rel="prev"'; - } - - $this->loopCount--; - - return $header; - } - - public function getContentType() - { - return 'application/json'; - } -} diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 494731523db..af9e767a5de 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -2,15 +2,20 @@ namespace Github\Tests; -use Github; -use Github\HttpClient\HttpClientInterface; -use Github\Tests\Mock\TestResponse; +use Github\Api\Organization; +use Github\Api\Organization\Members; +use Github\Api\Search; +use Github\Client; +use Github\ResultPager; +use Github\Tests\Mock\PaginatedResponse; +use Http\Client\HttpClient; /** * ResultPagerTest. * * @author Ramon de la Fuente * @author Mitchel Verschoof + * @author Tobias Nyholm */ class ResultPagerTest extends \PHPUnit_Framework_TestCase { @@ -21,32 +26,28 @@ class ResultPagerTest extends \PHPUnit_Framework_TestCase */ public function shouldGetAllResults() { - $amountLoops = 3; - $content = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - $responseMock = new TestResponse($amountLoops, $content); + $amountLoops = 3; + $content = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getHttpClientMock($responseMock); + $httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest')); $httpClientMock ->expects($this->exactly($amountLoops)) - ->method('get') - ->will($this->returnValue($responseMock)); + ->method('sendRequest') + ->will($this->returnValue($response)); - $clientMock = $this->getClientMock($httpClientMock); + $client = new Client($httpClientMock); // memberApi Mock - $memberApiMock = $this->getApiMock('Github\Api\Organization\Members'); - $memberApiMock - ->expects($this->once()) - ->method('all') - ->will($this->returnValue(array())); + $memberApi = new Members($client); - $method = 'all'; + $method = 'all'; $parameters = array('netwerven'); // Run fetchAll on result paginator - $paginator = new Github\ResultPager($clientMock); - $result = $paginator->fetchAll($memberApiMock, $method, $parameters); + $paginator = new ResultPager($client); + $result = $paginator->fetchAll($memberApi, $method, $parameters); $this->assertEquals($amountLoops * count($content), count($result)); } @@ -66,229 +67,47 @@ public function shouldGetAllResults() */ public function shouldGetAllSearchResults() { - $amountLoops = 3; + $amountLoops = 3; - $content = array( + $content = array( 'total_count' => 12, 'items' => array(1, 2, 3, 4) ); - $responseMock = new TestResponse($amountLoops, $content); + $response = new PaginatedResponse($amountLoops, $content); - $httpClientMock = $this->getHttpClientMock($responseMock); + // httpClient mock + $httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest')); $httpClientMock ->expects($this->exactly($amountLoops)) - ->method('get') - ->will($this->returnValue($responseMock)); - - $clientMock = $this->getClientMock($httpClientMock); + ->method('sendRequest') + ->will($this->returnValue($response)); - $searchApiMock = $this->getApiMock('Github\Api\Search'); - $searchApiMock - ->expects($this->once()) - ->method('users') - ->will($this->returnValue(array())); + $client = new Client($httpClientMock); - $method = 'users'; - $paginator = new Github\ResultPager($clientMock); - $result = $paginator->fetchAll($searchApiMock, $method, array('knplabs')); + $searchApi = new Search($client); + $method = 'users'; + $paginator = new ResultPager($client); + $result = $paginator->fetchAll($searchApi, $method, array('knplabs')); $this->assertEquals($amountLoops * count($content['items']), count($result)); } - /** - * @test - * - * description fetch - */ - public function shouldGetSomeResults() - { - $pagination = array('next' => 'http://github.com/next'); - $resultContent = 'organization test'; - - $responseMock = $this->getResponseMock('; rel="next"'); - $httpClient = $this->getHttpClientMock($responseMock); - $client = $this->getClientMock($httpClient); - - $organizationApiMock = $this->getApiMock('Github\Api\Organization'); - - $organizationApiMock - ->expects($this->once()) - ->method('show') - ->with('github') - ->will($this->returnValue($resultContent)); - - $paginator = new Github\ResultPager($client); - $result = $paginator->fetch($organizationApiMock, 'show', array('github')); - - $this->assertEquals($resultContent, $result); - $this->assertEquals($pagination, $paginator->getPagination()); - } - - /** - * @test - * - * description postFetch - */ - public function postFetch() - { - $header = <<; rel="first", -; rel="next", -; rel="prev", -; rel="last", -TEXT; - - $pagination = array( - 'first' => 'http://github.com', - 'next' => 'http://github.com', - 'prev' => 'http://github.com', - 'last' => 'http://github.com' - ); - - // response mock - $responseMock = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); - $responseMock - ->expects($this->any()) - ->method('getHeader') - ->with('Link') - ->will($this->returnValue($header)); - - $httpClient = $this->getHttpClientMock($responseMock); - $client = $this->getClientMock($httpClient); - - $paginator = new Github\ResultPager($client); - $paginator->postFetch(); - - $this->assertEquals($paginator->getPagination(), $pagination); - } - - /** - * @test - * - * description fetchNext - */ - public function fetchNext() + public function testFetch() { - $header = '; rel="next"'; - $pagination = array('next' => 'http://github.com/next'); - $resultContent = 'fetch test'; - - $responseMock = $this->getResponseMock($header); - $responseMock - ->expects($this->once()) - ->method('getBody') - ->will($this->returnValue($resultContent)); - // Expected 2 times, 1 for setup and 1 for the actual test - $responseMock - ->expects($this->exactly(2)) - ->method('getHeader') - ->with('Link'); + $result = 'foo'; + $method = 'bar'; + $parameters = array('baz'); + $api = $this->getMock('Github\Api\ApiInterface'); - $httpClient = $this->getHttpClientMock($responseMock); + $paginator = $this->getMock('Github\ResultPager', array('callApi', 'postFetch'), array(), '', false); + $paginator->expects($this->once()) + ->method('callApi') + ->with($api, $method, $parameters) + ->willReturn($result); - $httpClient - ->expects($this->once()) - ->method('get') - ->with($pagination['next']) - ->will($this->returnValue($responseMock)); - - $client = $this->getClientMock($httpClient); - - $paginator = new Github\ResultPager($client); - $paginator->postFetch(); - - $this->assertEquals($paginator->fetchNext(), $resultContent); - } - - /** - * @test - * - * description hasNext - */ - public function shouldHaveNext() - { - $responseMock = $this->getResponseMock('; rel="next"'); - $httpClient = $this->getHttpClientMock($responseMock); - $client = $this->getClientMock($httpClient); - - $paginator = new Github\ResultPager($client); - $paginator->postFetch(); - - $this->assertEquals($paginator->hasNext(), true); - $this->assertEquals($paginator->hasPrevious(), false); - } - - /** - * @test - * - * description hasPrevious - */ - public function shouldHavePrevious() - { - $responseMock = $this->getResponseMock('; rel="prev"'); - $httpClient = $this->getHttpClientMock($responseMock); - $client = $this->getClientMock($httpClient); - - $paginator = new Github\ResultPager($client); - $paginator->postFetch(); - - $this->assertEquals($paginator->hasPrevious(), true); - $this->assertEquals($paginator->hasNext(), false); - } - - protected function getResponseMock($header) - { - // response mock - $responseMock = $this->getMock('Guzzle\Http\Message\Response', array(), array(200)); - $responseMock - ->expects($this->any()) - ->method('getHeader') - ->with('Link') - ->will($this->returnValue($header)); - - return $responseMock; - } - - protected function getClientMock(HttpClientInterface $httpClient = null) - { - // if no httpClient isset use the default HttpClient mock - if (!$httpClient) { - $httpClient = $this->getHttpClientMock(); - } - - $client = new \Github\Client($httpClient); - $client->setHttpClient($httpClient); - - return $client; - } - - protected function getHttpClientMock($responseMock = null) - { - // mock the client interface - $clientInterfaceMock = $this->getMock('Guzzle\Http\Client', array('send')); - $clientInterfaceMock - ->expects($this->any()) - ->method('send'); - - // create the httpClient mock - $httpClientMock = $this->getMock('Github\HttpClient\HttpClient', array(), array(array(), $clientInterfaceMock)); - - if ($responseMock) { - $httpClientMock - ->expects($this->any()) - ->method('getLastResponse') - ->will($this->returnValue($responseMock)); - } - - return $httpClientMock; - } - - protected function getApiMock($apiClass) - { - $client = $this->getClientMock(); + $paginator->expects($this->once()) + ->method('postFetch'); - return $this->getMockBuilder($apiClass) - ->setConstructorArgs(array($client)) - ->getMock(); + $this->assertEquals($result, $paginator->fetch($api, $method, $parameters)); } } From 9cfff45ddeba3935b4091d5f4bf023ad8d3e81df Mon Sep 17 00:00:00 2001 From: Yevhenii Huselietov Date: Wed, 27 Jul 2016 11:26:13 +0300 Subject: [PATCH 374/951] Update branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a905ca9500b..0519519435c 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "2.0.x-dev" } } } From b680e6ce648382f3b0fcd440cbe628b4221517bf Mon Sep 17 00:00:00 2001 From: Yevhenii Huselietov Date: Wed, 27 Jul 2016 11:33:30 +0300 Subject: [PATCH 375/951] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d8e23466b1..31d63bb9404 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ -# PHP GitHub API +# PHP GitHub API 2.0 + +In 2.0 lib no longer uses guzzle 3.7, instead we have an HTTPlug abstraction layer. + +For old version please check: + +* [branch](https://github.com/KnpLabs/php-github-api/tree/1.7) +* [readme](https://github.com/KnpLabs/php-github-api/tree/1.7/README.md) +* [docs](https://github.com/KnpLabs/php-github-api/tree/1.7/doc) [![Build Status](https://travis-ci.org/KnpLabs/php-github-api.svg?branch=master)](https://travis-ci.org/KnpLabs/php-github-api) [![StyleCI](https://styleci.io/repos/3948501/shield?style=flat)](https://styleci.io/repos/3948501) From 9717e8edd357d29926c2083fb979398262d84bba Mon Sep 17 00:00:00 2001 From: Yevhenii Huselietov Date: Wed, 27 Jul 2016 11:34:02 +0300 Subject: [PATCH 376/951] Spelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31d63bb9404..25943a22197 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PHP GitHub API 2.0 -In 2.0 lib no longer uses guzzle 3.7, instead we have an HTTPlug abstraction layer. +In 2.0 lib no longer uses guzzle 3.7, instead it has an HTTPlug abstraction layer. For old version please check: From 2f362c1676aec2746a0811f7282d4c7f542e80af Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 10:18:25 +0200 Subject: [PATCH 377/951] Make sure we are following redirects --- lib/Github/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 9279ce5c4fd..da4ffa14f98 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -146,6 +146,7 @@ public function __construct(HttpClient $httpClient = null) $this->responseHistory = new History(); $this->addPlugin(new GithubExceptionThrower()); $this->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); + $this->addPlugin(new Plugin\RedirectPlugin()); $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com/'))); $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', From 24e4b08b5f679fba86d97810cebe4adbc2e3b8c5 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 12:51:36 +0200 Subject: [PATCH 378/951] Use PSR6 cache --- README.md | 16 ++-- composer.json | 5 +- lib/Github/Client.php | 18 ++-- .../HttpClient/Cache/CacheInterface.php | 51 ----------- .../HttpClient/Cache/FilesystemCache.php | 85 ------------------ .../HttpClient/Cache/GaufretteCache.php | 71 --------------- .../HttpClient/Cache/ResponseSerializer.php | 61 ------------- lib/Github/HttpClient/Plugin/Cache.php | 87 ------------------- .../HttpClient/Cache/FilesystemCacheTest.php | 43 --------- .../HttpClient/Cache/GaufretteCacheTest.php | 84 ------------------ 10 files changed, 17 insertions(+), 504 deletions(-) delete mode 100644 lib/Github/HttpClient/Cache/CacheInterface.php delete mode 100644 lib/Github/HttpClient/Cache/FilesystemCache.php delete mode 100644 lib/Github/HttpClient/Cache/GaufretteCache.php delete mode 100644 lib/Github/HttpClient/Cache/ResponseSerializer.php delete mode 100644 lib/Github/HttpClient/Plugin/Cache.php delete mode 100644 test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php delete mode 100644 test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php diff --git a/README.md b/README.md index 25943a22197..c279b888116 100644 --- a/README.md +++ b/README.md @@ -69,15 +69,15 @@ From `$client` object, you can access to all GitHub. // This file is generated by Composer require_once 'vendor/autoload.php'; +use Cache\Adapter\Redis\RedisCachePool; + +$client = new \Redis(); +$client->connect('127.0.0.1', 6379); +// Create a PSR6 cache pool +$pool = new RedisCachePool($client); + $client = new \Github\Client(); -$client->useCache(); - -// Or select directly which cache you want to use -$client->useCache( - // Built in one, or any cache implementing this interface: - // Github\HttpClient\Cache\CacheInterface - new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache') -); +$client->useCache($pool); ``` Using cache, the client will get cached responses if resources haven't changed since last time, diff --git a/composer.json b/composer.json index 0519519435c..378211fce5f 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,13 @@ ], "require": { "php": "^5.5|^7.0", + "psr/http-message": "^1.0", + "psr/cache": "^1.0", "php-http/httplug": "^1.0", "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.1" + "php-http/client-common": "^1.1", + "php-http/cache-plugin": "^1.0" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 9279ce5c4fd..1d807b62db5 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -5,9 +5,7 @@ use Github\Api\ApiInterface; use Github\Exception\InvalidArgumentException; use Github\Exception\BadMethodCallException; -use Github\HttpClient\Cache\CacheInterface; use Github\HttpClient\Plugin\Authentication; -use Github\HttpClient\Plugin\Cache; use Github\HttpClient\Plugin\GithubExceptionThrower; use Github\HttpClient\Plugin\History; use Github\HttpClient\Plugin\PathPrepend; @@ -19,6 +17,7 @@ use Http\Discovery\MessageFactoryDiscovery; use Http\Discovery\UriFactoryDiscovery; use Http\Message\MessageFactory; +use Psr\Cache\CacheItemPoolInterface; /** * Simple yet very cool PHP GitHub client. @@ -375,19 +374,12 @@ public function addHeaders(array $headers) } /** - * @param bool|CacheInterface $cache + * @param CacheItemPoolInterface $cache */ - public function useCache($cache = true) + public function useCache(CacheItemPoolInterface $cachePool) { - $this->removePlugin(Cache::class); - if ($cache !== false) { - if ($cache instanceof CacheInterface) { - $plugin = new Cache($cache); - } else { - $plugin = new Cache(); - } - $this->addPlugin($plugin); - } + $this->removePlugin(Plugin\CachePlugin::class); + $this->addPlugin(new Plugin\CachePlugin($cachePool)); } /** diff --git a/lib/Github/HttpClient/Cache/CacheInterface.php b/lib/Github/HttpClient/Cache/CacheInterface.php deleted file mode 100644 index 014e0d20626..00000000000 --- a/lib/Github/HttpClient/Cache/CacheInterface.php +++ /dev/null @@ -1,51 +0,0 @@ - - */ -interface CacheInterface -{ - /** - * @param string $id The id of the cached resource - * - * @return bool if present - */ - public function has($id); - - /** - * @param string $id The id of the cached resource - * - * @return null|int The modified since timestamp - */ - public function getModifiedSince($id); - - /** - * @param string $id The id of the cached resource - * - * @return null|string The ETag value - */ - public function getETag($id); - - /** - * @param string $id The id of the cached resource - * - * @throws \InvalidArgumentException If cache data don't exists - * - * @return ResponseInterface The cached response object - */ - public function get($id); - - /** - * @param string $id The id of the cached resource - * @param ResponseInterface $response The response to cache - * - * @throws \InvalidArgumentException If cache data cannot be saved - */ - public function set($id, ResponseInterface $response); -} diff --git a/lib/Github/HttpClient/Cache/FilesystemCache.php b/lib/Github/HttpClient/Cache/FilesystemCache.php deleted file mode 100644 index 82581b62a75..00000000000 --- a/lib/Github/HttpClient/Cache/FilesystemCache.php +++ /dev/null @@ -1,85 +0,0 @@ -path = $path; - } - - /** - * {@inheritdoc} - */ - public function get($id) - { - if (false !== $content = @file_get_contents($this->getPath($id))) { - return ResponseSerializer::unserialize($content); - } - - throw new \InvalidArgumentException(sprintf('File "%s" not found', $this->getPath($id))); - } - - /** - * {@inheritdoc} - */ - public function set($id, ResponseInterface $response) - { - if (!is_dir($this->path)) { - @mkdir($this->path, 0777, true); - } - - if (false === @file_put_contents($this->getPath($id), ResponseSerializer::serialize($response))) { - throw new \InvalidArgumentException(sprintf('Cannot put content in file "%s"', $this->getPath($id))); - } - if (false === @file_put_contents($this->getPath($id).'.etag', $response->getHeader('ETag'))) { - throw new \InvalidArgumentException(sprintf('Cannot put content in file "%s"', $this->getPath($id).'.etag')); - } - } - - /** - * {@inheritdoc} - */ - public function has($id) - { - return file_exists($this->getPath($id)); - } - - /** - * {@inheritdoc} - */ - public function getModifiedSince($id) - { - if ($this->has($id)) { - return filemtime($this->getPath($id)); - } - } - - public function getETag($id) - { - if (file_exists($this->getPath($id).'.etag')) { - return file_get_contents($this->getPath($id).'.etag'); - } - } - - /** - * @param $id string - * - * @return string - */ - protected function getPath($id) - { - return sprintf('%s%s%s', rtrim($this->path, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, md5($id)); - } -} diff --git a/lib/Github/HttpClient/Cache/GaufretteCache.php b/lib/Github/HttpClient/Cache/GaufretteCache.php deleted file mode 100644 index 812be7cbbb2..00000000000 --- a/lib/Github/HttpClient/Cache/GaufretteCache.php +++ /dev/null @@ -1,71 +0,0 @@ - - */ -class GaufretteCache implements CacheInterface -{ - /** - * @var Filesystem - */ - protected $filesystem; - - /** - * @param Filesystem $filesystem - */ - public function __construct(Filesystem $filesystem) - { - $this->filesystem = $filesystem; - } - - /** - * {@inheritdoc} - */ - public function get($id) - { - $content = $this->filesystem->read($id); - - return ResponseSerializer::unserialize($content); - } - - /** - * {@inheritdoc} - */ - public function set($id, ResponseInterface $response) - { - $this->filesystem->write($id, ResponseSerializer::serialize($response), true); - $this->filesystem->write($id.'.etag', $response->getHeader('ETag'), true); - } - - /** - * {@inheritdoc} - */ - public function has($id) - { - $this->filesystem->has($id); - } - - /** - * {@inheritdoc} - */ - public function getModifiedSince($id) - { - if ($this->filesystem->has($id)) { - return $this->filesystem->mtime($id); - } - } - - public function getETag($id) - { - if ($this->filesystem->has($id)) { - return $this->filesystem->read($id.'.etag'); - } - } -} diff --git a/lib/Github/HttpClient/Cache/ResponseSerializer.php b/lib/Github/HttpClient/Cache/ResponseSerializer.php deleted file mode 100644 index 43b8d95fa05..00000000000 --- a/lib/Github/HttpClient/Cache/ResponseSerializer.php +++ /dev/null @@ -1,61 +0,0 @@ - - */ -class ResponseSerializer -{ - /** - * @param ResponseInterface $response - * @param StreamFactory|null $streamFactory - * - * @return array - */ - public static function serialize(ResponseInterface $response, StreamFactory $streamFactory = null) - { - $streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); - - $bodyStream = $response->getBody(); - $body = $bodyStream->__toString(); - if ($bodyStream->isSeekable()) { - $bodyStream->rewind(); - } else { - /* - * If the body is not seekbable we can not rewind it. The stream could be a type of stream - * that you only can read once. That is why we have to replace the old stream with a new one. - */ - $response = $response->withBody($streamFactory->createStream($body)); - } - - return serialize(array('response' => serialize($response), 'body' => $body)); - } - - /** - * @param $data - * @param StreamFactory|null $streamFactory - * - * @return ResponseInterface|null - */ - public static function unserialize($serializedData, StreamFactory $streamFactory = null) - { - $data = unserialize($serializedData); - if (!isset($data['response']) || !isset($data['body'])) { - return null; - } - - $streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); - - $response = unserialize($data['response']); - $response = $response->withBody($streamFactory->createStream($data['body'])); - - return $response; - } -} diff --git a/lib/Github/HttpClient/Plugin/Cache.php b/lib/Github/HttpClient/Plugin/Cache.php deleted file mode 100644 index cc4397dd59e..00000000000 --- a/lib/Github/HttpClient/Plugin/Cache.php +++ /dev/null @@ -1,87 +0,0 @@ - - * @author Tobias Nyholm - */ -class Cache implements Plugin -{ - /** - * @var CacheInterface - */ - protected $cache; - - /** - * - * @param CacheInterface $cache - */ - public function __construct(CacheInterface $cache = null) - { - $this->cache = $cache; - } - - /** - * {@inheritdoc} - */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) - { - $cacheKey = sha1($request->getUri()->__toString()); - - if ($modifiedAt = $this->getCache()->getModifiedSince($cacheKey)) { - $modifiedAt = new \DateTime('@'.$modifiedAt); - $modifiedAt->setTimezone(new \DateTimeZone('GMT')); - - $request = $request->withHeader( - 'If-Modified-Since', - sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) - ); - } - if ($etag = $this->getCache()->getETag($cacheKey)) { - $request = $request->withHeader( - 'If-None-Match', - $etag - ); - } - - return $next($request)->then(function (ResponseInterface $response) use ($request, $cacheKey) { - if (304 === $response->getStatusCode()) { - $cacheResponse = $this->getCache()->get($cacheKey); - $this->lastCachedResponse = $cacheResponse; - - return $cacheResponse; - } - - if (in_array($request->getMethod(), array('GET', 'HEAD'), true)) { - $this->getCache()->set($cacheKey, $response); - } - - return $response; - }); - } - - - /** - * @return CacheInterface - */ - public function getCache() - { - if (null === $this->cache) { - $this->cache = new FilesystemCache(sys_get_temp_dir().DIRECTORY_SEPARATOR.'php-github-api-cache'); - } - - return $this->cache; - } -} diff --git a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php b/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php deleted file mode 100644 index 6383fecad5a..00000000000 --- a/test/Github/Tests/HttpClient/Cache/FilesystemCacheTest.php +++ /dev/null @@ -1,43 +0,0 @@ -set('test', new Response(200)); - - $this->assertNotNull($cache->get('test')); - } - - /** - * @test - */ - public function shouldGetATimestampForExistingFile() - { - $cache = new FilesystemCache('/tmp/github-api-test'); - - $cache->set('test', new Response(200)); - - $this->assertInternalType('int', $cache->getModifiedSince('test')); - } - - /** - * @test - */ - public function shouldNotGetATimestampForInexistingFile() - { - $cache = new FilesystemCache('/tmp/github-api-test'); - - $this->assertNull($cache->getModifiedSince('test2')); - } -} diff --git a/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php b/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php deleted file mode 100644 index 2e033f53b46..00000000000 --- a/test/Github/Tests/HttpClient/Cache/GaufretteCacheTest.php +++ /dev/null @@ -1,84 +0,0 @@ -markTestSkipped('Gaufrette not installed.'); - } - } - - /** - * @test - */ - public function shouldStoreAResponseForAGivenKey() - { - $response = new Response(200); - $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); - $filesystem - ->expects($this->once()) - ->method('write') - ->with('test', serialize($response)) - ; - $filesystem - ->expects($this->once()) - ->method('read') - ->with('test') - ->will($this->returnValue('a:0:{}')) - ; - - $cache = new GaufretteCache($filesystem); - $cache->set('test', $response); - $this->assertNotNull($cache->get('test')); - } - - /** - * @test - */ - public function shouldGetATimestampForExistingFile() - { - $response = new Response(200); - $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); - $filesystem - ->expects($this->once()) - ->method('has') - ->with('test') - ->will($this->returnValue(true)) - ; - $filesystem - ->expects($this->once()) - ->method('mtime') - ->with('test') - ->will($this->returnValue(100)) - ; - - $cache = new GaufretteCache($filesystem); - $cache->set('test', new Response(200)); - - $this->assertInternalType('int', $cache->getModifiedSince('test')); - } - - /** - * @test - */ - public function shouldNotGetATimestampForInexistingFile() - { - $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); - $filesystem - ->expects($this->once()) - ->method('has') - ->with('test2') - ->will($this->returnValue(false)) - ; - - $cache = new GaufretteCache($filesystem); - - $this->assertNull($cache->getModifiedSince('test2')); - } -} From 956f363181f9e94621e9be66d89b26cb3fc77977 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 12:59:28 +0200 Subject: [PATCH 379/951] Typos and bugfix --- lib/Github/Client.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 9279ce5c4fd..1c788492c48 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -312,15 +312,16 @@ protected function addPlugin(Plugin $plugin) } /** - * Remove a plugin by its fqn. + * Remove a plugin by its fully qualified class name (FQCN). * - * @param string $fqn + * @param string $fqcn */ - protected function removePlugin($fqn) + protected function removePlugin($fqcn) { foreach ($this->plugins as $idx => $plugin) { - if ($plugin instanceof $fqn) { + if ($plugin instanceof $fqcn) { unset($this->plugins[$idx]); + $this->httpClientModified = true; } } } From 035e6defe08379bd3086e0d5381bda9a8ce4f0af Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 13:04:49 +0200 Subject: [PATCH 380/951] Added a way to opt-out of the cache --- README.md | 7 ++++++- lib/Github/Client.php | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c279b888116..fe59dfaed82 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,12 @@ $client->connect('127.0.0.1', 6379); $pool = new RedisCachePool($client); $client = new \Github\Client(); -$client->useCache($pool); +$client->addCache($pool); + +// Do some request + +// Stop using cache +$client->removeCache(); ``` Using cache, the client will get cached responses if resources haven't changed since last time, diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 1d807b62db5..d59107674ae 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -374,14 +374,23 @@ public function addHeaders(array $headers) } /** + * Add a cache plugin to cache responses locally. * @param CacheItemPoolInterface $cache */ - public function useCache(CacheItemPoolInterface $cachePool) + public function addCache(CacheItemPoolInterface $cachePool) { $this->removePlugin(Plugin\CachePlugin::class); $this->addPlugin(new Plugin\CachePlugin($cachePool)); } + /** + * Remove the cache plugin + */ + public function removeCache() + { + $this->removePlugin(Plugin\CachePlugin::class); + } + /** * @param string $name * From 3a343d76169be7a11a2ef7339c7bd28d1498d861 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 13:06:40 +0200 Subject: [PATCH 381/951] Calling removeCache() --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index d59107674ae..62f239b8971 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -379,7 +379,7 @@ public function addHeaders(array $headers) */ public function addCache(CacheItemPoolInterface $cachePool) { - $this->removePlugin(Plugin\CachePlugin::class); + $this->removeCache(); $this->addPlugin(new Plugin\CachePlugin($cachePool)); } From d0e59997d54e027d30cfa7f747f6262df0f37144 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 13:10:41 +0200 Subject: [PATCH 382/951] proper indentation and syntax --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 378211fce5f..92f423931ee 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^5.5|^7.0", + "php": "^5.5 || ^7.0", "psr/http-message": "^1.0", "psr/cache": "^1.0", "php-http/httplug": "^1.0", From a1b836251090713d1dcd32dec4f6f233ea226658 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 29 Jul 2016 13:11:43 +0200 Subject: [PATCH 383/951] Remove the suggest for Gaufrette --- composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/composer.json b/composer.json index 92f423931ee..5b7eb44548a 100644 --- a/composer.json +++ b/composer.json @@ -32,9 +32,6 @@ "guzzlehttp/psr7": "^1.2", "sllh/php-cs-fixer-styleci-bridge": "~1.3" }, - "suggest": { - "knplabs/gaufrette": "Needed for optional Gaufrette cache" - }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } }, From ddcd7b40b778abbe45e9f16069119926cf8f51f5 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 29 Jul 2016 10:24:35 -0400 Subject: [PATCH 384/951] Allow access to the plugin methods --- lib/Github/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 317b8a769e4..03b4533b866 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -305,7 +305,7 @@ public function setEnterpriseUrl($enterpriseUrl) * * @param Plugin $plugin */ - protected function addPlugin(Plugin $plugin) + public function addPlugin(Plugin $plugin) { $this->plugins[] = $plugin; $this->httpClientModified = true; @@ -316,7 +316,7 @@ protected function addPlugin(Plugin $plugin) * * @param string $fqcn */ - protected function removePlugin($fqcn) + public function removePlugin($fqcn) { foreach ($this->plugins as $idx => $plugin) { if ($plugin instanceof $fqcn) { From 6ee45251939c535c287224ba9813e7013501756d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 29 Jul 2016 10:52:11 -0400 Subject: [PATCH 385/951] Fixed the cache plugin --- lib/Github/Client.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 317b8a769e4..c11f7cd3b16 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -15,8 +15,10 @@ use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\StreamFactoryDiscovery; use Http\Discovery\UriFactoryDiscovery; use Http\Message\MessageFactory; +use Http\Message\SteamFactory; use Psr\Cache\CacheItemPoolInterface; /** @@ -110,6 +112,11 @@ class Client */ private $messageFactory; + /** + * @var StreamFactory + */ + private $streamFactory; + /** * @var Plugin[] */ @@ -141,6 +148,7 @@ public function __construct(HttpClient $httpClient = null) { $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->messageFactory = MessageFactoryDiscovery::find(); + $this->streamFactory = StreamFactoryDiscovery::find(); $this->responseHistory = new History(); $this->addPlugin(new GithubExceptionThrower()); @@ -382,7 +390,7 @@ public function addHeaders(array $headers) public function addCache(CacheItemPoolInterface $cachePool) { $this->removeCache(); - $this->addPlugin(new Plugin\CachePlugin($cachePool)); + $this->addPlugin(new Plugin\CachePlugin($cachePool, $this->streamFactory)); } /** From b9d58dce7606c0c4717bc9bbac3747bbe6117e0a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 30 Jul 2016 06:19:33 -0400 Subject: [PATCH 386/951] Fixed the exceptions --- lib/Github/Exception/ExceptionInterface.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Github/Exception/ExceptionInterface.php b/lib/Github/Exception/ExceptionInterface.php index cba560542bb..87e6d2f77fa 100644 --- a/lib/Github/Exception/ExceptionInterface.php +++ b/lib/Github/Exception/ExceptionInterface.php @@ -2,6 +2,8 @@ namespace Github\Exception; -interface ExceptionInterface +use Http\Client\Exception; + +interface ExceptionInterface extends Exception { } From 6bf3574006b5cf51d2ef952667954f3855317783 Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Sun, 31 Jul 2016 04:49:50 +0200 Subject: [PATCH 387/951] Added missing parameters to repo/release API --- lib/Github/Api/Repository/Releases.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 94d130ef031..8e053a67c6d 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -44,12 +44,13 @@ public function tag($username, $repository, $tag) * * @param string $username the user who owns the repo * @param string $repository the name of the repo + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction * * @return array */ - public function all($username, $repository) + public function all($username, $repository, array $params = array()) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); } /** From 928177e7d0f248f45a4e1546375b7776eb89c8bf Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Sun, 31 Jul 2016 04:58:00 +0200 Subject: [PATCH 388/951] Allow short array due to php version constraint in composer.json --- lib/Github/Api/Repository/Releases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 8e053a67c6d..e25b1e7ef84 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -48,7 +48,7 @@ public function tag($username, $repository, $tag) * * @return array */ - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); } From 748f44ab13fb020509a44f9bf70304652eb7124b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 31 Jul 2016 14:49:39 +0200 Subject: [PATCH 389/951] Make sure cache is added after pathprepend and addHost plugins --- lib/Github/Client.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index bcf0ef0d792..c5b51f558dc 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -18,7 +18,7 @@ use Http\Discovery\StreamFactoryDiscovery; use Http\Discovery\UriFactoryDiscovery; use Http\Message\MessageFactory; -use Http\Message\SteamFactory; +use Nyholm\Psr7\Factory\StreamFactory; use Psr\Cache\CacheItemPoolInterface; /** @@ -309,7 +309,7 @@ public function setEnterpriseUrl($enterpriseUrl) } /** - * Add a new plugin to the chain + * Add a new plugin to the end of the plugin chain. * * @param Plugin $plugin */ @@ -341,6 +341,8 @@ public function getHttpClient() { if ($this->httpClientModified) { $this->httpClientModified = false; + $this->pushBackCachePlugin(); + $this->pluginClient = new HttpMethodsClient( new PluginClient($this->httpClient, $this->plugins), $this->messageFactory @@ -457,4 +459,22 @@ public function getLastResponse() { return $this->responseHistory->getLastResponse(); } + + + /** + * Make sure to move the cache plugin to the end of the chain + */ + private function pushBackCachePlugin() + { + $cachePlugin = null; + foreach ($this->plugins as $i => $plugin) { + if ($plugin instanceof Plugin\CachePlugin) { + $cachePlugin = $plugin; + unset($this->plugins[$i]); + + $this->plugins[] = $cachePlugin; + return; + } + } + } } From c11a4280eb40ff3c57fb3fae441e8599dc026a37 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 31 Jul 2016 15:00:11 +0200 Subject: [PATCH 390/951] Style fux --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c5b51f558dc..c8cab508f3c 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -460,7 +460,6 @@ public function getLastResponse() return $this->responseHistory->getLastResponse(); } - /** * Make sure to move the cache plugin to the end of the chain */ @@ -473,6 +472,7 @@ private function pushBackCachePlugin() unset($this->plugins[$i]); $this->plugins[] = $cachePlugin; + return; } } From 2dc30b5f2be9cca646d2c3a9d4fe67542eeb7a8a Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 31 Jul 2016 15:03:55 +0200 Subject: [PATCH 391/951] Make sure to add accept header --- lib/Github/Client.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index bcf0ef0d792..e108486d824 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -158,6 +158,8 @@ public function __construct(HttpClient $httpClient = null) $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ))); + // Add standard headers. + $this->clearHeaders(); } /** @@ -430,6 +432,12 @@ public function setOption($name, $value) throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); } + if ($name === 'api_version') { + $this->addHeaders([ + 'Accept' => sprintf('application/vnd.github.%s+json', $value), + ]); + } + $this->options[$name] = $value; } From 8fb3bfd3fd2310ac9b63458c7c7d0adb954f79c8 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 31 Jul 2016 15:14:23 +0200 Subject: [PATCH 392/951] Removed options on the client --- lib/Github/Api/GitData/Blobs.php | 4 +- lib/Github/Api/Issue/Comments.php | 2 +- lib/Github/Api/Repository/Comments.php | 10 ++-- lib/Github/Api/Repository/Stargazers.php | 2 +- lib/Github/Client.php | 71 +++++++++--------------- 5 files changed, 36 insertions(+), 53 deletions(-) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index a0a68e55be8..a5ebfd627bb 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -14,7 +14,7 @@ class Blobs extends AbstractApi { use AcceptHeaderTrait; - + /** * Configure the Accept header depending on the blob type. * @@ -23,7 +23,7 @@ class Blobs extends AbstractApi public function configure($bodyType = null) { if ('raw' === $bodyType) { - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getOption('api_version')); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getApiVersion()); } } diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index a8e6825d892..f1d19515718 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -27,7 +27,7 @@ public function configure($bodyType = null) $bodyType = 'full'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); } /** diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index d3fe8a09381..f9d2a54af2b 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -14,24 +14,24 @@ class Comments extends AbstractApi { use AcceptHeaderTrait; - + public function configure($bodyType = null) { switch ($bodyType) { case 'raw': - $header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version')); + $header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getApiVersion()); break; case 'text': - $header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version')); + $header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getApiVersion()); break; case 'html': - $header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version')); + $header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getApiVersion()); break; default: - $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version')); + $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getApiVersion()); } $this->acceptHeaderValue = $header; diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index f1d54db8fc2..9b7a8470002 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -24,7 +24,7 @@ class Stargazers extends AbstractApi public function configure($bodyType = null) { if ('star' === $bodyType) { - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getOption('api_version')); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e108486d824..8c1565d2f8d 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -87,11 +87,9 @@ class Client const AUTH_HTTP_TOKEN = 'http_token'; /** - * @var array + * @var string */ - private $options = array( - 'api_version' => 'v3', - ); + private $apiVersion = 'v3'; /** * The object that sends HTTP messages @@ -307,7 +305,7 @@ public function setEnterpriseUrl($enterpriseUrl) $this->removePlugin(PathPrepend::class); $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); - $this->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getOption('api_version')))); + $this->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); } /** @@ -361,13 +359,36 @@ public function setHttpClient(HttpClient $httpClient) $this->httpClient = $httpClient; } + /** + * @return string + */ + public function getApiVersion() + { + return $this->apiVersion; + } + + /** + * @param string $apiVersion + * + * @return Client + */ + public function setApiVersion($apiVersion) + { + $this->apiVersion = $apiVersion; + $this->addHeaders([ + 'Accept' => sprintf('application/vnd.github.%s+json', $apiVersion), + ]); + + return $this; + } + /** * Clears used headers. */ public function clearHeaders() { $this->headers = array( - 'Accept' => sprintf('application/vnd.github.%s+json', $this->options['api_version']), + 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), ); $this->removePlugin(Plugin\HeaderAppendPlugin::class); @@ -403,44 +424,6 @@ public function removeCache() $this->removePlugin(Plugin\CachePlugin::class); } - /** - * @param string $name - * - * @throws InvalidArgumentException - * - * @return mixed - */ - public function getOption($name) - { - if (!array_key_exists($name, $this->options)) { - throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); - } - - return $this->options[$name]; - } - - /** - * @param string $name - * @param mixed $value - * - * @throws InvalidArgumentException - * @throws InvalidArgumentException - */ - public function setOption($name, $value) - { - if (!array_key_exists($name, $this->options)) { - throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); - } - - if ($name === 'api_version') { - $this->addHeaders([ - 'Accept' => sprintf('application/vnd.github.%s+json', $value), - ]); - } - - $this->options[$name] = $value; - } - /** * @param string $name * From facf063444bef0bae216a592b8dd069edc988b02 Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Mon, 1 Aug 2016 03:11:01 +0200 Subject: [PATCH 393/951] Added missing parameters to repo/tags API --- lib/Github/Api/GitData/Tags.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index 4b2d0341ef3..07fdf6d15f6 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -16,12 +16,13 @@ class Tags extends AbstractApi * * @param string $username * @param string $repository + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction * * @return array */ - public function all($username, $repository) + public function all($username, $repository, array $params = []) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags', $params); } /** From 704f8fbd9d7efa87fbf830cac4d4efe46369880c Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Mon, 1 Aug 2016 03:46:32 +0200 Subject: [PATCH 394/951] Added missing parameters to repo/tags API, again --- lib/Github/Api/GitData/Tags.php | 5 ++--- lib/Github/Api/Repo.php | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index 07fdf6d15f6..4b2d0341ef3 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -16,13 +16,12 @@ class Tags extends AbstractApi * * @param string $username * @param string $repository - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction * * @return array */ - public function all($username, $repository, array $params = []) + public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags', $params); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } /** diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 9d98c3f1fe5..755c23bb91c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -420,12 +420,13 @@ public function languages($username, $repository) * * @param string $username the user who owns the repository * @param string $repository the name of the repository + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction * * @return array list of the repository tags */ - public function tags($username, $repository) + public function tags($username, $repository, array $params = []) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags'); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags', $params); } /** From 9f6c5beb185d7154808878c3987d43df956d1a6e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 1 Aug 2016 09:56:43 +0200 Subject: [PATCH 395/951] Updated functional tests with getApiVersion --- test/Github/Tests/Functional/RepoTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Functional/RepoTest.php b/test/Github/Tests/Functional/RepoTest.php index 7416a3384d8..3d6946f9ffe 100644 --- a/test/Github/Tests/Functional/RepoTest.php +++ b/test/Github/Tests/Functional/RepoTest.php @@ -15,7 +15,7 @@ public function shouldShowPRDiffIfHeaderIsPresent() $this->client->addHeaders( array('Accept' => sprintf( 'application/vnd.github.%s.diff', - $this->client->getOption('api_version') + $this->client->getApiVersion() )) ); From 71cee7d9482898beb560bbad3df446a722c8f839 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 1 Aug 2016 10:02:28 +0200 Subject: [PATCH 396/951] Added docs about api_version --- doc/api_version.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/api_version.md diff --git a/doc/api_version.md b/doc/api_version.md new file mode 100644 index 00000000000..a352f926968 --- /dev/null +++ b/doc/api_version.md @@ -0,0 +1,14 @@ +## Api version +[Back to the navigation](README.md) + +If you want to change the API version from its default ("v3") you may do that with +the `setApiVersion` function. +For example: + +```php +$client = new Github\Client(); + +echo $client->getApiVersion(); // prints "s3" + +$client->setApiVersion("v2"); +``` From a040008a051a12350f13554b285d0f92379b6310 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 1 Aug 2016 09:11:49 +0100 Subject: [PATCH 397/951] Allow setting the api version and enterprise url on construct --- lib/Github/Client.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index f6861a01010..ffbe5f2399d 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -89,7 +89,7 @@ class Client /** * @var string */ - private $apiVersion = 'v3'; + private $apiVersion; /** * The object that sends HTTP messages @@ -141,8 +141,10 @@ class Client * Instantiate a new GitHub client. * * @param HttpClient|null $httpClient + * @param string|null $apiVersion + * @param string|null $enterpriseUrl */ - public function __construct(HttpClient $httpClient = null) + public function __construct(HttpClient $httpClient = null, $apiVersion = null, $enterpriseUrl = null) { $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->messageFactory = MessageFactoryDiscovery::find(); @@ -156,8 +158,12 @@ public function __construct(HttpClient $httpClient = null) $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ))); - // Add standard headers. - $this->clearHeaders(); + + $this->setApiVersion($apiVersion ?: 'v3'); + + if ($enterpriseUrl) { + $this->setEnterpriseUrl($enterpriseUrl); + } } /** From e6d3ba19979e03a8fc8309abad5fdfc0fe5b6261 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 1 Aug 2016 11:12:59 +0200 Subject: [PATCH 398/951] Added docs for constructor argument --- doc/api_version.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/api_version.md b/doc/api_version.md index a352f926968..4ae8d84925a 100644 --- a/doc/api_version.md +++ b/doc/api_version.md @@ -1,14 +1,13 @@ ## Api version [Back to the navigation](README.md) -If you want to change the API version from its default ("v3") you may do that with -the `setApiVersion` function. +If you want to change the API version from its default ("v3") you may do that with a constructor argument. For example: ```php $client = new Github\Client(); - echo $client->getApiVersion(); // prints "s3" -$client->setApiVersion("v2"); +$client = new Github\Client($httpClient, 'v2'); +echo $client->getApiVersion(); // prints "s2" ``` From cf5d58eea3545f2b8e9887cb98d1f05fbbd55111 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 1 Aug 2016 11:15:24 +0200 Subject: [PATCH 399/951] Removed setter for ApiVersion and EnterpriceUrl --- lib/Github/Client.php | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ffbe5f2399d..582351505c9 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -159,7 +159,8 @@ public function __construct(HttpClient $httpClient = null, $apiVersion = null, $ 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ))); - $this->setApiVersion($apiVersion ?: 'v3'); + $this->apiVersion = $apiVersion ?: 'v3'; + $this->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); if ($enterpriseUrl) { $this->setEnterpriseUrl($enterpriseUrl); @@ -305,7 +306,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null * * @param string $enterpriseUrl URL of the API in the form of http(s)://hostname */ - public function setEnterpriseUrl($enterpriseUrl) + private function setEnterpriseUrl($enterpriseUrl) { $this->removePlugin(Plugin\AddHostPlugin::class); $this->removePlugin(PathPrepend::class); @@ -375,21 +376,6 @@ public function getApiVersion() return $this->apiVersion; } - /** - * @param string $apiVersion - * - * @return Client - */ - public function setApiVersion($apiVersion) - { - $this->apiVersion = $apiVersion; - $this->addHeaders([ - 'Accept' => sprintf('application/vnd.github.%s+json', $apiVersion), - ]); - - return $this; - } - /** * Clears used headers. */ From 08083e5a455f14ee8010b73f87715c576a84f27e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 1 Aug 2016 11:20:00 +0200 Subject: [PATCH 400/951] typo --- doc/api_version.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api_version.md b/doc/api_version.md index 4ae8d84925a..a8bc733461b 100644 --- a/doc/api_version.md +++ b/doc/api_version.md @@ -6,8 +6,8 @@ For example: ```php $client = new Github\Client(); -echo $client->getApiVersion(); // prints "s3" +echo $client->getApiVersion(); // prints "v3" $client = new Github\Client($httpClient, 'v2'); -echo $client->getApiVersion(); // prints "s2" +echo $client->getApiVersion(); // prints "v2" ``` From 51cd04cca6341ccca552127ed5921c24972204c1 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 2 Aug 2016 17:21:28 +0200 Subject: [PATCH 401/951] Make sure we always use valid urls --- lib/Github/Api/Authorizations.php | 18 ++++----- lib/Github/Api/CurrentUser.php | 22 +++++------ lib/Github/Api/CurrentUser/DeployKeys.php | 10 ++--- lib/Github/Api/CurrentUser/Emails.php | 6 +-- lib/Github/Api/CurrentUser/Followers.php | 8 ++-- lib/Github/Api/CurrentUser/Memberships.php | 6 +-- lib/Github/Api/CurrentUser/Notifications.php | 18 ++++----- lib/Github/Api/CurrentUser/Starring.php | 8 ++-- lib/Github/Api/CurrentUser/Watchers.php | 8 ++-- lib/Github/Api/Deployment.php | 8 ++-- lib/Github/Api/Enterprise/License.php | 2 +- lib/Github/Api/Enterprise/Stats.php | 2 +- lib/Github/Api/Enterprise/UserAdmin.php | 4 +- lib/Github/Api/Gist/Comments.php | 10 ++--- lib/Github/Api/Gists.php | 24 ++++++------ lib/Github/Api/GitData/Commits.php | 4 +- lib/Github/Api/GitData/References.php | 14 +++---- lib/Github/Api/GitData/Tags.php | 6 +-- lib/Github/Api/GitData/Trees.php | 4 +- lib/Github/Api/Issue.php | 12 +++--- lib/Github/Api/Issue/Events.php | 6 +-- lib/Github/Api/Issue/Labels.php | 18 ++++----- lib/Github/Api/Issue/Milestones.php | 12 +++--- lib/Github/Api/Markdown.php | 4 +- lib/Github/Api/Meta.php | 2 +- lib/Github/Api/Notification.php | 4 +- lib/Github/Api/Organization.php | 10 ++--- lib/Github/Api/Organization/Hooks.php | 12 +++--- lib/Github/Api/Organization/Members.php | 18 ++++----- lib/Github/Api/Organization/Teams.php | 26 ++++++------- lib/Github/Api/PullRequest.php | 16 ++++---- lib/Github/Api/PullRequest/Comments.php | 10 ++--- lib/Github/Api/RateLimit.php | 6 +-- lib/Github/Api/Repo.php | 40 ++++++++++---------- lib/Github/Api/Repository/Assets.php | 8 ++-- lib/Github/Api/Repository/Collaborators.php | 8 ++-- lib/Github/Api/Repository/Commits.php | 6 +-- lib/Github/Api/Repository/Contents.php | 14 +++---- lib/Github/Api/Repository/DeployKeys.php | 10 ++--- lib/Github/Api/Repository/Downloads.php | 6 +-- lib/Github/Api/Repository/Forks.php | 4 +- lib/Github/Api/Repository/Hooks.php | 14 +++---- lib/Github/Api/Repository/Labels.php | 10 ++--- lib/Github/Api/Repository/Releases.php | 14 +++---- lib/Github/Api/Repository/Statuses.php | 6 +-- lib/Github/Api/Search.php | 8 ++-- lib/Github/Api/User.php | 28 +++++++------- lib/Github/Client.php | 2 +- 48 files changed, 258 insertions(+), 258 deletions(-) diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index b8c4f5bd8fe..5e6853fd773 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -17,7 +17,7 @@ class Authorizations extends AbstractApi */ public function all() { - return $this->get('authorizations'); + return $this->get('/authorizations'); } /** @@ -29,7 +29,7 @@ public function all() */ public function show($clientId) { - return $this->get('authorizations/'.rawurlencode($clientId)); + return $this->get('/authorizations/'.rawurlencode($clientId)); } /** @@ -44,7 +44,7 @@ public function create(array $params, $OTPCode = null) { $headers = null === $OTPCode ? array() : array('X-GitHub-OTP' => $OTPCode); - return $this->post('authorizations', $params, $headers); + return $this->post('/authorizations', $params, $headers); } /** @@ -57,7 +57,7 @@ public function create(array $params, $OTPCode = null) */ public function update($clientId, array $params) { - return $this->patch('authorizations/'.rawurlencode($clientId), $params); + return $this->patch('/authorizations/'.rawurlencode($clientId), $params); } /** @@ -69,7 +69,7 @@ public function update($clientId, array $params) */ public function remove($clientId) { - return $this->delete('authorizations/'.rawurlencode($clientId)); + return $this->delete('/authorizations/'.rawurlencode($clientId)); } /** @@ -82,7 +82,7 @@ public function remove($clientId) */ public function check($clientId, $token) { - return $this->get('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); + return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } /** @@ -95,7 +95,7 @@ public function check($clientId, $token) */ public function reset($clientId, $token) { - return $this->post('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); + return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } /** @@ -106,7 +106,7 @@ public function reset($clientId, $token) */ public function revoke($clientId, $token) { - $this->delete('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); + $this->delete('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } /** @@ -116,6 +116,6 @@ public function revoke($clientId, $token) */ public function revokeAll($clientId) { - $this->delete('applications/'.rawurlencode($clientId).'/tokens'); + $this->delete('/applications/'.rawurlencode($clientId).'/tokens'); } } diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index b525ee185a9..bbaea2daafb 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -19,12 +19,12 @@ class CurrentUser extends AbstractApi { public function show() { - return $this->get('user'); + return $this->get('/user'); } public function update(array $params) { - return $this->patch('user', $params); + return $this->patch('/user', $params); } /** @@ -45,7 +45,7 @@ public function follow() public function followers($page = 1) { - return $this->get('user/followers', array( + return $this->get('/user/followers', array( 'page' => $page )); } @@ -60,7 +60,7 @@ public function followers($page = 1) */ public function issues(array $params = array(), $includeOrgIssues = true) { - return $this->get($includeOrgIssues ? 'issues' : 'user/issues', array_merge(array('page' => 1), $params)); + return $this->get($includeOrgIssues ? '/issues' : '/user/issues', array_merge(array('page' => 1), $params)); } /** @@ -94,7 +94,7 @@ public function memberships() */ public function organizations() { - return $this->get('user/orgs'); + return $this->get('/user/orgs'); } /** @@ -104,7 +104,7 @@ public function organizations() */ public function teams() { - return $this->get('user/teams'); + return $this->get('/user/teams'); } /** @@ -118,7 +118,7 @@ public function teams() */ public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->get('user/repos', array( + return $this->get('/user/repos', array( 'type' => $type, 'sort' => $sort, 'direction' => $direction @@ -138,7 +138,7 @@ public function watchers() */ public function watched($page = 1) { - return $this->get('user/watched', array( + return $this->get('/user/watched', array( 'page' => $page )); } @@ -156,16 +156,16 @@ public function starring() */ public function starred($page = 1) { - return $this->get('user/starred', array( + return $this->get('/user/starred', array( 'page' => $page )); } - + /** * @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched */ public function subscriptions() { - return $this->get('user/subscriptions'); + return $this->get('/user/subscriptions'); } } diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/DeployKeys.php index 66b51033da5..dc8df79941f 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/DeployKeys.php @@ -20,7 +20,7 @@ class DeployKeys extends AbstractApi */ public function all() { - return $this->get('user/keys'); + return $this->get('/user/keys'); } /** @@ -34,7 +34,7 @@ public function all() */ public function show($id) { - return $this->get('user/keys/'.rawurlencode($id)); + return $this->get('/user/keys/'.rawurlencode($id)); } /** @@ -54,7 +54,7 @@ public function create(array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->post('user/keys', $params); + return $this->post('/user/keys', $params); } /** @@ -75,7 +75,7 @@ public function update($id, array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->patch('user/keys/'.rawurlencode($id), $params); + return $this->patch('/user/keys/'.rawurlencode($id), $params); } /** @@ -89,6 +89,6 @@ public function update($id, array $params) */ public function remove($id) { - return $this->delete('user/keys/'.rawurlencode($id)); + return $this->delete('/user/keys/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index 9a1ce1e6c6d..8155301ed5d 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -20,7 +20,7 @@ class Emails extends AbstractApi */ public function all() { - return $this->get('user/emails'); + return $this->get('/user/emails'); } /** @@ -42,7 +42,7 @@ public function add($emails) throw new InvalidArgumentException(); } - return $this->post('user/emails', $emails); + return $this->post('/user/emails', $emails); } /** @@ -64,6 +64,6 @@ public function remove($emails) throw new InvalidArgumentException(); } - return $this->delete('user/emails', $emails); + return $this->delete('/user/emails', $emails); } } diff --git a/lib/Github/Api/CurrentUser/Followers.php b/lib/Github/Api/CurrentUser/Followers.php index 303637740cc..19a8e2d37c8 100644 --- a/lib/Github/Api/CurrentUser/Followers.php +++ b/lib/Github/Api/CurrentUser/Followers.php @@ -21,7 +21,7 @@ class Followers extends AbstractApi */ public function all($page = 1) { - return $this->get('user/following', array( + return $this->get('/user/following', array( 'page' => $page )); } @@ -37,7 +37,7 @@ public function all($page = 1) */ public function check($username) { - return $this->get('user/following/'.rawurlencode($username)); + return $this->get('/user/following/'.rawurlencode($username)); } /** @@ -51,7 +51,7 @@ public function check($username) */ public function follow($username) { - return $this->put('user/following/'.rawurlencode($username)); + return $this->put('/user/following/'.rawurlencode($username)); } /** @@ -65,6 +65,6 @@ public function follow($username) */ public function unfollow($username) { - return $this->delete('user/following/'.rawurlencode($username)); + return $this->delete('/user/following/'.rawurlencode($username)); } } diff --git a/lib/Github/Api/CurrentUser/Memberships.php b/lib/Github/Api/CurrentUser/Memberships.php index 650b348ad9f..df87596c38a 100644 --- a/lib/Github/Api/CurrentUser/Memberships.php +++ b/lib/Github/Api/CurrentUser/Memberships.php @@ -15,7 +15,7 @@ class Memberships extends AbstractApi */ public function all() { - return $this->get('user/memberships/orgs'); + return $this->get('/user/memberships/orgs'); } /** @@ -29,7 +29,7 @@ public function all() */ public function organization($organization) { - return $this->get('user/memberships/orgs/'.rawurlencode($organization)); + return $this->get('/user/memberships/orgs/'.rawurlencode($organization)); } /** @@ -43,6 +43,6 @@ public function organization($organization) */ public function edit($organization) { - return $this->patch('user/memberships/orgs/'.rawurlencode($organization), array('state' => 'active')); + return $this->patch('/user/memberships/orgs/'.rawurlencode($organization), array('state' => 'active')); } } diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index fa575eb8e21..ccc2af2aad5 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -21,7 +21,7 @@ class Notifications extends AbstractApi */ public function all(array $params = array()) { - return $this->get('notifications', $params); + return $this->get('/notifications', $params); } /** @@ -37,7 +37,7 @@ public function all(array $params = array()) */ public function allInRepository($username, $repository, array $params = array()) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); } /** @@ -51,7 +51,7 @@ public function allInRepository($username, $repository, array $params = array()) */ public function markAsReadAll(array $params = array()) { - return $this->put('notifications', $params); + return $this->put('/notifications', $params); } /** @@ -67,7 +67,7 @@ public function markAsReadAll(array $params = array()) */ public function markAsReadInRepository($username, $repository, array $params = array()) { - return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); } /** @@ -82,7 +82,7 @@ public function markAsReadInRepository($username, $repository, array $params = a */ public function markAsRead($id, array $params) { - return $this->patch('notifications/threads/'.rawurlencode($id), $params); + return $this->patch('/notifications/threads/'.rawurlencode($id), $params); } /** @@ -96,7 +96,7 @@ public function markAsRead($id, array $params) */ public function show($id) { - return $this->get('notifications/threads/'.rawurlencode($id)); + return $this->get('/notifications/threads/'.rawurlencode($id)); } /** @@ -110,7 +110,7 @@ public function show($id) */ public function showSubscription($id) { - return $this->get('notifications/threads/'.rawurlencode($id).'/subscription'); + return $this->get('/notifications/threads/'.rawurlencode($id).'/subscription'); } /** @@ -125,7 +125,7 @@ public function showSubscription($id) */ public function createSubscription($id, array $params) { - return $this->put('notifications/threads/'.rawurlencode($id).'/subscription', $params); + return $this->put('/notifications/threads/'.rawurlencode($id).'/subscription', $params); } /** @@ -139,6 +139,6 @@ public function createSubscription($id, array $params) */ public function removeSubscription($id) { - return $this->delete('notifications/threads/'.rawurlencode($id).'/subscription'); + return $this->delete('/notifications/threads/'.rawurlencode($id).'/subscription'); } } diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index 0e75da2c576..5085af06662 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -21,7 +21,7 @@ class Starring extends AbstractApi */ public function all($page = 1) { - return $this->get('user/starred', array( + return $this->get('/user/starred', array( 'page' => $page )); } @@ -38,7 +38,7 @@ public function all($page = 1) */ public function check($username, $repository) { - return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('/user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -53,7 +53,7 @@ public function check($username, $repository) */ public function star($username, $repository) { - return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->put('/user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -68,6 +68,6 @@ public function star($username, $repository) */ public function unstar($username, $repository) { - return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('/user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); } } diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 7f7b55457b5..a5a6d9b46f0 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -22,7 +22,7 @@ class Watchers extends AbstractApi */ public function all($page = 1) { - return $this->get('user/subscriptions', array( + return $this->get('/user/subscriptions', array( 'page' => $page )); } @@ -39,7 +39,7 @@ public function all($page = 1) */ public function check($username, $repository) { - return $this->get('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('/user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -54,7 +54,7 @@ public function check($username, $repository) */ public function watch($username, $repository) { - return $this->put('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->put('/user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -69,6 +69,6 @@ public function watch($username, $repository) */ public function unwatch($username, $repository) { - return $this->delete('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('/user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } } diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index eecee8d115b..7b19c25360c 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -22,7 +22,7 @@ class Deployment extends AbstractApi */ public function all($username, $repository, array $params = array()) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } /** @@ -45,7 +45,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('ref')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } /** @@ -68,7 +68,7 @@ public function updateStatus($username, $repository, $id, array $params) throw new MissingArgumentException(array('state')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); } /** @@ -81,6 +81,6 @@ public function updateStatus($username, $repository, $id, array $params) */ public function getStatuses($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses'); } } diff --git a/lib/Github/Api/Enterprise/License.php b/lib/Github/Api/Enterprise/License.php index de14f23eac3..67e1c2a96ea 100644 --- a/lib/Github/Api/Enterprise/License.php +++ b/lib/Github/Api/Enterprise/License.php @@ -15,6 +15,6 @@ class License extends AbstractApi */ public function show() { - return $this->get('enterprise/settings/license'); + return $this->get('/enterprise/settings/license'); } } diff --git a/lib/Github/Api/Enterprise/Stats.php b/lib/Github/Api/Enterprise/Stats.php index 7af932945a7..7d3b1953892 100644 --- a/lib/Github/Api/Enterprise/Stats.php +++ b/lib/Github/Api/Enterprise/Stats.php @@ -123,6 +123,6 @@ public function all() */ public function show($type) { - return $this->get('enterprise/stats/' . rawurlencode($type)); + return $this->get('/enterprise/stats/' . rawurlencode($type)); } } diff --git a/lib/Github/Api/Enterprise/UserAdmin.php b/lib/Github/Api/Enterprise/UserAdmin.php index 5a14114bca2..8f6ad10d91a 100644 --- a/lib/Github/Api/Enterprise/UserAdmin.php +++ b/lib/Github/Api/Enterprise/UserAdmin.php @@ -17,7 +17,7 @@ class UserAdmin extends AbstractApi */ public function suspend($username) { - return $this->put('users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); + return $this->put('/users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); } /** @@ -31,6 +31,6 @@ public function suspend($username) */ public function unsuspend($username) { - return $this->delete('users/'.rawurldecode($username).'/suspended'); + return $this->delete('/users/'.rawurldecode($username).'/suspended'); } } diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 7db73e59b29..521e4d03bb4 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -19,7 +19,7 @@ class Comments extends AbstractApi */ public function all($gist) { - return $this->get('gists/'.rawurlencode($gist).'/comments'); + return $this->get('/gists/'.rawurlencode($gist).'/comments'); } /** @@ -32,7 +32,7 @@ public function all($gist) */ public function show($gist, $comment) { - return $this->get('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + return $this->get('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } /** @@ -45,7 +45,7 @@ public function show($gist, $comment) */ public function create($gist, $body) { - return $this->post('gists/'.rawurlencode($gist).'/comments', array('body' => $body)); + return $this->post('/gists/'.rawurlencode($gist).'/comments', array('body' => $body)); } /** @@ -59,7 +59,7 @@ public function create($gist, $body) */ public function update($gist, $comment_id, $body) { - return $this->patch('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array('body' => $body)); + return $this->patch('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array('body' => $body)); } /** @@ -72,6 +72,6 @@ public function update($gist, $comment_id, $body) */ public function remove($gist, $comment) { - return $this->delete('gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + return $this->delete('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 07e8e1342f7..9710e6de683 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -17,15 +17,15 @@ class Gists extends AbstractApi public function all($type = null) { if (!in_array($type, array('public', 'starred'))) { - return $this->get('gists'); + return $this->get('/gists'); } - return $this->get('gists/'.rawurlencode($type)); + return $this->get('/gists/'.rawurlencode($type)); } public function show($number) { - return $this->get('gists/'.rawurlencode($number)); + return $this->get('/gists/'.rawurlencode($number)); } public function create(array $params) @@ -36,47 +36,47 @@ public function create(array $params) $params['public'] = (bool) $params['public']; - return $this->post('gists', $params); + return $this->post('/gists', $params); } public function update($id, array $params) { - return $this->patch('gists/'.rawurlencode($id), $params); + return $this->patch('/gists/'.rawurlencode($id), $params); } public function commits($id) { - return $this->get('gists/'.rawurlencode($id).'/commits'); + return $this->get('/gists/'.rawurlencode($id).'/commits'); } public function fork($id) { - return $this->post('gists/'.rawurlencode($id).'/fork'); + return $this->post('/gists/'.rawurlencode($id).'/fork'); } public function forks($id) { - return $this->get('gists/'.rawurlencode($id).'/forks'); + return $this->get('/gists/'.rawurlencode($id).'/forks'); } public function remove($id) { - return $this->delete('gists/'.rawurlencode($id)); + return $this->delete('/gists/'.rawurlencode($id)); } public function check($id) { - return $this->get('gists/'.rawurlencode($id).'/star'); + return $this->get('/gists/'.rawurlencode($id).'/star'); } public function star($id) { - return $this->put('gists/'.rawurlencode($id).'/star'); + return $this->put('/gists/'.rawurlencode($id).'/star'); } public function unstar($id) { - return $this->delete('gists/'.rawurlencode($id).'/star'); + return $this->delete('/gists/'.rawurlencode($id).'/star'); } /** diff --git a/lib/Github/Api/GitData/Commits.php b/lib/Github/Api/GitData/Commits.php index f2f5d217cda..e8d1bfe9d30 100644 --- a/lib/Github/Api/GitData/Commits.php +++ b/lib/Github/Api/GitData/Commits.php @@ -22,7 +22,7 @@ class Commits extends AbstractApi */ public function show($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits/'.rawurlencode($sha)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits/'.rawurlencode($sha)); } /** @@ -42,6 +42,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('message', 'tree', 'parents')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits', $params); } } diff --git a/lib/Github/Api/GitData/References.php b/lib/Github/Api/GitData/References.php index 3277b79e2b7..906a6ffc117 100644 --- a/lib/Github/Api/GitData/References.php +++ b/lib/Github/Api/GitData/References.php @@ -21,7 +21,7 @@ class References extends AbstractApi */ public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs'); } /** @@ -34,7 +34,7 @@ public function all($username, $repository) */ public function branches($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/heads'); } /** @@ -47,7 +47,7 @@ public function branches($username, $repository) */ public function tags($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } /** @@ -63,7 +63,7 @@ public function show($username, $repository, $reference) { $reference = $this->encodeReference($reference); - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); } /** @@ -83,7 +83,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('ref', 'sha')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params); } /** @@ -106,7 +106,7 @@ public function update($username, $repository, $reference, array $params) $reference = $this->encodeReference($reference); - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params); } /** @@ -122,7 +122,7 @@ public function remove($username, $repository, $reference) { $reference = $this->encodeReference($reference); - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference); } /** diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index 4b2d0341ef3..d1caefe91f1 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -21,7 +21,7 @@ class Tags extends AbstractApi */ public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/tags'); } /** @@ -35,7 +35,7 @@ public function all($username, $repository) */ public function show($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags/'.rawurlencode($sha)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags/'.rawurlencode($sha)); } /** @@ -63,6 +63,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('tagger.name', 'tagger.email', 'tagger.date')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags', $params); } } diff --git a/lib/Github/Api/GitData/Trees.php b/lib/Github/Api/GitData/Trees.php index 3fe61cdb236..80885682232 100644 --- a/lib/Github/Api/GitData/Trees.php +++ b/lib/Github/Api/GitData/Trees.php @@ -23,7 +23,7 @@ class Trees extends AbstractApi */ public function show($username, $repository, $sha, $recursive = false) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), $recursive ? array('recursive' => 1) : array()); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), $recursive ? array('recursive' => 1) : array()); } /** @@ -58,6 +58,6 @@ public function create($username, $repository, array $params) } } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees', $params); } } diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index c1b9a6e7992..f1f41d92ed1 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -31,7 +31,7 @@ class Issue extends AbstractApi */ public function all($username, $repository, array $params = array()) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(array('page' => 1), $params)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(array('page' => 1), $params)); } /** @@ -52,7 +52,7 @@ public function find($username, $repository, $state, $keyword) $state = 'open'; } - return $this->get('legacy/issues/search/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($state).'/'.rawurlencode($keyword)); + return $this->get('/legacy/issues/search/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($state).'/'.rawurlencode($keyword)); } /** @@ -72,7 +72,7 @@ public function org($organization, $state, array $params = array()) $state = 'open'; } - return $this->get('orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => 1, 'state' => $state), $params)); + return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => 1, 'state' => $state), $params)); } /** @@ -88,7 +88,7 @@ public function org($organization, $state, array $params = array()) */ public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id)); } /** @@ -111,7 +111,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('title', 'body')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', $params); } /** @@ -129,7 +129,7 @@ public function create($username, $repository, array $params) */ public function update($username, $repository, $id, array $params) { - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params); } /** diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 1fa5dc502e3..adfcde83e5e 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -23,9 +23,9 @@ class Events extends AbstractApi public function all($username, $repository, $issue = null, $page = 1) { if (null !== $issue) { - $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events'; + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events'; } else { - $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events'; + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events'; } return $this->get($path, array( @@ -44,6 +44,6 @@ public function all($username, $repository, $issue = null, $page = 1) */ public function show($username, $repository, $event) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event)); } } diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 0a67445d4e3..8f27887acfb 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -25,9 +25,9 @@ class Labels extends AbstractApi public function all($username, $repository, $issue = null) { if ($issue === null) { - $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'; + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'; } else { - $path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'; + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'; } return $this->get($path); @@ -54,7 +54,7 @@ public function create($username, $repository, array $params) $params['color'] = 'FFFFFF'; } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } /** @@ -69,7 +69,7 @@ public function create($username, $repository, array $params) */ public function deleteLabel($username, $repository, $label) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } /** @@ -91,7 +91,7 @@ public function update($username, $repository, $label, $newName, $color) 'color' => $color, ); - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); } /** @@ -115,7 +115,7 @@ public function add($username, $repository, $issue, $labels) throw new InvalidArgumentException(); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels); } /** @@ -131,7 +131,7 @@ public function add($username, $repository, $issue, $labels) */ public function replace($username, $repository, $issue, array $params) { - return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params); } /** @@ -147,7 +147,7 @@ public function replace($username, $repository, $issue, array $params) */ public function remove($username, $repository, $issue, $label) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label)); } /** @@ -162,6 +162,6 @@ public function remove($username, $repository, $issue, $label) */ public function clear($username, $repository, $issue) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); } } diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 55ba6fed998..87563da7abc 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -33,7 +33,7 @@ public function all($username, $repository, array $params = array()) $params['direction'] = 'desc'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array( 'page' => 1, 'state' => 'open', 'sort' => 'due_date', @@ -53,7 +53,7 @@ public function all($username, $repository, array $params = array()) */ public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } /** @@ -77,7 +77,7 @@ public function create($username, $repository, array $params) $params['state'] = 'open'; } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); } /** @@ -97,7 +97,7 @@ public function update($username, $repository, $id, array $params) $params['state'] = 'open'; } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params); } /** @@ -112,7 +112,7 @@ public function update($username, $repository, $id, array $params) */ public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } /** @@ -127,6 +127,6 @@ public function remove($username, $repository, $id) */ public function labels($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels'); } } diff --git a/lib/Github/Api/Markdown.php b/lib/Github/Api/Markdown.php index f97a142df5f..82d2ac55b6c 100644 --- a/lib/Github/Api/Markdown.php +++ b/lib/Github/Api/Markdown.php @@ -31,7 +31,7 @@ public function render($text, $mode = 'markdown', $context = null) $params['context'] = $context; } - return $this->post('markdown', $params); + return $this->post('/markdown', $params); } /** @@ -41,7 +41,7 @@ public function render($text, $mode = 'markdown', $context = null) */ public function renderRaw($file) { - return $this->post('markdown/raw', array( + return $this->post('/markdown/raw', array( 'file' => $file )); } diff --git a/lib/Github/Api/Meta.php b/lib/Github/Api/Meta.php index fa3668af98a..076b3dc501e 100644 --- a/lib/Github/Api/Meta.php +++ b/lib/Github/Api/Meta.php @@ -17,6 +17,6 @@ class Meta extends AbstractApi */ public function service() { - return $this->get('meta'); + return $this->get('/meta'); } } diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index a2ed530ad28..d7a1be66555 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -36,7 +36,7 @@ public function all($includingRead = false, $participating = false, DateTime $si $parameters['since'] = $since->format(DateTime::ISO8601); } - return $this->get('notifications', $parameters); + return $this->get('/notifications', $parameters); } /** @@ -55,6 +55,6 @@ public function markRead(DateTime $since = null) $parameters['last_read_at'] = $since->format(DateTime::ISO8601); } - $this->put('notifications', $parameters); + $this->put('/notifications', $parameters); } } diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 3f0321aefe5..71f948dcb0b 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -22,7 +22,7 @@ class Organization extends AbstractApi */ public function all($since = '') { - return $this->get('organizations?since='.rawurlencode($since)); + return $this->get('/organizations?since='.rawurlencode($since)); } /** @@ -36,12 +36,12 @@ public function all($since = '') */ public function show($organization) { - return $this->get('orgs/'.rawurlencode($organization)); + return $this->get('/orgs/'.rawurlencode($organization)); } public function update($organization, array $params) { - return $this->patch('orgs/'.rawurlencode($organization), $params); + return $this->patch('/orgs/'.rawurlencode($organization), $params); } /** @@ -56,7 +56,7 @@ public function update($organization, array $params) */ public function repositories($organization, $type = 'all') { - return $this->get('orgs/'.rawurlencode($organization).'/repos', array( + return $this->get('/orgs/'.rawurlencode($organization).'/repos', array( 'type' => $type )); } @@ -96,6 +96,6 @@ public function teams() */ public function issues($organization, array $params = array(), $page = 1) { - return $this->get('orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => $page), $params)); + return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => $page), $params)); } } diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index 109b7b3b6d6..e137dee1ab7 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -16,7 +16,7 @@ class Hooks extends AbstractApi */ public function all($organization) { - return $this->get('orgs/'.rawurlencode($organization).'/hooks'); + return $this->get('/orgs/'.rawurlencode($organization).'/hooks'); } /** @@ -29,7 +29,7 @@ public function all($organization) */ public function show($organization, $id) { - return $this->get('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); + return $this->get('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); } /** @@ -47,7 +47,7 @@ public function create($organization, array $params) throw new MissingArgumentException(array('name', 'config')); } - return $this->post('orgs/'.rawurlencode($organization).'/hooks', $params); + return $this->post('/orgs/'.rawurlencode($organization).'/hooks', $params); } /** @@ -66,7 +66,7 @@ public function update($organization, $id, array $params) throw new MissingArgumentException(array('config')); } - return $this->patch('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id), $params); + return $this->patch('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id), $params); } /** @@ -79,7 +79,7 @@ public function update($organization, $id, array $params) */ public function ping($organization, $id) { - return $this->post('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id).'/pings'); + return $this->post('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id).'/pings'); } /** @@ -92,6 +92,6 @@ public function ping($organization, $id) */ public function remove($organization, $id) { - return $this->delete('orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); + return $this->delete('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 72bb635c2dd..a3d466252ea 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -13,7 +13,7 @@ class Members extends AbstractApi public function all($organization, $type = null, $filter = 'all', $role = null) { $parameters = array(); - $path = 'orgs/'.rawurlencode($organization).'/'; + $path = '/orgs/'.rawurlencode($organization).'/'; if (null === $type) { $path .= 'members'; if (null !== $filter) { @@ -31,32 +31,32 @@ public function all($organization, $type = null, $filter = 'all', $role = null) public function show($organization, $username) { - return $this->get('orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); } public function member($organization, $username) { - return $this->get('orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); } public function check($organization, $username) { - return $this->get('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } public function addMember($organization, $username) { - return $this->put('orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); } public function publicize($organization, $username) { - return $this->put('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } public function conceal($organization, $username) { - return $this->delete('orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); + return $this->delete('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } /* @@ -64,11 +64,11 @@ public function conceal($organization, $username) */ public function add($organization, $username) { - return $this->put('orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); } public function remove($organization, $username) { - return $this->delete('orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); + return $this->delete('/orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); } } diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index c90ee12af6e..b4aa52ecfe3 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -13,7 +13,7 @@ class Teams extends AbstractApi { public function all($organization) { - return $this->get('orgs/'.rawurlencode($organization).'/teams'); + return $this->get('/orgs/'.rawurlencode($organization).'/teams'); } public function create($organization, array $params) @@ -28,12 +28,12 @@ public function create($organization, array $params) $params['permission'] = 'pull'; } - return $this->post('orgs/'.rawurlencode($organization).'/teams', $params); + return $this->post('/orgs/'.rawurlencode($organization).'/teams', $params); } public function show($team) { - return $this->get('teams/'.rawurlencode($team)); + return $this->get('/teams/'.rawurlencode($team)); } public function update($team, array $params) @@ -45,42 +45,42 @@ public function update($team, array $params) $params['permission'] = 'pull'; } - return $this->patch('teams/'.rawurlencode($team), $params); + return $this->patch('/teams/'.rawurlencode($team), $params); } public function remove($team) { - return $this->delete('teams/'.rawurlencode($team)); + return $this->delete('/teams/'.rawurlencode($team)); } public function members($team) { - return $this->get('teams/'.rawurlencode($team).'/members'); + return $this->get('/teams/'.rawurlencode($team).'/members'); } public function check($team, $username) { - return $this->get('teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function addMember($team, $username) { - return $this->put('teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function removeMember($team, $username) { - return $this->delete('teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function repositories($team) { - return $this->get('teams/'.rawurlencode($team).'/repos'); + return $this->get('/teams/'.rawurlencode($team).'/repos'); } public function repository($team, $username, $repository) { - return $this->get('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } public function addRepository($team, $username, $repository, $params = array()) @@ -89,11 +89,11 @@ public function addRepository($team, $username, $repository, $params = array()) $params['permission'] = 'pull'; } - return $this->put('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } public function removeRepository($team, $username, $repository) { - return $this->delete('teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } } diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 6e3028faf53..5419ded7db9 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -31,7 +31,7 @@ public function all($username, $repository, array $params = array()) 'per_page' => 30 ), $params); - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } /** @@ -47,17 +47,17 @@ public function all($username, $repository, array $params = array()) */ public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id)); } public function commits($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); } public function files($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files'); } public function comments() @@ -98,7 +98,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('issue', 'body')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params); } public function update($username, $repository, $id, array $params) @@ -107,12 +107,12 @@ public function update($username, $repository, $id, array $params) $params['state'] = 'open'; } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id), $params); } public function merged($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); } public function merge($username, $repository, $id, $message, $sha, $squash = false, $title = null) @@ -127,6 +127,6 @@ public function merge($username, $repository, $id, $message, $sha, $squash = fal $params['commit_title'] = $title; } - return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', $params); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge', $params); } } diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index dec30fb0566..971f38cee9e 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -13,12 +13,12 @@ class Comments extends AbstractApi { public function all($username, $repository, $pullRequest) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); } public function show($username, $repository, $comment) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); } public function create($username, $repository, $pullRequest, array $params) @@ -32,7 +32,7 @@ public function create($username, $repository, $pullRequest, array $params) throw new MissingArgumentException(array('commit_id', 'path', 'position')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params); } public function update($username, $repository, $comment, array $params) @@ -41,11 +41,11 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment), $params); } public function remove($username, $repository, $comment) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index a07eb781a6e..bfa42ae8288 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -17,7 +17,7 @@ class RateLimit extends AbstractApi */ public function getRateLimits() { - return $this->get('rate_limit'); + return $this->get('/rate_limit'); } /** @@ -28,7 +28,7 @@ public function getRateLimits() public function getCoreLimit() { $response = $this->getRateLimits(); - + return $response['resources']['core']['limit']; } @@ -40,7 +40,7 @@ public function getCoreLimit() public function getSearchLimit() { $response = $this->getRateLimits(); - + return $response['resources']['search']['limit']; } } diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 755c23bb91c..1a416cf81d5 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -37,7 +37,7 @@ class Repo extends AbstractApi */ public function find($keyword, array $params = array()) { - return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); + return $this->get('/legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); } /** @@ -52,10 +52,10 @@ public function find($keyword, array $params = array()) public function all($id = null) { if (!is_int($id)) { - return $this->get('repositories'); + return $this->get('/repositories'); } - return $this->get('repositories?since=' . rawurldecode($id)); + return $this->get('/repositories?since=' . rawurldecode($id)); } /** @@ -70,7 +70,7 @@ public function all($id = null) */ public function activity($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity'); } /** @@ -85,7 +85,7 @@ public function activity($username, $repository) */ public function statistics($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); } /** @@ -100,7 +100,7 @@ public function statistics($username, $repository) */ public function org($organization, array $params = array()) { - return $this->get('orgs/'.$organization.'/repos', array_merge(array('start_page' => 1), $params)); + return $this->get('/orgs/'.$organization.'/repos', array_merge(array('start_page' => 1), $params)); } /** @@ -115,7 +115,7 @@ public function org($organization, array $params = array()) */ public function show($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -148,7 +148,7 @@ public function create( $teamId = null, $autoInit = false ) { - $path = null !== $organization ? 'orgs/'.$organization.'/repos' : 'user/repos'; + $path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos'; $parameters = array( 'name' => $name, @@ -181,7 +181,7 @@ public function create( */ public function update($username, $repository, array $values) { - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository), $values); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository), $values); } /** @@ -196,7 +196,7 @@ public function update($username, $repository, array $values) */ public function remove($username, $repository) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -211,7 +211,7 @@ public function remove($username, $repository) */ public function readme($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme'); } /** @@ -371,7 +371,7 @@ public function statuses() */ public function branches($username, $repository, $branch = null) { - $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches'; + $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches'; if (null !== $branch) { $url .= '/'.rawurlencode($branch); } @@ -393,7 +393,7 @@ public function branches($username, $repository, $branch = null) */ public function contributors($username, $repository, $includingAnonymous = false) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', array( 'anon' => $includingAnonymous ?: null )); } @@ -410,7 +410,7 @@ public function contributors($username, $repository, $includingAnonymous = false */ public function languages($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/languages'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/languages'); } /** @@ -426,7 +426,7 @@ public function languages($username, $repository) */ public function tags($username, $repository, array $params = []) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags', $params); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/tags', $params); } /** @@ -441,7 +441,7 @@ public function tags($username, $repository, array $params = []) */ public function teams($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams'); } /** @@ -455,7 +455,7 @@ public function teams($username, $repository) */ public function watchers($username, $repository, $page = 1) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array( 'page' => $page )); } @@ -469,7 +469,7 @@ public function watchers($username, $repository, $page = 1) */ public function subscribers($username, $repository, $page = 1) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', array( 'page' => $page )); } @@ -498,7 +498,7 @@ public function merge($username, $repository, $base, $head, $message = null) $parameters['commit_message'] = $message; } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', $parameters); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merges', $parameters); } /** @@ -508,6 +508,6 @@ public function merge($username, $repository, $base, $head, $message = null) */ public function milestones($username, $repository) { - return $this->get('repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones'); + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones'); } } diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 7fa7a1dddfc..21b5a08cc5d 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -24,7 +24,7 @@ class Assets extends AbstractApi */ public function all($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets'); } /** @@ -39,7 +39,7 @@ public function all($username, $repository, $id) */ public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); } /** @@ -97,7 +97,7 @@ public function edit($username, $repository, $id, array $params) throw new MissingArgumentException('name'); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params); } /** @@ -112,6 +112,6 @@ public function edit($username, $repository, $id, array $params) */ public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index 89a95068559..116d8cc5a38 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -12,21 +12,21 @@ class Collaborators extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators'); } public function check($username, $repository, $collaborator) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } public function add($username, $repository, $collaborator) { - return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } public function remove($username, $repository, $collaborator) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } } diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index d8d45c73cd3..3aaa460d6c2 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -12,7 +12,7 @@ class Commits extends AbstractApi { public function all($username, $repository, array $params) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params); } public function compare($username, $repository, $base, $head, $mediaType = null) @@ -22,11 +22,11 @@ public function compare($username, $repository, $base, $head, $mediaType = null) $headers['Accept'] = $mediaType; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), array(), $headers); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), array(), $headers); } public function show($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha)); } } diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 450c14b5845..064f68490ff 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -27,7 +27,7 @@ class Contents extends AbstractApi */ public function readme($username, $repository, $reference = null) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', array( 'ref' => $reference )); } @@ -46,7 +46,7 @@ public function readme($username, $repository, $reference = null) */ public function show($username, $repository, $path = null, $reference = null) { - $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; + $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; if (null !== $path) { $url .= '/'.rawurlencode($path); } @@ -75,7 +75,7 @@ public function show($username, $repository, $path = null, $reference = null) */ public function create($username, $repository, $path, $content, $message, $branch = null, array $committer = null) { - $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); + $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); $parameters = array( 'content' => base64_encode($content), @@ -108,7 +108,7 @@ public function create($username, $repository, $path, $content, $message, $branc */ public function exists($username, $repository, $path, $reference = null) { - $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; + $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; if (null !== $path) { $url .= '/'.rawurlencode($path); @@ -151,7 +151,7 @@ public function exists($username, $repository, $path, $reference = null) */ public function update($username, $repository, $path, $content, $message, $sha, $branch = null, array $committer = null) { - $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); + $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); $parameters = array( 'content' => base64_encode($content), @@ -192,7 +192,7 @@ public function update($username, $repository, $path, $content, $message, $sha, */ public function rm($username, $repository, $path, $message, $sha, $branch = null, array $committer = null) { - $url = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); + $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); $parameters = array( 'message' => $message, @@ -231,7 +231,7 @@ public function archive($username, $repository, $format, $reference = null) $format = 'tarball'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format). + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format). ((null !== $reference) ? ('/'.rawurlencode($reference)) : '')); } diff --git a/lib/Github/Api/Repository/DeployKeys.php b/lib/Github/Api/Repository/DeployKeys.php index 390835798ac..2c25542dfc3 100644 --- a/lib/Github/Api/Repository/DeployKeys.php +++ b/lib/Github/Api/Repository/DeployKeys.php @@ -13,12 +13,12 @@ class DeployKeys extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys'); } public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id)); } public function create($username, $repository, array $params) @@ -27,7 +27,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys', $params); } public function update($username, $repository, $id, array $params) @@ -36,11 +36,11 @@ public function update($username, $repository, $id, array $params) throw new MissingArgumentException(array('title', 'key')); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params); } public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Downloads.php b/lib/Github/Api/Repository/Downloads.php index 63177e49903..bfde5b3ea5e 100644 --- a/lib/Github/Api/Repository/Downloads.php +++ b/lib/Github/Api/Repository/Downloads.php @@ -22,7 +22,7 @@ class Downloads extends AbstractApi */ public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads'); } /** @@ -38,7 +38,7 @@ public function all($username, $repository) */ public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); } /** @@ -54,6 +54,6 @@ public function show($username, $repository, $id) */ public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Forks.php b/lib/Github/Api/Repository/Forks.php index c165961856e..dbd4f3d3785 100644 --- a/lib/Github/Api/Repository/Forks.php +++ b/lib/Github/Api/Repository/Forks.php @@ -16,11 +16,11 @@ public function all($username, $repository, array $params = array()) $params['sort'] = 'newest'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', array_merge(array('page' => 1), $params)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', array_merge(array('page' => 1), $params)); } public function create($username, $repository, array $params = array()) { - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', $params); } } diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index 55940ea5009..30f887d726f 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -13,12 +13,12 @@ class Hooks extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks'); } public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id)); } public function create($username, $repository, array $params) @@ -27,7 +27,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('name', 'config')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks', $params); } public function update($username, $repository, $id, array $params) @@ -36,21 +36,21 @@ public function update($username, $repository, $id, array $params) throw new MissingArgumentException(array('name', 'config')); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params); } public function ping($username, $repository, $id) { - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/pings'); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/pings'); } public function test($username, $repository, $id) { - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/test'); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/test'); } public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id)); } } diff --git a/lib/Github/Api/Repository/Labels.php b/lib/Github/Api/Repository/Labels.php index e35b4ded71d..34535e8e1c9 100644 --- a/lib/Github/Api/Repository/Labels.php +++ b/lib/Github/Api/Repository/Labels.php @@ -13,12 +13,12 @@ class Labels extends AbstractApi { public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'); } public function show($username, $repository, $label) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } public function create($username, $repository, array $params) @@ -27,7 +27,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('name', 'color')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } public function update($username, $repository, $label, array $params) @@ -36,11 +36,11 @@ public function update($username, $repository, $label, array $params) throw new MissingArgumentException(array('name', 'color')); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); } public function remove($username, $repository, $label) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); } } diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index e25b1e7ef84..4d59318fe07 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -22,7 +22,7 @@ class Releases extends AbstractApi */ public function latest($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); } /** @@ -36,7 +36,7 @@ public function latest($username, $repository) */ public function tag($username, $repository, $tag) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); } /** @@ -50,7 +50,7 @@ public function tag($username, $repository, $tag) */ public function all($username, $repository, array $params = []) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); } /** @@ -64,7 +64,7 @@ public function all($username, $repository, array $params = []) */ public function show($username, $repository, $id) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); } /** @@ -84,7 +84,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException('tag_name'); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); } /** @@ -99,7 +99,7 @@ public function create($username, $repository, array $params) */ public function edit($username, $repository, $id, array $params) { - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); } /** @@ -113,7 +113,7 @@ public function edit($username, $repository, $id, array $params) */ public function remove($username, $repository, $id) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); } /** diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index caab1e2b524..728d1305f28 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -22,7 +22,7 @@ class Statuses extends AbstractApi */ public function show($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/statuses'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/statuses'); } /** @@ -36,7 +36,7 @@ public function show($username, $repository, $sha) */ public function combined($username, $repository, $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/status'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/status'); } /** @@ -57,6 +57,6 @@ public function create($username, $repository, $sha, array $params = array()) throw new MissingArgumentException('state'); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha), $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/statuses/'.rawurlencode($sha), $params); } } diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 6ca29ea62b7..15e698ac970 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -23,7 +23,7 @@ class Search extends AbstractApi */ public function repositories($q, $sort = 'updated', $order = 'desc') { - return $this->get('search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -39,7 +39,7 @@ public function repositories($q, $sort = 'updated', $order = 'desc') */ public function issues($q, $sort = 'updated', $order = 'desc') { - return $this->get('search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -55,7 +55,7 @@ public function issues($q, $sort = 'updated', $order = 'desc') */ public function code($q, $sort = 'updated', $order = 'desc') { - return $this->get('search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); } /** @@ -71,6 +71,6 @@ public function code($q, $sort = 'updated', $order = 'desc') */ public function users($q, $sort = 'updated', $order = 'desc') { - return $this->get('search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); } } diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index dd5ee1b2737..d866c93050b 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -22,7 +22,7 @@ class User extends AbstractApi */ public function find($keyword) { - return $this->get('legacy/user/search/'.rawurlencode($keyword)); + return $this->get('/legacy/user/search/'.rawurlencode($keyword)); } /** @@ -37,10 +37,10 @@ public function find($keyword) public function all($id = null) { if (!is_int($id)) { - return $this->get('users'); + return $this->get('/users'); } - return $this->get('users?since=' . rawurldecode($id)); + return $this->get('/users?since=' . rawurldecode($id)); } /** @@ -54,7 +54,7 @@ public function all($id = null) */ public function show($username) { - return $this->get('users/'.rawurlencode($username)); + return $this->get('/users/'.rawurlencode($username)); } /** @@ -68,7 +68,7 @@ public function show($username) */ public function organizations($username) { - return $this->get('users/'.rawurlencode($username).'/orgs'); + return $this->get('/users/'.rawurlencode($username).'/orgs'); } /** @@ -82,7 +82,7 @@ public function organizations($username) */ public function following($username) { - return $this->get('users/'.rawurlencode($username).'/following'); + return $this->get('/users/'.rawurlencode($username).'/following'); } /** @@ -96,7 +96,7 @@ public function following($username) */ public function followers($username) { - return $this->get('users/'.rawurlencode($username).'/followers'); + return $this->get('/users/'.rawurlencode($username).'/followers'); } /** @@ -110,7 +110,7 @@ public function followers($username) */ public function watched($username) { - return $this->get('users/'.rawurlencode($username).'/watched'); + return $this->get('/users/'.rawurlencode($username).'/watched'); } /** @@ -125,7 +125,7 @@ public function watched($username) */ public function starred($username, $page = 1) { - return $this->get('users/'.rawurlencode($username).'/starred', array( + return $this->get('/users/'.rawurlencode($username).'/starred', array( 'page' => $page )); } @@ -141,7 +141,7 @@ public function starred($username, $page = 1) */ public function subscriptions($username) { - return $this->get('users/'.rawurlencode($username).'/subscriptions'); + return $this->get('/users/'.rawurlencode($username).'/subscriptions'); } /** @@ -158,7 +158,7 @@ public function subscriptions($username) */ public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->get('users/'.rawurlencode($username).'/repos', array( + return $this->get('/users/'.rawurlencode($username).'/repos', array( 'type' => $type, 'sort' => $sort, 'direction' => $direction @@ -176,7 +176,7 @@ public function repositories($username, $type = 'owner', $sort = 'full_name', $d */ public function gists($username) { - return $this->get('users/'.rawurlencode($username).'/gists'); + return $this->get('/users/'.rawurlencode($username).'/gists'); } /** @@ -190,7 +190,7 @@ public function gists($username) */ public function keys($username) { - return $this->get('users/'.rawurlencode($username).'/keys'); + return $this->get('/users/'.rawurlencode($username).'/keys'); } /** @@ -204,6 +204,6 @@ public function keys($username) */ public function publicEvents($username) { - return $this->get('users/'.rawurlencode($username) . '/events/public'); + return $this->get('/users/'.rawurlencode($username) . '/events/public'); } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 582351505c9..3ec9f9bf82e 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -154,7 +154,7 @@ public function __construct(HttpClient $httpClient = null, $apiVersion = null, $ $this->addPlugin(new GithubExceptionThrower()); $this->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); $this->addPlugin(new Plugin\RedirectPlugin()); - $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com/'))); + $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ))); From 341f45739b4478deb2392b1ab5f70d81fe572684 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 2 Aug 2016 17:47:16 +0200 Subject: [PATCH 402/951] Fixed the tests --- lib/Github/Api/GitData/Blobs.php | 4 +- lib/Github/Api/Issue/Comments.php | 10 ++--- lib/Github/Api/Repository/Comments.php | 12 +++--- lib/Github/Api/Repository/Stargazers.php | 2 +- test/Github/Tests/Api/AuthorizationsTest.php | 18 ++++---- .../Tests/Api/CurrentUser/DeployKeysTest.php | 10 ++--- .../Tests/Api/CurrentUser/EmailsTest.php | 10 ++--- .../Tests/Api/CurrentUser/FollowersTest.php | 8 ++-- .../Tests/Api/CurrentUser/MembershipsTest.php | 6 +-- .../Tests/Api/CurrentUser/StarringTest.php | 8 ++-- .../Tests/Api/CurrentUser/WatchersTest.php | 8 ++-- test/Github/Tests/Api/CurrentUserTest.php | 10 ++--- test/Github/Tests/Api/DeploymentTest.php | 10 ++--- .../Tests/Api/Enterprise/LicenseTest.php | 2 +- .../Github/Tests/Api/Enterprise/StatsTest.php | 4 +- .../Tests/Api/Enterprise/UserAdminTest.php | 4 +- test/Github/Tests/Api/Gist/CommentsTest.php | 10 ++--- test/Github/Tests/Api/GistsTest.php | 24 +++++------ test/Github/Tests/Api/GitData/BlobsTest.php | 6 +-- test/Github/Tests/Api/GitData/CommitsTest.php | 4 +- .../Tests/Api/GitData/ReferencesTest.php | 16 +++---- test/Github/Tests/Api/GitData/TagsTest.php | 6 +-- test/Github/Tests/Api/GitData/TreesTest.php | 6 +-- test/Github/Tests/Api/Issue/CommentsTest.php | 10 ++--- test/Github/Tests/Api/Issue/EventsTest.php | 6 +-- test/Github/Tests/Api/Issue/LabelsTest.php | 22 +++++----- .../Github/Tests/Api/Issue/MilestonesTest.php | 24 +++++------ test/Github/Tests/Api/IssueTest.php | 18 ++++---- test/Github/Tests/Api/MarkdownTest.php | 12 +++--- test/Github/Tests/Api/NotificationTest.php | 10 ++--- .../Tests/Api/Organization/HooksTest.php | 12 +++--- .../Tests/Api/Organization/MembersTest.php | 16 +++---- .../Tests/Api/Organization/TeamsTest.php | 32 +++++++------- test/Github/Tests/Api/OrganizationTest.php | 8 ++-- test/Github/Tests/Api/PullRequestTest.php | 22 +++++----- test/Github/Tests/Api/RateLimitTest.php | 2 +- test/Github/Tests/Api/RepoTest.php | 42 +++++++++---------- .../Tests/Api/Repository/AssetsTest.php | 8 ++-- .../Api/Repository/CollaboratorsTest.php | 8 ++-- .../Tests/Api/Repository/CommentsTest.php | 14 +++---- .../Tests/Api/Repository/CommitsTest.php | 6 +-- .../Tests/Api/Repository/ContentsTest.php | 28 ++++++------- .../Tests/Api/Repository/DeployKeysTest.php | 10 ++--- .../Tests/Api/Repository/DownloadsTest.php | 6 +-- .../Github/Tests/Api/Repository/ForksTest.php | 6 +-- .../Github/Tests/Api/Repository/HooksTest.php | 12 +++--- .../Tests/Api/Repository/LabelsTest.php | 10 ++--- .../Tests/Api/Repository/ReleasesTest.php | 14 +++---- .../Tests/Api/Repository/StargazersTest.php | 4 +- .../Tests/Api/Repository/StatusesTest.php | 6 +-- test/Github/Tests/Api/SearchTest.php | 16 +++---- test/Github/Tests/Api/UserTest.php | 18 ++++---- 52 files changed, 300 insertions(+), 300 deletions(-) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index a5ebfd627bb..b8abb415193 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -38,7 +38,7 @@ public function configure($bodyType = null) */ public function show($username, $repository, $sha) { - $response = $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha)); + $response = $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha)); return $response; } @@ -60,6 +60,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(array('content', 'encoding')); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs', $params); } } diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index f1d19515718..e72b964f02e 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -43,7 +43,7 @@ public function configure($bodyType = null) */ public function all($username, $repository, $issue, $page = 1) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array( 'page' => $page )); } @@ -60,7 +60,7 @@ public function all($username, $repository, $issue, $page = 1) */ public function show($username, $repository, $comment) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); } /** @@ -81,7 +81,7 @@ public function create($username, $repository, $issue, array $params) throw new MissingArgumentException('body'); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params); } /** @@ -102,7 +102,7 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params); } /** @@ -117,6 +117,6 @@ public function update($username, $repository, $comment, array $params) */ public function remove($username, $repository, $comment) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index f9d2a54af2b..b1d9abe7cbe 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -40,15 +40,15 @@ public function configure($bodyType = null) public function all($username, $repository, $sha = null) { if (null === $sha) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments'); } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments'); } public function show($username, $repository, $comment) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment)); } public function create($username, $repository, $sha, array $params) @@ -57,7 +57,7 @@ public function create($username, $repository, $sha, array $params) throw new MissingArgumentException('body'); } - return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/comments', $params); } public function update($username, $repository, $comment, array $params) @@ -66,11 +66,11 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment), $params); } public function remove($username, $repository, $comment) { - return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/comments/'.rawurlencode($comment)); } } diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index 9b7a8470002..9267dff4fbd 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -30,6 +30,6 @@ public function configure($bodyType = null) public function all($username, $repository) { - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stargazers'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stargazers'); } } diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php index 059c2ffe7f8..d0570c79956 100644 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -14,7 +14,7 @@ public function shouldGetAllAuthorizations() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('authorizations') + ->with('/authorizations') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all()); @@ -31,7 +31,7 @@ public function shouldShowAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('authorizations/'.$id) + ->with('/authorizations/'.$id) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show($id)); @@ -49,7 +49,7 @@ public function shouldAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('authorizations', $input); + ->with('/authorizations', $input); $api->create($input); } @@ -67,7 +67,7 @@ public function shouldUpdateAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('authorizations/'.$id, $input); + ->with('/authorizations/'.$id, $input); $api->update($id, $input); } @@ -81,7 +81,7 @@ public function shouldDeleteAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('authorizations/'.$id); + ->with('/authorizations/'.$id); $api->remove($id); } @@ -98,7 +98,7 @@ public function shouldCheckAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('applications/'.$id.'/tokens/'.$token) + ->with('/applications/'.$id.'/tokens/'.$token) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->check($id, $token)); @@ -115,7 +115,7 @@ public function shouldResetAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('applications/'.$id.'/tokens/'.$token); + ->with('/applications/'.$id.'/tokens/'.$token); $api->reset($id, $token); } @@ -131,7 +131,7 @@ public function shouldRevokeAuthorization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('applications/'.$id.'/tokens/'.$token); + ->with('/applications/'.$id.'/tokens/'.$token); $api->revoke($id, $token); } @@ -146,7 +146,7 @@ public function shouldRevokeAllAuthorizations() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('applications/'.$id.'/tokens'); + ->with('/applications/'.$id.'/tokens'); $api->revokeAll($id); } diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index f813ca80673..f72d9405736 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -14,7 +14,7 @@ public function shouldShowKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/keys/12') + ->with('/user/keys/12') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show(12)); @@ -30,7 +30,7 @@ public function shouldGetKeys() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/keys') + ->with('/user/keys') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -47,7 +47,7 @@ public function shouldCreateKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/keys', $data) + ->with('/user/keys', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create($data)); @@ -94,7 +94,7 @@ public function shouldUpdateKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('user/keys/123', $data) + ->with('/user/keys/123', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update(123, $data)); @@ -140,7 +140,7 @@ public function shouldRemoveKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/keys/123') + ->with('/user/keys/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove(123)); diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index 33e1f704c7f..af8e90490da 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -14,7 +14,7 @@ public function shouldGetEmails() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/emails') + ->with('/user/emails') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -30,7 +30,7 @@ public function shouldRemoveEmail() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/emails', array('email@example.com')) + ->with('/user/emails', array('email@example.com')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('email@example.com')); @@ -46,7 +46,7 @@ public function shouldRemoveEmails() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/emails', array('email@example.com', 'email2@example.com')) + ->with('/user/emails', array('email@example.com', 'email2@example.com')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove(array('email@example.com', 'email2@example.com'))); @@ -75,7 +75,7 @@ public function shouldAddEmail() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/emails', array('email@example.com')) + ->with('/user/emails', array('email@example.com')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('email@example.com')); @@ -91,7 +91,7 @@ public function shouldAddEmails() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/emails', array('email@example.com', 'email2@example.com')) + ->with('/user/emails', array('email@example.com', 'email2@example.com')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add(array('email@example.com', 'email2@example.com'))); diff --git a/test/Github/Tests/Api/CurrentUser/FollowersTest.php b/test/Github/Tests/Api/CurrentUser/FollowersTest.php index d2e74ec438b..4d1b1215634 100644 --- a/test/Github/Tests/Api/CurrentUser/FollowersTest.php +++ b/test/Github/Tests/Api/CurrentUser/FollowersTest.php @@ -17,7 +17,7 @@ public function shouldGetFollowers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/following') + ->with('/user/following') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -31,7 +31,7 @@ public function shouldCheckFollower() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/following/l3l0') + ->with('/user/following/l3l0') ->will($this->returnValue(null)); $this->assertNull($api->check('l3l0')); @@ -45,7 +45,7 @@ public function shouldFollowUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('user/following/l3l0') + ->with('/user/following/l3l0') ->will($this->returnValue(null)); $this->assertNull($api->follow('l3l0')); @@ -59,7 +59,7 @@ public function shouldUnfollowUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/following/l3l0') + ->with('/user/following/l3l0') ->will($this->returnValue(null)); $this->assertNull($api->unfollow('l3l0')); diff --git a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php index 571f1bce41d..ef9f5c4d40c 100644 --- a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php +++ b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php @@ -35,7 +35,7 @@ public function shouldGetMemberships() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/memberships/orgs') + ->with('/user/memberships/orgs') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -60,7 +60,7 @@ public function shouldGetMembershipsForOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/memberships/orgs/invitocat') + ->with('/user/memberships/orgs/invitocat') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->organization('invitocat')); @@ -78,7 +78,7 @@ public function shouldEditMembershipsForOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('user/memberships/orgs/invitocat') + ->with('/user/memberships/orgs/invitocat') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->edit('invitocat')); diff --git a/test/Github/Tests/Api/CurrentUser/StarringTest.php b/test/Github/Tests/Api/CurrentUser/StarringTest.php index bc5943ee4e3..51242409c88 100644 --- a/test/Github/Tests/Api/CurrentUser/StarringTest.php +++ b/test/Github/Tests/Api/CurrentUser/StarringTest.php @@ -17,7 +17,7 @@ public function shouldGetStarred() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/starred') + ->with('/user/starred') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -31,7 +31,7 @@ public function shouldCheckStar() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/starred/l3l0/test') + ->with('/user/starred/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->check('l3l0', 'test')); @@ -45,7 +45,7 @@ public function shouldStarUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('user/starred/l3l0/test') + ->with('/user/starred/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->star('l3l0', 'test')); @@ -59,7 +59,7 @@ public function shouldUnstarUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/starred/l3l0/test') + ->with('/user/starred/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->unstar('l3l0', 'test')); diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index c8383935b70..487cafad456 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -17,7 +17,7 @@ public function shouldGetWatchers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/subscriptions') + ->with('/user/subscriptions') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -31,7 +31,7 @@ public function shouldCheckWatcher() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/subscriptions/l3l0/test') + ->with('/user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->check('l3l0', 'test')); @@ -45,7 +45,7 @@ public function shouldWatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('user/subscriptions/l3l0/test') + ->with('/user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->watch('l3l0', 'test')); @@ -59,7 +59,7 @@ public function shouldUnwatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/subscriptions/l3l0/test') + ->with('/user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->unwatch('l3l0', 'test')); diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index f1dd27b0b77..cb447ff1b9c 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -14,7 +14,7 @@ public function shouldShowCurrentUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user') + ->with('/user') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show()); @@ -30,7 +30,7 @@ public function shouldUpdateCurrentUserData() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('user', array('value' => 'toChange')) + ->with('/user', array('value' => 'toChange')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->update(array('value' => 'toChange'))); @@ -46,7 +46,7 @@ public function shouldGetUserFollowers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/followers', array('page' => 1)) + ->with('/user/followers', array('page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->followers(1)); @@ -62,7 +62,7 @@ public function shouldGetIssuesAssignedToUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('issues', array('page' => 1, 'some' => 'param')) + ->with('/issues', array('page' => 1, 'some' => 'param')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->issues(array('some' => 'param'))); @@ -78,7 +78,7 @@ public function shouldGetWatchedRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched', array('page' => 1)) + ->with('/user/watched', array('page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->watched(1)); diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index baa692e430b..996afcdc8be 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -13,7 +13,7 @@ public function shouldCreateDeployment() $deploymentData = array('ref' => 'fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9'); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/deployments', $deploymentData); + ->with('/repos/KnpLabs/php-github-api/deployments', $deploymentData); $api->create('KnpLabs', 'php-github-api', $deploymentData); } @@ -26,7 +26,7 @@ public function shouldGetAllDeployments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/deployments'); + ->with('/repos/KnpLabs/php-github-api/deployments'); $api->all('KnpLabs', 'php-github-api'); } @@ -41,7 +41,7 @@ public function shouldGetAllDeploymentsWithFilterParameters() $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/deployments', $filterData); + ->with('/repos/KnpLabs/php-github-api/deployments', $filterData); $api->all('KnpLabs', 'php-github-api', $filterData); } @@ -56,7 +56,7 @@ public function shouldCreateStatusUpdate() $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/deployments/1/statuses', $statusData); + ->with('/repos/KnpLabs/php-github-api/deployments/1/statuses', $statusData); $api->updateStatus('KnpLabs', 'php-github-api', 1, $statusData); } @@ -81,7 +81,7 @@ public function shouldGetAllStatuses() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/deployments/1/statuses'); + ->with('/repos/KnpLabs/php-github-api/deployments/1/statuses'); $api->getStatuses('KnpLabs', 'php-github-api', 1); } diff --git a/test/Github/Tests/Api/Enterprise/LicenseTest.php b/test/Github/Tests/Api/Enterprise/LicenseTest.php index af383dcf469..170e478b029 100644 --- a/test/Github/Tests/Api/Enterprise/LicenseTest.php +++ b/test/Github/Tests/Api/Enterprise/LicenseTest.php @@ -23,7 +23,7 @@ public function shouldShowLicenseInformation() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('enterprise/settings/license') + ->with('/enterprise/settings/license') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show()); diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 3bd34ef3fae..18c04799290 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -16,7 +16,7 @@ public function shouldShowStats() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('enterprise/stats/all') + ->with('/enterprise/stats/all') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show('all')); @@ -33,7 +33,7 @@ public function shouldShowStatsByType($type) $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with(sprintf('enterprise/stats/%s', $type)) + ->with(sprintf('/enterprise/stats/%s', $type)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, call_user_func(array($api, $type))); diff --git a/test/Github/Tests/Api/Enterprise/UserAdminTest.php b/test/Github/Tests/Api/Enterprise/UserAdminTest.php index 34e6b6e910b..ea6f3fc615f 100644 --- a/test/Github/Tests/Api/Enterprise/UserAdminTest.php +++ b/test/Github/Tests/Api/Enterprise/UserAdminTest.php @@ -15,7 +15,7 @@ public function shouldSuspendUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('users/l3l0/suspended') + ->with('/users/l3l0/suspended') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->suspend('l3l0')); } @@ -30,7 +30,7 @@ public function shouldUnsuspendUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('users/l3l0/suspended') + ->with('/users/l3l0/suspended') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->unsuspend('l3l0')); diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index daa8f04c5e0..22895e554f0 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllGistComments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/123/comments') + ->with('/gists/123/comments') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('123')); @@ -32,7 +32,7 @@ public function shouldShowGistComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/123/comments/123') + ->with('/gists/123/comments/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show(123, 123)); @@ -48,7 +48,7 @@ public function shouldCreateGistComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('gists/123/comments', array('body' => 'Test body')) + ->with('/gists/123/comments', array('body' => 'Test body')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('123', 'Test body')); @@ -65,7 +65,7 @@ public function shouldUpdateGistComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('gists/123/comments/233', $data) + ->with('/gists/123/comments/233', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update(123, 233, 'body test')); @@ -81,7 +81,7 @@ public function shouldRemoveComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('gists/123/comments/233') + ->with('/gists/123/comments/233') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove(123, 233)); diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 7f5ffe35843..f1a2d0c4134 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -14,7 +14,7 @@ public function shouldGetStarredGists() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/starred') + ->with('/gists/starred') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('starred')); @@ -30,7 +30,7 @@ public function shouldGetAllGists() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists') + ->with('/gists') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all()); @@ -46,7 +46,7 @@ public function shouldShowGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/123') + ->with('/gists/123') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show(123)); @@ -62,7 +62,7 @@ public function shouldShowCommits() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/123/commits') + ->with('/gists/123/commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->commits(123)); @@ -88,7 +88,7 @@ public function shouldForkGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('gists/123/fork') + ->with('/gists/123/fork') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->fork(123)); @@ -104,7 +104,7 @@ public function shouldListGistForks() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/123/forks') + ->with('/gists/123/forks') ->will($this->returnValue($expectedArray)); $api->forks(123); @@ -138,7 +138,7 @@ public function shouldCheckGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('gists/123/star') + ->with('/gists/123/star') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->check(123)); @@ -154,7 +154,7 @@ public function shouldStarGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('gists/123/star') + ->with('/gists/123/star') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->star(123)); @@ -170,7 +170,7 @@ public function shouldUnstarGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('gists/123/star') + ->with('/gists/123/star') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->unstar(123)); @@ -194,7 +194,7 @@ public function shouldCreateAnonymousGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('gists', $input); + ->with('/gists', $input); $api->create($input); } @@ -220,7 +220,7 @@ public function shouldUpdateGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('gists/5', $input); + ->with('/gists/5', $input); $api->update(5, $input); } @@ -233,7 +233,7 @@ public function shouldDeleteGist() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('gists/5'); + ->with('/gists/5'); $api->remove(5); } diff --git a/test/Github/Tests/Api/GitData/BlobsTest.php b/test/Github/Tests/Api/GitData/BlobsTest.php index 4df2c67a723..25451a2efbb 100644 --- a/test/Github/Tests/Api/GitData/BlobsTest.php +++ b/test/Github/Tests/Api/GitData/BlobsTest.php @@ -14,7 +14,7 @@ public function shouldShowBlob() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/blobs/123456sha') + ->with('/repos/l3l0/l3l0repo/git/blobs/123456sha') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('l3l0', 'l3l0repo', '123456sha')); @@ -40,7 +40,7 @@ public function shouldShowRawBlob() ->with('raw'); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/blobs/123456sha') + ->with('/repos/l3l0/l3l0repo/git/blobs/123456sha') ->will($this->returnValue($expectedValue)); $api->configure('raw'); @@ -59,7 +59,7 @@ public function shouldCreateBlob() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/l3l0/l3l0repo/git/blobs', $data) + ->with('/repos/l3l0/l3l0repo/git/blobs', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('l3l0', 'l3l0repo', $data)); diff --git a/test/Github/Tests/Api/GitData/CommitsTest.php b/test/Github/Tests/Api/GitData/CommitsTest.php index fa3cd60f1a8..9c881805bcb 100644 --- a/test/Github/Tests/Api/GitData/CommitsTest.php +++ b/test/Github/Tests/Api/GitData/CommitsTest.php @@ -14,7 +14,7 @@ public function shouldShowCommitUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/git/commits/123') + ->with('/repos/KnpLabs/php-github-api/git/commits/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -31,7 +31,7 @@ public function shouldCreateCommit() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/git/commits', $data) + ->with('/repos/KnpLabs/php-github-api/git/commits', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 48f1775c6e5..600d7c42f30 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -14,7 +14,7 @@ public function shouldNotEscapeSlashesInReferences() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/refs/master/some%2A%26%40%23branch/dasd1212') + ->with('/repos/l3l0/l3l0repo/git/refs/master/some%2A%26%40%23branch/dasd1212') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('l3l0', 'l3l0repo', 'master/some*&@#branch/dasd1212')); @@ -30,7 +30,7 @@ public function shouldShowReference() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/refs/123456sha') + ->with('/repos/l3l0/l3l0repo/git/refs/123456sha') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('l3l0', 'l3l0repo', '123456sha')); @@ -46,7 +46,7 @@ public function shouldRemoveReference() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/l3l0/l3l0repo/git/refs/123456sha') + ->with('/repos/l3l0/l3l0repo/git/refs/123456sha') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('l3l0', 'l3l0repo', '123456sha')); @@ -62,7 +62,7 @@ public function shouldGetAllRepoReferences() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/refs') + ->with('/repos/l3l0/l3l0repo/git/refs') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('l3l0', 'l3l0repo')); @@ -78,7 +78,7 @@ public function shouldGetAllRepoBranches() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/refs/heads') + ->with('/repos/l3l0/l3l0repo/git/refs/heads') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->branches('l3l0', 'l3l0repo')); @@ -94,7 +94,7 @@ public function shouldGetAllRepoTags() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/l3l0/l3l0repo/git/refs/tags') + ->with('/repos/l3l0/l3l0repo/git/refs/tags') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->tags('l3l0', 'l3l0repo')); @@ -111,7 +111,7 @@ public function shouldCreateReference() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/l3l0/l3l0repo/git/refs', $data) + ->with('/repos/l3l0/l3l0repo/git/refs', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('l3l0', 'l3l0repo', $data)); @@ -158,7 +158,7 @@ public function shouldUpdateReference() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/l3l0/l3l0repo/git/refs/someRefs', $data) + ->with('/repos/l3l0/l3l0repo/git/refs/someRefs', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('l3l0', 'l3l0repo', 'someRefs', $data)); diff --git a/test/Github/Tests/Api/GitData/TagsTest.php b/test/Github/Tests/Api/GitData/TagsTest.php index 3062e5bba2f..80920fca840 100644 --- a/test/Github/Tests/Api/GitData/TagsTest.php +++ b/test/Github/Tests/Api/GitData/TagsTest.php @@ -14,7 +14,7 @@ public function shouldShowTagUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/git/tags/123') + ->with('/repos/KnpLabs/php-github-api/git/tags/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -30,7 +30,7 @@ public function shouldGetAllTags() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/git/refs/tags') + ->with('/repos/KnpLabs/php-github-api/git/refs/tags') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -57,7 +57,7 @@ public function shouldCreateTag() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/git/tags', $data) + ->with('/repos/KnpLabs/php-github-api/git/tags', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index 1313f282f41..2333744f987 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -14,7 +14,7 @@ public function shouldShowTreeUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/git/trees/123', array()) + ->with('/repos/KnpLabs/php-github-api/git/trees/123', array()) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -46,7 +46,7 @@ public function shouldCreateTreeUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/git/trees', $data) + ->with('/repos/KnpLabs/php-github-api/git/trees', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -78,7 +78,7 @@ public function shouldCreateTreeUsingContent() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/git/trees', $data) + ->with('/repos/KnpLabs/php-github-api/git/trees', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index eca7bf45a98..128e4401637 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllIssueComments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/issues/123/comments', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/issues/123/comments', array('page' => 1)) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); @@ -32,7 +32,7 @@ public function shouldShowIssueComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/issues/comments/123') + ->with('/repos/KnpLabs/php-github-api/issues/comments/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -64,7 +64,7 @@ public function shouldCreateIssueComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/issues/123/comments', $data) + ->with('/repos/KnpLabs/php-github-api/issues/123/comments', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', '123', $data)); @@ -96,7 +96,7 @@ public function shouldUpdateIssueComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/issues/comments/233', $data) + ->with('/repos/KnpLabs/php-github-api/issues/comments/233', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', '233', $data)); @@ -112,7 +112,7 @@ public function shouldRemoveComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/issues/comments/123') + ->with('/repos/KnpLabs/php-github-api/issues/comments/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/Issue/EventsTest.php b/test/Github/Tests/Api/Issue/EventsTest.php index a86aa02cfc4..5168bfd90ba 100644 --- a/test/Github/Tests/Api/Issue/EventsTest.php +++ b/test/Github/Tests/Api/Issue/EventsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepoIssuesEvents() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/issues/events', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/issues/events', array('page' => 1)) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldGetIssueEvents() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/issues/123/events', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/issues/123/events', array('page' => 1)) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); @@ -48,7 +48,7 @@ public function shouldShowIssueEvent() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/issues/events/123') + ->with('/repos/KnpLabs/php-github-api/issues/events/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index c8a457e0ac5..24c0bdfead5 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -19,7 +19,7 @@ public function shouldGetProjectLabels() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/labels', array()) + ->with('/repos/KnpLabs/php-github-api/labels', array()) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -35,7 +35,7 @@ public function shouldGetAllIssueLabels() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/issues/123/labels') + ->with('/repos/KnpLabs/php-github-api/issues/123/labels') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', '123')); @@ -52,7 +52,7 @@ public function shouldCreateLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/labels', $data + array('color' => 'FFFFFF')) + ->with('/repos/KnpLabs/php-github-api/labels', $data + array('color' => 'FFFFFF')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -69,7 +69,7 @@ public function shouldCreateLabelWithColor() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/labels', $data) + ->with('/repos/KnpLabs/php-github-api/labels', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -85,7 +85,7 @@ public function shouldDeleteLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/labels/foo') + ->with('/repos/KnpLabs/php-github-api/labels/foo') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->deleteLabel('KnpLabs', 'php-github-api', 'foo')); @@ -102,7 +102,7 @@ public function shouldUpdateLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/labels/foo', $data) + ->with('/repos/KnpLabs/php-github-api/labels/foo', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'foo', 'bar', 'FFF')); @@ -118,7 +118,7 @@ public function shouldRemoveLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/issues/123/labels/somename') + ->with('/repos/KnpLabs/php-github-api/issues/123/labels/somename') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123, 'somename')); @@ -134,7 +134,7 @@ public function shouldAddOneLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/issues/123/labels', array('labelname')) + ->with('/repos/KnpLabs/php-github-api/issues/123/labels', array('labelname')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('KnpLabs', 'php-github-api', 123, 'labelname')); @@ -150,7 +150,7 @@ public function shouldAddManyLabels() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/issues/123/labels', array('labelname', 'labelname2')) + ->with('/repos/KnpLabs/php-github-api/issues/123/labels', array('labelname', 'labelname2')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('KnpLabs', 'php-github-api', 123, array('labelname', 'labelname2'))); @@ -167,7 +167,7 @@ public function shouldReplaceLabels() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/KnpLabs/php-github-api/issues/123/labels', $data) + ->with('/repos/KnpLabs/php-github-api/issues/123/labels', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->replace('KnpLabs', 'php-github-api', 123, $data)); @@ -196,7 +196,7 @@ public function shouldClearLabels() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/issues/123/labels') + ->with('/repos/KnpLabs/php-github-api/issues/123/labels') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->clear('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/Issue/MilestonesTest.php b/test/Github/Tests/Api/Issue/MilestonesTest.php index 85594f69844..e9c0b3dde21 100644 --- a/test/Github/Tests/Api/Issue/MilestonesTest.php +++ b/test/Github/Tests/Api/Issue/MilestonesTest.php @@ -16,7 +16,7 @@ public function shouldGetMilestones() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -33,7 +33,7 @@ public function shouldCreateMilestone() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/milestones', $data) + ->with('/repos/KnpLabs/php-github-api/milestones', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -65,7 +65,7 @@ public function shouldSetStateToOpenWhileCreationWhenStateParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/milestones', array('state' => 'open', 'title' => 'milestone')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('state' => 'open', 'title' => 'milestone')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', array('state' => 'clos', 'title' => 'milestone'))); @@ -82,7 +82,7 @@ public function shouldUpdateMilestone() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/milestones/123', array('title' => 'milestone')) + ->with('/repos/KnpLabs/php-github-api/milestones/123', array('title' => 'milestone')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -99,7 +99,7 @@ public function shouldUpdateMilestoneWithClosedStatus() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/milestones/123', $data) + ->with('/repos/KnpLabs/php-github-api/milestones/123', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -116,7 +116,7 @@ public function shouldSetStateToOpenWhileUpdateWhenStateParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/milestones/123', array('state' => 'open', 'title' => 'milestone')) + ->with('/repos/KnpLabs/php-github-api/milestones/123', array('state' => 'open', 'title' => 'milestone')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -132,7 +132,7 @@ public function shouldSortByDueDateWhenSortParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('sort' => 'completenes'))); @@ -148,7 +148,7 @@ public function shouldSetStateToOpenWhenStateParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('state' => 'clos'))); @@ -164,7 +164,7 @@ public function shouldSetDirectionToDescWhenDirectionParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('direction' => 'des'))); @@ -180,7 +180,7 @@ public function shouldRemoveMilestones() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/milestones/123') + ->with('/repos/KnpLabs/php-github-api/milestones/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); @@ -196,7 +196,7 @@ public function shouldShowMilestone() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones/123') + ->with('/repos/KnpLabs/php-github-api/milestones/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -212,7 +212,7 @@ public function shouldGetMilestoneLabels() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones/123/labels') + ->with('/repos/KnpLabs/php-github-api/milestones/123/labels') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->labels('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 52bb39a240c..b20efbf9233 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -19,7 +19,7 @@ public function shouldGetIssues() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ornicar/php-github-api/issues', $sentData); + ->with('/repos/ornicar/php-github-api/issues', $sentData); $api->all('ornicar', 'php-github-api', $data); } @@ -46,7 +46,7 @@ public function shouldGetIssuesUsingAdditionalParameters() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ornicar/php-github-api/issues', $sentData) + ->with('/repos/ornicar/php-github-api/issues', $sentData) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ornicar', 'php-github-api', $data)); @@ -62,7 +62,7 @@ public function shouldShowIssue() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ornicar/php-github-api/issues/14') + ->with('/repos/ornicar/php-github-api/issues/14') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show('ornicar', 'php-github-api', 14)); @@ -81,7 +81,7 @@ public function shouldCreateIssue() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/ornicar/php-github-api/issues', $data); + ->with('/repos/ornicar/php-github-api/issues', $data); $api->create('ornicar', 'php-github-api', $data); } @@ -132,7 +132,7 @@ public function shouldCloseIssue() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/ornicar/php-github-api/issues/14', $data); + ->with('/repos/ornicar/php-github-api/issues/14', $data); $api->update('ornicar', 'php-github-api', 14, $data); } @@ -149,7 +149,7 @@ public function shouldReOpenIssue() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/ornicar/php-github-api/issues/14', $data); + ->with('/repos/ornicar/php-github-api/issues/14', $data); $api->update('ornicar', 'php-github-api', 14, $data); } @@ -164,7 +164,7 @@ public function shouldSearchOpenIssues() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') + ->with('/legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'open', 'Invalid Commits')); @@ -180,7 +180,7 @@ public function shouldSearchClosedIssues() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/issues/search/KnpLabs/php-github-api/closed/Invalid%20Commits') + ->with('/legacy/issues/search/KnpLabs/php-github-api/closed/Invalid%20Commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'closed', 'Invalid Commits')); @@ -196,7 +196,7 @@ public function shouldSearchOpenIssuesWhenStateNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') + ->with('/legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'abc', 'Invalid Commits')); diff --git a/test/Github/Tests/Api/MarkdownTest.php b/test/Github/Tests/Api/MarkdownTest.php index 6208a4b84e5..9bd91651e23 100644 --- a/test/Github/Tests/Api/MarkdownTest.php +++ b/test/Github/Tests/Api/MarkdownTest.php @@ -14,7 +14,7 @@ public function shouldRenderMarkdown() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('markdown', array('text' => $input, 'mode' => 'markdown')); + ->with('/markdown', array('text' => $input, 'mode' => 'markdown')); $api->render($input); } @@ -29,7 +29,7 @@ public function shouldRenderMarkdownUsingGfmMode() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('markdown', array('text' => $input, 'mode' => 'gfm')); + ->with('/markdown', array('text' => $input, 'mode' => 'gfm')); $api->render($input, 'gfm'); } @@ -44,7 +44,7 @@ public function shouldSetModeToMarkdownWhenIsNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('markdown', array('text' => $input, 'mode' => 'markdown')); + ->with('/markdown', array('text' => $input, 'mode' => 'markdown')); $api->render($input, 'abc'); } @@ -59,12 +59,12 @@ public function shouldSetContextOnlyForGfmMode() $apiWithMarkdown = $this->getApiMock(); $apiWithMarkdown->expects($this->once()) ->method('post') - ->with('markdown', array('text' => $input, 'mode' => 'markdown')); + ->with('/markdown', array('text' => $input, 'mode' => 'markdown')); $apiWithGfm = $this->getApiMock(); $apiWithGfm->expects($this->once()) ->method('post') - ->with('markdown', array('text' => $input, 'mode' => 'gfm', 'context' => 'someContext')); + ->with('/markdown', array('text' => $input, 'mode' => 'gfm', 'context' => 'someContext')); $apiWithMarkdown->render($input, 'markdown', 'someContext'); $apiWithGfm->render($input, 'gfm', 'someContext'); @@ -80,7 +80,7 @@ public function shouldRenderRawFile() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('markdown/raw', array('file' => $file)); + ->with('/markdown/raw', array('file' => $file)); $api->renderRaw($file); } diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index a212530fffd..35fc09a188c 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -19,7 +19,7 @@ public function shouldGetNotifications() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('notifications', $parameters); + ->with('/notifications', $parameters); $api->all(); } @@ -40,7 +40,7 @@ public function shouldGetNotificationsSince() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('notifications', $parameters); + ->with('/notifications', $parameters); $api->all(false, false, $since); } @@ -58,7 +58,7 @@ public function shouldGetNotificationsIncludingAndParticipating() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('notifications', $parameters); + ->with('/notifications', $parameters); $api->all(true, true); } @@ -73,7 +73,7 @@ public function shouldMarkNotificationsAsRead() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('notifications', $parameters); + ->with('/notifications', $parameters); $api->markRead(); } @@ -92,7 +92,7 @@ public function shouldMarkNotificationsAsReadForGivenDate() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('notifications', $parameters); + ->with('/notifications', $parameters); $api->markRead($since); } diff --git a/test/Github/Tests/Api/Organization/HooksTest.php b/test/Github/Tests/Api/Organization/HooksTest.php index a3cdd4fcba4..113c7bb2433 100644 --- a/test/Github/Tests/Api/Organization/HooksTest.php +++ b/test/Github/Tests/Api/Organization/HooksTest.php @@ -16,7 +16,7 @@ public function shouldGetAllOrganizationsHooks() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/hooks') + ->with('/orgs/KnpLabs/hooks') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs')); @@ -32,7 +32,7 @@ public function shouldShowHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/hooks/123') + ->with('/orgs/KnpLabs/hooks/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 123)); @@ -48,7 +48,7 @@ public function shouldRemoveHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('orgs/KnpLabs/hooks/123') + ->with('/orgs/KnpLabs/hooks/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 123)); @@ -95,7 +95,7 @@ public function shouldCreateHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/hooks', $data) + ->with('/orgs/KnpLabs/hooks', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); @@ -127,7 +127,7 @@ public function shouldUpdateHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('orgs/KnpLabs/hooks/123', $data) + ->with('/orgs/KnpLabs/hooks/123', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 123, $data)); @@ -143,7 +143,7 @@ public function shouldPingHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/hooks/123/pings') + ->with('/orgs/KnpLabs/hooks/123/pings') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->ping('KnpLabs', 123)); diff --git a/test/Github/Tests/Api/Organization/MembersTest.php b/test/Github/Tests/Api/Organization/MembersTest.php index 8a6a252e0c8..f25b74b47f3 100644 --- a/test/Github/Tests/Api/Organization/MembersTest.php +++ b/test/Github/Tests/Api/Organization/MembersTest.php @@ -16,7 +16,7 @@ public function shouldGetAllOrganizationMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/members') + ->with('/orgs/KnpLabs/members') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs')); @@ -32,7 +32,7 @@ public function shouldGetPublicOrganizationMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/public_members') + ->with('/orgs/KnpLabs/public_members') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', true)); @@ -48,7 +48,7 @@ public function shouldCheckIfOrganizationMember() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/public_members/l3l0') + ->with('/orgs/KnpLabs/public_members/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->check('KnpLabs', 'l3l0')); @@ -64,7 +64,7 @@ public function shouldAddOrganizationMember() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('orgs/KnpLabs/memberships/l3l0') + ->with('/orgs/KnpLabs/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('KnpLabs', 'l3l0')); @@ -80,7 +80,7 @@ public function shouldRemoveOrganizationMember() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('orgs/KnpLabs/members/l3l0') + ->with('/orgs/KnpLabs/members/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'l3l0')); @@ -96,7 +96,7 @@ public function shouldPublicizeOrganizationMembership() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('orgs/KnpLabs/public_members/l3l0') + ->with('/orgs/KnpLabs/public_members/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->publicize('KnpLabs', 'l3l0')); @@ -112,7 +112,7 @@ public function shouldConcealOrganizationMembership() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('orgs/KnpLabs/public_members/l3l0') + ->with('/orgs/KnpLabs/public_members/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->conceal('KnpLabs', 'l3l0')); @@ -128,7 +128,7 @@ public function shouldShowOrganizationMember() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/members/l3l0') + ->with('/orgs/KnpLabs/members/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'l3l0')); diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 5a38555f1d5..fa21be45dc7 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllOrganizationTeams() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/teams') + ->with('/orgs/KnpLabs/teams') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs')); @@ -32,7 +32,7 @@ public function shouldCheckIfMemberIsInOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('teams/KnpWorld/memberships/l3l0') + ->with('/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0')); @@ -48,7 +48,7 @@ public function shouldRemoveOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('teams/KnpWorld') + ->with('/teams/KnpWorld') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpWorld')); @@ -64,7 +64,7 @@ public function shouldShowOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('teams/KnpWorld') + ->with('/teams/KnpWorld') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpWorld')); @@ -80,7 +80,7 @@ public function shouldGetTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('teams/KnpWorld/members') + ->with('/teams/KnpWorld/members') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->members('KnpWorld')); @@ -96,7 +96,7 @@ public function shouldAddTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('teams/KnpWorld/memberships/l3l0') + ->with('/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0')); @@ -112,7 +112,7 @@ public function shouldRemoveTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('teams/KnpWorld/memberships/l3l0') + ->with('/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0')); @@ -128,7 +128,7 @@ public function shouldGetTeamRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('teams/KnpWorld/repos') + ->with('/teams/KnpWorld/repos') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->repositories('KnpWorld')); @@ -144,7 +144,7 @@ public function shouldGetTeamRepository() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('teams/KnpWorld/repos/l3l0/l3l0Repo') + ->with('/teams/KnpWorld/repos/l3l0/l3l0Repo') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->repository('KnpWorld', 'l3l0', 'l3l0Repo')); @@ -160,7 +160,7 @@ public function shouldAddTeamRepository() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('teams/KnpWorld/repos/l3l0/l3l0Repo') + ->with('/teams/KnpWorld/repos/l3l0/l3l0Repo') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->addRepository('KnpWorld', 'l3l0', 'l3l0Repo')); @@ -176,7 +176,7 @@ public function shouldRemoveTeamRepository() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('teams/KnpWorld/repos/l3l0/l3l0Repo') + ->with('/teams/KnpWorld/repos/l3l0/l3l0Repo') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->removeRepository('KnpWorld', 'l3l0', 'l3l0Repo')); @@ -208,7 +208,7 @@ public function shouldCreateOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/teams', $data) + ->with('/orgs/KnpLabs/teams', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); @@ -225,7 +225,7 @@ public function shouldCreateOrganizationTeamWithRepoName() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/teams', array('name' => 'KnpWorld', 'repo_names' => array('somerepo'))) + ->with('/orgs/KnpLabs/teams', array('name' => 'KnpWorld', 'repo_names' => array('somerepo'))) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); @@ -242,7 +242,7 @@ public function shouldCreateWithPullPermissionWhenPermissionParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/teams', array('name' => 'KnpWorld', 'permission' => 'pull')) + ->with('/orgs/KnpLabs/teams', array('name' => 'KnpWorld', 'permission' => 'pull')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); @@ -274,7 +274,7 @@ public function shouldUpdateOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('teams/KnpWorld', $data) + ->with('/teams/KnpWorld', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); @@ -291,7 +291,7 @@ public function shouldUpdateWithPullPermissionWhenPermissionParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('teams/KnpWorld', array('name' => 'KnpWorld', 'permission' => 'pull')) + ->with('/teams/KnpWorld', array('name' => 'KnpWorld', 'permission' => 'pull')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 0a673dbb065..ca70ffbb232 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -14,7 +14,7 @@ public function shouldGetAllOrganizations() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('organizations?since=1') + ->with('/organizations?since=1') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all(1)); @@ -30,7 +30,7 @@ public function shouldShowOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs') + ->with('/orgs/KnpLabs') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show('KnpLabs')); @@ -46,7 +46,7 @@ public function shouldUpdateOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('orgs/KnpLabs', array('value' => 'toUpdate')) + ->with('/orgs/KnpLabs', array('value' => 'toUpdate')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->update('KnpLabs', array('value' => 'toUpdate'))); @@ -62,7 +62,7 @@ public function shouldGetOrganizationRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('orgs/KnpLabs/repos', array('type' => 'all')) + ->with('/orgs/KnpLabs/repos', array('type' => 'all')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('KnpLabs')); diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index cf18f9e3b82..6e0f562765f 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -14,7 +14,7 @@ public function shouldGetAllPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls') + ->with('/repos/ezsystems/ezpublish/pulls') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish')); @@ -30,7 +30,7 @@ public function shouldGetOpenPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) + ->with('/repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'open'))); @@ -46,7 +46,7 @@ public function shouldGetClosedPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) + ->with('/repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'closed'))); @@ -63,7 +63,7 @@ public function shouldShowPullRequest() $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls/15') + ->with('/repos/ezsystems/ezpublish/pulls/15') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show('ezsystems', 'ezpublish', '15')); @@ -79,7 +79,7 @@ public function shouldShowCommitsFromPullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls/15/commits') + ->with('/repos/ezsystems/ezpublish/pulls/15/commits') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->commits('ezsystems', 'ezpublish', '15')); @@ -95,7 +95,7 @@ public function shouldShowFilesFromPullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls/15/files') + ->with('/repos/ezsystems/ezpublish/pulls/15/files') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15')); @@ -111,7 +111,7 @@ public function shouldUpdatePullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/ezsystems/ezpublish/pulls/15', array('state' => 'open', 'some' => 'param')) + ->with('/repos/ezsystems/ezpublish/pulls/15', array('state' => 'open', 'some' => 'param')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', 15, array('state' => 'aa', 'some' => 'param'))); @@ -127,7 +127,7 @@ public function shouldCheckIfPullRequestIsMerged() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls/15/merge') + ->with('/repos/ezsystems/ezpublish/pulls/15/merge') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merged('ezsystems', 'ezpublish', 15)); @@ -143,7 +143,7 @@ public function shouldMergePullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'squash' => false)) + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'squash' => false)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40))); @@ -164,7 +164,7 @@ public function shouldCreatePullRequestUsingTitle() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/ezsystems/ezpublish/pulls', $data); + ->with('/repos/ezsystems/ezpublish/pulls', $data); $api->create('ezsystems', 'ezpublish', $data); } @@ -183,7 +183,7 @@ public function shouldCreatePullRequestUsingIssueId() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/ezsystems/ezpublish/pulls', $data); + ->with('/repos/ezsystems/ezpublish/pulls', $data); $api->create('ezsystems', 'ezpublish', $data); } diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index 4f1b8c467d3..382e0411792 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -27,7 +27,7 @@ public function shouldReturnRateLimitArray() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('rate_limit') + ->with('/rate_limit') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->getRateLimits()); diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 3ada7d440fb..6ef8af7b375 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -14,7 +14,7 @@ public function shouldShowRepository() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api') + ->with('/repos/KnpLabs/php-github-api') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api')); @@ -33,7 +33,7 @@ public function shouldSearchRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/repos/search/php', array('myparam' => 2, 'start_page' => 1)) + ->with('/legacy/repos/search/php', array('myparam' => 2, 'start_page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('php', array('myparam' => 2))); @@ -52,7 +52,7 @@ public function shouldPaginateFoundRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/repos/search/php', array('start_page' => 2)) + ->with('/legacy/repos/search/php', array('start_page' => 2)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('php', array('start_page' => 2))); @@ -73,7 +73,7 @@ public function shouldGetAllRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repositories') + ->with('/repositories') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all()); @@ -94,7 +94,7 @@ public function shouldGetAllRepositoriesStartingIndex() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repositories?since=2') + ->with('/repositories?since=2') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all(2)); @@ -110,7 +110,7 @@ public function shouldCreateRepositoryUsingNameOnly() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/repos', array( + ->with('/user/repos', array( 'name' => 'l3l0Repo', 'description' => '', 'homepage' => '', @@ -135,7 +135,7 @@ public function shouldCreateRepositoryForOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('orgs/KnpLabs/repos', array( + ->with('/orgs/KnpLabs/repos', array( 'name' => 'KnpLabsRepo', 'description' => '', 'homepage' => '', @@ -160,7 +160,7 @@ public function shouldGetRepositorySubscribers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/subscribers', array('page' => 2)) + ->with('/repos/KnpLabs/php-github-api/subscribers', array('page' => 2)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->subscribers('KnpLabs', 'php-github-api', 2)); @@ -176,7 +176,7 @@ public function shouldGetRepositoryTags() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/tags') + ->with('/repos/KnpLabs/php-github-api/tags') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->tags('KnpLabs', 'php-github-api')); @@ -192,7 +192,7 @@ public function shouldGetRepositoryBranches() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/branches') + ->with('/repos/KnpLabs/php-github-api/branches') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->branches('KnpLabs', 'php-github-api')); @@ -208,7 +208,7 @@ public function shouldGetRepositoryBranch() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/branches/master') + ->with('/repos/KnpLabs/php-github-api/branches/master') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->branches('KnpLabs', 'php-github-api', 'master')); @@ -224,7 +224,7 @@ public function shouldGetRepositoryLanguages() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/languages') + ->with('/repos/KnpLabs/php-github-api/languages') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->languages('KnpLabs', 'php-github-api')); @@ -240,7 +240,7 @@ public function shouldGetRepositoryMilestones() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/milestones') + ->with('/repos/KnpLabs/php-github-api/milestones') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->milestones('KnpLabs', 'php-github-api')); @@ -256,7 +256,7 @@ public function shouldGetContributorsExcludingAnonymousOnes() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/contributors', array('anon' => null)) + ->with('/repos/KnpLabs/php-github-api/contributors', array('anon' => null)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->contributors('KnpLabs', 'php-github-api', false)); @@ -272,7 +272,7 @@ public function shouldGetContributorsIncludingAnonymousOnes() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/contributors', array('anon' => true)) + ->with('/repos/KnpLabs/php-github-api/contributors', array('anon' => true)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->contributors('KnpLabs', 'php-github-api', true)); @@ -288,7 +288,7 @@ public function shouldGetRepositoryTeams() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/teams') + ->with('/repos/KnpLabs/php-github-api/teams') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->teams('KnpLabs', 'php-github-api')); @@ -304,7 +304,7 @@ public function shouldCreateUsingAllParams() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('user/repos', array( + ->with('/user/repos', array( 'name' => 'l3l0Repo', 'description' => 'test', 'homepage' => 'http://l3l0.eu', @@ -329,7 +329,7 @@ public function shouldUpdate() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/l3l0Repo/test', array('description' => 'test', 'homepage' => 'http://l3l0.eu')) + ->with('/repos/l3l0Repo/test', array('description' => 'test', 'homepage' => 'http://l3l0.eu')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->update('l3l0Repo', 'test', array('description' => 'test', 'homepage' => 'http://l3l0.eu'))); @@ -343,7 +343,7 @@ public function shouldDelete() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/l3l0Repo/test') + ->with('/repos/l3l0Repo/test') ->will($this->returnValue(null)); $this->assertNull($api->remove('l3l0Repo', 'test')); @@ -359,7 +359,7 @@ public function shouldNotDelete() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/l3l0Repo/uknown-repo') + ->with('/repos/l3l0Repo/uknown-repo') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->remove('l3l0Repo', 'uknown-repo')); @@ -495,7 +495,7 @@ public function shouldGetCommitActivity() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/stats/commit_activity') + ->with('/repos/KnpLabs/php-github-api/stats/commit_activity') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 174268468ca..67c6213b4ce 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -17,7 +17,7 @@ public function shouldGetAllReleaseAssets() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/releases/'.$id.'/assets') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id.'/assets') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', $id)); @@ -34,7 +34,7 @@ public function shouldGetSingleReleaseAsset() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/releases/assets/'.$assetId) + ->with('/repos/KnpLabs/php-github-api/releases/assets/'.$assetId) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $assetId)); @@ -78,7 +78,7 @@ public function shouldEditReleaseAsset() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/releases/assets/'.$assetId) + ->with('/repos/KnpLabs/php-github-api/releases/assets/'.$assetId) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $assetId, $data)); @@ -111,7 +111,7 @@ public function shouldRemoveReleaseAsset() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/releases/assets/'.$assetId) + ->with('/repos/KnpLabs/php-github-api/releases/assets/'.$assetId) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $assetId)); diff --git a/test/Github/Tests/Api/Repository/CollaboratorsTest.php b/test/Github/Tests/Api/Repository/CollaboratorsTest.php index 6f8c924151a..0eb75818277 100644 --- a/test/Github/Tests/Api/Repository/CollaboratorsTest.php +++ b/test/Github/Tests/Api/Repository/CollaboratorsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryCollaborators() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/collaborators') + ->with('/repos/KnpLabs/php-github-api/collaborators') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldCheckIfRepositoryCollaborator() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/collaborators/l3l0') + ->with('/repos/KnpLabs/php-github-api/collaborators/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->check('KnpLabs', 'php-github-api', 'l3l0')); @@ -48,7 +48,7 @@ public function shouldAddRepositoryCollaborator() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/KnpLabs/php-github-api/collaborators/l3l0') + ->with('/repos/KnpLabs/php-github-api/collaborators/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('KnpLabs', 'php-github-api', 'l3l0')); @@ -64,7 +64,7 @@ public function shouldRemoveRepositoryCollaborator() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/collaborators/l3l0') + ->with('/repos/KnpLabs/php-github-api/collaborators/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0')); diff --git a/test/Github/Tests/Api/Repository/CommentsTest.php b/test/Github/Tests/Api/Repository/CommentsTest.php index 586736a183f..6fea4a62a70 100644 --- a/test/Github/Tests/Api/Repository/CommentsTest.php +++ b/test/Github/Tests/Api/Repository/CommentsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryComments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/comments') + ->with('/repos/KnpLabs/php-github-api/comments') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldGetSpecificCommitRepositoryComments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/comments') + ->with('/repos/KnpLabs/php-github-api/commits/commitSHA123456/comments') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 'commitSHA123456')); @@ -48,7 +48,7 @@ public function shouldShowComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/comments/123') + ->with('/repos/KnpLabs/php-github-api/comments/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -80,7 +80,7 @@ public function shouldCreateRepositoryCommitComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/comments', $data) + ->with('/repos/KnpLabs/php-github-api/commits/commitSHA123456/comments', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data)); @@ -97,7 +97,7 @@ public function shouldCreateRepositoryCommitCommentWithoutLine() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/comments', $data) + ->with('/repos/KnpLabs/php-github-api/commits/commitSHA123456/comments', $data) ->will($this->returnValue($expectedValue)); $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data); @@ -127,7 +127,7 @@ public function shouldUpdateComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/comments/123', $data) + ->with('/repos/KnpLabs/php-github-api/comments/123', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -143,7 +143,7 @@ public function shouldRemoveComment() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/comments/123') + ->with('/repos/KnpLabs/php-github-api/comments/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/Repository/CommitsTest.php b/test/Github/Tests/Api/Repository/CommitsTest.php index b36f81b16c0..395ee1ac259 100644 --- a/test/Github/Tests/Api/Repository/CommitsTest.php +++ b/test/Github/Tests/Api/Repository/CommitsTest.php @@ -17,7 +17,7 @@ public function shouldGetAllRepositoryCommits() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/commits', $data) + ->with('/repos/KnpLabs/php-github-api/commits', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', $data)); @@ -33,7 +33,7 @@ public function shouldCompareTwoCommits() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/compare/v3...HEAD') + ->with('/repos/KnpLabs/php-github-api/compare/v3...HEAD') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->compare('KnpLabs', 'php-github-api', 'v3', 'HEAD')); @@ -49,7 +49,7 @@ public function shouldShowCommitUsingSha() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/commits/123') + ->with('/repos/KnpLabs/php-github-api/commits/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index cc9bb693940..5be3b227ba6 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -18,7 +18,7 @@ public function shouldShowContentForGivenPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); @@ -34,7 +34,7 @@ public function shouldShowReadme() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/readme', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/readme', array('ref' => null)) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->readme('KnpLabs', 'php-github-api')); @@ -50,7 +50,7 @@ public function shouldReturnTrueWhenFileExists() $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') - ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) ->will($this->returnValue($response)); $this->assertEquals(true, $api->exists('KnpLabs', 'php-github-api', 'composer.json')); @@ -77,7 +77,7 @@ public function shouldReturnFalseWhenFileIsNotFound(\PHPUnit_Framework_MockObjec $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') - ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) ->will($failureStub); $this->assertFalse($api->exists('KnpLabs', 'php-github-api', 'composer.json')); @@ -92,7 +92,7 @@ public function shouldBubbleTwoFactorAuthenticationRequiredExceptionsWhenCheckin $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') - ->with('repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) ->will($this->throwException(new TwoFactorAuthenticationRequiredException(0))); $api->exists('KnpLabs', 'php-github-api', 'composer.json'); @@ -118,7 +118,7 @@ public function shouldCreateNewFile() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $content, $message, $branch, $committer)); @@ -158,7 +158,7 @@ public function shouldUpdateFile() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $content, $message, $sha, $branch, $committer)); @@ -196,7 +196,7 @@ public function shouldDeleteFile() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $message, $sha, $branch, $committer)); @@ -224,7 +224,7 @@ public function shouldFetchTarballArchiveWhenFormatNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/tarball') + ->with('/repos/KnpLabs/php-github-api/tarball') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'someFormat')); @@ -240,7 +240,7 @@ public function shouldFetchTarballArchive() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/tarball') + ->with('/repos/KnpLabs/php-github-api/tarball') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'tarball')); @@ -256,7 +256,7 @@ public function shouldFetchZipballArchive() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/zipball') + ->with('/repos/KnpLabs/php-github-api/zipball') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball')); @@ -272,7 +272,7 @@ public function shouldFetchZipballArchiveByReference() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/zipball/master') + ->with('/repos/KnpLabs/php-github-api/zipball/master') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball', 'master')); @@ -292,7 +292,7 @@ public function shouldDownloadForGivenPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) ->will($this->returnValue($getValue)); $this->assertEquals($expectedValue, $api->download('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); @@ -312,7 +312,7 @@ public function shouldDownloadForSpacedPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/mads379/scala.tmbundle/contents/Syntaxes%2FSimple%20Build%20Tool.tmLanguage', array('ref' => null)) + ->with('/repos/mads379/scala.tmbundle/contents/Syntaxes%2FSimple%20Build%20Tool.tmLanguage', array('ref' => null)) ->will($this->returnValue($getValue)); $this->assertEquals($expectedValue, $api->download('mads379', 'scala.tmbundle', 'Syntaxes/Simple Build Tool.tmLanguage')); diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index 1654471b69e..535ede4e5ab 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryDeployKeys() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/keys') + ->with('/repos/KnpLabs/php-github-api/keys') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldShowDeployKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/keys/123') + ->with('/repos/KnpLabs/php-github-api/keys/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -48,7 +48,7 @@ public function shouldRemoveDeployKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/keys/123') + ->with('/repos/KnpLabs/php-github-api/keys/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); @@ -95,7 +95,7 @@ public function shouldCreateDeployKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/keys', $data) + ->with('/repos/KnpLabs/php-github-api/keys', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -142,7 +142,7 @@ public function shouldUpdateDeployKey() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/keys/123', $data) + ->with('/repos/KnpLabs/php-github-api/keys/123', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); diff --git a/test/Github/Tests/Api/Repository/DownloadsTest.php b/test/Github/Tests/Api/Repository/DownloadsTest.php index b352c12efbf..ad7897cc8f7 100644 --- a/test/Github/Tests/Api/Repository/DownloadsTest.php +++ b/test/Github/Tests/Api/Repository/DownloadsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryDownloads() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/downloads') + ->with('/repos/KnpLabs/php-github-api/downloads') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldShowRepositoryDownload() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/downloads/l3l0') + ->with('/repos/KnpLabs/php-github-api/downloads/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'l3l0')); @@ -48,7 +48,7 @@ public function shouldRemoveRepositoryDownload() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/downloads/l3l0') + ->with('/repos/KnpLabs/php-github-api/downloads/l3l0') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0')); diff --git a/test/Github/Tests/Api/Repository/ForksTest.php b/test/Github/Tests/Api/Repository/ForksTest.php index 151fbc3837b..12530a98647 100644 --- a/test/Github/Tests/Api/Repository/ForksTest.php +++ b/test/Github/Tests/Api/Repository/ForksTest.php @@ -16,7 +16,7 @@ public function shouldGetForks() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/forks', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/forks', array('page' => 1)) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -33,7 +33,7 @@ public function shouldCreateFork() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/forks', $data) + ->with('/repos/KnpLabs/php-github-api/forks', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -49,7 +49,7 @@ public function shouldSortByNewestWhenSortParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/forks', array('page' => 1, 'sort' => 'newest')) + ->with('/repos/KnpLabs/php-github-api/forks', array('page' => 1, 'sort' => 'newest')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('sort' => 'oldes'))); diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index aa8e32b485d..dfe2d77b083 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryHooks() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/hooks') + ->with('/repos/KnpLabs/php-github-api/hooks') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldShowHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/hooks/123') + ->with('/repos/KnpLabs/php-github-api/hooks/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -48,7 +48,7 @@ public function shouldRemoveHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/hooks/123') + ->with('/repos/KnpLabs/php-github-api/hooks/123') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); @@ -95,7 +95,7 @@ public function shouldCreateHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/hooks', $data) + ->with('/repos/KnpLabs/php-github-api/hooks', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -142,7 +142,7 @@ public function shouldUpdateHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/hooks/123', $data) + ->with('/repos/KnpLabs/php-github-api/hooks/123', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -158,7 +158,7 @@ public function shouldTestHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/hooks/123/test') + ->with('/repos/KnpLabs/php-github-api/hooks/123/test') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->test('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index 8b430e6b3f1..7e81cea8188 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryLabelss() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/labels') + ->with('/repos/KnpLabs/php-github-api/labels') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldShowLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/labels/somename') + ->with('/repos/KnpLabs/php-github-api/labels/somename') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'somename')); @@ -48,7 +48,7 @@ public function shouldRemoveLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/labels/somename') + ->with('/repos/KnpLabs/php-github-api/labels/somename') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'somename')); @@ -95,7 +95,7 @@ public function shouldCreateLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/labels', $data) + ->with('/repos/KnpLabs/php-github-api/labels', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -142,7 +142,7 @@ public function shouldUpdateLabel() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/labels/labelName', $data) + ->with('/repos/KnpLabs/php-github-api/labels/labelName', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'labelName', $data)); diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index f9188e137a0..a05d0bdc422 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -16,7 +16,7 @@ public function shouldGetLatestRelease() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/releases/latest') + ->with('/repos/KnpLabs/php-github-api/releases/latest') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldGetReleaseByTag() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') + ->with('/repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->tag( @@ -52,7 +52,7 @@ public function shouldGetAllRepositoryReleases() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/releases') + ->with('/repos/KnpLabs/php-github-api/releases') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -69,7 +69,7 @@ public function shouldGetSingleRepositoryRelease() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/releases/'.$id) + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); @@ -86,7 +86,7 @@ public function shouldCreateRepositoryRelease() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/releases') + ->with('/repos/KnpLabs/php-github-api/releases') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -119,7 +119,7 @@ public function shouldEditRepositoryRelease() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('repos/KnpLabs/php-github-api/releases/'.$id) + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $id, $data)); @@ -136,7 +136,7 @@ public function shouldRemoveRepositoryRelease() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('repos/KnpLabs/php-github-api/releases/'.$id) + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $id)); diff --git a/test/Github/Tests/Api/Repository/StargazersTest.php b/test/Github/Tests/Api/Repository/StargazersTest.php index e9c2dbbb50c..142ce8ba6c7 100644 --- a/test/Github/Tests/Api/Repository/StargazersTest.php +++ b/test/Github/Tests/Api/Repository/StargazersTest.php @@ -16,7 +16,7 @@ public function shouldGetAllRepositoryStargazers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/stargazers') + ->with('/repos/KnpLabs/php-github-api/stargazers') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -32,7 +32,7 @@ public function shouldGetAllRepositoryStargazersWithAlternativeResponse() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/stargazers') + ->with('/repos/KnpLabs/php-github-api/stargazers') ->will($this->returnValue($expectedValue)); $api->configure('star'); diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php index 68667fca7b1..55d96af0bf1 100644 --- a/test/Github/Tests/Api/Repository/StatusesTest.php +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -19,7 +19,7 @@ public function shouldShowCommitStatuses() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/statuses') + ->with('/repos/KnpLabs/php-github-api/commits/commitSHA123456/statuses') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'commitSHA123456')); @@ -49,7 +49,7 @@ public function shouldShowCombinedCommitStatuses() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/status') + ->with('/repos/KnpLabs/php-github-api/commits/commitSHA123456/status') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->combined('KnpLabs', 'php-github-api', 'commitSHA123456')); @@ -81,7 +81,7 @@ public function shouldCreateCommitStatus() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('repos/KnpLabs/php-github-api/statuses/commitSHA123456', $data) + ->with('/repos/KnpLabs/php-github-api/statuses/commitSHA123456', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data)); diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index d5c41f2e0ed..d5fe9b08494 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -16,7 +16,7 @@ public function shouldSearchRepositoriesByQuery() $api->expects($this->once()) ->method('get') ->with( - 'search/repositories', + '/search/repositories', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -36,7 +36,7 @@ public function shouldSearchRepositoriesRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - 'search/repositories', + '/search/repositories', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); @@ -59,7 +59,7 @@ public function shouldSearchIssuesByQuery() $api->expects($this->once()) ->method('get') ->with( - 'search/issues', + '/search/issues', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -79,7 +79,7 @@ public function shouldSearchIssuesRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - 'search/issues', + '/search/issues', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); @@ -102,7 +102,7 @@ public function shouldSearchCodeByQuery() $api->expects($this->once()) ->method('get') ->with( - 'search/code', + '/search/code', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -122,7 +122,7 @@ public function shouldSearchCodeRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - 'search/code', + '/search/code', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); @@ -145,7 +145,7 @@ public function shouldSearchUsersByQuery() $api->expects($this->once()) ->method('get') ->with( - 'search/users', + '/search/users', array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') ) ->will($this->returnValue($expectedArray)); @@ -165,7 +165,7 @@ public function shouldSearchUsersRegardingSortAndOrder() $api->expects($this->once()) ->method('get') ->with( - 'search/users', + '/search/users', array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') ) ->will($this->returnValue($expectedArray)); diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index dec69d7944b..6f4f4e9fc00 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -14,7 +14,7 @@ public function shouldShowUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0') + ->with('/users/l3l0') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->show('l3l0')); @@ -37,7 +37,7 @@ public function shouldGetUserOrganizations() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/orgs') + ->with('/users/l3l0/orgs') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->organizations('l3l0')); @@ -56,7 +56,7 @@ public function shouldGetAllUsers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users') + ->with('/users') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all()); @@ -75,7 +75,7 @@ public function shouldSearchUsers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('legacy/user/search/l3l0') + ->with('/legacy/user/search/l3l0') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->find('l3l0')); @@ -91,7 +91,7 @@ public function shouldGetFollowingUsers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/following') + ->with('/users/l3l0/following') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->following('l3l0')); @@ -107,7 +107,7 @@ public function shouldGetUserFollowers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/followers') + ->with('/users/l3l0/followers') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->followers('l3l0')); @@ -123,7 +123,7 @@ public function shouldGetSubscriptionsToRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/subscriptions') + ->with('/users/l3l0/subscriptions') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->subscriptions('l3l0')); @@ -139,7 +139,7 @@ public function shouldGetUserRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/repos', array('type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc')) + ->with('/users/l3l0/repos', array('type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('l3l0')); @@ -155,7 +155,7 @@ public function shouldGetUserGists() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('users/l3l0/gists') + ->with('/users/l3l0/gists') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->gists('l3l0')); From e0b673c78b6fe9c70fdc0e13d8b46d4d92da2cf8 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 2 Aug 2016 16:52:09 +0100 Subject: [PATCH 403/951] Use consistent notation --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5b7eb44548a..8a80d9d2056 100644 --- a/composer.json +++ b/composer.json @@ -28,9 +28,9 @@ }, "require-dev": { "phpunit/phpunit": "~4.0", - "php-http/guzzle6-adapter": "~1.0", + "php-http/guzzle6-adapter": "^1.0", "guzzlehttp/psr7": "^1.2", - "sllh/php-cs-fixer-styleci-bridge": "~1.3" + "sllh/php-cs-fixer-styleci-bridge": "^1.3" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } From 13e45fe077bd6159e557f533ce496e9e166cdff2 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 2 Aug 2016 16:52:35 +0100 Subject: [PATCH 404/951] Test on PHP 7.1 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 30c91afd2f1..7d4fd26b3c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm sudo: false From dcc79f093a41ea37486e63e637f5e12fb5546c3e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 4 Aug 2016 10:26:32 +0200 Subject: [PATCH 405/951] Bumped version of cache plugin Version 1.1 has support for 304 responses which is needed to not effect our API limit. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8a80d9d2056..220c50f5268 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", "php-http/client-common": "^1.1", - "php-http/cache-plugin": "^1.0" + "php-http/cache-plugin": "^1.1" }, "require-dev": { "phpunit/phpunit": "~4.0", From 1d93776591242b079e74734d0ef8d6b67fddde5e Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 4 Aug 2016 09:30:50 +0100 Subject: [PATCH 406/951] Support passing through config when enabling caching --- lib/Github/Client.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 3ec9f9bf82e..41e6a150d35 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -402,12 +402,14 @@ public function addHeaders(array $headers) /** * Add a cache plugin to cache responses locally. + * * @param CacheItemPoolInterface $cache + * @param array $config */ - public function addCache(CacheItemPoolInterface $cachePool) + public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { $this->removeCache(); - $this->addPlugin(new Plugin\CachePlugin($cachePool, $this->streamFactory)); + $this->addPlugin(new Plugin\CachePlugin($cachePool, $this->streamFactory, $config)); } /** From 09149c710b5f342a438ef967962e348a9664913b Mon Sep 17 00:00:00 2001 From: Corentin REGNIER Date: Mon, 8 Aug 2016 15:05:12 +0200 Subject: [PATCH 407/951] Update comment.md At line 55 : change create by update --- doc/issue/comments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issue/comments.md b/doc/issue/comments.md index 632bd3459b1..19c95ecedbe 100644 --- a/doc/issue/comments.md +++ b/doc/issue/comments.md @@ -52,7 +52,7 @@ $client->api('issue')->comments()->create('KnpLabs', 'php-github-api', 4, array( > Requires [authentication](../security.md). ```php -$client->api('issue')->comments()->create('KnpLabs', 'php-github-api', 33793831, array('body' => 'My updated comment')); +$client->api('issue')->comments()->update('KnpLabs', 'php-github-api', 33793831, array('body' => 'My updated comment')); ``` * `KnpLabs` : the owner of the repository From 52394dc8a1a94e28dc35adf72de11bb7b324aee2 Mon Sep 17 00:00:00 2001 From: syropian Date: Wed, 10 Aug 2016 15:24:14 -0400 Subject: [PATCH 408/951] Add per_page support to starring()->all() --- lib/Github/Api/CurrentUser/Starring.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index 5085af06662..39de729fe99 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -6,6 +6,7 @@ /** * @link https://developer.github.com/v3/activity/starring/ + * * @author Felipe Valtl de Mello */ class Starring extends AbstractApi @@ -16,13 +17,15 @@ class Starring extends AbstractApi * @link https://developer.github.com/v3/activity/starring/ * * @param int $page + * @param int $perPage * * @return array */ - public function all($page = 1) + public function all($page = 1, $perPage = 30) { return $this->get('/user/starred', array( - 'page' => $page + 'page' => $page, + 'per_page' => $perPage, )); } From 0faa54f2bf27e9683c738fe54b9832600b8e4d0a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 16 Aug 2016 13:49:41 +0100 Subject: [PATCH 409/951] Fixed bad caching defaults --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 220c50f5268..188808e50b4 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", "php-http/client-common": "^1.1", - "php-http/cache-plugin": "^1.1" + "php-http/cache-plugin": "^1.2" }, "require-dev": { "phpunit/phpunit": "~4.0", From afa690f2c68db23c9a4715800e1629c9c45bf9b7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 3 Sep 2016 11:07:05 +0100 Subject: [PATCH 410/951] Bumped min versions to address the plugin interface issues --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 188808e50b4..2afd3b56dbb 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ "php": "^5.5 || ^7.0", "psr/http-message": "^1.0", "psr/cache": "^1.0", - "php-http/httplug": "^1.0", + "php-http/httplug": "^1.1", "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.1", + "php-http/client-common": "^1.3", "php-http/cache-plugin": "^1.2" }, "require-dev": { - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^4.0", "php-http/guzzle6-adapter": "^1.0", "guzzlehttp/psr7": "^1.2", "sllh/php-cs-fixer-styleci-bridge": "^1.3" From 5fcb35858908ccd8b99f127f8963792b0f042bbd Mon Sep 17 00:00:00 2001 From: Pablo Morales Date: Mon, 5 Sep 2016 13:18:32 +0200 Subject: [PATCH 411/951] Add support for Organisations\Members --- lib/Github/Client.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 41e6a150d35..c4dbfcd57f6 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -252,6 +252,11 @@ public function api($name) $api = new Api\Organization\Teams($this); break; + case 'member': + case 'members': + $api = new Api\Organization\Members($this); + break; + case 'user': case 'users': $api = new Api\User($this); From 374ba99e0b0f475ce44bb69d8b5fc364a6260668 Mon Sep 17 00:00:00 2001 From: Martin Peverelli Date: Mon, 19 Sep 2016 14:46:33 -0300 Subject: [PATCH 412/951] Update tests for PHPUnit 5.5 --- composer.json | 2 +- test/Github/Tests/Api/AbstractApiTest.php | 34 +++++++++++++++++------ test/Github/Tests/Api/TestCase.php | 4 ++- test/Github/Tests/ClientTest.php | 20 +++++++++---- test/Github/Tests/ResultPagerTest.php | 15 +++++++--- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 2afd3b56dbb..62e44e009cc 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php-http/cache-plugin": "^1.2" }, "require-dev": { - "phpunit/phpunit": "^4.0", + "phpunit/phpunit": "^4.0 || ^5.5", "php-http/guzzle6-adapter": "^1.0", "guzzlehttp/psr7": "^1.2", "sllh/php-cs-fixer-styleci-bridge": "^1.3" diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 0edd5daf7b7..676f9944bf7 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -20,7 +20,9 @@ public function shouldPassGETRequestToClient() ->method('get') ->with('/path?param1=param1value', array('header1' => 'header1value')) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMock('Github\Client', array('getHttpClient')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('getHttpClient')) + ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); @@ -44,7 +46,9 @@ public function shouldPassPOSTRequestToClient() ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMock('Github\Client', array('getHttpClient')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('getHttpClient')) + ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); @@ -68,7 +72,9 @@ public function shouldPassPATCHRequestToClient() ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMock('Github\Client', array('getHttpClient')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('getHttpClient')) + ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); @@ -92,7 +98,9 @@ public function shouldPassPUTRequestToClient() ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMock('Github\Client', array('getHttpClient')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('getHttpClient')) + ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); @@ -116,7 +124,9 @@ public function shouldPassDELETERequestToClient() ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMock('Github\Client', array('getHttpClient')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('getHttpClient')) + ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); @@ -141,7 +151,9 @@ public function shouldNotPassEmptyRefToClient() ->with('/path', array()) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMock('Github\Client', array('getHttpClient')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('getHttpClient')) + ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); @@ -166,12 +178,16 @@ protected function getClientMock() /** * Return a HttpMethods client mock * + * @param array $methods * @return \Http\Client\Common\HttpMethodsClient */ protected function getHttpMethodsMock(array $methods = array()) { $methods = array_merge(array('sendRequest'), $methods); - $mock = $this->getMock('Http\Client\Common\HttpMethodsClient', $methods, array(), '', false); + $mock = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient') + ->disableOriginalConstructor() + ->setMethods($methods) + ->getMock(); $mock ->expects($this->any()) ->method('sendRequest'); @@ -183,7 +199,9 @@ protected function getHttpMethodsMock(array $methods = array()) */ protected function getHttpClientMock() { - $mock = $this->getMock('Http\Client\HttpClient', array('sendRequest')); + $mock = $this->getMockBuilder('Http\Client\HttpClient') + ->setMethods(array('sendRequest')) + ->getMock(); $mock ->expects($this->any()) ->method('sendRequest'); diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 965781cd9d7..5add05e1bfd 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -8,7 +8,9 @@ abstract protected function getApiClass(); protected function getApiMock() { - $httpClient = $this->getMock('Http\Client\HttpClient', array('sendRequest')); + $httpClient = $this->getMockBuilder('Http\Client\HttpClient') + ->setMethods(array('sendRequest')) + ->getMock(); $httpClient ->expects($this->any()) ->method('sendRequest'); diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 0a9983eb20b..a719e2f3254 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -24,7 +24,9 @@ public function shouldNotHaveToPassHttpClientToConstructor() */ public function shouldPassHttpClientInterfaceToConstructor() { - $client = new Client($this->getMock('Http\Client\HttpClient')); + $httpClientMock = $this->getMockBuilder('Http\Client\HttpClient') + ->getMock(); + $client = new Client($httpClientMock); $this->assertInstanceOf('Http\Client\HttpClient', $client->getHttpClient()); } @@ -35,7 +37,9 @@ public function shouldPassHttpClientInterfaceToConstructor() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('addPlugin', 'removePlugin')) + ->getMock(); $client->expects($this->once()) ->method('addPlugin') ->with($this->equalTo(new Authentication($login, $password, $method))); @@ -63,7 +67,9 @@ public function getAuthenticationFullData() */ public function shouldAuthenticateUsingGivenParameters($token, $method) { - $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('addPlugin', 'removePlugin')) + ->getMock(); $client->expects($this->once()) ->method('addPlugin') ->with($this->equalTo(new Authentication($token, null, $method))); @@ -99,7 +105,9 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet() */ public function shouldClearHeaders() { - $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('addPlugin', 'removePlugin')) + ->getMock(); $client->expects($this->once()) ->method('addPlugin') ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); @@ -118,7 +126,9 @@ public function shouldAddHeaders() { $headers = array('header1', 'header2'); - $client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin')); + $client = $this->getMockBuilder('Github\Client') + ->setMethods(array('addPlugin', 'removePlugin')) + ->getMock(); $client->expects($this->once()) ->method('addPlugin') // TODO verify that headers exists diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index af9e767a5de..317cefedb5b 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -31,7 +31,9 @@ public function shouldGetAllResults() $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest')); + $httpClientMock = $this->getMockBuilder('Http\Client\HttpClient') + ->setMethods(array('sendRequest')) + ->getMock(); $httpClientMock ->expects($this->exactly($amountLoops)) ->method('sendRequest') @@ -76,7 +78,9 @@ public function shouldGetAllSearchResults() $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest')); + $httpClientMock = $this->getMockBuilder('Http\Client\HttpClient') + ->setMethods(array('sendRequest')) + ->getMock(); $httpClientMock ->expects($this->exactly($amountLoops)) ->method('sendRequest') @@ -97,9 +101,12 @@ public function testFetch() $result = 'foo'; $method = 'bar'; $parameters = array('baz'); - $api = $this->getMock('Github\Api\ApiInterface'); + $api = $this->createMock('Github\Api\ApiInterface'); - $paginator = $this->getMock('Github\ResultPager', array('callApi', 'postFetch'), array(), '', false); + $paginator = $this->getMockBuilder('Github\ResultPager') + ->disableOriginalConstructor() + ->setMethods(array('callApi', 'postFetch')) + ->getMock(); $paginator->expects($this->once()) ->method('callApi') ->with($api, $method, $parameters) From 129aefd1680832b186e40016c8d02a99b1ab6efc Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 26 Sep 2016 19:05:47 +0200 Subject: [PATCH 413/951] Add JWT authentication introduced with GitHub integrations --- lib/Github/Client.php | 6 ++++++ lib/Github/HttpClient/Plugin/Authentication.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 41e6a150d35..4ec28ee2515 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -86,6 +86,12 @@ class Client */ const AUTH_HTTP_TOKEN = 'http_token'; + /** + * Constant for authentication method. Indicates JSON Web Token + * authentication required for integration access to the API. + */ + const AUTH_JWT = 'jwt'; + /** * @var string */ diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 4651e6bf302..9601eb12c67 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -71,6 +71,10 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $request = $request->withUri($uri); break; + case Client::AUTH_JWT: + $request = $request->withHeader('Authorization', sprintf('Bearer %s', $this->tokenOrLogin)); + break; + default: throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); break; From 51eb698526dfb882b5189152ed599573f8f2a0a7 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 26 Sep 2016 20:01:03 +0200 Subject: [PATCH 414/951] JWT: Accept authenticate() method shortcut on Client class --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 4ec28ee2515..615c73f4aa1 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -294,7 +294,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null throw new InvalidArgumentException('You need to specify authentication method!'); } - if (null === $authMethod && in_array($password, array(self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN))) { + if (null === $authMethod && in_array($password, array(self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT))) { $authMethod = $password; $password = null; } From 116f3663b077c0ede8311c21eb48aa71706c58d3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 27 Sep 2016 22:35:24 +0200 Subject: [PATCH 415/951] Installations: Add create access token endpoint --- lib/Github/Api/Installations.php | 28 ++++++++++++++++++++++++++++ lib/Github/Client.php | 5 +++++ 2 files changed, 33 insertions(+) create mode 100644 lib/Github/Api/Installations.php diff --git a/lib/Github/Api/Installations.php b/lib/Github/Api/Installations.php new file mode 100644 index 00000000000..bef32332831 --- /dev/null +++ b/lib/Github/Api/Installations.php @@ -0,0 +1,28 @@ + + */ +class Installations extends AbstractApi +{ + /** + * Create an access token for an installation + * + * @param int $installationId An integration installation id + * @param int $userId An optional user id on behalf of whom the + * token will be requested + * + * @return array token and token metadata + */ + public function createAccessToken($installationId, $userId = null) + { + $parameters = array(); + if ($userId) { + $paramters['user_id'] = $userId; + } + return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 615c73f4aa1..62196a87686 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -210,6 +210,11 @@ public function api($name) $api = new Api\Gists($this); break; + case 'installation': + case 'installations': + $api = new Api\Installations($this); + break; + case 'issue': case 'issues': $api = new Api\Issue($this); From e77f21a165c7f200ed73fa136a772eaca5a34c82 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 12 Oct 2016 15:26:31 +0200 Subject: [PATCH 416/951] Code Style: add blank line --- lib/Github/Api/Installations.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/Installations.php b/lib/Github/Api/Installations.php index bef32332831..4e99494606a 100644 --- a/lib/Github/Api/Installations.php +++ b/lib/Github/Api/Installations.php @@ -23,6 +23,7 @@ public function createAccessToken($installationId, $userId = null) if ($userId) { $paramters['user_id'] = $userId; } + return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); } } From 9680038e26fce4548041108ad82a22670896ca46 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 12 Oct 2016 15:54:41 +0200 Subject: [PATCH 417/951] Rename installations endpoint to integrations as per APIv3 docs --- lib/Github/Api/{Installations.php => Integrations.php} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename lib/Github/Api/{Installations.php => Integrations.php} (71%) diff --git a/lib/Github/Api/Installations.php b/lib/Github/Api/Integrations.php similarity index 71% rename from lib/Github/Api/Installations.php rename to lib/Github/Api/Integrations.php index 4e99494606a..f8cdadb00bc 100644 --- a/lib/Github/Api/Installations.php +++ b/lib/Github/Api/Integrations.php @@ -3,10 +3,10 @@ namespace Github\Api; /** - * @link https://developer.github.com/early-access/integrations/authentication/ + * @link https://developer.github.com/v3/integrations/ * @author Nils Adermann */ -class Installations extends AbstractApi +class Integrations extends AbstractApi { /** * Create an access token for an installation @@ -17,11 +17,11 @@ class Installations extends AbstractApi * * @return array token and token metadata */ - public function createAccessToken($installationId, $userId = null) + public function createInstallationToken($installationId, $userId = null) { $parameters = array(); if ($userId) { - $paramters['user_id'] = $userId; + $parameters['user_id'] = $userId; } return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); From 06d2cf9a58e692b4c1b2c449a706471781003427 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 12 Oct 2016 15:54:59 +0200 Subject: [PATCH 418/951] Integrations: Add documentation for integrations and authentication --- doc/README.md | 1 + doc/integrations.md | 15 +++++++++++++++ doc/security.md | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 doc/integrations.md diff --git a/doc/README.md b/doc/README.md index da189b1f86f..ea9e1f48959 100644 --- a/doc/README.md +++ b/doc/README.md @@ -7,6 +7,7 @@ APIs: * [Enterprise](enterprise.md) * [Gists](gists.md) * [Comments](gists/comments.md) +* [Integrations](integrations.md) * [Issues](issues.md) * [Comments](issue/comments.md) * [Labels](issue/labels.md) diff --git a/doc/integrations.md b/doc/integrations.md new file mode 100644 index 00000000000..9e34e6a0b9e --- /dev/null +++ b/doc/integrations.md @@ -0,0 +1,15 @@ +## Instegrations API +[Back to the navigation](README.md) + +Wraps [GitHub Integrations API](http://developer.github.com/v3/integrations/). + +### Create a new installation token +For the installation id 123 use the following: +```php +$token = $client->api('integrations')->createInstallationToken(123); +``` + +To create an access token on behalf of a user with id 456 use: +```php +$token = $client->api('integrations')->createInstallationToken(123, 456); +``` diff --git a/doc/security.md b/doc/security.md index 358bfe8abab..41a97f5b2cb 100644 --- a/doc/security.md +++ b/doc/security.md @@ -13,15 +13,17 @@ $client->authenticate($usernameOrToken, $password, $method); ``` `$usernameOrToken` is, of course, the username (or in some cases token/client ID, more details you can find below), -and guess what should contain `$password`. The `$method` can contain one of the three allowed values: +and guess what should contain `$password`. The `$method` can contain one of the five allowed values: * `Github\Client::AUTH_URL_TOKEN` * `Github\Client::AUTH_URL_CLIENT_ID` * `Github\Client::AUTH_HTTP_TOKEN` * `Github\Client::AUTH_HTTP_PASSWORD` +* `Github\Client::AUTH_JWT` -The required value of `$password` depends on the chosen `$method`. For the `Github\Client::AUTH_*_TOKEN` methods, -you should provide the API token in `$username` variable (`$password` is omitted in this particular case). For the +The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`, +`Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in +`$username` variable (`$password` is omitted in this particular case). For the `Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID` `$usernameOrToken` should contain your client ID, and `$password` should contain client secret. @@ -32,10 +34,37 @@ all further requests are done as the given user. The `Github\Client::AUTH_URL_TOKEN` authentication method sends the API token in URL parameters. The `Github\Client::AUTH_URL_CLIENT_ID` authentication method sends the client ID and secret in URL parameters. -The `Github_Client::AUTH_HTTP_*` authentication methods send their values to GitHub using HTTP Basic Authentication. +The `Github\Client::AUTH_HTTP_*` authentication methods send their values to GitHub using HTTP Basic Authentication. +The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header. `Github\Client::AUTH_URL_TOKEN` used to be the only available authentication method. To prevent existing applications from changing their behavior in case of an API upgrade, this method is chosen as the default for this API implementation. Note however that GitHub describes this method as deprecated. In most case you should use the `Github\Client::AUTH_HTTP_TOKEN` instead. + +### Authenticating as an Integration + +To authenticate as an integration you need to supply a JSON Web Token with `Github\Client::AUTH_JWT` to request +and installation access token which is then usable with `Github\Client::AUTH_HTTP_TOKEN`. [Github´s integration +authentication docs](https://developer.github.com/early-access/integrations/authentication/) describe the flow in detail. +It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. + +The following sample code authenticates as an installation using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.2.0) +to generate a JSON Web Token (JWT). + +```php +$github = new Github\Client(new GuzzleClient(), 'machine-man-preview'); + +$jwt = (new Builder) + ->setIssuer($integrationId) + ->setIssuedAt(time()) + ->setExpiration(time() + 60) + ->sign(new Sha256(), (new Keychain)->getPrivateKey($pemPrivateKeyPath)) + ->getToken(); + +$github->authenticate($jwt, null, Github\Client::AUTH_JWT); + +$token = $github->api('installations')->createAccessToken($installationId); +$github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); +``` From 6478e8a6414ab8f461fa8a8a87dfee12d40d52ab Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 12 Oct 2016 16:03:48 +0200 Subject: [PATCH 419/951] Integrations: correct the name of the integrations entry point --- lib/Github/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 62196a87686..a6321fee0b5 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -210,9 +210,9 @@ public function api($name) $api = new Api\Gists($this); break; - case 'installation': - case 'installations': - $api = new Api\Installations($this); + case 'integration': + case 'integrations': + $api = new Api\Integrations($this); break; case 'issue': From 5a91711f3812a28da0779b77ab6be6c0fad7c623 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 12 Oct 2016 16:08:36 +0200 Subject: [PATCH 420/951] Integrations: Correct documentation after renames --- doc/security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/security.md b/doc/security.md index 41a97f5b2cb..4da1f1b18a5 100644 --- a/doc/security.md +++ b/doc/security.md @@ -65,6 +65,6 @@ $jwt = (new Builder) $github->authenticate($jwt, null, Github\Client::AUTH_JWT); -$token = $github->api('installations')->createAccessToken($installationId); +$token = $github->api('integrations')->createInstallationToken($installationId); $github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); ``` From ca0623fbb148781876e1cb9d31c9fb94650a2fa4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 13 Oct 2016 14:27:01 +0200 Subject: [PATCH 421/951] name is not a required argument to update a hook --- lib/Github/Api/Repository/Hooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index 30f887d726f..a44a01a9f29 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -32,8 +32,8 @@ public function create($username, $repository, array $params) public function update($username, $repository, $id, array $params) { - if (!isset($params['name'], $params['config'])) { - throw new MissingArgumentException(array('name', 'config')); + if (!isset($params['config'])) { + throw new MissingArgumentException(array('config')); } return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params); From 4ea6a3a4bdaa70d2f33bfaad9eec5a96be0a146c Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2016 13:42:50 +0200 Subject: [PATCH 422/951] Explain cache pool origin --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fe59dfaed82..4ccdbdb0965 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ From `$client` object, you can access to all GitHub. ## Cache usage +This example uses the PSR6 cache pool [redis-adapter](https://github.com/php-cache/redis-adapter). See http://www.php-cache.com/ for alternatives. + ```php Date: Sat, 15 Oct 2016 00:33:01 +0200 Subject: [PATCH 423/951] Updated throws doc --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 398b418fdc3..b074db5a14a 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -439,7 +439,7 @@ public function removeCache() /** * @param string $name * - * @throws InvalidArgumentException + * @throws BadMethodCallException * * @return ApiInterface */ From 637fce5519e282569f39d5e25195800ed9e14b64 Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Sat, 15 Oct 2016 21:35:32 +0200 Subject: [PATCH 424/951] removed unit test shouldNotUpdateHookWithoutName for https://github.com/KnpLabs/php-github-api/pull/442 AbstractApiTest cleanup with ReflectionMethod createMock removed in ResultPagerTest like in https://github.com/KnpLabs/php-github-api/pull/438 comment written --- test/Github/Tests/Api/AbstractApiTest.php | 100 +++++------------- .../Github/Tests/Api/Repository/HooksTest.php | 15 --- test/Github/Tests/Api/TestCase.php | 5 +- test/Github/Tests/ResultPagerTest.php | 3 +- 4 files changed, 34 insertions(+), 89 deletions(-) diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 676f9944bf7..8a7def68aa1 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -29,7 +29,10 @@ public function shouldPassGETRequestToClient() $api = $this->getAbstractApiObject($client); - $this->assertEquals($expectedArray, $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); + $method = new \ReflectionMethod($api, 'get'); + $method->setAccessible(true); + + $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('header1' => 'header1value')])); } /** @@ -54,8 +57,10 @@ public function shouldPassPOSTRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); + $method = new \ReflectionMethod($api, 'post'); + $method->setAccessible(true); - $this->assertEquals($expectedArray, $api->post('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))); + $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } /** @@ -80,8 +85,10 @@ public function shouldPassPATCHRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); + $method = new \ReflectionMethod($api, 'patch'); + $method->setAccessible(true); - $this->assertEquals($expectedArray, $api->patch('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))); + $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } /** @@ -106,8 +113,10 @@ public function shouldPassPUTRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); + $method = new \ReflectionMethod($api, 'put'); + $method->setAccessible(true); - $this->assertEquals($expectedArray, $api->put('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))); + $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } /** @@ -133,8 +142,10 @@ public function shouldPassDELETERequestToClient() $api = $this->getAbstractApiObject($client); + $method = new \ReflectionMethod($api, 'delete'); + $method->setAccessible(true); - $this->assertEquals($expectedArray, $api->delete('/path', array('param1' => 'param1value'), array('option1' => 'option1value'))); + $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } /** @@ -159,12 +170,22 @@ public function shouldNotPassEmptyRefToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $api->get('/path', array('ref' => null)); + $method = new \ReflectionMethod($api, 'get'); + $method->setAccessible(true); + + $this->assertInternalType('array', $method->invokeArgs($api, ['/path', array('ref' => null)])); } + /** + * @param $client + * @return AbstractApi + */ protected function getAbstractApiObject($client) { - return new AbstractApiTestInstance($client); + return $this->getMockBuilder(AbstractApi::class) + ->setMethods(null) + ->setConstructorArgs([$client]) + ->getMock(); } /** @@ -223,68 +244,3 @@ private function getPSR7Response($expectedArray) ); } } - -class AbstractApiTestInstance extends AbstractApi -{ - /** - * {@inheritDoc} - */ - public function get($path, array $parameters = array(), $requestHeaders = array()) - { - return parent::get($path, $parameters, $requestHeaders); - } - - /** - * {@inheritDoc} - */ - public function post($path, array $parameters = array(), $requestHeaders = array()) - { - return parent::post($path, $parameters, $requestHeaders); - } - - /** - * {@inheritDoc} - */ - public function postRaw($path, $body, $requestHeaders = array()) - { - return parent::postRaw($path, $body, $requestHeaders); - } - - /** - * {@inheritDoc} - */ - public function patch($path, array $parameters = array(), $requestHeaders = array()) - { - return parent::patch($path, $parameters, $requestHeaders); - } - - /** - * {@inheritDoc} - */ - public function put($path, array $parameters = array(), $requestHeaders = array()) - { - return parent::put($path, $parameters, $requestHeaders); - } - - /** - * {@inheritDoc} - */ - public function delete($path, array $parameters = array(), $requestHeaders = array()) - { - return parent::delete($path, $parameters, $requestHeaders); - } -} - -/** - * @deprecated - */ -class ExposedAbstractApiTestInstance extends AbstractApi -{ - /** - * {@inheritDoc} - */ - public function get($path, array $parameters = array(), $requestHeaders = array()) - { - return parent::get($path, $parameters, $requestHeaders); - } -} diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index dfe2d77b083..dbca3c062e4 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -101,21 +101,6 @@ public function shouldCreateHook() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** - * @test - * @expectedException \Github\Exception\MissingArgumentException - */ - public function shouldNotUpdateHookWithoutName() - { - $data = array('config' => 'someconf'); - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('patch'); - - $api->update('KnpLabs', 'php-github-api', 123, $data); - } - /** * @test * @expectedException \Github\Exception\MissingArgumentException diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 5add05e1bfd..5cb69203c8c 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -6,9 +6,12 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { abstract protected function getApiClass(); + /** + * @return \PHPUnit_Framework_MockObject_MockObject + */ protected function getApiMock() { - $httpClient = $this->getMockBuilder('Http\Client\HttpClient') + $httpClient = $this->getMockBuilder(\Http\Client\HttpClient::class) ->setMethods(array('sendRequest')) ->getMock(); $httpClient diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 317cefedb5b..f758adb1a25 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -101,7 +101,8 @@ public function testFetch() $result = 'foo'; $method = 'bar'; $parameters = array('baz'); - $api = $this->createMock('Github\Api\ApiInterface'); + $api = $this->getMockBuilder('Github\Api\ApiInterface') + ->getMock(); $paginator = $this->getMockBuilder('Github\ResultPager') ->disableOriginalConstructor() From 66f7b18daaabc922db8dc667317dd53a0a5621b2 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 16 Oct 2016 09:10:45 +0200 Subject: [PATCH 425/951] Updated exception description --- lib/Github/Exception/ValidationFailedException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Exception/ValidationFailedException.php b/lib/Github/Exception/ValidationFailedException.php index e43bc43e067..c689e2d695d 100644 --- a/lib/Github/Exception/ValidationFailedException.php +++ b/lib/Github/Exception/ValidationFailedException.php @@ -3,7 +3,7 @@ namespace Github\Exception; /** - * ValidationFailedException. + * When GitHub returns with a HTTP response that says our request is invalid. * * @author Joseph Bielawski */ From 55a6a7890b7d34cf86446154cc2e6006c83fa1eb Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 16 Oct 2016 20:08:41 +0200 Subject: [PATCH 426/951] Added support for the projects api. Fixes #437 --- doc/README.md | 3 + doc/repo/cards.md | 53 ++++++ doc/repo/columns.md | 53 ++++++ doc/repo/projects.md | 45 +++++ lib/Github/Api/Repo.php | 6 + lib/Github/Api/Repository/Cards.php | 56 ++++++ lib/Github/Api/Repository/Columns.php | 69 ++++++++ lib/Github/Api/Repository/Projects.php | 56 ++++++ .../Github/Tests/Api/Repository/CardsTest.php | 127 +++++++++++++ .../Tests/Api/Repository/ColumnsTest.php | 167 ++++++++++++++++++ .../Tests/Api/Repository/ProjectsTest.php | 120 +++++++++++++ 11 files changed, 755 insertions(+) create mode 100644 doc/repo/cards.md create mode 100644 doc/repo/columns.md create mode 100644 doc/repo/projects.md create mode 100644 lib/Github/Api/Repository/Cards.php create mode 100644 lib/Github/Api/Repository/Columns.php create mode 100644 lib/Github/Api/Repository/Projects.php create mode 100644 test/Github/Tests/Api/Repository/CardsTest.php create mode 100644 test/Github/Tests/Api/Repository/ColumnsTest.php create mode 100644 test/Github/Tests/Api/Repository/ProjectsTest.php diff --git a/doc/README.md b/doc/README.md index ea9e1f48959..b86b1289907 100644 --- a/doc/README.md +++ b/doc/README.md @@ -20,6 +20,9 @@ APIs: * [Repositories](repos.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) + * [Projects](repo/projects.md) + * [Columns](repo/columns.md) + * [Cards](repo/cards.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) * [Stargazers](repo/stargazers.md) diff --git a/doc/repo/cards.md b/doc/repo/cards.md new file mode 100644 index 00000000000..baed1aa83be --- /dev/null +++ b/doc/repo/cards.md @@ -0,0 +1,53 @@ +## Repo / Cards API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +This api is currently only available to developers in Early Access. To access the API during the Early Access period, +you must provide a custom media type in the Accept header. + +```php +$client->api('repo')->projects()->columns()->cards()->configure(); +``` + +### List all cards of a column + +```php +$cards = $client->api('repo')->projects()->columns()->cards()->all('twbs', 'bootstrap', $columnId); +``` + +### List one card + +```php +$card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'bootstrap', $cardId); +``` + +### Create a card + +> Requires [authentication](../security.md). + +```php +$card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bootstrap', $columnId, array('content_type' => 'Issue', 'content_id' => '452')); +``` + +### Edit a card + +> Requires [authentication](../security.md). + +```php +$card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'bootstrap', $cardId, array('note' => 'card note')); +``` + +### Remove a card + +> Requires [authentication](../security.md). + +```php +$card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', 'bootstrap', $cardId); +``` + +### Move a card + +> Requires [authentication](../security.md). + +```php +$card = $client->api('repo')->projects()->columns()->cards()->move('twbs', 'bootstrap', $cardId, array('position' => 'top)); +``` diff --git a/doc/repo/columns.md b/doc/repo/columns.md new file mode 100644 index 00000000000..94263efd9fd --- /dev/null +++ b/doc/repo/columns.md @@ -0,0 +1,53 @@ +## Repo / Columns API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +This api is currently only available to developers in Early Access. To access the API during the Early Access period, +you must provide a custom media type in the Accept header. + +```php +$client->api('repo')->projects()->columns()->configure(); +``` + +### List all columns of a project + +```php +$columns = $client->api('repo')->projects()->columns()->all('twbs', 'bootstrap', $projectId); +``` + +### List one column + +```php +$column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', $columnId); +``` + +### Create a column + +> Requires [authentication](../security.md). + +```php +$column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap', $projectId, array('name' => 'Column name')); +``` + +### Edit a column + +> Requires [authentication](../security.md). + +```php +$column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap', $columnId, array('name' => 'New name')); +``` + +### Remove a column + +> Requires [authentication](../security.md). + +```php +$column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'bootstrap', $columnId); +``` + +### Move a column + +> Requires [authentication](../security.md). + +```php +$column = $client->api('repo')->projects()->columns()->move('twbs', 'bootstrap', $columnId, array('position' => 'first)); +``` diff --git a/doc/repo/projects.md b/doc/repo/projects.md new file mode 100644 index 00000000000..2743973b73c --- /dev/null +++ b/doc/repo/projects.md @@ -0,0 +1,45 @@ +## Repo / Projects API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +This api is currently only available to developers in Early Access. To access the API during the Early Access period, +you must provide a custom media type in the Accept header. + +```php +$client->api('repo')->projects()->configure(); +``` + +### List all projects + +```php +$projects = $client->api('repo')->projects()->all('twbs', 'bootstrap'); +``` + +### List one project + +```php +$project = $client->api('repo')->projects()->show('twbs', 'bootstrap', $projectId); +``` + +### Create a project + +> Requires [authentication](../security.md). + +```php +$project = $client->api('repo')->projects()->create('twbs', 'bootstrap', array('name' => 'Project name')); +``` + +### Edit a project + +> Requires [authentication](../security.md). + +```php +$project = $client->api('repo')->project()->update('twbs', 'bootstrap', $projectId, array('name' => 'New name')); +``` + +### Remove a project + +> Requires [authentication](../security.md). + +```php +$project = $client->api('repo')->projects()->deleteProject('twbs', 'bootstrap', $projectId); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 1a416cf81d5..d0d0070af9e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -8,6 +8,7 @@ use Github\Api\Repository\Contents; use Github\Api\Repository\DeployKeys; use Github\Api\Repository\Downloads; +use Github\Api\Repository\Projects; use Github\Api\Repository\Releases; use Github\Api\Repository\Forks; use Github\Api\Repository\Hooks; @@ -510,4 +511,9 @@ public function milestones($username, $repository) { return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones'); } + + public function projects() + { + return new Projects($this->client); + } } diff --git a/lib/Github/Api/Repository/Cards.php b/lib/Github/Api/Repository/Cards.php new file mode 100644 index 00000000000..e772ca97328 --- /dev/null +++ b/lib/Github/Api/Repository/Cards.php @@ -0,0 +1,56 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($username, $repository, $columnId, array $params = array()) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params)); + } + + public function show($username, $repository, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id)); + } + + public function create($username, $repository, $columnId, array $params) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', $params); + } + + public function update($username, $repository, $id, array $params) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id), $params); + } + + public function deleteCard($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id)); + } + + public function move($username, $repository, $id, array $params) + { + if (!isset($params['position'])) { + throw new MissingArgumentException(array('position')); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id) . '/moves', $params); + } +} diff --git a/lib/Github/Api/Repository/Columns.php b/lib/Github/Api/Repository/Columns.php new file mode 100644 index 00000000000..1b4e016a87b --- /dev/null +++ b/lib/Github/Api/Repository/Columns.php @@ -0,0 +1,69 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($username, $repository, $projectId, array $params = array()) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params)); + } + + public function show($username, $repository, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id)); + } + + public function create($username, $repository, $projectId, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', $params); + } + + public function update($username, $repository, $id, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id), $params); + } + + public function deleteColumn($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id)); + } + + public function move($username, $repository, $id, array $params) + { + if (!isset($params['position'])) { + throw new MissingArgumentException(array('position')); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id) . '/moves', $params); + } + + public function cards() + { + return new Cards($this->client); + } +} diff --git a/lib/Github/Api/Repository/Projects.php b/lib/Github/Api/Repository/Projects.php new file mode 100644 index 00000000000..1b791a90be4 --- /dev/null +++ b/lib/Github/Api/Repository/Projects.php @@ -0,0 +1,56 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($username, $repository, array $params = array()) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(array('page' => 1), $params)); + } + + public function show($username, $repository, $id, array $params = array()) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params)); + } + + public function create($username, $repository, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', $params); + } + + public function update($username, $repository, $id, array $params) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id), $params); + } + + public function deleteProject($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id)); + } + + public function columns() + { + return new Columns($this->client); + } +} diff --git a/test/Github/Tests/Api/Repository/CardsTest.php b/test/Github/Tests/Api/Repository/CardsTest.php new file mode 100644 index 00000000000..407e4f5bab0 --- /dev/null +++ b/test/Github/Tests/Api/Repository/CardsTest.php @@ -0,0 +1,127 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/projects/columns/123/cards') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + */ + public function shouldShowCard() + { + $expectedValue = array('card1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + */ + public function shouldCreateCard() + { + $expectedValue = array('card1data'); + $data = array('content_id' => '123', 'content_type' => 'Issue'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/projects/columns/1234/cards', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', '1234', $data)); + } + + /** + * @test + */ + public function shouldUpdateCard() + { + $expectedValue = array('note1data'); + $data = array('note' => 'note test'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + } + + /** + * @test + */ + public function shouldRemoveCard() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteCard('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotMoveWithoutPosition() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->move('KnpLabs', 'php-github-api', '123', $data); + } + + /** + * @test + */ + public function shouldMoveCard() + { + $expectedValue = array('card1'); + $data = array('position' => 'top'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123/moves') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Cards'; + } +} diff --git a/test/Github/Tests/Api/Repository/ColumnsTest.php b/test/Github/Tests/Api/Repository/ColumnsTest.php new file mode 100644 index 00000000000..95a14fd545b --- /dev/null +++ b/test/Github/Tests/Api/Repository/ColumnsTest.php @@ -0,0 +1,167 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/projects/123/columns') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + */ + public function shouldShowColumn() + { + $expectedValue = array('column1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/projects/columns/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateWithoutName() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', '123', $data); + } + + /** + * @test + */ + public function shouldCreateColumn() + { + $expectedValue = array('column1data'); + $data = array('name' => 'column 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/projects/123/columns', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 123, $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotUpdateWithoutName() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->update('KnpLabs', 'php-github-api', '123', $data); + } + + /** + * @test + */ + public function shouldUpdateColumn() + { + $expectedValue = array('column1data'); + $data = array('name' => 'column 1 update'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/projects/columns/123', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + } + + /** + * @test + */ + public function shouldRemoveCard() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/projects/columns/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteColumn('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotMoveWithoutPosition() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->move('KnpLabs', 'php-github-api', '123', $data); + } + + /** + * @test + */ + public function shouldMoveCard() + { + $expectedValue = array('card1'); + $data = array('position' => 'first'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/projects/columns/123/moves') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); + } + + /** + * @test + */ + public function shouldGetCardsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Cards', $api->cards()); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Columns'; + } +} diff --git a/test/Github/Tests/Api/Repository/ProjectsTest.php b/test/Github/Tests/Api/Repository/ProjectsTest.php new file mode 100644 index 00000000000..5713fbfda5a --- /dev/null +++ b/test/Github/Tests/Api/Repository/ProjectsTest.php @@ -0,0 +1,120 @@ + 'Test project 1')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/projects') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldShowProject() + { + $expectedValue = array('name' => 'Test project 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/projects/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateWithoutName() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', $data); + } + + /** + * @test + */ + public function shouldCreateColumn() + { + $expectedValue = array('column1data'); + $data = array('name' => 'Project 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/projects', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + */ + public function shouldUpdateProject() + { + $expectedValue = array('project1data'); + $data = array('name' => 'Project 1 update'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/projects/123', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + } + + /** + * @test + */ + public function shouldRemoveProject() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/projects/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteProject('KnpLabs', 'php-github-api', 123)); + } + + /** + * @test + */ + public function shouldGetColumnsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Columns', $api->columns()); + } + + protected function getApiClass() + { + return 'Github\Api\Repository\Projects'; + } +} From 417a29167f7523b384c86fd52349ff58ce440b7e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 16 Oct 2016 21:06:08 +0200 Subject: [PATCH 427/951] Issue comment api expects issue number instead of id. Fixes: #359 --- doc/issue/comments.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/issue/comments.md b/doc/issue/comments.md index 19c95ecedbe..ac0f8a619ea 100644 --- a/doc/issue/comments.md +++ b/doc/issue/comments.md @@ -11,7 +11,7 @@ $comments = $client->api('issue')->comments()->all('KnpLabs', 'php-github-api', * `KnpLabs` : the owner of the repository * `php-github-api` : the name of the repository -* `4` : the id of the issue +* `4` : the issue number * You can select another page of comments using one more parameter (default: 1) Returns an array of comments. @@ -41,7 +41,7 @@ $client->api('issue')->comments()->create('KnpLabs', 'php-github-api', 4, array( * `KnpLabs` : the owner of the repository * `php-github-api` : the name of the repository -* `4` : the id of the issue +* `4` : the issue number * You can set a `body` and optionally a `title` From b571ad29fe5e997d1f1a3338b28e9fe9a390fd82 Mon Sep 17 00:00:00 2001 From: Mohamed Elkholy Date: Mon, 17 Oct 2016 18:14:21 +0200 Subject: [PATCH 428/951] Added two new endpoints --- lib/Github/Api/Repo.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 1a416cf81d5..648bad0e073 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -88,6 +88,36 @@ public function statistics($username, $repository) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors'); } + /** + * Get a weekly aggregate of the number of additions and deletions pushed to a repository. + * + * @link http://developer.github.com/v3/repos/statistics/#code-frequency + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * + * @return array list of weeks and their commit statistics + */ + public function frequency($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/code_frequency'); + } + + /** + * Get the weekly commit count for the repository owner and everyone else. + * + * @link http://developer.github.com/v3/repos/statistics/#participation + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * + * @return array list of weekly commit count grouped by 'all' and 'owner' + */ + public function participation($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/participation'); + } + /** * List all repositories for an organization. * From 1dde54442c284ce7a2e01c4946c1c9957ee73477 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 17 Oct 2016 18:47:06 +0200 Subject: [PATCH 429/951] Update AbstractApiTest.php trigger rebuild --- test/Github/Tests/Api/AbstractApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 8a7def68aa1..5ddb09b2e95 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -32,7 +32,7 @@ public function shouldPassGETRequestToClient() $method = new \ReflectionMethod($api, 'get'); $method->setAccessible(true); - $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('header1' => 'header1value')])); + $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['header1' => 'header1value']])); } /** From 1a01e28dcf38a162781f36f0a6531febed524f96 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 18 Oct 2016 22:16:13 +0200 Subject: [PATCH 430/951] Fixed test for #442 --- test/Github/Tests/Api/Repository/HooksTest.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index dfe2d77b083..dbca3c062e4 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -101,21 +101,6 @@ public function shouldCreateHook() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** - * @test - * @expectedException \Github\Exception\MissingArgumentException - */ - public function shouldNotUpdateHookWithoutName() - { - $data = array('config' => 'someconf'); - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('patch'); - - $api->update('KnpLabs', 'php-github-api', 123, $data); - } - /** * @test * @expectedException \Github\Exception\MissingArgumentException From 164bf78ecab70eec5739e29c454e909f3698ca36 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 18 Oct 2016 21:47:49 +0200 Subject: [PATCH 431/951] Fixed comments and type hints --- lib/Github/Api/AbstractApi.php | 22 +++++++++++++++------- lib/Github/Api/AcceptHeaderTrait.php | 14 +++++++------- test/Github/Tests/Api/AbstractApiTest.php | 16 ++++++++-------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index bb2e1c7855b..6feff8ea2bb 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -65,7 +65,7 @@ public function setPerPage($perPage) * * @return array|string */ - protected function get($path, array $parameters = array(), $requestHeaders = array()) + protected function get($path, array $parameters = array(), array $requestHeaders = array()) { if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; @@ -92,7 +92,7 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr * * @return \Psr\Http\Message\ResponseInterface */ - protected function head($path, array $parameters = array(), $requestHeaders = array()) + protected function head($path, array $parameters = array(), array $requestHeaders = array()) { if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { unset($parameters['ref']); @@ -109,8 +109,10 @@ protected function head($path, array $parameters = array(), $requestHeaders = ar * @param string $path Request path. * @param array $parameters POST parameters to be JSON encoded. * @param array $requestHeaders Request headers. + * + * @return array|string */ - protected function post($path, array $parameters = array(), $requestHeaders = array()) + protected function post($path, array $parameters = array(), array $requestHeaders = array()) { return $this->postRaw( $path, @@ -128,7 +130,7 @@ protected function post($path, array $parameters = array(), $requestHeaders = ar * * @return array|string */ - protected function postRaw($path, $body, $requestHeaders = array()) + protected function postRaw($path, $body, array $requestHeaders = array()) { $response = $this->client->getHttpClient()->post( $path, @@ -145,8 +147,10 @@ protected function postRaw($path, $body, $requestHeaders = array()) * @param string $path Request path. * @param array $parameters POST parameters to be JSON encoded. * @param array $requestHeaders Request headers. + * + * @return array|string */ - protected function patch($path, array $parameters = array(), $requestHeaders = array()) + protected function patch($path, array $parameters = array(), array $requestHeaders = array()) { $response = $this->client->getHttpClient()->patch( $path, @@ -163,8 +167,10 @@ protected function patch($path, array $parameters = array(), $requestHeaders = a * @param string $path Request path. * @param array $parameters POST parameters to be JSON encoded. * @param array $requestHeaders Request headers. + * + * @return array|string */ - protected function put($path, array $parameters = array(), $requestHeaders = array()) + protected function put($path, array $parameters = array(), array $requestHeaders = array()) { $response = $this->client->getHttpClient()->put( $path, @@ -181,8 +187,10 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr * @param string $path Request path. * @param array $parameters POST parameters to be JSON encoded. * @param array $requestHeaders Request headers. + * + * @return array|string */ - protected function delete($path, array $parameters = array(), $requestHeaders = array()) + protected function delete($path, array $parameters = array(), array $requestHeaders = array()) { $response = $this->client->getHttpClient()->delete( $path, diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php index 039f3f4c4f6..387a6e68be8 100644 --- a/lib/Github/Api/AcceptHeaderTrait.php +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -11,37 +11,37 @@ trait AcceptHeaderTrait { protected $acceptHeaderValue = null; - protected function get($path, array $parameters = array(), $requestHeaders = array()) + protected function get($path, array $parameters = array(), array $requestHeaders = array()) { return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function head($path, array $parameters = array(), $requestHeaders = array()) + protected function head($path, array $parameters = array(), array $requestHeaders = array()) { return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function post($path, array $parameters = array(), $requestHeaders = array()) + protected function post($path, array $parameters = array(), array $requestHeaders = array()) { return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function postRaw($path, $body, $requestHeaders = array()) + protected function postRaw($path, $body, array $requestHeaders = array()) { return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders)); } - protected function patch($path, array $parameters = array(), $requestHeaders = array()) + protected function patch($path, array $parameters = array(), array $requestHeaders = array()) { return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function put($path, array $parameters = array(), $requestHeaders = array()) + protected function put($path, array $parameters = array(), array $requestHeaders = array()) { return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function delete($path, array $parameters = array(), $requestHeaders = array()) + protected function delete($path, array $parameters = array(), array $requestHeaders = array()) { return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders)); } diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 676f9944bf7..162102ba4f0 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -26,7 +26,7 @@ public function shouldPassGETRequestToClient() $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); - + $api = $this->getAbstractApiObject($client); $this->assertEquals($expectedArray, $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); @@ -229,7 +229,7 @@ class AbstractApiTestInstance extends AbstractApi /** * {@inheritDoc} */ - public function get($path, array $parameters = array(), $requestHeaders = array()) + public function get($path, array $parameters = array(), array $requestHeaders = array()) { return parent::get($path, $parameters, $requestHeaders); } @@ -237,7 +237,7 @@ public function get($path, array $parameters = array(), $requestHeaders = array( /** * {@inheritDoc} */ - public function post($path, array $parameters = array(), $requestHeaders = array()) + public function post($path, array $parameters = array(), array $requestHeaders = array()) { return parent::post($path, $parameters, $requestHeaders); } @@ -245,7 +245,7 @@ public function post($path, array $parameters = array(), $requestHeaders = array /** * {@inheritDoc} */ - public function postRaw($path, $body, $requestHeaders = array()) + public function postRaw($path, $body, array $requestHeaders = array()) { return parent::postRaw($path, $body, $requestHeaders); } @@ -253,7 +253,7 @@ public function postRaw($path, $body, $requestHeaders = array()) /** * {@inheritDoc} */ - public function patch($path, array $parameters = array(), $requestHeaders = array()) + public function patch($path, array $parameters = array(), array $requestHeaders = array()) { return parent::patch($path, $parameters, $requestHeaders); } @@ -261,7 +261,7 @@ public function patch($path, array $parameters = array(), $requestHeaders = arra /** * {@inheritDoc} */ - public function put($path, array $parameters = array(), $requestHeaders = array()) + public function put($path, array $parameters = array(), array $requestHeaders = array()) { return parent::put($path, $parameters, $requestHeaders); } @@ -269,7 +269,7 @@ public function put($path, array $parameters = array(), $requestHeaders = array( /** * {@inheritDoc} */ - public function delete($path, array $parameters = array(), $requestHeaders = array()) + public function delete($path, array $parameters = array(), array $requestHeaders = array()) { return parent::delete($path, $parameters, $requestHeaders); } @@ -283,7 +283,7 @@ class ExposedAbstractApiTestInstance extends AbstractApi /** * {@inheritDoc} */ - public function get($path, array $parameters = array(), $requestHeaders = array()) + public function get($path, array $parameters = array(), array $requestHeaders = array()) { return parent::get($path, $parameters, $requestHeaders); } From dafc9426d8d6cf611bb34291cc50ebfabb623fb0 Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Wed, 19 Oct 2016 00:56:40 +0200 Subject: [PATCH 432/951] added getMethodReflection and remove duplicating reflection parts --- test/Github/Tests/Api/AbstractApiTest.php | 32 ++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 5ddb09b2e95..62455d327d1 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -4,6 +4,7 @@ use Github\Api\AbstractApi; use GuzzleHttp\Psr7\Response; +use ReflectionMethod; class AbstractApiTest extends \PHPUnit_Framework_TestCase { @@ -29,8 +30,7 @@ public function shouldPassGETRequestToClient() $api = $this->getAbstractApiObject($client); - $method = new \ReflectionMethod($api, 'get'); - $method->setAccessible(true); + $method = $this->getMethodReflection($api, 'get'); $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['header1' => 'header1value']])); } @@ -57,8 +57,7 @@ public function shouldPassPOSTRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = new \ReflectionMethod($api, 'post'); - $method->setAccessible(true); + $method = $this->getMethodReflection($api, 'post'); $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } @@ -85,8 +84,7 @@ public function shouldPassPATCHRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = new \ReflectionMethod($api, 'patch'); - $method->setAccessible(true); + $method = $this->getMethodReflection($api, 'patch'); $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } @@ -113,8 +111,7 @@ public function shouldPassPUTRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = new \ReflectionMethod($api, 'put'); - $method->setAccessible(true); + $method = $this->getMethodReflection($api, 'put'); $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } @@ -142,8 +139,7 @@ public function shouldPassDELETERequestToClient() $api = $this->getAbstractApiObject($client); - $method = new \ReflectionMethod($api, 'delete'); - $method->setAccessible(true); + $method = $this->getMethodReflection($api, 'delete'); $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); } @@ -170,8 +166,7 @@ public function shouldNotPassEmptyRefToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = new \ReflectionMethod($api, 'get'); - $method->setAccessible(true); + $method = $this->getMethodReflection($api, 'get'); $this->assertInternalType('array', $method->invokeArgs($api, ['/path', array('ref' => null)])); } @@ -188,6 +183,19 @@ protected function getAbstractApiObject($client) ->getMock(); } + /** + * @param $api + * @param $methodName + * @return ReflectionMethod + */ + public function getMethodReflection($api, $methodName) + { + $method = new ReflectionMethod($api, $methodName); + $method->setAccessible(true); + + return $method; + } + /** * @return \Github\Client */ From 2d72db090c40b11bf15ee5dcd62c4ce7e6c1569c Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Wed, 19 Oct 2016 00:57:14 +0200 Subject: [PATCH 433/951] added getMethodReflection and remove duplicating reflection parts (protected) --- test/Github/Tests/Api/AbstractApiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 62455d327d1..bf68fd976a6 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -188,7 +188,7 @@ protected function getAbstractApiObject($client) * @param $methodName * @return ReflectionMethod */ - public function getMethodReflection($api, $methodName) + protected function getMethodReflection($api, $methodName) { $method = new ReflectionMethod($api, $methodName); $method->setAccessible(true); From 12a614cd9a76171b30e3fe6a9b222daa6f23bb58 Mon Sep 17 00:00:00 2001 From: Mohamed Elkholy Date: Thu, 13 Oct 2016 05:59:21 +0200 Subject: [PATCH 434/951] Improve rate limit exception --- .../Exception/ApiLimitExceedException.php | 20 +++++++++++++++++-- .../Plugin/GithubExceptionThrower.php | 7 ++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index 539243a6837..0283175f19b 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -9,8 +9,24 @@ */ class ApiLimitExceedException extends RuntimeException { - public function __construct($limit = 5000, $code = 0, $previous = null) + private $limit; + private $reset; + + public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = null) + { + $this->limit = (int) $limit; + $this->reset = (int) $reset; + + parent::__construct(sprintf('You have reached GitHub hourly limit! Actual limit is: %d', $limit), $code, $previous); + } + + public function getLimit() + { + return $this->limit; + } + + public function getResetTime() { - parent::__construct('You have reached GitHub hour limit! Actual limit is: '. $limit, $code, $previous); + return $this->reset; } } diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index d3042bc6dc0..cc9581e9c61 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -30,10 +30,11 @@ public function handleRequest(RequestInterface $request, callable $next, callabl // If error: $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); - $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); - if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { - throw new ApiLimitExceedException($limit); + $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); + $reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); + + throw new ApiLimitExceedException($limit, $reset); } if (401 === $response->getStatusCode()) { From 33452067e61c0eec83f3daaa987c8ebe154a51b1 Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Thu, 20 Oct 2016 23:33:02 +0200 Subject: [PATCH 435/951] added `ReflectionMethod` in TestCase --- test/Github/Tests/Api/AbstractApiTest.php | 47 +++++++++++------------ test/Github/Tests/Api/TestCase.php | 18 +++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 898d58f3f40..2228f1392c5 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -4,9 +4,8 @@ use Github\Api\AbstractApi; use GuzzleHttp\Psr7\Response; -use ReflectionMethod; -class AbstractApiTest extends \PHPUnit_Framework_TestCase +class AbstractApiTest extends TestCase { /** * @test @@ -30,9 +29,10 @@ public function shouldPassGETRequestToClient() $api = $this->getAbstractApiObject($client); - $method = $this->getMethodReflection($api, 'get'); + $actual = $this->getMethod($api, 'get') + ->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['header1' => 'header1value']]); - $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['header1' => 'header1value']])); + $this->assertEquals($expectedArray, $actual); } /** @@ -57,9 +57,10 @@ public function shouldPassPOSTRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = $this->getMethodReflection($api, 'post'); + $actual = $this->getMethod($api, 'post') + ->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['option1' => 'option1value']]); - $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); + $this->assertEquals($expectedArray, $actual); } /** @@ -84,9 +85,10 @@ public function shouldPassPATCHRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = $this->getMethodReflection($api, 'patch'); + $actual = $this->getMethod($api, 'patch') + ->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['option1' => 'option1value']]); - $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); + $this->assertEquals($expectedArray, $actual); } /** @@ -111,9 +113,10 @@ public function shouldPassPUTRequestToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = $this->getMethodReflection($api, 'put'); + $actual = $this->getMethod($api, 'put') + ->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['option1' => 'option1value']]); - $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); + $this->assertEquals($expectedArray, $actual); } /** @@ -139,9 +142,10 @@ public function shouldPassDELETERequestToClient() $api = $this->getAbstractApiObject($client); - $method = $this->getMethodReflection($api, 'delete'); + $actual = $this->getMethod($api, 'delete') + ->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['option1' => 'option1value']]); - $this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')])); + $this->assertEquals($expectedArray, $actual); } /** @@ -166,34 +170,29 @@ public function shouldNotPassEmptyRefToClient() ->willReturn($httpClient); $api = $this->getAbstractApiObject($client); - $method = $this->getMethodReflection($api, 'get'); + $actual = $this->getMethod($api, 'get')->invokeArgs($api, ['/path', ['ref' => null]]); - $this->assertInternalType('array', $method->invokeArgs($api, ['/path', array('ref' => null)])); + $this->assertInternalType('array', $actual); } /** * @param $client - * @return AbstractApi + * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getAbstractApiObject($client) { - return $this->getMockBuilder(AbstractApi::class) + return $this->getMockBuilder($this->getApiClass()) ->setMethods(null) ->setConstructorArgs([$client]) ->getMock(); } /** - * @param $api - * @param $methodName - * @return ReflectionMethod + * @return string */ - protected function getMethodReflection($api, $methodName) + protected function getApiClass() { - $method = new ReflectionMethod($api, $methodName); - $method->setAccessible(true); - - return $method; + return AbstractApi::class; } /** diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 5cb69203c8c..7e5fa029b99 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -2,8 +2,13 @@ namespace Github\Tests\Api; +use ReflectionMethod; + abstract class TestCase extends \PHPUnit_Framework_TestCase { + /** + * @return string + */ abstract protected function getApiClass(); /** @@ -25,4 +30,17 @@ protected function getApiMock() ->setConstructorArgs(array($client)) ->getMock(); } + + /** + * @param object $object + * @param string $methodName + * @return ReflectionMethod + */ + protected function getMethod($object, $methodName) + { + $method = new ReflectionMethod($object, $methodName); + $method->setAccessible(true); + + return $method; + } } From 4f44bb3cbaab823fc8bb94ad95bfbccb2f91e2cc Mon Sep 17 00:00:00 2001 From: KoKsPfLaNzE Date: Fri, 21 Oct 2016 00:02:41 +0200 Subject: [PATCH 436/951] added ::class in all tests --- test/Github/Tests/Api/AbstractApiTest.php | 12 ++-- test/Github/Tests/Api/AuthorizationsTest.php | 5 +- .../Tests/Api/CurrentUser/DeployKeysTest.php | 5 +- .../Tests/Api/CurrentUser/EmailsTest.php | 5 +- .../Tests/Api/CurrentUser/FollowersTest.php | 5 +- .../Tests/Api/CurrentUser/MembershipsTest.php | 5 +- .../Tests/Api/CurrentUser/StarringTest.php | 5 +- .../Tests/Api/CurrentUser/WatchersTest.php | 5 +- test/Github/Tests/Api/CurrentUserTest.php | 17 +++-- test/Github/Tests/Api/DeploymentTest.php | 5 +- .../Tests/Api/Enterprise/LicenseTest.php | 5 +- .../Api/Enterprise/ManagementConsoleTest.php | 5 +- .../Github/Tests/Api/Enterprise/StatsTest.php | 5 +- .../Tests/Api/Enterprise/UserAdminTest.php | 5 +- test/Github/Tests/Api/EnterpriseTest.php | 13 ++-- test/Github/Tests/Api/Gist/CommentsTest.php | 5 +- test/Github/Tests/Api/GistsTest.php | 7 +- test/Github/Tests/Api/GitData/BlobsTest.php | 5 +- test/Github/Tests/Api/GitData/CommitsTest.php | 5 +- .../Tests/Api/GitData/ReferencesTest.php | 5 +- test/Github/Tests/Api/GitData/TagsTest.php | 5 +- test/Github/Tests/Api/GitData/TreesTest.php | 5 +- test/Github/Tests/Api/GitDataTest.php | 15 ++-- test/Github/Tests/Api/Issue/CommentsTest.php | 5 +- test/Github/Tests/Api/Issue/EventsTest.php | 5 +- test/Github/Tests/Api/Issue/LabelsTest.php | 5 +- .../Github/Tests/Api/Issue/MilestonesTest.php | 5 +- test/Github/Tests/Api/IssueTest.php | 13 ++-- test/Github/Tests/Api/MarkdownTest.php | 5 +- test/Github/Tests/Api/MetaTest.php | 5 +- test/Github/Tests/Api/NotificationTest.php | 5 +- .../Tests/Api/Organization/HooksTest.php | 5 +- .../Tests/Api/Organization/MembersTest.php | 5 +- .../Tests/Api/Organization/TeamsTest.php | 5 +- test/Github/Tests/Api/OrganizationTest.php | 9 ++- test/Github/Tests/Api/PullRequestTest.php | 7 +- test/Github/Tests/Api/RateLimitTest.php | 5 +- test/Github/Tests/Api/RepoTest.php | 29 ++++---- .../Tests/Api/Repository/AssetsTest.php | 5 +- .../Github/Tests/Api/Repository/CardsTest.php | 5 +- .../Api/Repository/CollaboratorsTest.php | 5 +- .../Tests/Api/Repository/ColumnsTest.php | 5 +- .../Tests/Api/Repository/CommentsTest.php | 5 +- .../Tests/Api/Repository/CommitsTest.php | 5 +- .../Tests/Api/Repository/ContentsTest.php | 5 +- .../Tests/Api/Repository/DeployKeysTest.php | 5 +- .../Tests/Api/Repository/DownloadsTest.php | 5 +- .../Github/Tests/Api/Repository/ForksTest.php | 5 +- .../Github/Tests/Api/Repository/HooksTest.php | 5 +- .../Tests/Api/Repository/LabelsTest.php | 5 +- .../Tests/Api/Repository/ProjectsTest.php | 5 +- .../Tests/Api/Repository/ReleasesTest.php | 5 +- .../Tests/Api/Repository/StargazersTest.php | 5 +- .../Tests/Api/Repository/StatusesTest.php | 5 +- test/Github/Tests/Api/SearchTest.php | 5 +- test/Github/Tests/Api/UserTest.php | 5 +- test/Github/Tests/ClientTest.php | 71 ++++++++++--------- test/Github/Tests/ResultPagerTest.php | 8 +-- 58 files changed, 301 insertions(+), 135 deletions(-) diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 898d58f3f40..9d2c2f13922 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -21,7 +21,7 @@ public function shouldPassGETRequestToClient() ->method('get') ->with('/path?param1=param1value', array('header1' => 'header1value')) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('getHttpClient')) ->getMock(); $client->expects($this->any()) @@ -49,7 +49,7 @@ public function shouldPassPOSTRequestToClient() ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('getHttpClient')) ->getMock(); $client->expects($this->any()) @@ -76,7 +76,7 @@ public function shouldPassPATCHRequestToClient() ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('getHttpClient')) ->getMock(); $client->expects($this->any()) @@ -158,7 +158,7 @@ public function shouldNotPassEmptyRefToClient() ->with('/path', array()) ->will($this->returnValue($this->getPSR7Response($expectedArray))); - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('getHttpClient')) ->getMock(); $client->expects($this->any()) @@ -213,7 +213,7 @@ protected function getClientMock() protected function getHttpMethodsMock(array $methods = array()) { $methods = array_merge(array('sendRequest'), $methods); - $mock = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient') + $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) ->disableOriginalConstructor() ->setMethods($methods) ->getMock(); @@ -228,7 +228,7 @@ protected function getHttpMethodsMock(array $methods = array()) */ protected function getHttpClientMock() { - $mock = $this->getMockBuilder('Http\Client\HttpClient') + $mock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->setMethods(array('sendRequest')) ->getMock(); $mock diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php index d0570c79956..62ca0222c0c 100644 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -151,8 +151,11 @@ public function shouldRevokeAllAuthorizations() $api->revokeAll($id); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Authorizations'; + return \Github\Api\Authorizations::class; } } diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index f72d9405736..edbd58991f9 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -146,8 +146,11 @@ public function shouldRemoveKey() $this->assertEquals($expectedValue, $api->remove(123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser\DeployKeys'; + return \Github\Api\CurrentUser\DeployKeys::class; } } diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index af8e90490da..cba52d12be3 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -110,8 +110,11 @@ public function shouldNotAddEmailsWhenAreNotPass() $api->add(array()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser\Emails'; + return \Github\Api\CurrentUser\Emails::class; } } diff --git a/test/Github/Tests/Api/CurrentUser/FollowersTest.php b/test/Github/Tests/Api/CurrentUser/FollowersTest.php index 4d1b1215634..6ea021f201f 100644 --- a/test/Github/Tests/Api/CurrentUser/FollowersTest.php +++ b/test/Github/Tests/Api/CurrentUser/FollowersTest.php @@ -65,8 +65,11 @@ public function shouldUnfollowUser() $this->assertNull($api->unfollow('l3l0')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser\Followers'; + return \Github\Api\CurrentUser\Followers::class; } } diff --git a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php index ef9f5c4d40c..60edaa07e16 100644 --- a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php +++ b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php @@ -84,8 +84,11 @@ public function shouldEditMembershipsForOrganization() $this->assertEquals($expectedValue, $api->edit('invitocat')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser\Memberships'; + return \Github\Api\CurrentUser\Memberships::class; } } diff --git a/test/Github/Tests/Api/CurrentUser/StarringTest.php b/test/Github/Tests/Api/CurrentUser/StarringTest.php index 51242409c88..3cf8b7dae02 100644 --- a/test/Github/Tests/Api/CurrentUser/StarringTest.php +++ b/test/Github/Tests/Api/CurrentUser/StarringTest.php @@ -65,8 +65,11 @@ public function shouldUnstarUser() $this->assertNull($api->unstar('l3l0', 'test')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser\Starring'; + return \Github\Api\CurrentUser\Starring::class; } } diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index 487cafad456..79f8c9fee83 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -65,8 +65,11 @@ public function shouldUnwatchUser() $this->assertNull($api->unwatch('l3l0', 'test')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser\Watchers'; + return \Github\Api\CurrentUser\Watchers::class; } } diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index cb447ff1b9c..c062494179f 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -91,7 +91,7 @@ public function shouldGetDeployKeysApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\DeployKeys', $api->keys()); + $this->assertInstanceOf(\Github\Api\CurrentUser\DeployKeys::class, $api->keys()); } /** @@ -101,7 +101,7 @@ public function shouldGetEmailsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Emails', $api->emails()); + $this->assertInstanceOf(\Github\Api\CurrentUser\Emails::class, $api->emails()); } /** @@ -111,7 +111,7 @@ public function shouldGetFollowersApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Followers', $api->follow()); + $this->assertInstanceOf(\Github\Api\CurrentUser\Followers::class, $api->follow()); } /** @@ -121,7 +121,7 @@ public function shouldGetNotificationsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Notifications', $api->notifications()); + $this->assertInstanceOf(\Github\Api\CurrentUser\Notifications::class, $api->notifications()); } /** @@ -131,7 +131,7 @@ public function shouldGetWatchersApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Watchers', $api->watchers()); + $this->assertInstanceOf(\Github\Api\CurrentUser\Watchers::class, $api->watchers()); } /** @@ -141,11 +141,14 @@ public function shouldGetStarredApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Starring', $api->starring()); + $this->assertInstanceOf(\Github\Api\CurrentUser\Starring::class, $api->starring()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\CurrentUser'; + return \Github\Api\CurrentUser::class; } } diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 996afcdc8be..af21652cf97 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -86,8 +86,11 @@ public function shouldGetAllStatuses() $api->getStatuses('KnpLabs', 'php-github-api', 1); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Deployment'; + return \Github\Api\Deployment::class; } } diff --git a/test/Github/Tests/Api/Enterprise/LicenseTest.php b/test/Github/Tests/Api/Enterprise/LicenseTest.php index 170e478b029..798a362752f 100644 --- a/test/Github/Tests/Api/Enterprise/LicenseTest.php +++ b/test/Github/Tests/Api/Enterprise/LicenseTest.php @@ -29,8 +29,11 @@ public function shouldShowLicenseInformation() $this->assertEquals($expectedArray, $api->show()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Enterprise\License'; + return \Github\Api\Enterprise\License::class; } } diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php index 60755693f82..df1b64ce743 100644 --- a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -107,8 +107,11 @@ protected function getLicenseHash() return '1234567890abcdefghijklmnopqrstuv'; } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Enterprise\ManagementConsole'; + return \Github\Api\Enterprise\ManagementConsole::class; } } diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 18c04799290..fe902257e17 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -83,8 +83,11 @@ protected function getStatsData($key = '') } } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Enterprise\Stats'; + return \Github\Api\Enterprise\Stats::class; } } diff --git a/test/Github/Tests/Api/Enterprise/UserAdminTest.php b/test/Github/Tests/Api/Enterprise/UserAdminTest.php index ea6f3fc615f..d9eddf8aa08 100644 --- a/test/Github/Tests/Api/Enterprise/UserAdminTest.php +++ b/test/Github/Tests/Api/Enterprise/UserAdminTest.php @@ -36,8 +36,11 @@ public function shouldUnsuspendUser() $this->assertEquals($expectedArray, $api->unsuspend('l3l0')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Enterprise\UserAdmin'; + return \Github\Api\Enterprise\UserAdmin::class; } } diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php index 319e6e16232..eb69b8e05d0 100644 --- a/test/Github/Tests/Api/EnterpriseTest.php +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -11,7 +11,7 @@ public function shouldGetEntepriseStatsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Enterprise\Stats', $api->stats()); + $this->assertInstanceOf(\Github\Api\Enterprise\Stats::class, $api->stats()); } /** @@ -21,7 +21,7 @@ public function shouldGetEnterpriseLicenseApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Enterprise\License', $api->license()); + $this->assertInstanceOf(\Github\Api\Enterprise\License::class, $api->license()); } /** @@ -31,7 +31,7 @@ public function shouldGetEnterpriseManagementConsoleApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console()); + $this->assertInstanceOf(\Github\Api\Enterprise\ManagementConsole::class, $api->console()); } /** @@ -41,11 +41,14 @@ public function shouldGetEnterpriseUserAdminApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Enterprise\UserAdmin', $api->userAdmin()); + $this->assertInstanceOf(\Github\Api\Enterprise\UserAdmin::class, $api->userAdmin()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Enterprise'; + return \Github\Api\Enterprise::class; } } diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index 22895e554f0..3a7fe8febd5 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -87,8 +87,11 @@ public function shouldRemoveComment() $this->assertEquals($expectedValue, $api->remove(123, 233)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Gist\Comments'; + return \Github\Api\Gist\Comments::class; } } diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index f1a2d0c4134..2a7a6464bbb 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -75,7 +75,7 @@ public function shouldGetCommentsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Gist\Comments', $api->comments()); + $this->assertInstanceOf(\Github\Api\Gist\Comments::class, $api->comments()); } /** @@ -238,8 +238,11 @@ public function shouldDeleteGist() $api->remove(5); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Gists'; + return \Github\Api\Gists::class; } } diff --git a/test/Github/Tests/Api/GitData/BlobsTest.php b/test/Github/Tests/Api/GitData/BlobsTest.php index 25451a2efbb..4c96ba303a5 100644 --- a/test/Github/Tests/Api/GitData/BlobsTest.php +++ b/test/Github/Tests/Api/GitData/BlobsTest.php @@ -95,8 +95,11 @@ public function shouldNotCreateBlobWithoutContent() $api->create('l3l0', 'l3l0repo', $data); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\GitData\Blobs'; + return \Github\Api\GitData\Blobs::class; } } diff --git a/test/Github/Tests/Api/GitData/CommitsTest.php b/test/Github/Tests/Api/GitData/CommitsTest.php index 9c881805bcb..964956439cf 100644 --- a/test/Github/Tests/Api/GitData/CommitsTest.php +++ b/test/Github/Tests/Api/GitData/CommitsTest.php @@ -82,8 +82,11 @@ public function shouldNotCreateCommitWithoutParentsParam() $api->create('KnpLabs', 'php-github-api', $data); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\GitData\Commits'; + return \Github\Api\GitData\Commits::class; } } diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 600d7c42f30..2c094492f2a 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -179,8 +179,11 @@ public function shouldNoUpdateReferenceWithoutSha() $api->update('l3l0', 'l3l0repo', 'someRefs', $data); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\GitData\References'; + return \Github\Api\GitData\References::class; } } diff --git a/test/Github/Tests/Api/GitData/TagsTest.php b/test/Github/Tests/Api/GitData/TagsTest.php index 80920fca840..8b109d0b9be 100644 --- a/test/Github/Tests/Api/GitData/TagsTest.php +++ b/test/Github/Tests/Api/GitData/TagsTest.php @@ -251,8 +251,11 @@ public function shouldNotCreateTagWithoutTypeParam() $api->create('KnpLabs', 'php-github-api', $data); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\GitData\Tags'; + return \Github\Api\GitData\Tags::class; } } diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index 2333744f987..bd8db13f688 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -200,8 +200,11 @@ public function shouldNotCreateTreeWhenTreeParamIsNotArray() $api->create('KnpLabs', 'php-github-api', $data); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\GitData\Trees'; + return \Github\Api\GitData\Trees::class; } } diff --git a/test/Github/Tests/Api/GitDataTest.php b/test/Github/Tests/Api/GitDataTest.php index cdbfcc6571e..4c25936b994 100644 --- a/test/Github/Tests/Api/GitDataTest.php +++ b/test/Github/Tests/Api/GitDataTest.php @@ -11,7 +11,7 @@ public function shouldGetBlobsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\GitData\Blobs', $api->blobs()); + $this->assertInstanceOf(\Github\Api\GitData\Blobs::class, $api->blobs()); } /** @@ -21,7 +21,7 @@ public function shouldGetCommitsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\GitData\Commits', $api->commits()); + $this->assertInstanceOf(\Github\Api\GitData\Commits::class, $api->commits()); } /** @@ -31,7 +31,7 @@ public function shouldGetReferencesApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\GitData\References', $api->references()); + $this->assertInstanceOf(\Github\Api\GitData\References::class, $api->references()); } /** @@ -41,7 +41,7 @@ public function shouldGetTagsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\GitData\Tags', $api->tags()); + $this->assertInstanceOf(\Github\Api\GitData\Tags::class, $api->tags()); } /** @@ -51,11 +51,14 @@ public function shouldGetTreesApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\GitData\Trees', $api->trees()); + $this->assertInstanceOf(\Github\Api\GitData\Trees::class, $api->trees()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\GitData'; + return \Github\Api\GitData::class; } } diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 128e4401637..daa7207c37f 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -118,8 +118,11 @@ public function shouldRemoveComment() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Issue\Comments'; + return \Github\Api\Issue\Comments::class; } } diff --git a/test/Github/Tests/Api/Issue/EventsTest.php b/test/Github/Tests/Api/Issue/EventsTest.php index 5168bfd90ba..6e965c5ff22 100644 --- a/test/Github/Tests/Api/Issue/EventsTest.php +++ b/test/Github/Tests/Api/Issue/EventsTest.php @@ -54,8 +54,11 @@ public function shouldShowIssueEvent() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Issue\Events'; + return \Github\Api\Issue\Events::class; } } diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index 24c0bdfead5..e6be19d27c3 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -202,8 +202,11 @@ public function shouldClearLabels() $this->assertEquals($expectedValue, $api->clear('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Issue\Labels'; + return \Github\Api\Issue\Labels::class; } } diff --git a/test/Github/Tests/Api/Issue/MilestonesTest.php b/test/Github/Tests/Api/Issue/MilestonesTest.php index e9c0b3dde21..363a47fb546 100644 --- a/test/Github/Tests/Api/Issue/MilestonesTest.php +++ b/test/Github/Tests/Api/Issue/MilestonesTest.php @@ -218,8 +218,11 @@ public function shouldGetMilestoneLabels() $this->assertEquals($expectedValue, $api->labels('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Issue\Milestones'; + return \Github\Api\Issue\Milestones::class; } } diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index b20efbf9233..242a650a3e7 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -209,7 +209,7 @@ public function shouldGetCommentsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Issue\Comments', $api->comments()); + $this->assertInstanceOf(\Github\Api\Issue\Comments::class, $api->comments()); } /** @@ -219,7 +219,7 @@ public function shouldGetEventsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Issue\Events', $api->events()); + $this->assertInstanceOf(\Github\Api\Issue\Events::class, $api->events()); } /** @@ -229,7 +229,7 @@ public function shouldGetLabelsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Issue\Labels', $api->labels()); + $this->assertInstanceOf(\Github\Api\Issue\Labels::class, $api->labels()); } /** @@ -239,11 +239,14 @@ public function shouldGetMilestonesApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Issue\Milestones', $api->milestones()); + $this->assertInstanceOf(\Github\Api\Issue\Milestones::class, $api->milestones()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Issue'; + return \Github\Api\Issue::class; } } diff --git a/test/Github/Tests/Api/MarkdownTest.php b/test/Github/Tests/Api/MarkdownTest.php index 9bd91651e23..296a2778575 100644 --- a/test/Github/Tests/Api/MarkdownTest.php +++ b/test/Github/Tests/Api/MarkdownTest.php @@ -85,8 +85,11 @@ public function shouldRenderRawFile() $api->renderRaw($file); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Markdown'; + return \Github\Api\Markdown::class; } } diff --git a/test/Github/Tests/Api/MetaTest.php b/test/Github/Tests/Api/MetaTest.php index f2f8374f314..57e2cac8bac 100644 --- a/test/Github/Tests/Api/MetaTest.php +++ b/test/Github/Tests/Api/MetaTest.php @@ -27,8 +27,11 @@ public function shouldGetInformationService() $this->assertEquals($expectedArray, $api->service()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Meta'; + return \Github\Api\Meta::class; } } diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index 35fc09a188c..70cec8e31c9 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -97,8 +97,11 @@ public function shouldMarkNotificationsAsReadForGivenDate() $api->markRead($since); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Notification'; + return \Github\Api\Notification::class; } } diff --git a/test/Github/Tests/Api/Organization/HooksTest.php b/test/Github/Tests/Api/Organization/HooksTest.php index 113c7bb2433..f61b4b54302 100644 --- a/test/Github/Tests/Api/Organization/HooksTest.php +++ b/test/Github/Tests/Api/Organization/HooksTest.php @@ -149,8 +149,11 @@ public function shouldPingHook() $this->assertEquals($expectedValue, $api->ping('KnpLabs', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Organization\Hooks'; + return \Github\Api\Organization\Hooks::class; } } diff --git a/test/Github/Tests/Api/Organization/MembersTest.php b/test/Github/Tests/Api/Organization/MembersTest.php index f25b74b47f3..19f072e14ef 100644 --- a/test/Github/Tests/Api/Organization/MembersTest.php +++ b/test/Github/Tests/Api/Organization/MembersTest.php @@ -134,8 +134,11 @@ public function shouldShowOrganizationMember() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'l3l0')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Organization\Members'; + return \Github\Api\Organization\Members::class; } } diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index fa21be45dc7..44cb781c8ce 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -297,8 +297,11 @@ public function shouldUpdateWithPullPermissionWhenPermissionParamNotRecognized() $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Organization\Teams'; + return \Github\Api\Organization\Teams::class; } } diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index ca70ffbb232..3d3aaee998c 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -75,7 +75,7 @@ public function shouldGetMembersApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Organization\Members', $api->members()); + $this->assertInstanceOf(\Github\Api\Organization\Members::class, $api->members()); } /** @@ -85,11 +85,14 @@ public function shouldGetTeamsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Organization\Teams', $api->teams()); + $this->assertInstanceOf(\Github\Api\Organization\Teams::class, $api->teams()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Organization'; + return \Github\Api\Organization::class; } } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 6e0f562765f..975c131aebf 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -270,11 +270,14 @@ public function shouldGetCommentsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\PullRequest\Comments', $api->comments()); + $this->assertInstanceOf(\Github\Api\PullRequest\Comments::class, $api->comments()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\PullRequest'; + return \Github\Api\PullRequest::class; } } diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index 382e0411792..dbbc1d7e722 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -33,8 +33,11 @@ public function shouldReturnRateLimitArray() $this->assertEquals($expectedArray, $api->getRateLimits()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\RateLimit'; + return \Github\Api\RateLimit::class; } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 6ef8af7b375..cc2e9c8e52c 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -372,7 +372,7 @@ public function shouldGetCollaboratorsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Collaborators', $api->collaborators()); + $this->assertInstanceOf(\Github\Api\Repository\Collaborators::class, $api->collaborators()); } /** @@ -382,7 +382,7 @@ public function shouldGetCommentsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Comments', $api->comments()); + $this->assertInstanceOf(\Github\Api\Repository\Comments::class, $api->comments()); } /** @@ -392,7 +392,7 @@ public function shouldGetCommitsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Commits', $api->commits()); + $this->assertInstanceOf(\Github\Api\Repository\Commits::class, $api->commits()); } /** @@ -402,7 +402,7 @@ public function shouldGetContentsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Contents', $api->contents()); + $this->assertInstanceOf(\Github\Api\Repository\Contents::class, $api->contents()); } /** @@ -412,7 +412,7 @@ public function shouldGetDeployKeysApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\DeployKeys', $api->keys()); + $this->assertInstanceOf(\Github\Api\Repository\DeployKeys::class, $api->keys()); } /** @@ -422,7 +422,7 @@ public function shouldGetDownloadsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Downloads', $api->downloads()); + $this->assertInstanceOf(\Github\Api\Repository\Downloads::class, $api->downloads()); } /** @@ -432,7 +432,7 @@ public function shouldGetForksApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Forks', $api->forks()); + $this->assertInstanceOf(\Github\Api\Repository\Forks::class, $api->forks()); } /** @@ -442,7 +442,7 @@ public function shouldGetHooksApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Hooks', $api->hooks()); + $this->assertInstanceOf(\Github\Api\Repository\Hooks::class, $api->hooks()); } /** @@ -452,7 +452,7 @@ public function shouldGetLabelsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Labels', $api->labels()); + $this->assertInstanceOf(\Github\Api\Repository\Labels::class, $api->labels()); } /** @@ -462,7 +462,7 @@ public function shouldGetStatusesApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Statuses', $api->statuses()); + $this->assertInstanceOf(\Github\Api\Repository\Statuses::class, $api->statuses()); } /** @@ -472,7 +472,7 @@ public function shouldGetStargazersApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Stargazers', $api->stargazers()); + $this->assertInstanceOf(\Github\Api\Repository\Stargazers::class, $api->stargazers()); } /** @@ -482,7 +482,7 @@ public function shouldGetReleasesApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases()); + $this->assertInstanceOf(\Github\Api\Repository\Releases::class, $api->releases()); } /** @@ -501,8 +501,11 @@ public function shouldGetCommitActivity() $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repo'; + return \Github\Api\Repo::class; } } diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 67c6213b4ce..353a3431640 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -117,8 +117,11 @@ public function shouldRemoveReleaseAsset() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $assetId)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Assets'; + return \Github\Api\Repository\Assets::class; } } diff --git a/test/Github/Tests/Api/Repository/CardsTest.php b/test/Github/Tests/Api/Repository/CardsTest.php index 407e4f5bab0..d4795b802f1 100644 --- a/test/Github/Tests/Api/Repository/CardsTest.php +++ b/test/Github/Tests/Api/Repository/CardsTest.php @@ -120,8 +120,11 @@ public function shouldMoveCard() $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Cards'; + return \Github\Api\Repository\Cards::class; } } diff --git a/test/Github/Tests/Api/Repository/CollaboratorsTest.php b/test/Github/Tests/Api/Repository/CollaboratorsTest.php index 0eb75818277..cbbacd1a94e 100644 --- a/test/Github/Tests/Api/Repository/CollaboratorsTest.php +++ b/test/Github/Tests/Api/Repository/CollaboratorsTest.php @@ -70,8 +70,11 @@ public function shouldRemoveRepositoryCollaborator() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Collaborators'; + return \Github\Api\Repository\Collaborators::class; } } diff --git a/test/Github/Tests/Api/Repository/ColumnsTest.php b/test/Github/Tests/Api/Repository/ColumnsTest.php index 95a14fd545b..b12c0706cf2 100644 --- a/test/Github/Tests/Api/Repository/ColumnsTest.php +++ b/test/Github/Tests/Api/Repository/ColumnsTest.php @@ -160,8 +160,11 @@ public function shouldGetCardsApiObject() $this->assertInstanceOf('Github\Api\Repository\Cards', $api->cards()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Columns'; + return \Github\Api\Repository\Columns::class; } } diff --git a/test/Github/Tests/Api/Repository/CommentsTest.php b/test/Github/Tests/Api/Repository/CommentsTest.php index 6fea4a62a70..0924dbb1606 100644 --- a/test/Github/Tests/Api/Repository/CommentsTest.php +++ b/test/Github/Tests/Api/Repository/CommentsTest.php @@ -149,8 +149,11 @@ public function shouldRemoveComment() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Comments'; + return \Github\Api\Repository\Comments::class; } } diff --git a/test/Github/Tests/Api/Repository/CommitsTest.php b/test/Github/Tests/Api/Repository/CommitsTest.php index 395ee1ac259..727b39f4a18 100644 --- a/test/Github/Tests/Api/Repository/CommitsTest.php +++ b/test/Github/Tests/Api/Repository/CommitsTest.php @@ -55,8 +55,11 @@ public function shouldShowCommitUsingSha() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Commits'; + return \Github\Api\Repository\Commits::class; } } diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 5be3b227ba6..e14b3785b46 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -318,8 +318,11 @@ public function shouldDownloadForSpacedPath() $this->assertEquals($expectedValue, $api->download('mads379', 'scala.tmbundle', 'Syntaxes/Simple Build Tool.tmLanguage')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Contents'; + return \Github\Api\Repository\Contents::class; } } diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index 535ede4e5ab..557d259f483 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -148,8 +148,11 @@ public function shouldUpdateDeployKey() $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\DeployKeys'; + return \Github\Api\Repository\DeployKeys::class; } } diff --git a/test/Github/Tests/Api/Repository/DownloadsTest.php b/test/Github/Tests/Api/Repository/DownloadsTest.php index ad7897cc8f7..33fe2b4b277 100644 --- a/test/Github/Tests/Api/Repository/DownloadsTest.php +++ b/test/Github/Tests/Api/Repository/DownloadsTest.php @@ -54,8 +54,11 @@ public function shouldRemoveRepositoryDownload() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Downloads'; + return \Github\Api\Repository\Downloads::class; } } diff --git a/test/Github/Tests/Api/Repository/ForksTest.php b/test/Github/Tests/Api/Repository/ForksTest.php index 12530a98647..36912fd93df 100644 --- a/test/Github/Tests/Api/Repository/ForksTest.php +++ b/test/Github/Tests/Api/Repository/ForksTest.php @@ -55,8 +55,11 @@ public function shouldSortByNewestWhenSortParamNotRecognized() $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('sort' => 'oldes'))); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Forks'; + return \Github\Api\Repository\Forks::class; } } diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index dbca3c062e4..6b5447d762e 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -149,8 +149,11 @@ public function shouldTestHook() $this->assertEquals($expectedValue, $api->test('KnpLabs', 'php-github-api', 123)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Hooks'; + return \Github\Api\Repository\Hooks::class; } } diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index 7e81cea8188..b7be0312b66 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -148,8 +148,11 @@ public function shouldUpdateLabel() $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'labelName', $data)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Labels'; + return \Github\Api\Repository\Labels::class; } } diff --git a/test/Github/Tests/Api/Repository/ProjectsTest.php b/test/Github/Tests/Api/Repository/ProjectsTest.php index 5713fbfda5a..d82b7bbe4dd 100644 --- a/test/Github/Tests/Api/Repository/ProjectsTest.php +++ b/test/Github/Tests/Api/Repository/ProjectsTest.php @@ -113,8 +113,11 @@ public function shouldGetColumnsApiObject() $this->assertInstanceOf('Github\Api\Repository\Columns', $api->columns()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Projects'; + return \Github\Api\Repository\Projects::class; } } diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index a05d0bdc422..64b164cb237 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -152,8 +152,11 @@ public function shouldGetAssetsApiObject() $this->assertInstanceOf('Github\Api\Repository\Assets', $api->assets()); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Releases'; + return \Github\Api\Repository\Releases::class; } } diff --git a/test/Github/Tests/Api/Repository/StargazersTest.php b/test/Github/Tests/Api/Repository/StargazersTest.php index 142ce8ba6c7..ef5e5d6d5f8 100644 --- a/test/Github/Tests/Api/Repository/StargazersTest.php +++ b/test/Github/Tests/Api/Repository/StargazersTest.php @@ -39,8 +39,11 @@ public function shouldGetAllRepositoryStargazersWithAlternativeResponse() $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Stargazers'; + return \Github\Api\Repository\Stargazers::class; } } diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php index 55d96af0bf1..9b64708d452 100644 --- a/test/Github/Tests/Api/Repository/StatusesTest.php +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -87,8 +87,11 @@ public function shouldCreateCommitStatus() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data)); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Repository\Statuses'; + return \Github\Api\Repository\Statuses::class; } } diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index d5fe9b08494..69ec3e032eb 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -176,8 +176,11 @@ public function shouldSearchUsersRegardingSortAndOrder() ); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\Search'; + return \Github\Api\Search::class; } } diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 6f4f4e9fc00..711c50ecba6 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -161,8 +161,11 @@ public function shouldGetUserGists() $this->assertEquals($expectedArray, $api->gists('l3l0')); } + /** + * @return string + */ protected function getApiClass() { - return 'Github\Api\User'; + return \Github\Api\User::class; } } diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index a719e2f3254..0450c0f8882 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -2,6 +2,7 @@ namespace Github\Tests; +use Github\Api; use Github\Client; use Github\Exception\BadMethodCallException; use Github\HttpClient\Plugin\Authentication; @@ -16,7 +17,7 @@ public function shouldNotHaveToPassHttpClientToConstructor() { $client = new Client(); - $this->assertInstanceOf('\Http\Client\HttpClient', $client->getHttpClient()); + $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); } /** @@ -24,11 +25,11 @@ public function shouldNotHaveToPassHttpClientToConstructor() */ public function shouldPassHttpClientInterfaceToConstructor() { - $httpClientMock = $this->getMockBuilder('Http\Client\HttpClient') + $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->getMock(); $client = new Client($httpClientMock); - $this->assertInstanceOf('Http\Client\HttpClient', $client->getHttpClient()); + $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); } /** @@ -37,7 +38,7 @@ public function shouldPassHttpClientInterfaceToConstructor() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('addPlugin', 'removePlugin')) ->getMock(); $client->expects($this->once()) @@ -67,7 +68,7 @@ public function getAuthenticationFullData() */ public function shouldAuthenticateUsingGivenParameters($token, $method) { - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('addPlugin', 'removePlugin')) ->getMock(); $client->expects($this->once()) @@ -105,7 +106,7 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet() */ public function shouldClearHeaders() { - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('addPlugin', 'removePlugin')) ->getMock(); $client->expects($this->once()) @@ -126,7 +127,7 @@ public function shouldAddHeaders() { $headers = array('header1', 'header2'); - $client = $this->getMockBuilder('Github\Client') + $client = $this->getMockBuilder(\Github\Client::class) ->setMethods(array('addPlugin', 'removePlugin')) ->getMock(); $client->expects($this->once()) @@ -186,45 +187,45 @@ public function shouldNotGetMagicApiInstance() public function getApiClassesProvider() { return array( - array('user', 'Github\Api\User'), - array('users', 'Github\Api\User'), + array('user', Api\User::class), + array('users', Api\User::class), - array('me', 'Github\Api\CurrentUser'), - array('current_user', 'Github\Api\CurrentUser'), - array('currentUser', 'Github\Api\CurrentUser'), + array('me', Api\CurrentUser::class), + array('current_user', Api\CurrentUser::class), + array('currentUser', Api\CurrentUser::class), - array('git', 'Github\Api\GitData'), - array('git_data', 'Github\Api\GitData'), - array('gitData', 'Github\Api\GitData'), + array('git', Api\GitData::class), + array('git_data', Api\GitData::class), + array('gitData', Api\GitData::class), - array('gist', 'Github\Api\Gists'), - array('gists', 'Github\Api\Gists'), + array('gist', Api\Gists::class), + array('gists', Api\Gists::class), - array('issue', 'Github\Api\Issue'), - array('issues', 'Github\Api\Issue'), + array('issue', Api\Issue::class), + array('issues', Api\Issue::class), - array('markdown', 'Github\Api\Markdown'), + array('markdown', Api\Markdown::class), - array('organization', 'Github\Api\Organization'), - array('organizations', 'Github\Api\Organization'), + array('organization', Api\Organization::class), + array('organizations', Api\Organization::class), - array('repo', 'Github\Api\Repo'), - array('repos', 'Github\Api\Repo'), - array('repository', 'Github\Api\Repo'), - array('repositories', 'Github\Api\Repo'), + array('repo', Api\Repo::class), + array('repos', Api\Repo::class), + array('repository', Api\Repo::class), + array('repositories', Api\Repo::class), - array('search', 'Github\Api\Search'), + array('search', Api\Search::class), - array('pr', 'Github\Api\PullRequest'), - array('pullRequest', 'Github\Api\PullRequest'), - array('pull_request', 'Github\Api\PullRequest'), - array('pullRequests', 'Github\Api\PullRequest'), - array('pull_requests', 'Github\Api\PullRequest'), + array('pr', Api\PullRequest::class), + array('pullRequest', Api\PullRequest::class), + array('pull_request', Api\PullRequest::class), + array('pullRequests', Api\PullRequest::class), + array('pull_requests', Api\PullRequest::class), - array('authorization', 'Github\Api\Authorizations'), - array('authorizations', 'Github\Api\Authorizations'), + array('authorization', Api\Authorizations::class), + array('authorizations', Api\Authorizations::class), - array('meta', 'Github\Api\Meta') + array('meta', Api\Meta::class) ); } } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index f758adb1a25..19224b5e4ef 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -31,7 +31,7 @@ public function shouldGetAllResults() $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getMockBuilder('Http\Client\HttpClient') + $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->setMethods(array('sendRequest')) ->getMock(); $httpClientMock @@ -78,7 +78,7 @@ public function shouldGetAllSearchResults() $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getMockBuilder('Http\Client\HttpClient') + $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->setMethods(array('sendRequest')) ->getMock(); $httpClientMock @@ -101,10 +101,10 @@ public function testFetch() $result = 'foo'; $method = 'bar'; $parameters = array('baz'); - $api = $this->getMockBuilder('Github\Api\ApiInterface') + $api = $this->getMockBuilder(\Github\Api\ApiInterface::class) ->getMock(); - $paginator = $this->getMockBuilder('Github\ResultPager') + $paginator = $this->getMockBuilder(\Github\ResultPager::class) ->disableOriginalConstructor() ->setMethods(array('callApi', 'postFetch')) ->getMock(); From 1cf494020a53d411a77384f0e63cac6c99248505 Mon Sep 17 00:00:00 2001 From: Martins Sipenko Date: Fri, 21 Oct 2016 14:03:00 +0300 Subject: [PATCH 437/951] Fix params not being passed through --- lib/Github/Api/Organization/Teams.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index b4aa52ecfe3..47208c6d0de 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -89,7 +89,7 @@ public function addRepository($team, $username, $repository, $params = array()) $params['permission'] = 'pull'; } - return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository), $params); } public function removeRepository($team, $username, $repository) From 73c647f65adb63b884216ecca57dc1698d2e09d8 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 25 Oct 2016 19:17:04 +0200 Subject: [PATCH 438/951] Added changelog --- CHANGELOG.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000000..49e6cee0644 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,52 @@ +# Change Log + +The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. + + +## 2.0.0-rc5 (UNRELEASED) + +### Added + +- Support for JWT authentication +- API for Organization\Members +- API for Integrations +- API for Repo\Cards +- API for Repo\Columns +- API for Repo\Projects +- Methods in Repo API for frequency and participation + +### Changed + +- `ApiLimitExceedException::__construct` has a new second parameter for the remaining API calls. + +## 2.0.0-rc4 + +### Added + +- HTTPlug to decouple from Guzzle +- `Github\Client::getLastResponse` was added +- Support for PSR-6 cache +- `Github\Client::addPlugin` and `Github\Client::removePlugin` +- `Github\Client::getApiVersion` +- `Github\Client::removeCache` + +### Changed + +- Uses of `Github\HttpClient\HttpClientInterface` is replaced by `Http\Client\HttpClient` ie the constructor of `Github\Client`. +- We use PSR-7's representation of HTTP message instead of `Guzzle\Http\Message\Response` and `Guzzle\Http\Message\Request`. +- `Github\Client::addHeaders` was added instead of `Github\Client::setHeaders` +- Signature of `Github\Client::useCache` has changed. First argument must be a `CacheItemPoolInterface` +- We use PSR-4 instead of PSR-0 + +### Removed + +- Support for PHP 5.3 and 5.4 +- `Github/HttpClient/HttpClientInterface` was removed +- `Github/HttpClient/HttpClient` was removed +- All classes in `Github/HttpClient/HttpClient/Listener/*` were removed +- `Github/HttpClient/CachedHttpClient` was removed +- All classes in `Github/HttpClient/Cache/*` were removed + +## 1.7.1 + +No change log before this version From fba4363b715e6a6712d9fd41024329287eae6d21 Mon Sep 17 00:00:00 2001 From: Styxit Date: Sun, 30 Oct 2016 21:38:05 +0100 Subject: [PATCH 439/951] Add Deployment show method Get a single deployment by id. --- doc/repo/deployments.md | 6 ++++++ lib/Github/Api/Deployment.php | 14 ++++++++++++++ test/Github/Tests/Api/DeploymentTest.php | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/doc/repo/deployments.md b/doc/repo/deployments.md index 386025d936f..740bac4dd0c 100644 --- a/doc/repo/deployments.md +++ b/doc/repo/deployments.md @@ -15,6 +15,12 @@ You can also filter the returned results (see [the documentation](https://develo $deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api', array('environment' => 'production')); ``` +### List one deployment. + +```php +$deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id); +``` + #### Create a new deployments. The `ref` parameter is required. diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 7b19c25360c..265be431b74 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -25,6 +25,20 @@ public function all($username, $repository, array $params = array()) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } + /** + * Get a deployment in selected repository. + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the deployment + * + * @return array + */ + public function show($username, $repository, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id)); + } + /** * Create a new deployment for the given username and repo. * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index af21652cf97..96f72498fee 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -46,6 +46,22 @@ public function shouldGetAllDeploymentsWithFilterParameters() $api->all('KnpLabs', 'php-github-api', $filterData); } + /** + * @test + */ + public function shouldShowProject() + { + $expectedValue = array('id' => 123, 'ref' => 'master'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/deployments/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + } + /** * @test */ From d7d7307cc57b57ff3eac5a1efc639f104a7c4cdf Mon Sep 17 00:00:00 2001 From: Styxit Date: Sun, 30 Oct 2016 21:44:31 +0100 Subject: [PATCH 440/951] Apply StyleCI fixes --- test/Github/Tests/Api/DeploymentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 96f72498fee..0aab01db155 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -51,7 +51,7 @@ public function shouldGetAllDeploymentsWithFilterParameters() */ public function shouldShowProject() { - $expectedValue = array('id' => 123, 'ref' => 'master'); + $expectedValue = array('id' => 123, 'ref' => 'master'); $api = $this->getApiMock(); $api->expects($this->once()) From 4b00198031b03be28fdaa7ff7be2d058c3c18d79 Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Wed, 2 Nov 2016 13:13:08 +0100 Subject: [PATCH 441/951] Update PullRequest::merge for polaris --- lib/Github/Api/PullRequest.php | 8 ++++-- test/Github/Tests/Api/PullRequestTest.php | 34 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 5419ded7db9..b7df369b99d 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -115,12 +115,16 @@ public function merged($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/merge'); } - public function merge($username, $repository, $id, $message, $sha, $squash = false, $title = null) + public function merge($username, $repository, $id, $message, $sha, $mergeMethod = 'merge', $title = null) { + if (is_bool($mergeMethod)) { + $mergeMethod = $mergeMethod ? 'squash' : 'merge'; + } + $params = array( 'commit_message' => $message, 'sha' => $sha, - 'squash' => $squash, + 'merge_method' => $mergeMethod, ); if (is_string($title)) { diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 975c131aebf..8bb3bcb1f72 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -143,12 +143,44 @@ public function shouldMergePullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'squash' => false)) + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'merge')) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40))); } + /** + * @test + */ + public function shouldMergePullRequestWithSquashAsBool() + { + $expectedArray = array('some' => 'response'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'squash')) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40), true)); + } + + /** + * @test + */ + public function shouldMergePullRequestWithMergeMethod() + { + $expectedArray = array('some' => 'response'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'rebase')) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40), 'rebase')); + } + /** * @test */ From f11f0796b37e2ae983007dcbb2404e912f2ac586 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Sun, 20 Nov 2016 13:57:12 +0200 Subject: [PATCH 442/951] add new alias for pull request --- lib/Github/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index b074db5a14a..f2550861e3d 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -235,6 +235,7 @@ public function api($name) break; case 'pr': + case 'pulls': case 'pullRequest': case 'pull_request': case 'pullRequests': From 017ec1bf757c877de09225f9ab3b023ccb893dee Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 20 Nov 2016 19:09:09 +0100 Subject: [PATCH 443/951] Reworked projects api --- doc/README.md | 6 +- doc/{repo => project}/cards.md | 16 ++-- doc/{repo => project}/columns.md | 16 ++-- doc/{repo => project}/projects.md | 15 +++- lib/Github/Api/Organization/Projects.php | 23 ++++++ lib/Github/Api/Project/AbstractProjectApi.php | 41 ++++++++++ lib/Github/Api/Project/Cards.php | 56 ++++++++++++++ lib/Github/Api/Project/Columns.php | 69 +++++++++++++++++ lib/Github/Api/Repository/Cards.php | 56 -------------- lib/Github/Api/Repository/Columns.php | 69 ----------------- lib/Github/Api/Repository/Projects.php | 37 +-------- lib/Github/Client.php | 6 ++ .../Tests/Api/Organization/ProjectsTest.php | 64 ++++++++++++++++ .../Api/{Repository => Project}/CardsTest.php | 30 ++++---- .../{Repository => Project}/ColumnsTest.php | 36 ++++----- .../Github/Tests/Api/Project/ProjectsTest.php | 76 +++++++++++++++++++ .../Tests/Api/Repository/ProjectsTest.php | 61 +-------------- 17 files changed, 405 insertions(+), 272 deletions(-) rename doc/{repo => project}/cards.md (69%) rename doc/{repo => project}/columns.md (51%) rename doc/{repo => project}/projects.md (55%) create mode 100644 lib/Github/Api/Organization/Projects.php create mode 100644 lib/Github/Api/Project/AbstractProjectApi.php create mode 100644 lib/Github/Api/Project/Cards.php create mode 100644 lib/Github/Api/Project/Columns.php delete mode 100644 lib/Github/Api/Repository/Cards.php delete mode 100644 lib/Github/Api/Repository/Columns.php create mode 100644 test/Github/Tests/Api/Organization/ProjectsTest.php rename test/Github/Tests/Api/{Repository => Project}/CardsTest.php (65%) rename test/Github/Tests/Api/{Repository => Project}/ColumnsTest.php (68%) create mode 100644 test/Github/Tests/Api/Project/ProjectsTest.php diff --git a/doc/README.md b/doc/README.md index b86b1289907..02dd0c2cb5a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,15 +14,15 @@ APIs: * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) +* [Projects](project/projects.md) + * [Columns](project/columns.md) + * [Cards](project/cards.md) * [Pull Requests](pull_requests.md) * [Comments](pull_request/comments.md) * [Rate Limits](rate_limits.md) * [Repositories](repos.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) - * [Projects](repo/projects.md) - * [Columns](repo/columns.md) - * [Cards](repo/cards.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) * [Stargazers](repo/stargazers.md) diff --git a/doc/repo/cards.md b/doc/project/cards.md similarity index 69% rename from doc/repo/cards.md rename to doc/project/cards.md index baed1aa83be..b66707e6779 100644 --- a/doc/repo/cards.md +++ b/doc/project/cards.md @@ -4,6 +4,10 @@ This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. +Both repositories and organisations have projects. The api is only different for getting all project or retrieving a single project. +All the example use the repository projects column card api but this also works form the organization api (`$client->api('org_projects')->columns()->cards()`) + + ```php $client->api('repo')->projects()->columns()->cards()->configure(); ``` @@ -11,13 +15,13 @@ $client->api('repo')->projects()->columns()->cards()->configure(); ### List all cards of a column ```php -$cards = $client->api('repo')->projects()->columns()->cards()->all('twbs', 'bootstrap', $columnId); +$cards = $client->api('repo')->projects()->columns()->cards()->all($columnId); ``` ### List one card ```php -$card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'bootstrap', $cardId); +$card = $client->api('repo')->projects()->columns()->cards()->show($cardId); ``` ### Create a card @@ -25,7 +29,7 @@ $card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'boot > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bootstrap', $columnId, array('content_type' => 'Issue', 'content_id' => '452')); +$card = $client->api('repo')->projects()->columns()->cards()->create($columnId, array('content_type' => 'Issue', 'content_id' => '452')); ``` ### Edit a card @@ -33,7 +37,7 @@ $card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bo > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'bootstrap', $cardId, array('note' => 'card note')); +$card = $client->api('repo')->project()->columns()->cards()->update($cardId, array('note' => 'card note')); ``` ### Remove a card @@ -41,7 +45,7 @@ $card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'boo > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', 'bootstrap', $cardId); +$card = $client->api('repo')->projects()->columns()->cards()->deleteCard($cardId); ``` ### Move a card @@ -49,5 +53,5 @@ $card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->projects()->columns()->cards()->move('twbs', 'bootstrap', $cardId, array('position' => 'top)); +$card = $client->api('repo')->projects()->columns()->cards()->move($cardId, array('position' => 'top)); ``` diff --git a/doc/repo/columns.md b/doc/project/columns.md similarity index 51% rename from doc/repo/columns.md rename to doc/project/columns.md index 94263efd9fd..2f4a990942d 100644 --- a/doc/repo/columns.md +++ b/doc/project/columns.md @@ -4,6 +4,10 @@ This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. +Both repositories and organisations have projects. The api is only different for getting all project or retrieving a single project. +All the example use the repository projects column api but this also works form the organization api (`$client->api('org_projects')->columns()`) + + ```php $client->api('repo')->projects()->columns()->configure(); ``` @@ -11,13 +15,13 @@ $client->api('repo')->projects()->columns()->configure(); ### List all columns of a project ```php -$columns = $client->api('repo')->projects()->columns()->all('twbs', 'bootstrap', $projectId); +$columns = $client->api('repo')->projects()->columns()->all($projectId); ``` ### List one column ```php -$column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', $columnId); +$column = $client->api('repo')->projects()->columns()->show($columnId); ``` ### Create a column @@ -25,7 +29,7 @@ $column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap', $projectId, array('name' => 'Column name')); +$column = $client->api('repo')->projects()->columns()->create($projectId, array('name' => 'Column name')); ``` ### Edit a column @@ -33,7 +37,7 @@ $column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap', $columnId, array('name' => 'New name')); +$column = $client->api('repo')->project()->columns()->update($columnId, array('name' => 'New name')); ``` ### Remove a column @@ -41,7 +45,7 @@ $column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap' > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'bootstrap', $columnId); +$column = $client->api('repo')->projects()->columns()->deleteColumn($columnId); ``` ### Move a column @@ -49,5 +53,5 @@ $column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'boo > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->projects()->columns()->move('twbs', 'bootstrap', $columnId, array('position' => 'first)); +$column = $client->api('repo')->projects()->columns()->move($columnId, array('position' => 'first)); ``` diff --git a/doc/repo/projects.md b/doc/project/projects.md similarity index 55% rename from doc/repo/projects.md rename to doc/project/projects.md index 2743973b73c..5763e0060e7 100644 --- a/doc/repo/projects.md +++ b/doc/project/projects.md @@ -1,9 +1,12 @@ ## Repo / Projects API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +[Back to the "Repos API"](../) | [Back to the navigation](../README.md) This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. +Both repositories and organisations have projects. The api is only different for gettings all or a single project. +All the example use the repository projects api but this also works form the organization api (`$client->api('org_projects')`) + ```php $client->api('repo')->projects()->configure(); ``` @@ -12,12 +15,16 @@ $client->api('repo')->projects()->configure(); ```php $projects = $client->api('repo')->projects()->all('twbs', 'bootstrap'); + +//or + +$projects = $client->api('org_projects')->all('twbs'); ``` ### List one project ```php -$project = $client->api('repo')->projects()->show('twbs', 'bootstrap', $projectId); +$project = $client->api('repo')->projects()->show($projectId); ``` ### Create a project @@ -33,7 +40,7 @@ $project = $client->api('repo')->projects()->create('twbs', 'bootstrap', array(' > Requires [authentication](../security.md). ```php -$project = $client->api('repo')->project()->update('twbs', 'bootstrap', $projectId, array('name' => 'New name')); +$project = $client->api('repo')->project()->update($projectId, array('name' => 'New name')); ``` ### Remove a project @@ -41,5 +48,5 @@ $project = $client->api('repo')->project()->update('twbs', 'bootstrap', $project > Requires [authentication](../security.md). ```php -$project = $client->api('repo')->projects()->deleteProject('twbs', 'bootstrap', $projectId); +$project = $client->api('repo')->projects()->deleteProject($projectId); ``` diff --git a/lib/Github/Api/Organization/Projects.php b/lib/Github/Api/Organization/Projects.php new file mode 100644 index 00000000000..dcff9c86c98 --- /dev/null +++ b/lib/Github/Api/Organization/Projects.php @@ -0,0 +1,23 @@ +get('/orgs/'.rawurlencode($organization).'/projects', array_merge(array('page' => 1), $params)); + } + + public function create($organization, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->post('/orgs/'.rawurlencode($organization).'/projects', $params); + } +} diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php new file mode 100644 index 00000000000..55bc733424f --- /dev/null +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -0,0 +1,41 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function show($id, array $params = array()) + { + return $this->get('/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params)); + } + + public function update($id, array $params) + { + return $this->patch('/projects/'.rawurlencode($id), $params); + } + + public function deleteProject($id) + { + return $this->delete('/projects/'.rawurlencode($id)); + } + + public function columns() + { + return new Columns($this->client); + } +} diff --git a/lib/Github/Api/Project/Cards.php b/lib/Github/Api/Project/Cards.php new file mode 100644 index 00000000000..65765b75907 --- /dev/null +++ b/lib/Github/Api/Project/Cards.php @@ -0,0 +1,56 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($columnId, array $params = array()) + { + return $this->get('/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params)); + } + + public function show($id) + { + return $this->get('/projects/columns/cards/'.rawurlencode($id)); + } + + public function create($columnId, array $params) + { + return $this->post('/projects/columns/' . rawurlencode($columnId) . '/cards', $params); + } + + public function update($id, array $params) + { + return $this->patch('/projects/columns/cards/' . rawurlencode($id), $params); + } + + public function deleteCard($id) + { + return $this->delete('/projects/columns/cards/'.rawurlencode($id)); + } + + public function move($id, array $params) + { + if (!isset($params['position'])) { + throw new MissingArgumentException(array('position')); + } + + return $this->post('/projects/columns/cards/' . rawurlencode($id) . '/moves', $params); + } +} diff --git a/lib/Github/Api/Project/Columns.php b/lib/Github/Api/Project/Columns.php new file mode 100644 index 00000000000..16b9f25c327 --- /dev/null +++ b/lib/Github/Api/Project/Columns.php @@ -0,0 +1,69 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($projectId, array $params = array()) + { + return $this->get('/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params)); + } + + public function show($id) + { + return $this->get('/projects/columns/'.rawurlencode($id)); + } + + public function create($projectId, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->post('/projects/' . rawurlencode($projectId) . '/columns', $params); + } + + public function update($id, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->patch('/projects/columns/' . rawurlencode($id), $params); + } + + public function deleteColumn($id) + { + return $this->delete('/projects/columns/'.rawurlencode($id)); + } + + public function move($id, array $params) + { + if (!isset($params['position'])) { + throw new MissingArgumentException(array('position')); + } + + return $this->post('/projects/columns/' . rawurlencode($id) . '/moves', $params); + } + + public function cards() + { + return new Cards($this->client); + } +} diff --git a/lib/Github/Api/Repository/Cards.php b/lib/Github/Api/Repository/Cards.php deleted file mode 100644 index e772ca97328..00000000000 --- a/lib/Github/Api/Repository/Cards.php +++ /dev/null @@ -1,56 +0,0 @@ -acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; - } - - public function all($username, $repository, $columnId, array $params = array()) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params)); - } - - public function show($username, $repository, $id) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id)); - } - - public function create($username, $repository, $columnId, array $params) - { - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', $params); - } - - public function update($username, $repository, $id, array $params) - { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id), $params); - } - - public function deleteCard($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id)); - } - - public function move($username, $repository, $id, array $params) - { - if (!isset($params['position'])) { - throw new MissingArgumentException(array('position')); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id) . '/moves', $params); - } -} diff --git a/lib/Github/Api/Repository/Columns.php b/lib/Github/Api/Repository/Columns.php deleted file mode 100644 index 1b4e016a87b..00000000000 --- a/lib/Github/Api/Repository/Columns.php +++ /dev/null @@ -1,69 +0,0 @@ -acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; - } - - public function all($username, $repository, $projectId, array $params = array()) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params)); - } - - public function show($username, $repository, $id) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id)); - } - - public function create($username, $repository, $projectId, array $params) - { - if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', $params); - } - - public function update($username, $repository, $id, array $params) - { - if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); - } - - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id), $params); - } - - public function deleteColumn($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id)); - } - - public function move($username, $repository, $id, array $params) - { - if (!isset($params['position'])) { - throw new MissingArgumentException(array('position')); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id) . '/moves', $params); - } - - public function cards() - { - return new Cards($this->client); - } -} diff --git a/lib/Github/Api/Repository/Projects.php b/lib/Github/Api/Repository/Projects.php index 1b791a90be4..279a1d45f92 100644 --- a/lib/Github/Api/Repository/Projects.php +++ b/lib/Github/Api/Repository/Projects.php @@ -2,34 +2,16 @@ namespace Github\Api\Repository; -use Github\Api\AbstractApi; -use Github\Api\AcceptHeaderTrait; +use Github\Api\Project\AbstractProjectApi; use Github\Exception\MissingArgumentException; -class Projects extends AbstractApi +class Projects extends AbstractProjectApi { - use AcceptHeaderTrait; - - /** - * Configure the accept header for Early Access to the projects api - * - * @see https://developer.github.com/v3/repos/projects/#projects - */ - public function configure() - { - $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; - } - public function all($username, $repository, array $params = array()) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(array('page' => 1), $params)); } - public function show($username, $repository, $id, array $params = array()) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params)); - } - public function create($username, $repository, array $params) { if (!isset($params['name'])) { @@ -38,19 +20,4 @@ public function create($username, $repository, array $params) return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', $params); } - - public function update($username, $repository, $id, array $params) - { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id), $params); - } - - public function deleteProject($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id)); - } - - public function columns() - { - return new Columns($this->client); - } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index b074db5a14a..25e8915c323 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -233,6 +233,12 @@ public function api($name) case 'organizations': $api = new Api\Organization($this); break; + case 'org_project': + case 'org_projects': + case 'organization_project': + case 'organization_projects': + $api = new Api\Organization\Projects($this); + break; case 'pr': case 'pullRequest': diff --git a/test/Github/Tests/Api/Organization/ProjectsTest.php b/test/Github/Tests/Api/Organization/ProjectsTest.php new file mode 100644 index 00000000000..1415949a343 --- /dev/null +++ b/test/Github/Tests/Api/Organization/ProjectsTest.php @@ -0,0 +1,64 @@ + 'Test project 1')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/projects') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs')); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateWithoutName() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', $data); + } + + /** + * @test + */ + public function shouldCreateColumn() + { + $expectedValue = array('project1data'); + $data = array('name' => 'Project 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/orgs/KnpLabs/projects', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Organization\Projects::class; + } +} diff --git a/test/Github/Tests/Api/Repository/CardsTest.php b/test/Github/Tests/Api/Project/CardsTest.php similarity index 65% rename from test/Github/Tests/Api/Repository/CardsTest.php rename to test/Github/Tests/Api/Project/CardsTest.php index d4795b802f1..0b68310274f 100644 --- a/test/Github/Tests/Api/Repository/CardsTest.php +++ b/test/Github/Tests/Api/Project/CardsTest.php @@ -1,6 +1,6 @@ getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123/cards') + ->with('/projects/columns/123/cards') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->all(123)); } /** @@ -32,10 +32,10 @@ public function shouldShowCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123') + ->with('/projects/columns/cards/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->show(123)); } /** @@ -49,10 +49,10 @@ public function shouldCreateCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/columns/1234/cards', $data) + ->with('/projects/columns/1234/cards', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', '1234', $data)); + $this->assertEquals($expectedValue, $api->create('1234', $data)); } /** @@ -66,10 +66,10 @@ public function shouldUpdateCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123', $data) + ->with('/projects/columns/cards/123', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->update(123, $data)); } /** @@ -82,10 +82,10 @@ public function shouldRemoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123') + ->with('/projects/columns/cards/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->deleteCard('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->deleteCard(123)); } /** @@ -100,7 +100,7 @@ public function shouldNotMoveWithoutPosition() $api->expects($this->never()) ->method('post'); - $api->move('KnpLabs', 'php-github-api', '123', $data); + $api->move('123', $data); } /** @@ -114,10 +114,10 @@ public function shouldMoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123/moves') + ->with('/projects/columns/cards/123/moves') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->move(123, $data)); } /** @@ -125,6 +125,6 @@ public function shouldMoveCard() */ protected function getApiClass() { - return \Github\Api\Repository\Cards::class; + return \Github\Api\Project\Cards::class; } } diff --git a/test/Github/Tests/Api/Repository/ColumnsTest.php b/test/Github/Tests/Api/Project/ColumnsTest.php similarity index 68% rename from test/Github/Tests/Api/Repository/ColumnsTest.php rename to test/Github/Tests/Api/Project/ColumnsTest.php index b12c0706cf2..cb244623095 100644 --- a/test/Github/Tests/Api/Repository/ColumnsTest.php +++ b/test/Github/Tests/Api/Project/ColumnsTest.php @@ -1,6 +1,6 @@ getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/123/columns') + ->with('/projects/123/columns') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->all(123)); } /** @@ -32,10 +32,10 @@ public function shouldShowColumn() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123') + ->with('/projects/columns/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->show(123)); } /** @@ -50,7 +50,7 @@ public function shouldNotCreateWithoutName() $api->expects($this->never()) ->method('post'); - $api->create('KnpLabs', 'php-github-api', '123', $data); + $api->create('123', $data); } /** @@ -64,10 +64,10 @@ public function shouldCreateColumn() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/123/columns', $data) + ->with('/projects/123/columns', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->create(123, $data)); } /** @@ -82,7 +82,7 @@ public function shouldNotUpdateWithoutName() $api->expects($this->never()) ->method('post'); - $api->update('KnpLabs', 'php-github-api', '123', $data); + $api->update('123', $data); } /** @@ -96,10 +96,10 @@ public function shouldUpdateColumn() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123', $data) + ->with('/projects/columns/123', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->update(123, $data)); } /** @@ -112,10 +112,10 @@ public function shouldRemoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123') + ->with('/projects/columns/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->deleteColumn('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->deleteColumn(123)); } /** @@ -130,7 +130,7 @@ public function shouldNotMoveWithoutPosition() $api->expects($this->never()) ->method('post'); - $api->move('KnpLabs', 'php-github-api', '123', $data); + $api->move('123', $data); } /** @@ -144,10 +144,10 @@ public function shouldMoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123/moves') + ->with('/projects/columns/123/moves') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->move(123, $data)); } /** @@ -157,7 +157,7 @@ public function shouldGetCardsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Cards', $api->cards()); + $this->assertInstanceOf('Github\Api\Project\Cards', $api->cards()); } /** @@ -165,6 +165,6 @@ public function shouldGetCardsApiObject() */ protected function getApiClass() { - return \Github\Api\Repository\Columns::class; + return \Github\Api\Project\Columns::class; } } diff --git a/test/Github/Tests/Api/Project/ProjectsTest.php b/test/Github/Tests/Api/Project/ProjectsTest.php new file mode 100644 index 00000000000..3278b6b0ee1 --- /dev/null +++ b/test/Github/Tests/Api/Project/ProjectsTest.php @@ -0,0 +1,76 @@ + 'Test project 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show(123)); + } + + /** + * @test + */ + public function shouldUpdateProject() + { + $expectedValue = array('project1data'); + $data = array('name' => 'Project 1 update'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/projects/123', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(123, $data)); + } + + /** + * @test + */ + public function shouldRemoveProject() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/projects/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteProject(123)); + } + + /** + * @test + */ + public function shouldGetColumnsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Project\Columns', $api->columns()); + } + + /** + * @return string + */ + protected function getApiClass() + { + return AbstractProjectApi::class; + } +} diff --git a/test/Github/Tests/Api/Repository/ProjectsTest.php b/test/Github/Tests/Api/Repository/ProjectsTest.php index d82b7bbe4dd..2b0c50d2cf0 100644 --- a/test/Github/Tests/Api/Repository/ProjectsTest.php +++ b/test/Github/Tests/Api/Repository/ProjectsTest.php @@ -22,22 +22,6 @@ public function shouldGetAllRepositoryProjects() $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); } - /** - * @test - */ - public function shouldShowProject() - { - $expectedValue = array('name' => 'Test project 1'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/123') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); - } - /** * @test * @expectedException \Github\Exception\MissingArgumentException @@ -58,7 +42,7 @@ public function shouldNotCreateWithoutName() */ public function shouldCreateColumn() { - $expectedValue = array('column1data'); + $expectedValue = array('project1data'); $data = array('name' => 'Project 1'); $api = $this->getApiMock(); @@ -70,49 +54,6 @@ public function shouldCreateColumn() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** - * @test - */ - public function shouldUpdateProject() - { - $expectedValue = array('project1data'); - $data = array('name' => 'Project 1 update'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/repos/KnpLabs/php-github-api/projects/123', $data) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); - } - - /** - * @test - */ - public function shouldRemoveProject() - { - $expectedValue = array('someOutput'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/repos/KnpLabs/php-github-api/projects/123') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->deleteProject('KnpLabs', 'php-github-api', 123)); - } - - /** - * @test - */ - public function shouldGetColumnsApiObject() - { - $api = $this->getApiMock(); - - $this->assertInstanceOf('Github\Api\Repository\Columns', $api->columns()); - } - /** * @return string */ From b7581a9d20f6b604280735825c1033f581ab5fc5 Mon Sep 17 00:00:00 2001 From: Alexander Holman Date: Mon, 21 Nov 2016 12:00:53 +0000 Subject: [PATCH 444/951] refactor:Make addMember an alias of add Duplicate code existed for adding member to an organisation Under lib/Github/Api/Organisation/Members.php the addMember and add methods returned the exact same code and used the exact same arguments. With that in mind I made addMember an "alias" returning $this->add passing the same arguments through. --- lib/Github/Api/Organization/Members.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index a3d466252ea..2e314e4ad7a 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -44,11 +44,6 @@ public function check($organization, $username) return $this->get('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); } - public function addMember($organization, $username) - { - return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); - } - public function publicize($organization, $username) { return $this->put('/orgs/'.rawurlencode($organization).'/public_members/'.rawurlencode($username)); @@ -67,6 +62,11 @@ public function add($organization, $username) return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); } + public function addMember($organization, $username) + { + return $this->add($organization, $username); + } + public function remove($organization, $username) { return $this->delete('/orgs/'.rawurlencode($organization).'/members/'.rawurlencode($username)); From 895c7c1edeef65eae328191b163f02787b1d2112 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Tue, 22 Nov 2016 23:22:33 +0200 Subject: [PATCH 445/951] added 'user/repos' missing endpoint --- lib/Github/Api/User.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index d866c93050b..4dcdf7d21da 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -145,6 +145,8 @@ public function subscriptions($username) } /** + * @deprecated use repos($username, $options) instead + * * Get the repositories of a user. * * @link http://developer.github.com/v3/repos/ @@ -158,13 +160,26 @@ public function subscriptions($username) */ public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->get('/users/'.rawurlencode($username).'/repos', array( + return $this->repos($username, array( 'type' => $type, 'sort' => $sort, 'direction' => $direction )); } + /** + * @param null $username + * @param array $options + * + * @return array list of the user repositories + */ + public function repos($username = null, array $options = array()) + { + $url = $username ? 'users/'.rawurldecode($username).'/repos' : 'user/repos'; + + return $this->get($url, $options); + } + /** * Get the public gists for a user. * From e78407fe21a1a98f90ee86f9d74619b5e61e6fb3 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Tue, 22 Nov 2016 23:27:32 +0200 Subject: [PATCH 446/951] fix path --- lib/Github/Api/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 4dcdf7d21da..a7f0f849817 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -175,7 +175,7 @@ public function repositories($username, $type = 'owner', $sort = 'full_name', $d */ public function repos($username = null, array $options = array()) { - $url = $username ? 'users/'.rawurldecode($username).'/repos' : 'user/repos'; + $url = $username ? '/users/'.rawurldecode($username).'/repos' : '/user/repos'; return $this->get($url, $options); } From df09c20c483bea72968a947eee0678e4988c651b Mon Sep 17 00:00:00 2001 From: Alexander Holman Date: Thu, 1 Dec 2016 08:25:40 +0000 Subject: [PATCH 447/951] fix styleci issue --- lib/Github/Api/Organization/Members.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 2e314e4ad7a..13bda339eb2 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -62,10 +62,10 @@ public function add($organization, $username) return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); } - public function addMember($organization, $username) - { - return $this->add($organization, $username); - } + public function addMember($organization, $username) + { + return $this->add($organization, $username); + } public function remove($organization, $username) { From f17a3e7030db7717b1b84ec95709e095f1f110c1 Mon Sep 17 00:00:00 2001 From: Sergii Bondarenko Date: Fri, 2 Dec 2016 16:54:59 +0200 Subject: [PATCH 448/951] #474: Allow getting README contents in different formats --- lib/Github/Api/Repo.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index cfcdbf509d6..0285f44886a 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -237,12 +237,15 @@ public function remove($username, $repository) * * @param string $username the user who owns the repository * @param string $repository the name of the repository + * @param string $format one of formats: "raw" or "html" * * @return array the readme content */ - public function readme($username, $repository) + public function readme($username, $repository, $format = 'raw') { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', [], [ + 'Accept' => "application/vnd.github.$format", + ]); } /** From 86d9d002a2510ca8d6327a121a05e7c1a0accabd Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 15:00:58 +0100 Subject: [PATCH 449/951] Added HTTP Client Builder --- lib/Github/Client.php | 194 +++++---------------------- lib/Github/HttpClient/Builder.php | 209 ++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+), 162 deletions(-) create mode 100644 lib/Github/HttpClient/Builder.php diff --git a/lib/Github/Client.php b/lib/Github/Client.php index d396f67e4ce..d7244a39105 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -5,20 +5,14 @@ use Github\Api\ApiInterface; use Github\Exception\InvalidArgumentException; use Github\Exception\BadMethodCallException; +use Github\HttpClient\Builder; use Github\HttpClient\Plugin\Authentication; use Github\HttpClient\Plugin\GithubExceptionThrower; use Github\HttpClient\Plugin\History; use Github\HttpClient\Plugin\PathPrepend; use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\Plugin; -use Http\Client\Common\PluginClient; -use Http\Client\HttpClient; -use Http\Discovery\HttpClientDiscovery; -use Http\Discovery\MessageFactoryDiscovery; -use Http\Discovery\StreamFactoryDiscovery; use Http\Discovery\UriFactoryDiscovery; -use Http\Message\MessageFactory; -use Nyholm\Psr7\Factory\StreamFactory; use Psr\Cache\CacheItemPoolInterface; /** @@ -98,45 +92,9 @@ class Client private $apiVersion; /** - * The object that sends HTTP messages - * - * @var HttpClient - */ - private $httpClient; - - /** - * A HTTP client with all our plugins - * - * @var PluginClient - */ - private $pluginClient; - - /** - * @var MessageFactory - */ - private $messageFactory; - - /** - * @var StreamFactory - */ - private $streamFactory; - - /** - * @var Plugin[] - */ - private $plugins = []; - - /** - * True if we should create a new Plugin client at next request. - * @var bool + * @var Builder */ - private $httpClientModified = true; - - /** - * Http headers - * @var array - */ - private $headers = []; + private $httpClientBuilder; /** * @var History @@ -146,27 +104,28 @@ class Client /** * Instantiate a new GitHub client. * - * @param HttpClient|null $httpClient - * @param string|null $apiVersion - * @param string|null $enterpriseUrl + * @param Builder|null $httpClient + * @param string|null $apiVersion + * @param string|null $enterpriseUrl */ - public function __construct(HttpClient $httpClient = null, $apiVersion = null, $enterpriseUrl = null) + public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { - $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); - $this->messageFactory = MessageFactoryDiscovery::find(); - $this->streamFactory = StreamFactoryDiscovery::find(); - $this->responseHistory = new History(); - $this->addPlugin(new GithubExceptionThrower()); - $this->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); - $this->addPlugin(new Plugin\RedirectPlugin()); - $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); - $this->addPlugin(new Plugin\HeaderDefaultsPlugin(array( - 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', + $this->httpClientBuilder = new Builder(); + $this->httpClientBuilder->addDefaultHeaders([ + 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), + ]); + + $this->httpClientBuilder->addPlugin(new GithubExceptionThrower()); + $this->httpClientBuilder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); + $this->httpClientBuilder->addPlugin(new Plugin\RedirectPlugin()); + $this->httpClientBuilder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); + $this->httpClientBuilder->addPlugin(new Plugin\HeaderDefaultsPlugin(array( + 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ))); $this->apiVersion = $apiVersion ?: 'v3'; - $this->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); + $this->httpClientBuilder->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); if ($enterpriseUrl) { $this->setEnterpriseUrl($enterpriseUrl); @@ -313,15 +272,15 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null if (null === $authMethod && in_array($password, array(self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT))) { $authMethod = $password; - $password = null; + $password = null; } if (null === $authMethod) { $authMethod = self::AUTH_HTTP_PASSWORD; } - $this->removePlugin(Authentication::class); - $this->addPlugin(new Authentication($tokenOrLogin, $password, $authMethod)); + $this->httpClientBuilder->removePlugin(Authentication::class); + $this->httpClientBuilder->addPlugin(new Authentication($tokenOrLogin, $password, $authMethod)); } /** @@ -331,64 +290,11 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null */ private function setEnterpriseUrl($enterpriseUrl) { - $this->removePlugin(Plugin\AddHostPlugin::class); - $this->removePlugin(PathPrepend::class); - - $this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); - $this->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); - } - - /** - * Add a new plugin to the end of the plugin chain. - * - * @param Plugin $plugin - */ - public function addPlugin(Plugin $plugin) - { - $this->plugins[] = $plugin; - $this->httpClientModified = true; - } - - /** - * Remove a plugin by its fully qualified class name (FQCN). - * - * @param string $fqcn - */ - public function removePlugin($fqcn) - { - foreach ($this->plugins as $idx => $plugin) { - if ($plugin instanceof $fqcn) { - unset($this->plugins[$idx]); - $this->httpClientModified = true; - } - } - } + $this->httpClientBuilder->removePlugin(Plugin\AddHostPlugin::class); + $this->httpClientBuilder->removePlugin(PathPrepend::class); - /** - * @return HttpMethodsClient - */ - public function getHttpClient() - { - if ($this->httpClientModified) { - $this->httpClientModified = false; - $this->pushBackCachePlugin(); - - $this->pluginClient = new HttpMethodsClient( - new PluginClient($this->httpClient, $this->plugins), - $this->messageFactory - ); - } - - return $this->pluginClient; - } - - /** - * @param HttpClient $httpClient - */ - public function setHttpClient(HttpClient $httpClient) - { - $this->httpClientModified = true; - $this->httpClient = $httpClient; + $this->httpClientBuilder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); + $this->httpClientBuilder->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); } /** @@ -399,30 +305,6 @@ public function getApiVersion() return $this->apiVersion; } - /** - * Clears used headers. - */ - public function clearHeaders() - { - $this->headers = array( - 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), - ); - - $this->removePlugin(Plugin\HeaderAppendPlugin::class); - $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); - } - - /** - * @param array $headers - */ - public function addHeaders(array $headers) - { - $this->headers = array_merge($this->headers, $headers); - - $this->removePlugin(Plugin\HeaderAppendPlugin::class); - $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); - } - /** * Add a cache plugin to cache responses locally. * @@ -431,16 +313,15 @@ public function addHeaders(array $headers) */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { - $this->removeCache(); - $this->addPlugin(new Plugin\CachePlugin($cachePool, $this->streamFactory, $config)); + $this->httpClientBuilder->addCache($cachePool, $config); } /** - * Remove the cache plugin + * Remove the cache plugin. */ public function removeCache() { - $this->removePlugin(Plugin\CachePlugin::class); + $this->httpClientBuilder->removeCache(); } /** @@ -460,7 +341,6 @@ public function __call($name, $args) } /** - * * @return null|\Psr\Http\Message\ResponseInterface */ public function getLastResponse() @@ -469,20 +349,10 @@ public function getLastResponse() } /** - * Make sure to move the cache plugin to the end of the chain + * @return HttpMethodsClient */ - private function pushBackCachePlugin() + public function getHttpClient() { - $cachePlugin = null; - foreach ($this->plugins as $i => $plugin) { - if ($plugin instanceof Plugin\CachePlugin) { - $cachePlugin = $plugin; - unset($this->plugins[$i]); - - $this->plugins[] = $cachePlugin; - - return; - } - } + return $this->httpClientBuilder->getHttpClient(); } } diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php new file mode 100644 index 00000000000..60cfefe161a --- /dev/null +++ b/lib/Github/HttpClient/Builder.php @@ -0,0 +1,209 @@ + + */ +class Builder +{ + /** + * The object that sends HTTP messages. + * + * @var HttpClient + */ + private $httpClient; + + /** + * A HTTP client with all our plugins. + * + * @var PluginClient + */ + private $pluginClient; + + /** + * @var MessageFactory + */ + private $requestFactory; + + /** + * @var StreamFactory + */ + private $streamFactory; + + /** + * True if we should create a new Plugin client at next request. + * + * @var bool + */ + private $httpClientModified = true; + + /** + * @var Plugin[] + */ + private $plugins = []; + + /** + * This plugin is speacal treated because it has to be the very last plugin. + * + * @var Plugin\CachePlugin + */ + private $cachePlugin; + + /** + * Http headers. + * + * @var array + */ + private $headers = []; + + /** + * Headers that will always be in the client. + * + * @var array + */ + private $defaultHeaders = []; + + /** + * @param HttpClient $httpClient + * @param RequestFactory $requestFactory + * @param StreamFactory $streamFactory + */ + public function __construct( + HttpClient $httpClient = null, + RequestFactory $requestFactory = null, + StreamFactory $streamFactory = null + ) { + $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); + $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); + $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); + } + + /** + * @return HttpMethodsClient + */ + public function getHttpClient() + { + if ($this->httpClientModified) { + $this->httpClientModified = false; + + $plugins = $this->plugins; + if ($this->cachePlugin) { + $plugins[] = $this->cachePlugin; + } + + $this->pluginClient = new HttpMethodsClient( + new PluginClient($this->httpClient, $plugins), + $this->requestFactory + ); + } + + return $this->pluginClient; + } + + /** + * Add a new plugin to the end of the plugin chain. + * + * @param Plugin $plugin + */ + public function addPlugin(Plugin $plugin) + { + $this->plugins[] = $plugin; + $this->httpClientModified = true; + } + + /** + * Remove a plugin by its fully qualified class name (FQCN). + * + * @param string $fqcn + */ + public function removePlugin($fqcn) + { + foreach ($this->plugins as $idx => $plugin) { + if ($plugin instanceof $fqcn) { + unset($this->plugins[$idx]); + $this->httpClientModified = true; + } + } + } + + /** + * @param HttpClient $httpClient + */ + public function setHttpClient(HttpClient $httpClient) + { + $this->httpClientModified = true; + $this->httpClient = $httpClient; + } + + /** + * Clears used headers. + */ + public function clearHeaders() + { + $this->headers = $this->defaultHeaders; + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); + } + + /** + * @param array $headers + */ + public function addHeaders(array $headers) + { + $this->headers = array_merge($this->headers, $headers); + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); + } + + /** + * Add default headers. Default headers will not be cleared when calling clearHeaders. + * + * @param array $headers + */ + public function addDefaultHeaders(array $headers) + { + $this->defaultHeaders = array_merge($this->defaultHeaders, $headers); + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin(array_merge($this->defaultHeaders, $this->headers))); + } + + /** + * Add a cache plugin to cache responses locally. + * + * @param CacheItemPoolInterface $cache + * @param array $config + */ + public function addCache(CacheItemPoolInterface $cachePool, array $config = []) + { + $this->cachePlugin = new Plugin\CachePlugin($cachePool, $this->streamFactory, $config); + $this->httpClientModified = true; + } + + /** + * Remove the cache plugin. + */ + public function removeCache() + { + $this->cachePlugin = null; + $this->httpClientModified = true; + } +} From 51ba284941204b218a885b152ac878dd758e3b47 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 15:37:56 +0100 Subject: [PATCH 450/951] Bugfixes --- lib/Github/Client.php | 42 ++++++----- lib/Github/HttpClient/Builder.php | 9 --- test/Github/Tests/Api/TestCase.php | 3 +- test/Github/Tests/ClientTest.php | 77 +++++++------------- test/Github/Tests/HttpClient/BuilderTest.php | 55 ++++++++++++++ test/Github/Tests/ResultPagerTest.php | 5 +- 6 files changed, 112 insertions(+), 79 deletions(-) create mode 100644 test/Github/Tests/HttpClient/BuilderTest.php diff --git a/lib/Github/Client.php b/lib/Github/Client.php index d7244a39105..5fe80066afe 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -111,21 +111,21 @@ class Client public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); - $this->httpClientBuilder = new Builder(); - $this->httpClientBuilder->addDefaultHeaders([ + $this->httpClientBuilder = $httpClientBuilder ?: new Builder(); + $this->getHttpClientBuilder()->addDefaultHeaders([ 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), ]); - $this->httpClientBuilder->addPlugin(new GithubExceptionThrower()); - $this->httpClientBuilder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); - $this->httpClientBuilder->addPlugin(new Plugin\RedirectPlugin()); - $this->httpClientBuilder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); - $this->httpClientBuilder->addPlugin(new Plugin\HeaderDefaultsPlugin(array( + $this->getHttpClientBuilder()->addPlugin(new GithubExceptionThrower()); + $this->getHttpClientBuilder()->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); + $this->getHttpClientBuilder()->addPlugin(new Plugin\RedirectPlugin()); + $this->getHttpClientBuilder()->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); + $this->getHttpClientBuilder()->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ))); $this->apiVersion = $apiVersion ?: 'v3'; - $this->httpClientBuilder->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); + $this->getHttpClientBuilder()->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); if ($enterpriseUrl) { $this->setEnterpriseUrl($enterpriseUrl); @@ -279,8 +279,8 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null $authMethod = self::AUTH_HTTP_PASSWORD; } - $this->httpClientBuilder->removePlugin(Authentication::class); - $this->httpClientBuilder->addPlugin(new Authentication($tokenOrLogin, $password, $authMethod)); + $this->getHttpClientBuilder()->removePlugin(Authentication::class); + $this->getHttpClientBuilder()->addPlugin(new Authentication($tokenOrLogin, $password, $authMethod)); } /** @@ -290,11 +290,11 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null */ private function setEnterpriseUrl($enterpriseUrl) { - $this->httpClientBuilder->removePlugin(Plugin\AddHostPlugin::class); - $this->httpClientBuilder->removePlugin(PathPrepend::class); + $this->getHttpClientBuilder()->removePlugin(Plugin\AddHostPlugin::class); + $this->getHttpClientBuilder()->removePlugin(PathPrepend::class); - $this->httpClientBuilder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); - $this->httpClientBuilder->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); + $this->getHttpClientBuilder()->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); + $this->getHttpClientBuilder()->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); } /** @@ -313,7 +313,7 @@ public function getApiVersion() */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { - $this->httpClientBuilder->addCache($cachePool, $config); + $this->getHttpClientBuilder()->addCache($cachePool, $config); } /** @@ -321,7 +321,7 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) */ public function removeCache() { - $this->httpClientBuilder->removeCache(); + $this->getHttpClientBuilder()->removeCache(); } /** @@ -353,6 +353,14 @@ public function getLastResponse() */ public function getHttpClient() { - return $this->httpClientBuilder->getHttpClient(); + return $this->getHttpClientBuilder()->getHttpClient(); + } + + /** + * @return Builder + */ + protected function getHttpClientBuilder() + { + return $this->httpClientBuilder; } } diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 60cfefe161a..b9881d5d17e 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -142,15 +142,6 @@ public function removePlugin($fqcn) } } - /** - * @param HttpClient $httpClient - */ - public function setHttpClient(HttpClient $httpClient) - { - $this->httpClientModified = true; - $this->httpClient = $httpClient; - } - /** * Clears used headers. */ diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 7e5fa029b99..f73e4471d63 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api; +use Github\HttpClient\Builder; use ReflectionMethod; abstract class TestCase extends \PHPUnit_Framework_TestCase @@ -23,7 +24,7 @@ protected function getApiMock() ->expects($this->any()) ->method('sendRequest'); - $client = new \Github\Client($httpClient); + $client = new \Github\Client(new Builder($httpClient)); return $this->getMockBuilder($this->getApiClass()) ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 0450c0f8882..54ffbc259cd 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -5,6 +5,7 @@ use Github\Api; use Github\Client; use Github\Exception\BadMethodCallException; +use Github\HttpClient\Builder; use Github\HttpClient\Plugin\Authentication; use Http\Client\Common\Plugin; @@ -23,11 +24,12 @@ public function shouldNotHaveToPassHttpClientToConstructor() /** * @test */ - public function shouldPassHttpClientInterfaceToConstructor() + public function shouldPassHttpClientBulderInterfaceToConstructor() { $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->getMock(); - $client = new Client($httpClientMock); + + $client = new Client(new Builder($httpClientMock)); $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); } @@ -38,17 +40,25 @@ public function shouldPassHttpClientInterfaceToConstructor() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $client = $this->getMockBuilder(\Github\Client::class) + $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) ->setMethods(array('addPlugin', 'removePlugin')) + ->disableOriginalConstructor() ->getMock(); - $client->expects($this->once()) + $builder->expects($this->once()) ->method('addPlugin') ->with($this->equalTo(new Authentication($login, $password, $method))); - - $client->expects($this->once()) + $builder->expects($this->once()) ->method('removePlugin') ->with(Authentication::class); + $client = $this->getMockBuilder(\Github\Client::class) + ->disableOriginalConstructor() + ->setMethods(['getHttpClientBuilder']) + ->getMock(); + $client->expects($this->any()) + ->method('getHttpClientBuilder') + ->willReturn($builder); + $client->authenticate($login, $password, $method); } @@ -68,17 +78,25 @@ public function getAuthenticationFullData() */ public function shouldAuthenticateUsingGivenParameters($token, $method) { - $client = $this->getMockBuilder(\Github\Client::class) + $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) ->setMethods(array('addPlugin', 'removePlugin')) ->getMock(); - $client->expects($this->once()) + $builder->expects($this->once()) ->method('addPlugin') ->with($this->equalTo(new Authentication($token, null, $method))); - $client->expects($this->once()) + $builder->expects($this->once()) ->method('removePlugin') ->with(Authentication::class); + $client = $this->getMockBuilder(\Github\Client::class) + ->disableOriginalConstructor() + ->setMethods(['getHttpClientBuilder']) + ->getMock(); + $client->expects($this->any()) + ->method('getHttpClientBuilder') + ->willReturn($builder); + $client->authenticate($token, $method); } @@ -101,47 +119,6 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet() $client->authenticate('login', null, null); } - /** - * @test - */ - public function shouldClearHeaders() - { - $client = $this->getMockBuilder(\Github\Client::class) - ->setMethods(array('addPlugin', 'removePlugin')) - ->getMock(); - $client->expects($this->once()) - ->method('addPlugin') - ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); - - $client->expects($this->once()) - ->method('removePlugin') - ->with(Plugin\HeaderAppendPlugin::class); - - $client->clearHeaders(); - } - - /** - * @test - */ - public function shouldAddHeaders() - { - $headers = array('header1', 'header2'); - - $client = $this->getMockBuilder(\Github\Client::class) - ->setMethods(array('addPlugin', 'removePlugin')) - ->getMock(); - $client->expects($this->once()) - ->method('addPlugin') - // TODO verify that headers exists - ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); - - $client->expects($this->once()) - ->method('removePlugin') - ->with(Plugin\HeaderAppendPlugin::class); - - $client->addHeaders($headers); - } - /** * @test * @dataProvider getApiClassesProvider diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php new file mode 100644 index 00000000000..4a668f7956c --- /dev/null +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -0,0 +1,55 @@ +getMockBuilder(\Github\HttpClient\Builder::class) + ->setMethods(array('addPlugin', 'removePlugin')) + ->getMock(); + $builder->expects($this->once()) + ->method('addPlugin') + ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); + + $builder->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); + + $builder->clearHeaders(); + } + + + + /** + * @test + */ + public function shouldAddHeaders() + { + $headers = array('header1', 'header2'); + + $client = $this->getMockBuilder(\Github\HttpClient\Builder::class) + ->setMethods(array('addPlugin', 'removePlugin')) + ->getMock(); + $client->expects($this->once()) + ->method('addPlugin') + // TODO verify that headers exists + ->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class)); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); + + $client->addHeaders($headers); + } +} diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 19224b5e4ef..89d7d49cc82 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -6,6 +6,7 @@ use Github\Api\Organization\Members; use Github\Api\Search; use Github\Client; +use Github\HttpClient\Builder; use Github\ResultPager; use Github\Tests\Mock\PaginatedResponse; use Http\Client\HttpClient; @@ -39,7 +40,7 @@ public function shouldGetAllResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = new Client($httpClientMock); + $client = new Client(new Builder($httpClientMock)); // memberApi Mock $memberApi = new Members($client); @@ -86,7 +87,7 @@ public function shouldGetAllSearchResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = new Client($httpClientMock); + $client = new Client(new Builder($httpClientMock)); $searchApi = new Search($client); $method = 'users'; From 715310135edd883bf92a78d1f709ffc583af433e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 15:38:04 +0100 Subject: [PATCH 451/951] Added changelog --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49e6cee0644..32ea8b42bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## 2.0.0-rc5 (UNRELEASED) +### Changed + +First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to +`Github\HttpClient\Builder`. To upgrade you need to change: + + ```php +// Old way does not work: +$github = new Github\Client($httpClient); + +// New way will work: +$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); + + ``` + + ### Added - Support for JWT authentication From f2b1a7740e8b74da25b7a32b0ea161cbcc8e8302 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 15:44:34 +0100 Subject: [PATCH 452/951] Removed support for default headers in the builder --- lib/Github/Client.php | 25 ++++++++++++------------- lib/Github/HttpClient/Builder.php | 22 +--------------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 5fe80066afe..0e43486e388 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -111,17 +111,15 @@ class Client public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); - $this->httpClientBuilder = $httpClientBuilder ?: new Builder(); - $this->getHttpClientBuilder()->addDefaultHeaders([ - 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), - ]); + $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder(); - $this->getHttpClientBuilder()->addPlugin(new GithubExceptionThrower()); - $this->getHttpClientBuilder()->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); - $this->getHttpClientBuilder()->addPlugin(new Plugin\RedirectPlugin()); - $this->getHttpClientBuilder()->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); - $this->getHttpClientBuilder()->addPlugin(new Plugin\HeaderDefaultsPlugin(array( + $builder->addPlugin(new GithubExceptionThrower()); + $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); + $builder->addPlugin(new Plugin\RedirectPlugin()); + $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); + $builder->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', + 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), ))); $this->apiVersion = $apiVersion ?: 'v3'; @@ -290,11 +288,12 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null */ private function setEnterpriseUrl($enterpriseUrl) { - $this->getHttpClientBuilder()->removePlugin(Plugin\AddHostPlugin::class); - $this->getHttpClientBuilder()->removePlugin(PathPrepend::class); + $builder = $this->getHttpClientBuilder(); + $builder->removePlugin(Plugin\AddHostPlugin::class); + $builder->removePlugin(PathPrepend::class); - $this->getHttpClientBuilder()->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); - $this->getHttpClientBuilder()->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); + $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); + $builder->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); } /** diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index b9881d5d17e..930063e9f17 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -72,13 +72,6 @@ class Builder */ private $headers = []; - /** - * Headers that will always be in the client. - * - * @var array - */ - private $defaultHeaders = []; - /** * @param HttpClient $httpClient * @param RequestFactory $requestFactory @@ -147,7 +140,7 @@ public function removePlugin($fqcn) */ public function clearHeaders() { - $this->headers = $this->defaultHeaders; + $this->headers = []; $this->removePlugin(Plugin\HeaderAppendPlugin::class); $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); @@ -164,19 +157,6 @@ public function addHeaders(array $headers) $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); } - /** - * Add default headers. Default headers will not be cleared when calling clearHeaders. - * - * @param array $headers - */ - public function addDefaultHeaders(array $headers) - { - $this->defaultHeaders = array_merge($this->defaultHeaders, $headers); - - $this->removePlugin(Plugin\HeaderAppendPlugin::class); - $this->addPlugin(new Plugin\HeaderAppendPlugin(array_merge($this->defaultHeaders, $this->headers))); - } - /** * Add a cache plugin to cache responses locally. * From 02b38a2ccefa5bc897b4ce1636fd4dc5446f418f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 15:46:10 +0100 Subject: [PATCH 453/951] minor --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 0e43486e388..8caa2ed9bf7 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -123,7 +123,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul ))); $this->apiVersion = $apiVersion ?: 'v3'; - $this->getHttpClientBuilder()->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); + $builder->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); if ($enterpriseUrl) { $this->setEnterpriseUrl($enterpriseUrl); From 3fe4dbc5eff2b908ee01a56c4f47d558cdda2eac Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 15:52:28 +0100 Subject: [PATCH 454/951] Making builder final --- lib/Github/HttpClient/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 930063e9f17..4029fc94f19 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -20,7 +20,7 @@ * * @author Tobias Nyholm */ -class Builder +final class Builder { /** * The object that sends HTTP messages. From 88191f5a550d3341e7215be63998a4713b68b022 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 4 Dec 2016 15:43:59 +0100 Subject: [PATCH 455/951] Updating a user public key is not allowed --- lib/Github/Api/CurrentUser/DeployKeys.php | 21 --------- .../Tests/Api/CurrentUser/DeployKeysTest.php | 47 ------------------- 2 files changed, 68 deletions(-) diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/DeployKeys.php index dc8df79941f..fb64ba73ff1 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/DeployKeys.php @@ -57,27 +57,6 @@ public function create(array $params) return $this->post('/user/keys', $params); } - /** - * Updates deploy key for the authenticated user. - * - * @link http://developer.github.com/v3/repos/keys/ - * - * @param string $id - * @param array $params - * - * @throws \Github\Exception\MissingArgumentException - * - * @return array - */ - public function update($id, array $params) - { - if (!isset($params['title'], $params['key'])) { - throw new MissingArgumentException(array('title', 'key')); - } - - return $this->patch('/user/keys/'.rawurlencode($id), $params); - } - /** * Removes deploy key for the authenticated user. * diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index edbd58991f9..33149397193 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -83,53 +83,6 @@ public function shouldNotCreateKeyWithoutKeyParam() $api->create($data); } - /** - * @test - */ - public function shouldUpdateKey() - { - $expectedValue = array('id' => '123', 'key' => 'ssh-rsa ...'); - $data = array('title' => 'my key', 'key' => 'ssh-rsa ...'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/user/keys/123', $data) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->update(123, $data)); - } - - /** - * @test - * @expectedException \Github\Exception\MissingArgumentException - */ - public function shouldNotUpdateKeyWithoutTitleParam() - { - $data = array('key' => 'ssh-rsa ...'); - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('patch'); - - $api->update(123, $data); - } - - /** - * @test - * @expectedException \Github\Exception\MissingArgumentException - */ - public function shouldNotUpdateKeyWithoutKeyParam() - { - $data = array('title' => 'my key'); - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('patch'); - - $api->update(123, $data); - } - /** * @test */ From bd2dd4148390545fe8b2e3d8b416dfb175363688 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 4 Dec 2016 20:09:39 +0100 Subject: [PATCH 456/951] removed final --- lib/Github/HttpClient/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 4029fc94f19..930063e9f17 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -20,7 +20,7 @@ * * @author Tobias Nyholm */ -final class Builder +class Builder { /** * The object that sends HTTP messages. From 461f27b338dbd1fc0e4e95e21ff3032649271ce4 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 5 Dec 2016 15:48:16 +0100 Subject: [PATCH 457/951] Updating docs for new constructor --- doc/customize.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/customize.md b/doc/customize.md index 9327afb4858..d8c64899373 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -8,11 +8,10 @@ yourself by calling `\Github\Client::setHttpClient`. A HTTP client must implement `Http\Client\HttpClient`. A list of community provided clients is found here: https://packagist.org/providers/php-http/client-implementation -You can inject a HTTP client through `Github\Client#setHttpClient()` method: +You can inject a HTTP client through the `Github\Client` constructor: ```php -$client = new Github\Client(); -$client->setHttpClient(new Http\Adapter\Guzzle6\Client()); +$client = new Github\Client(new \Github\HttpClient\Builder(new Http\Adapter\Guzzle6\Client())); ``` ### Configure the HTTP client From fa4d1d9d712d69a92877bb954373c8f600ba028b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 5 Dec 2016 16:02:46 +0100 Subject: [PATCH 458/951] Updated docs --- doc/api_version.md | 2 +- doc/security.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api_version.md b/doc/api_version.md index a8bc733461b..a4e0d11b282 100644 --- a/doc/api_version.md +++ b/doc/api_version.md @@ -8,6 +8,6 @@ For example: $client = new Github\Client(); echo $client->getApiVersion(); // prints "v3" -$client = new Github\Client($httpClient, 'v2'); +$client = new Github\Client(new Github\HttpClient\Builder(), 'v2'); echo $client->getApiVersion(); // prints "v2" ``` diff --git a/doc/security.md b/doc/security.md index 4da1f1b18a5..b1cf7262ee9 100644 --- a/doc/security.md +++ b/doc/security.md @@ -54,7 +54,7 @@ The following sample code authenticates as an installation using [lcobucci/jwt]( to generate a JSON Web Token (JWT). ```php -$github = new Github\Client(new GuzzleClient(), 'machine-man-preview'); +$github = new Github\Client(new Github\HttpClient\Builder(), 'machine-man-preview'); $jwt = (new Builder) ->setIssuer($integrationId) From 789fe80d891abdaf59621632a1a2d65b0956f232 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 4 Dec 2016 15:28:04 +0100 Subject: [PATCH 459/951] Added missing docs for currentuser public keys --- doc/README.md | 3 ++ doc/currentuser/deploykeys.md | 36 +++++++++++++++++++++++ lib/Github/Api/CurrentUser/DeployKeys.php | 8 ++--- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 doc/currentuser/deploykeys.md diff --git a/doc/README.md b/doc/README.md index 02dd0c2cb5a..93bdf307335 100644 --- a/doc/README.md +++ b/doc/README.md @@ -4,6 +4,9 @@ Navigation APIs: * [Authorizations](authorizations.md) * [Commits](commits.md) +* Current User + * [Deploy keys / Public keys](currentuser/deploykeys.md) + * [Memberships](currentuser/memberships.md) * [Enterprise](enterprise.md) * [Gists](gists.md) * [Comments](gists/comments.md) diff --git a/doc/currentuser/deploykeys.md b/doc/currentuser/deploykeys.md new file mode 100644 index 00000000000..5cfcf82b77e --- /dev/null +++ b/doc/currentuser/deploykeys.md @@ -0,0 +1,36 @@ +## Current user / Public Keys API +[Back to the navigation](../README.md) + +Wraps [GitHub User Public Keys API](https://developer.github.com/v3/users/keys/#public-keys). + +### List your public keys + +```php +$keys = $client->user()->keys()->all(); +``` + +Returns a list of public keys for the authenticated user. + +### Shows a public key for the authenticated user. + +```php +$key = $client->user()->keys()->show(1234); +``` + +### Add a public key to the authenticated user. + +> Requires [authentication](security.md). + +```php +$key = $client->user()->keys()->create(array('title' => 'key title', 'key' => 12345)); +``` + +Adds a key with title 'key title' to the authenticated user and returns a the created key for the user. + +### Remove a public key from the authenticated user. + +> Requires [authentication](security.md). + +```php +$client->user()->keys()->remove(12345); +``` diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/DeployKeys.php index fb64ba73ff1..2d53d1a87a8 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/DeployKeys.php @@ -14,7 +14,7 @@ class DeployKeys extends AbstractApi /** * List deploy keys for the authenticated user. * - * @link http://developer.github.com/v3/repos/keys/ + * @link https://developer.github.com/v3/users/keys/ * * @return array */ @@ -26,7 +26,7 @@ public function all() /** * Shows deploy key for the authenticated user. * - * @link http://developer.github.com/v3/repos/keys/ + * @link https://developer.github.com/v3/users/keys/ * * @param string $id * @@ -40,7 +40,7 @@ public function show($id) /** * Adds deploy key for the authenticated user. * - * @link http://developer.github.com/v3/repos/keys/ + * @link https://developer.github.com/v3/users/keys/ * * @param array $params * @@ -60,7 +60,7 @@ public function create(array $params) /** * Removes deploy key for the authenticated user. * - * @link http://developer.github.com/v3/repos/keys/ + * @link https://developer.github.com/v3/users/keys/ * * @param string $id * From a8f60a1ad93f40c9a8fb8ef329501a01cac33960 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 6 Dec 2016 10:50:35 +0100 Subject: [PATCH 460/951] Style fix --- lib/Github/HttpClient/Builder.php | 4 ++-- test/Github/Tests/HttpClient/BuilderTest.php | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 930063e9f17..f67c2c9dd08 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -15,8 +15,8 @@ use Psr\Cache\CacheItemPoolInterface; /** - * A builder that builds the API client. This will allow you to fluently add and remove - * plugins. + * A builder that builds the API client. + * This will allow you to fluently add and remove plugins. * * @author Tobias Nyholm */ diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php index 4a668f7956c..3643dd292fa 100644 --- a/test/Github/Tests/HttpClient/BuilderTest.php +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -2,12 +2,11 @@ namespace Github\Tests\HttpClient; -use Github\Api; -use Github\Client; -use Github\Exception\BadMethodCallException; -use Github\HttpClient\Plugin\Authentication; use Http\Client\Common\Plugin; +/** + * @author Tobias Nyholm + */ class BuilderTest extends \PHPUnit_Framework_TestCase { /** @@ -29,8 +28,6 @@ public function shouldClearHeaders() $builder->clearHeaders(); } - - /** * @test */ From 511775ac78bb4f5c289f78d36fa805e437cdfb9d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 6 Dec 2016 10:56:05 +0100 Subject: [PATCH 461/951] Added http client to constructor --- lib/Github/Client.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 8caa2ed9bf7..2dbaecdd8ab 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -12,6 +12,7 @@ use Github\HttpClient\Plugin\PathPrepend; use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\Plugin; +use Http\Client\HttpClient; use Http\Discovery\UriFactoryDiscovery; use Psr\Cache\CacheItemPoolInterface; @@ -104,14 +105,15 @@ class Client /** * Instantiate a new GitHub client. * - * @param Builder|null $httpClient - * @param string|null $apiVersion - * @param string|null $enterpriseUrl + * @param HttpClient|null $httpClient + * @param Builder|null $httpClientBuilder If a builder is provided we assume that $httpClient is added to the builder already. + * @param string|null $apiVersion + * @param string|null $enterpriseUrl */ - public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) + public function __construct(HttpClient $httpClient, Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); - $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder(); + $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder($httpClient); $builder->addPlugin(new GithubExceptionThrower()); $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); From c9151873738b23903d735e6cc7f37f80b60c9cef Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 6 Dec 2016 11:20:13 +0100 Subject: [PATCH 462/951] Fixed tests and docs --- doc/api_version.md | 2 +- doc/customize.md | 7 +++++-- doc/security.md | 2 +- lib/Github/Client.php | 2 +- test/Github/Tests/Api/TestCase.php | 2 +- test/Github/Tests/ClientTest.php | 4 ++-- test/Github/Tests/ResultPagerTest.php | 4 ++-- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/api_version.md b/doc/api_version.md index a4e0d11b282..a8bc733461b 100644 --- a/doc/api_version.md +++ b/doc/api_version.md @@ -8,6 +8,6 @@ For example: $client = new Github\Client(); echo $client->getApiVersion(); // prints "v3" -$client = new Github\Client(new Github\HttpClient\Builder(), 'v2'); +$client = new Github\Client($httpClient, 'v2'); echo $client->getApiVersion(); // prints "v2" ``` diff --git a/doc/customize.md b/doc/customize.md index d8c64899373..1e0e0d77071 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -11,7 +11,7 @@ community provided clients is found here: https://packagist.org/providers/php-ht You can inject a HTTP client through the `Github\Client` constructor: ```php -$client = new Github\Client(new \Github\HttpClient\Builder(new Http\Adapter\Guzzle6\Client())); +$client = new Github\Client(new Http\Adapter\Guzzle6\Client()); ``` ### Configure the HTTP client @@ -36,7 +36,10 @@ class CustomUserAgentPlugin implements Plugin } } -$githubClient->addPlugin(new CustomUserAgentPlugin()); +$httpBuilder = new Github\HttpClient\Builder(new Http\Adapter\Guzzle6\Client()); +$httpBuilder->addPlugin(new CustomUserAgentPlugin()); + +$client = new Github\Client(null, $httpBuilder); ``` ### Run Test Suite diff --git a/doc/security.md b/doc/security.md index b1cf7262ee9..4da1f1b18a5 100644 --- a/doc/security.md +++ b/doc/security.md @@ -54,7 +54,7 @@ The following sample code authenticates as an installation using [lcobucci/jwt]( to generate a JSON Web Token (JWT). ```php -$github = new Github\Client(new Github\HttpClient\Builder(), 'machine-man-preview'); +$github = new Github\Client(new GuzzleClient(), 'machine-man-preview'); $jwt = (new Builder) ->setIssuer($integrationId) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 2dbaecdd8ab..bddddd7d1ca 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -110,7 +110,7 @@ class Client * @param string|null $apiVersion * @param string|null $enterpriseUrl */ - public function __construct(HttpClient $httpClient, Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) + public function __construct(HttpClient $httpClient = null, Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder($httpClient); diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index f73e4471d63..1ffa48b6e56 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -24,7 +24,7 @@ protected function getApiMock() ->expects($this->any()) ->method('sendRequest'); - $client = new \Github\Client(new Builder($httpClient)); + $client = new \Github\Client($httpClient); return $this->getMockBuilder($this->getApiClass()) ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 54ffbc259cd..201ceea9eb6 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -24,12 +24,12 @@ public function shouldNotHaveToPassHttpClientToConstructor() /** * @test */ - public function shouldPassHttpClientBulderInterfaceToConstructor() + public function shouldPassHttpClientInterfaceToConstructor() { $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->getMock(); - $client = new Client(new Builder($httpClientMock)); + $client = new Client($httpClientMock); $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 89d7d49cc82..17ae88438f2 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -40,7 +40,7 @@ public function shouldGetAllResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = new Client(new Builder($httpClientMock)); + $client = new Client($httpClientMock); // memberApi Mock $memberApi = new Members($client); @@ -87,7 +87,7 @@ public function shouldGetAllSearchResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = new Client(new Builder($httpClientMock)); + $client = new Client($httpClientMock); $searchApi = new Search($client); $method = 'users'; From 3160b9c500a7da4adbd9102aeaab75439161cb7b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 6 Dec 2016 12:55:38 +0100 Subject: [PATCH 463/951] Adding a factory class --- doc/api_version.md | 2 +- doc/customize.md | 4 ++-- doc/security.md | 3 ++- lib/Github/Client.php | 25 +++++++++++++++++++------ test/Github/Tests/Api/TestCase.php | 2 +- test/Github/Tests/ClientTest.php | 2 +- test/Github/Tests/ResultPagerTest.php | 4 ++-- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/doc/api_version.md b/doc/api_version.md index a8bc733461b..c8cbfdde2ae 100644 --- a/doc/api_version.md +++ b/doc/api_version.md @@ -8,6 +8,6 @@ For example: $client = new Github\Client(); echo $client->getApiVersion(); // prints "v3" -$client = new Github\Client($httpClient, 'v2'); +$client = new Github\Client(new Github\HttpClient\Builder($httpClient), 'v2'); echo $client->getApiVersion(); // prints "v2" ``` diff --git a/doc/customize.md b/doc/customize.md index 1e0e0d77071..ccfb120766c 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -11,7 +11,7 @@ community provided clients is found here: https://packagist.org/providers/php-ht You can inject a HTTP client through the `Github\Client` constructor: ```php -$client = new Github\Client(new Http\Adapter\Guzzle6\Client()); +$client = Github\Client::createFromHttpClient(new Http\Adapter\Guzzle6\Client()); ``` ### Configure the HTTP client @@ -39,7 +39,7 @@ class CustomUserAgentPlugin implements Plugin $httpBuilder = new Github\HttpClient\Builder(new Http\Adapter\Guzzle6\Client()); $httpBuilder->addPlugin(new CustomUserAgentPlugin()); -$client = new Github\Client(null, $httpBuilder); +$client = new Github\Client($httpBuilder); ``` ### Run Test Suite diff --git a/doc/security.md b/doc/security.md index 4da1f1b18a5..e31adce4f8d 100644 --- a/doc/security.md +++ b/doc/security.md @@ -54,7 +54,8 @@ The following sample code authenticates as an installation using [lcobucci/jwt]( to generate a JSON Web Token (JWT). ```php -$github = new Github\Client(new GuzzleClient(), 'machine-man-preview'); +$builder = new Github\HttpClient\Builder(new GuzzleClient()); +$github = new Github\Client($builder, 'machine-man-preview'); $jwt = (new Builder) ->setIssuer($integrationId) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index bddddd7d1ca..f6935a0c284 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -105,15 +105,14 @@ class Client /** * Instantiate a new GitHub client. * - * @param HttpClient|null $httpClient - * @param Builder|null $httpClientBuilder If a builder is provided we assume that $httpClient is added to the builder already. - * @param string|null $apiVersion - * @param string|null $enterpriseUrl + * @param Builder|null $httpClientBuilder + * @param string|null $apiVersion + * @param string|null $enterpriseUrl */ - public function __construct(HttpClient $httpClient = null, Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) + public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); - $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder($httpClient); + $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder(); $builder->addPlugin(new GithubExceptionThrower()); $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); @@ -132,6 +131,20 @@ public function __construct(HttpClient $httpClient = null, Builder $httpClientBu } } + /** + * Create a Github\Client using a HttpClient. + * + * @param HttpClient $httpClient + * + * @return Client + */ + public static function createFromHttpClient(HttpClient $httpClient) + { + $builder = new Builder($httpClient); + + return new self($builder); + } + /** * @param string $name * diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index 1ffa48b6e56..c79ef3f0115 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -24,7 +24,7 @@ protected function getApiMock() ->expects($this->any()) ->method('sendRequest'); - $client = new \Github\Client($httpClient); + $client = \Github\Client::createFromHttpClient($httpClient); return $this->getMockBuilder($this->getApiClass()) ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 201ceea9eb6..90befbfb760 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -29,7 +29,7 @@ public function shouldPassHttpClientInterfaceToConstructor() $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->getMock(); - $client = new Client($httpClientMock); + $client = Client::createFromHttpClient($httpClientMock); $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 17ae88438f2..8cfa039bb9b 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -40,7 +40,7 @@ public function shouldGetAllResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = new Client($httpClientMock); + $client = \Github\Client::createFromHttpClient($httpClientMock); // memberApi Mock $memberApi = new Members($client); @@ -87,7 +87,7 @@ public function shouldGetAllSearchResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = new Client($httpClientMock); + $client = \Github\Client::createFromHttpClient($httpClientMock); $searchApi = new Search($client); $method = 'users'; From 38ceb9795abb31c6e1f4d7494a616486ac8aaebe Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 6 Dec 2016 12:58:55 +0100 Subject: [PATCH 464/951] Updated changelog --- CHANGELOG.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32ea8b42bd8..91fafb9d6c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,17 +8,16 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to -`Github\HttpClient\Builder`. To upgrade you need to change: +`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: - ```php +```php // Old way does not work: $github = new Github\Client($httpClient); // New way will work: $github = new Github\Client(new Github\HttpClient\Builder($httpClient)); - - ``` - +$github = Github\Client::createFromHttpClient($httpClient); +``` ### Added From ee64ec5126af300c7b905d4f116f0740a3ab20e8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 6 Dec 2016 21:03:09 +0100 Subject: [PATCH 465/951] Use correct parameter name for organisation/teams api --- lib/Github/Api/Organization/Teams.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 47208c6d0de..b6b0b72eb5e 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -78,22 +78,22 @@ public function repositories($team) return $this->get('/teams/'.rawurlencode($team).'/repos'); } - public function repository($team, $username, $repository) + public function repository($team, $organization, $repository) { - return $this->get('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository)); } - public function addRepository($team, $username, $repository, $params = array()) + public function addRepository($team, $organization, $repository, $params = array()) { if (isset($params['permission']) && !in_array($params['permission'], array('pull', 'push', 'admin'))) { $params['permission'] = 'pull'; } - return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository), $params); + return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository), $params); } - public function removeRepository($team, $username, $repository) + public function removeRepository($team, $organization, $repository) { - return $this->delete('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository)); } } From 2b51e107aba132e855a6f7c01afebda59ffc3c9a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 6 Dec 2016 20:46:49 +0100 Subject: [PATCH 466/951] Use same default sort as github api does --- lib/Github/Api/Issue/Milestones.php | 4 ++-- test/Github/Tests/Api/Issue/MilestonesTest.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 87563da7abc..c7ac0f4bd3f 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -30,14 +30,14 @@ public function all($username, $repository, array $params = array()) $params['sort'] = 'due_date'; } if (isset($params['direction']) && !in_array($params['direction'], array('asc', 'desc'))) { - $params['direction'] = 'desc'; + $params['direction'] = 'asc'; } return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array( 'page' => 1, 'state' => 'open', 'sort' => 'due_date', - 'direction' => 'desc' + 'direction' => 'asc' ), $params)); } diff --git a/test/Github/Tests/Api/Issue/MilestonesTest.php b/test/Github/Tests/Api/Issue/MilestonesTest.php index 363a47fb546..74f7b50fcda 100644 --- a/test/Github/Tests/Api/Issue/MilestonesTest.php +++ b/test/Github/Tests/Api/Issue/MilestonesTest.php @@ -16,7 +16,7 @@ public function shouldGetMilestones() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -132,7 +132,7 @@ public function shouldSortByDueDateWhenSortParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('sort' => 'completenes'))); @@ -148,7 +148,7 @@ public function shouldSetStateToOpenWhenStateParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('state' => 'clos'))); @@ -164,10 +164,10 @@ public function shouldSetDirectionToDescWhenDirectionParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc')) + ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('direction' => 'des'))); + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('direction' => 'asc'))); } /** From 0efb5938bfb774046ee6eb9ebba6e2cdc7b5ee36 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 7 Dec 2016 11:04:33 +0100 Subject: [PATCH 467/951] Renamed to createWithHttpClient --- CHANGELOG.md | 2 +- doc/customize.md | 2 +- lib/Github/Client.php | 2 +- test/Github/Tests/Api/TestCase.php | 2 +- test/Github/Tests/ClientTest.php | 2 +- test/Github/Tests/ResultPagerTest.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91fafb9d6c6..4118197589e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ $github = new Github\Client($httpClient); // New way will work: $github = new Github\Client(new Github\HttpClient\Builder($httpClient)); -$github = Github\Client::createFromHttpClient($httpClient); +$github = Github\Client::createWithHttpClient($httpClient); ``` ### Added diff --git a/doc/customize.md b/doc/customize.md index ccfb120766c..8d7536e0e91 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -11,7 +11,7 @@ community provided clients is found here: https://packagist.org/providers/php-ht You can inject a HTTP client through the `Github\Client` constructor: ```php -$client = Github\Client::createFromHttpClient(new Http\Adapter\Guzzle6\Client()); +$client = Github\Client::createWithHttpClient(new Http\Adapter\Guzzle6\Client()); ``` ### Configure the HTTP client diff --git a/lib/Github/Client.php b/lib/Github/Client.php index f6935a0c284..9ead7faf2b6 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -138,7 +138,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul * * @return Client */ - public static function createFromHttpClient(HttpClient $httpClient) + public static function createWithHttpClient(HttpClient $httpClient) { $builder = new Builder($httpClient); diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index c79ef3f0115..c15228e63bb 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -24,7 +24,7 @@ protected function getApiMock() ->expects($this->any()) ->method('sendRequest'); - $client = \Github\Client::createFromHttpClient($httpClient); + $client = \Github\Client::createWithHttpClient($httpClient); return $this->getMockBuilder($this->getApiClass()) ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 90befbfb760..b08531aa7ae 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -29,7 +29,7 @@ public function shouldPassHttpClientInterfaceToConstructor() $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) ->getMock(); - $client = Client::createFromHttpClient($httpClientMock); + $client = Client::createWithHttpClient($httpClientMock); $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 8cfa039bb9b..ee79058e79a 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -40,7 +40,7 @@ public function shouldGetAllResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = \Github\Client::createFromHttpClient($httpClientMock); + $client = \Github\Client::createWithHttpClient($httpClientMock); // memberApi Mock $memberApi = new Members($client); @@ -87,7 +87,7 @@ public function shouldGetAllSearchResults() ->method('sendRequest') ->will($this->returnValue($response)); - $client = \Github\Client::createFromHttpClient($httpClientMock); + $client = \Github\Client::createWithHttpClient($httpClientMock); $searchApi = new Search($client); $method = 'users'; From d7cde53253333f203dbc67962de1f08496414bbb Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 7 Dec 2016 15:07:06 +0100 Subject: [PATCH 468/951] Updated changelog --- CHANGELOG.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4118197589e..bd1436f000d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,20 +5,6 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## 2.0.0-rc5 (UNRELEASED) -### Changed - -First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to -`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: - -```php -// Old way does not work: -$github = new Github\Client($httpClient); - -// New way will work: -$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); -$github = Github\Client::createWithHttpClient($httpClient); -``` - ### Added - Support for JWT authentication @@ -32,6 +18,18 @@ $github = Github\Client::createWithHttpClient($httpClient); ### Changed - `ApiLimitExceedException::__construct` has a new second parameter for the remaining API calls. +- First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to +`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: + +```php +// Old way does not work: +$github = new Github\Client($httpClient); + +// New way will work: +$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); +$github = Github\Client::createWithHttpClient($httpClient); +``` + ## 2.0.0-rc4 From 706ba5d8496a8f7db4e7b2041129d31bca03b3c8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 6 Dec 2016 13:57:21 +0100 Subject: [PATCH 469/951] Renamed deploykeys class to reflect to github api name --- CHANGELOG.md | 2 +- doc/README.md | 2 +- doc/currentuser/{deploykeys.md => publickeys.md} | 0 lib/Github/Api/CurrentUser.php | 6 +++--- .../Api/CurrentUser/{DeployKeys.php => PublicKeys.php} | 2 +- test/Github/Tests/Api/CurrentUser/DeployKeysTest.php | 2 +- test/Github/Tests/Api/CurrentUserTest.php | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) rename doc/currentuser/{deploykeys.md => publickeys.md} (100%) rename lib/Github/Api/CurrentUser/{DeployKeys.php => PublicKeys.php} (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd1436f000d..080fbee39ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ $github = new Github\Client($httpClient); $github = new Github\Client(new Github\HttpClient\Builder($httpClient)); $github = Github\Client::createWithHttpClient($httpClient); ``` - +- Renamed the currentuser `DeployKeys` api class to `PublicKeys` to reflect to github api name. ## 2.0.0-rc4 diff --git a/doc/README.md b/doc/README.md index 93bdf307335..d74f2d32594 100644 --- a/doc/README.md +++ b/doc/README.md @@ -5,7 +5,7 @@ APIs: * [Authorizations](authorizations.md) * [Commits](commits.md) * Current User - * [Deploy keys / Public keys](currentuser/deploykeys.md) + * [Public keys](currentuser/publickeys.md) * [Memberships](currentuser/memberships.md) * [Enterprise](enterprise.md) * [Gists](gists.md) diff --git a/doc/currentuser/deploykeys.md b/doc/currentuser/publickeys.md similarity index 100% rename from doc/currentuser/deploykeys.md rename to doc/currentuser/publickeys.md diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index bbaea2daafb..dc2a877d7e3 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -2,7 +2,7 @@ namespace Github\Api; -use Github\Api\CurrentUser\DeployKeys; +use Github\Api\CurrentUser\PublicKeys; use Github\Api\CurrentUser\Emails; use Github\Api\CurrentUser\Followers; use Github\Api\CurrentUser\Memberships; @@ -64,11 +64,11 @@ public function issues(array $params = array(), $includeOrgIssues = true) } /** - * @return DeployKeys + * @return PublicKeys */ public function keys() { - return new DeployKeys($this->client); + return new PublicKeys($this->client); } /** diff --git a/lib/Github/Api/CurrentUser/DeployKeys.php b/lib/Github/Api/CurrentUser/PublicKeys.php similarity index 97% rename from lib/Github/Api/CurrentUser/DeployKeys.php rename to lib/Github/Api/CurrentUser/PublicKeys.php index 2d53d1a87a8..418e78b8639 100644 --- a/lib/Github/Api/CurrentUser/DeployKeys.php +++ b/lib/Github/Api/CurrentUser/PublicKeys.php @@ -9,7 +9,7 @@ * @link http://developer.github.com/v3/users/keys/ * @author Joseph Bielawski */ -class DeployKeys extends AbstractApi +class PublicKeys extends AbstractApi { /** * List deploy keys for the authenticated user. diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index 33149397193..bb03fa70339 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -104,6 +104,6 @@ public function shouldRemoveKey() */ protected function getApiClass() { - return \Github\Api\CurrentUser\DeployKeys::class; + return \Github\Api\CurrentUser\PublicKeys::class; } } diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index c062494179f..355c0498538 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -91,7 +91,7 @@ public function shouldGetDeployKeysApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf(\Github\Api\CurrentUser\DeployKeys::class, $api->keys()); + $this->assertInstanceOf(\Github\Api\CurrentUser\PublicKeys::class, $api->keys()); } /** From 97b41148ca201b4dc0dea97703ba275f5836efb9 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Sat, 10 Dec 2016 21:45:19 +0200 Subject: [PATCH 470/951] my repositories added --- CHANGELOG.md | 1 + lib/Github/Api/User.php | 25 ++++++++++++------------- test/Github/Tests/Api/UserTest.php | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49e6cee0644..70cd9c67047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - API for Repo\Cards - API for Repo\Columns - API for Repo\Projects +- API for User\MyRepositories - Methods in Repo API for frequency and participation ### Changed diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index a7f0f849817..b5003667dac 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -145,11 +145,9 @@ public function subscriptions($username) } /** - * @deprecated use repos($username, $options) instead + * List public repositories for the specified user. * - * Get the repositories of a user. - * - * @link http://developer.github.com/v3/repos/ + * @link https://developer.github.com/v3/repos/#list-user-repositories * * @param string $username the username * @param string $type role in the repository @@ -160,24 +158,25 @@ public function subscriptions($username) */ public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->repos($username, array( + return $this->get('/users/'.rawurlencode($username).'/repos', [ 'type' => $type, 'sort' => $sort, - 'direction' => $direction - )); + 'direction' => $direction, + ]); } /** - * @param null $username - * @param array $options + * List repositories that are accessible to the authenticated user. + * + * @link https://developer.github.com/v3/repos/#list-your-repositories + * + * @param array $params visibility, affiliation, type, sort, direction * * @return array list of the user repositories */ - public function repos($username = null, array $options = array()) + public function myRepositories(array $params = []) { - $url = $username ? '/users/'.rawurldecode($username).'/repos' : '/user/repos'; - - return $this->get($url, $options); + return $this->get('/user/repos', $params); } /** diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 711c50ecba6..99b32c8ac52 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -145,6 +145,21 @@ public function shouldGetUserRepositories() $this->assertEquals($expectedArray, $api->repositories('l3l0')); } + /** + * @test + */ + public function shouldGetMyRepositories() + { + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get')->with('/user/repos', []) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->myRepositories()); + } + /** * @test */ From 0bce4dc2331e823bff29c2efc85d647bb254efc1 Mon Sep 17 00:00:00 2001 From: Yevhenii Huselietov Date: Mon, 12 Dec 2016 02:58:51 +0800 Subject: [PATCH 471/951] Not rc, but 2.0 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e63b8fd6756..7b2216c1154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 2.0.0-rc5 (UNRELEASED) +## 2.0.0 ### Added From d78b022569360ff65230a1e0236b7e7f785936c6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 11 Dec 2016 20:16:22 +0000 Subject: [PATCH 472/951] Fixed method docs and routing to organization projects --- lib/Github/Client.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 9ead7faf2b6..9b215aa00a4 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -34,6 +34,10 @@ * @method Api\Notification notifications() * @method Api\Organization organization() * @method Api\Organization organizations() + * @method Api\Organization\Projects orgProject() + * @method Api\Organization\Projects orgProjects() + * @method Api\Organization\Projects organizationProject() + * @method Api\Organization\Projects organizationProjects() * @method Api\PullRequest pr() * @method Api\PullRequest pullRequest() * @method Api\PullRequest pullRequests() @@ -206,9 +210,13 @@ public function api($name) $api = new Api\Organization($this); break; case 'org_project': + case 'orgProject': case 'org_projects': + case 'orgProjects': case 'organization_project': + case 'organizationProject': case 'organization_projects': + case 'organizationProjects': $api = new Api\Organization\Projects($this); break; From b37b3e8230ad18b170e99d11bb6a5e81c667cf20 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 12 Dec 2016 01:56:32 +0100 Subject: [PATCH 473/951] Remove Accept form default plugin --- lib/Github/Client.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 9ead7faf2b6..fac034c0755 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -120,7 +120,6 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); $builder->addPlugin(new Plugin\HeaderDefaultsPlugin(array( 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', - 'Accept' => sprintf('application/vnd.github.%s+json', $this->getApiVersion()), ))); $this->apiVersion = $apiVersion ?: 'v3'; From 893908ed277d483775ebb09f8cf504537d925c89 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 20 Dec 2016 15:59:53 +0100 Subject: [PATCH 474/951] Add support for retrieving a single notification info using his ID (#489) * Add support for retrieving a single notification info using his ID * Syntax * StyleCI * Apply fixes from StyleCI * Fix input type * Fix as said * Apply fixes from StyleCI * Remove undocumented * Add documentation --- doc/notification.md | 7 +++++++ lib/Github/Api/Notification.php | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/notification.md b/doc/notification.md index d586b364c74..b47c1d5f7c3 100644 --- a/doc/notification.md +++ b/doc/notification.md @@ -36,3 +36,10 @@ $client->api('notification')->markRead(new DateTime('2015/01/01')); ``` Marks all notifications as read up until the current date, unless a date is given + +## Get a single notification using his ID + +```php +$client->api('notification')->id($id); +``` +Retrieves single notification data using his ID. diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index d7a1be66555..e8d5d8f7810 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -57,4 +57,15 @@ public function markRead(DateTime $since = null) $this->put('/notifications', $parameters); } + /** + * Gets a single notification using his ID + * + * @link https://developer.github.com/v3/activity/notifications/#view-a-single-thread + * + * @param int $id + */ + public function id($id) + { + return $this->get('/notifications/threads/'.$id); + } } From 39118bd808e037f7e4b6188f39b969bc1df7f410 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Wed, 21 Dec 2016 13:25:46 +0100 Subject: [PATCH 475/951] Add tests for notification by id (#490) * Add tests for notification by id --- test/Github/Tests/Api/NotificationTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index 70cec8e31c9..0f2616996e2 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -96,6 +96,17 @@ public function shouldMarkNotificationsAsReadForGivenDate() $api->markRead($since); } + + public function shouldGetNotification() + { + $id = mt_rand(1, time()); + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/notification/'.$id); + + $api->id($id); + } /** * @return string From ac3f4c5812f89517544cdfa330fa89c3f5e8d78b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 12 Jan 2017 09:16:14 +0100 Subject: [PATCH 476/951] Adding docs how to write tests --- doc/README.md | 3 +- doc/customize.md | 10 +------ doc/testing.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 doc/testing.md diff --git a/doc/README.md b/doc/README.md index d74f2d32594..8cffeaaff07 100644 --- a/doc/README.md +++ b/doc/README.md @@ -40,4 +40,5 @@ Additional features: * [Pagination support](result_pager.md) * [Authentication & Security](security.md) * [Request any Route](request_any_route.md) -* [Customize `php-github-api` and testing](customize.md) +* [Customize `php-github-api`](customize.md) +* [Running and writing tests](testing.md) diff --git a/doc/customize.md b/doc/customize.md index 8d7536e0e91..f25f4e40dc8 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -1,4 +1,4 @@ -## Customize `php-github-api` and testing +## Customize `php-github-api` [Back to the navigation](README.md) @@ -41,11 +41,3 @@ $httpBuilder->addPlugin(new CustomUserAgentPlugin()); $client = new Github\Client($httpBuilder); ``` - -### Run Test Suite - -The code is unit tested, there are also some functional tests. To run tests on your machine, from a CLI, run - -```bash -$ phpunit -``` diff --git a/doc/testing.md b/doc/testing.md new file mode 100644 index 00000000000..ec2effb3b5c --- /dev/null +++ b/doc/testing.md @@ -0,0 +1,73 @@ +## Running and writing tests +[Back to the navigation](README.md) + + +### Run Test Suite + +The code is unit tested, there are also some functional tests. To run tests on +your machine, from a CLI, run + +```bash +$ composer update +$ phpunit +``` + +### Write tests + +It is always great if someone wants to contribute and extend the functionality of +the API client. But all new features must be properly tested. To test a new API +function, one should test its communication with the HTTP client. The code should +never make an actual call to Github. Testing could easily be done with mocking. + +If you want to write test for the function that shows you comments to a gist. + +```php +class Comments extends AbstractApi +{ + // ... + public function show($gist, $comment) + { + return $this->get('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + } +} +``` + +The test will look like this: + +```php +use Github\Tests\Api\TestCase; + +class CommentsTest extends TestCase +{ + // ... + + /** + * @test + */ + public function shouldShowGistComment() + { + // Create a variable with the "Server response". + $expectedValue = array('comment1'); + + // Get the API mock (see "getApiClass" below). + $api = $this->getApiMock(); + + $api->expects($this->once()) // Expect one call + ->method('get') // A GET request + ->with('/gists/123/comments/456') // URI should be "/gists/123/comments/456" + ->will($this->returnValue($expectedValue)); // Should return the "Server response" + + // Call Comments::show + $result = $api->show(123, 456); + + // Verify that the result is the "Server response" as we expect. + $this->assertEquals($expectedValue, $result); + } + + protected function getApiClass() + { + // Tell the "getAPIMock" what class to mock. + return \Github\Api\Gist\Comments::class; + } +} +``` From fea608b00e273b3965b3e30a2c274f1120cf34f3 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sat, 14 Jan 2017 12:38:18 +0100 Subject: [PATCH 477/951] Add a function to get user organizations --- lib/Github/Api/User.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index b5003667dac..9693f8e2c74 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -71,6 +71,17 @@ public function organizations($username) return $this->get('/users/'.rawurlencode($username).'/orgs'); } + /** + * Get user organizations + * + * @link https://developer.github.com/v3/orgs/#list-your-organizations + * + * @return array information about organizations that authenticated user belongs to + */ + public function orgs($username) + { + return $this->get('/user/orgs'); + } /** * Request the users that a specific user is following. * From db686b64b7fe54095049b45d4cf974c6d357fdbb Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sat, 14 Jan 2017 12:39:22 +0100 Subject: [PATCH 478/951] Cleanup --- lib/Github/Api/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 9693f8e2c74..65702296f5e 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -78,7 +78,7 @@ public function organizations($username) * * @return array information about organizations that authenticated user belongs to */ - public function orgs($username) + public function orgs() { return $this->get('/user/orgs'); } From 3a78482f7eb86aa20d53f46b30404cf34a491141 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sat, 14 Jan 2017 12:40:58 +0100 Subject: [PATCH 479/951] Add tests for orgs() --- test/Github/Tests/Api/UserTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 99b32c8ac52..62d14ad95e9 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -42,7 +42,25 @@ public function shouldGetUserOrganizations() $this->assertEquals($expectedArray, $api->organizations('l3l0')); } +public function shouldGetUserOrgs() + { + $expectedArray = array(array( + 'id' => 202732, + 'url' => 'https://api.github.com/orgs/KnpLabs', + 'repos_url' => 'https://api.github.com/orgs/KnpLabs/repos', + 'events_url' => 'https://api.github.com/orgs/KnpLabs/events', + 'members_url' => 'https://api.github.com/orgs/KnpLabs/members{/member}', + 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}' + )); + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/orgs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->orgs()); + } /** * @test */ From 4919340974c78387d85c7635ded39e76ed3737b6 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sat, 14 Jan 2017 11:41:03 +0000 Subject: [PATCH 480/951] Apply fixes from StyleCI [ci skip] [skip ci] --- test/Github/Tests/Api/UserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 62d14ad95e9..19f2e380e29 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -42,7 +42,7 @@ public function shouldGetUserOrganizations() $this->assertEquals($expectedArray, $api->organizations('l3l0')); } -public function shouldGetUserOrgs() + public function shouldGetUserOrgs() { $expectedArray = array(array( 'id' => 202732, From 08b2a34f6a1423de45b77dadd95856ee14030cd0 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 23 Jan 2017 18:37:47 +0100 Subject: [PATCH 481/951] Create GraphQL.php --- lib/Github/Api/GraphQL.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/Github/Api/GraphQL.php diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php new file mode 100644 index 00000000000..091f87fce34 --- /dev/null +++ b/lib/Github/Api/GraphQL.php @@ -0,0 +1,23 @@ + + */ +class GraphQL extends AbstractApi +{ + /** + * @param string $query + * + * @return array + */ + public function graphql($query) + { + $params = array( + 'query' => $query + ); + return $this->post('/graphql', $params); + } +} From 3a1dd27dabd51d667d9d4cbc46984a9de033f5e9 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 23 Jan 2017 17:37:51 +0000 Subject: [PATCH 482/951] Apply fixes from StyleCI [ci skip] [skip ci] --- lib/Github/Api/GraphQL.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 091f87fce34..4adb0731540 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -1,5 +1,6 @@ $query ); + return $this->post('/graphql', $params); } } From abac0563dd2ead80988f3a18f0b59fbddff9c8a3 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 23 Jan 2017 18:39:23 +0100 Subject: [PATCH 483/951] Update Client.php --- lib/Github/Client.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index eb7f3e727dd..ecb94f971de 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -54,6 +54,7 @@ * @method Api\Authorizations authorization() * @method Api\Authorizations authorizations() * @method Api\Meta meta() + * @method Api\GraphQL graphql() * * @author Joseph Bielawski * @@ -267,6 +268,9 @@ public function api($name) case 'meta': $api = new Api\Meta($this); break; + case 'graphql': + $api = new Api\GraphQL($this); + break; default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); From a79b2b3d4a373969c93511d0e58c32b90eb45982 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Wed, 25 Jan 2017 19:40:31 +0100 Subject: [PATCH 484/951] Syntax --- lib/Github/Api/GraphQL.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 4adb0731540..a17d43cacb0 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -1,4 +1,5 @@ Date: Thu, 26 Jan 2017 09:35:09 +0100 Subject: [PATCH 485/951] Fix links --- lib/Github/Api/GraphQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index a17d43cacb0..df150a17381 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -5,7 +5,7 @@ /** * GraphQL API. * - * @link http://developer.github.com/v3/markdown/ + * @link https://developer.github.com/early-access/graphql/ * @author Miguel Piedrafita */ class GraphQL extends AbstractApi From 25d30c1375d75509d6f48b235114dd383dc9192f Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 09:36:28 +0100 Subject: [PATCH 486/951] Add Early Access note --- lib/Github/Api/GraphQL.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index df150a17381..9b507ee634d 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -5,6 +5,7 @@ /** * GraphQL API. * + * Part of the Github API Early-Access Program * @link https://developer.github.com/early-access/graphql/ * @author Miguel Piedrafita */ From d31ef0b4eb2a22e21f46c1b32a6a175712ac1511 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 09:47:53 +0100 Subject: [PATCH 487/951] Add Test --- test/Github/Tests/Api/GraphQLTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/Github/Tests/Api/GraphQLTest.php diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php new file mode 100644 index 00000000000..37840a60cc7 --- /dev/null +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -0,0 +1,25 @@ +class GraphQLTest extends TestCase +{ + // ... + + /** + * @test + */ + public function shouldShowGistComment() + { + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('post') + ->with('/graphql', 'bar') + ->will($this->returnValue('foo')); + + $result = $api->graphql('bar'); + $this->assertEquals('foo', $result); + } + + protected function getApiClass() + { + return \Github\Api\GraphQL::class; + } +} From eb43204c0e0b90be74e59adb494bd42a1210bfb9 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 09:51:11 +0100 Subject: [PATCH 488/951] Change function name --- lib/Github/Api/GraphQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 9b507ee634d..59fef2827bd 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -16,7 +16,7 @@ class GraphQL extends AbstractApi * * @return array */ - public function graphql($query) + public function execute($query) { $params = array( 'query' => $query From e9f57e65f49fea07eb2123c61fd70b5279f590ab Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 09:51:49 +0100 Subject: [PATCH 489/951] Change function name --- test/Github/Tests/Api/GraphQLTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index 37840a60cc7..40968c1a30b 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -14,7 +14,7 @@ public function shouldShowGistComment() ->with('/graphql', 'bar') ->will($this->returnValue('foo')); - $result = $api->graphql('bar'); + $result = $api->execute('bar'); $this->assertEquals('foo', $result); } From 0be9dc1995611e56cc03327215b0784fe7fb196a Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 10:08:54 +0100 Subject: [PATCH 490/951] Whitespace --- lib/Github/Api/GraphQL.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 59fef2827bd..90974015463 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -6,6 +6,7 @@ * GraphQL API. * * Part of the Github API Early-Access Program + * * @link https://developer.github.com/early-access/graphql/ * @author Miguel Piedrafita */ From 222e7755aa1db0c0813ccf7488456df3d432c0f6 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 10:10:35 +0100 Subject: [PATCH 491/951] Updates --- test/Github/Tests/Api/GraphQLTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index 40968c1a30b..ed57b408a1d 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -1,11 +1,13 @@ +getApiMock(); From 9f309889342d846d630e16253e71a207e4b6954a Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 10:12:07 +0100 Subject: [PATCH 492/951] Add Namespace --- test/Github/Tests/Api/GraphQLTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index ed57b408a1d..ebd9bf2bd40 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -1,5 +1,7 @@ Date: Thu, 26 Jan 2017 10:13:12 +0100 Subject: [PATCH 493/951] Format --- test/Github/Tests/Api/GraphQLTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index ebd9bf2bd40..c05de99fb25 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -4,11 +4,11 @@ class GraphQLTest extends TestCase { - // GraphQL Tests /** * @test */ + public function shouldTestGraphQL() { $api = $this->getApiMock(); From 21138e65b8cd9db717fad2736d76c17f9e2a0e95 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 26 Jan 2017 10:50:54 +0100 Subject: [PATCH 494/951] Fix Tests --- test/Github/Tests/Api/GraphQLTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index c05de99fb25..c209a733b75 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -8,14 +8,13 @@ class GraphQLTest extends TestCase /** * @test */ - public function shouldTestGraphQL() { $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/graphql', 'bar') + ->with($this->equalTo('/graphql'), $this->equalTo(['query'=>'bar'])) ->will($this->returnValue('foo')); $result = $api->execute('bar'); From 457d0ad2493a44d7371fa32eca9b24274b0b252b Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 27 Jan 2017 10:51:57 +0100 Subject: [PATCH 495/951] Removed extra slash after enterprise URL This will fix #511 --- lib/Github/Client.php | 2 +- test/Github/Tests/ClientTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index eb7f3e727dd..adf84c03cf9 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -315,7 +315,7 @@ private function setEnterpriseUrl($enterpriseUrl) $builder->removePlugin(PathPrepend::class); $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); - $builder->addPlugin(new PathPrepend(sprintf('/api/%s/', $this->getApiVersion()))); + $builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion()))); } /** diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index b08531aa7ae..8f10c4ca8d9 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -7,7 +7,10 @@ use Github\Exception\BadMethodCallException; use Github\HttpClient\Builder; use Github\HttpClient\Plugin\Authentication; +use GuzzleHttp\Psr7\Response; use Http\Client\Common\Plugin; +use Http\Client\HttpClient; +use Psr\Http\Message\RequestInterface; class ClientTest extends \PHPUnit_Framework_TestCase { @@ -205,4 +208,25 @@ public function getApiClassesProvider() array('meta', Api\Meta::class) ); } + + /** + * Make sure that the URL is correct when using enterprise. + */ + public function testEnterpriseUrl() + { + $httpClientMock = $this->getMockBuilder(HttpClient::class) + ->setMethods(['sendRequest']) + ->getMock(); + + $httpClientMock->expects($this->once()) + ->method('sendRequest') + ->with($this->callback(function(RequestInterface $request) { + return (string) $request->getUri() === 'https://foobar.com/api/v3/enterprise/stats/all'; + })) + ->willReturn(new Response(200, [], '[]')); + + $httpClientBuilder = new Builder($httpClientMock); + $client = new Client($httpClientBuilder, null, 'https://foobar.com'); + $client->enterprise()->stats()->show('all'); + } } From 2a6b55b3ef04ebcf4656bc6a59eb5c1340139095 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 27 Jan 2017 10:55:18 +0100 Subject: [PATCH 496/951] Added changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2216c1154..20e27839991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.0.2 + +### Fixed + +- Bug with double slashes when using enterprise URL. ## 2.0.0 From 32eadaaab36812a227e305eb7a9940c85685ee37 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 27 Jan 2017 10:58:00 +0100 Subject: [PATCH 497/951] Code style --- 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 8f10c4ca8d9..71ce371c353 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -220,7 +220,7 @@ public function testEnterpriseUrl() $httpClientMock->expects($this->once()) ->method('sendRequest') - ->with($this->callback(function(RequestInterface $request) { + ->with($this->callback(function (RequestInterface $request) { return (string) $request->getUri() === 'https://foobar.com/api/v3/enterprise/stats/all'; })) ->willReturn(new Response(200, [], '[]')); From 875971e551a14ba18499159c46ccd33b6e67b776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=ABss=20J=C4=81nis=20=C4=80bolti=C5=86=C5=A1?= Date: Wed, 1 Feb 2017 18:08:20 +0200 Subject: [PATCH 498/951] Add page variable to organization repo list (#518) * Update Organization.php * Update OrganizationTest.php --- lib/Github/Api/Organization.php | 6 ++++-- test/Github/Tests/Api/OrganizationTest.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 71f948dcb0b..077211a4987 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -51,13 +51,15 @@ public function update($organization, array $params) * * @param string $organization the user name * @param string $type the type of repositories + * @param int $page the page * * @return array the repositories */ - public function repositories($organization, $type = 'all') + public function repositories($organization, $type = 'all', $page = 1) { return $this->get('/orgs/'.rawurlencode($organization).'/repos', array( - 'type' => $type + 'type' => $type, + 'page' => $page, )); } diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 3d3aaee998c..2090827655a 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -62,7 +62,7 @@ public function shouldGetOrganizationRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/orgs/KnpLabs/repos', array('type' => 'all')) + ->with('/orgs/KnpLabs/repos', array('type' => 'all', 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('KnpLabs')); From bd3318dadc5be8960c33af108bbce2decdbd1deb Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 1 Feb 2017 17:08:37 +0100 Subject: [PATCH 499/951] Replace #495 (#519) * allow fetching prerelease data * fix line endings * use 0th element for test * only update documentation * update docs by request. add draft auth detail * fixed typo --- doc/repo/releases.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index 31f5fa5e10d..b64468a8171 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -9,6 +9,15 @@ Provides information about releases for a repository. Wraps [GitHub Releases API $release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); ``` +The `latest()` method fetches only releases which are not marked "prerelease" or "draft". + +To obtain the latest release *including* prereleases and drafts, select the first element in the "all releases" function: +```php +$release = $client->api('repo')->releases()->all('username', 'repo')[0]; +``` + +Note: Draft releases are only visible to authenticated users who have push access to the repository. + ### List releases for a tag ```php From 6e024250175222c90269b364a2bb6bce2445cf83 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 24 Jan 2017 21:03:03 +0100 Subject: [PATCH 500/951] add support for the pull request reviews API --- lib/Github/Api/PullRequest.php | 6 + lib/Github/Api/PullRequest/Comments.php | 8 +- lib/Github/Api/PullRequest/Review.php | 161 ++++++ lib/Github/Client.php | 2 +- lib/Github/HttpClient/Builder.php | 13 + .../Tests/Api/PullRequest/CommentsTest.php | 495 ++++++++++++++++++ .../Tests/Api/PullRequest/ReviewTest.php | 401 ++++++++++++++ test/Github/Tests/Api/PullRequestTest.php | 10 + 8 files changed, 1093 insertions(+), 3 deletions(-) create mode 100644 lib/Github/Api/PullRequest/Review.php create mode 100644 test/Github/Tests/Api/PullRequest/CommentsTest.php create mode 100644 test/Github/Tests/Api/PullRequest/ReviewTest.php diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index b7df369b99d..52cc77fe348 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -3,6 +3,7 @@ namespace Github\Api; use Github\Api\PullRequest\Comments; +use Github\Api\PullRequest\Review; use Github\Exception\MissingArgumentException; /** @@ -65,6 +66,11 @@ public function comments() return new Comments($this->client); } + public function reviews() + { + return new Review($this->client); + } + /** * Create a pull request. * diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 971f38cee9e..b2de809ed7a 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -11,9 +11,13 @@ */ class Comments extends AbstractApi { - public function all($username, $repository, $pullRequest) + public function all($username, $repository, $pullRequest = null) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); + if (null !== $pullRequest) { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); + } + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments'); } public function show($username, $repository, $comment) diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php new file mode 100644 index 00000000000..8977bddf8dd --- /dev/null +++ b/lib/Github/Api/PullRequest/Review.php @@ -0,0 +1,161 @@ + + */ +class Review extends AbstractApi +{ + /** + * Get a listing of a pull request's reviews by the username, repository and pull request number. + * + * @link https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param array $params a list of extra parameters. + * + * @return array array of pull request reviews for the pull request + */ + public function all($username, $repository, $pullRequest, array $params = []) + { + $parameters = array_merge([ + 'page' => 1, + 'per_page' => 30 + ], $params); + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $parameters); + } + + /** + * Get a single pull request review by the username, repository, pull request number and the review id. + * + * @link https://developer.github.com/v3/pulls/reviews/#get-a-single-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param int $id the review id + * + * @return array the pull request review + */ + public function show($username, $repository, $pullRequest, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id); + } + + /** + * Delete a single pull request review by the username, repository, pull request number and the review id. + * + * @link https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param int $id the review id + * + * @return array|string + */ + public function remove($username, $repository, $pullRequest, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id); + } + + /** + * Get comments for a single pull request review. + * + * @link https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param int $id the review id + * + * @return array|string + */ + public function comments($username, $repository, $pullRequest, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/reviews/'.rawurlencode($id).'/comments'); + } + + /** + * Create a pull request review by the username, repository and pull request number. + * + * @link https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param array $params a list of extra parameters. + * + * @throws MissingArgumentException + * + * @return array the pull request review + */ + public function create($username, $repository, $pullRequest, array $params = []) + { + if (!isset($params['event'])) { + throw new MissingArgumentException('event'); + } + + if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { + throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $params); + } + + /** + * Submit a pull request review by the username, repository, pull request number and the review id. + * + * @link https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param int $id the review id + * @param array $params a list of extra parameters. + * + * @throws MissingArgumentException + * + * @return array the pull request review + */ + public function submit($username, $repository, $pullRequest, $id, array $params = []) + { + if (!isset($params['event'])) { + throw new MissingArgumentException('event'); + } + + if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { + throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/events', $params); + } + + /** + * Dismiss a pull request review by the username, repository, pull request number and the review id. + * + * @link https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param int $id the review id + * + * @return array|string + */ + public function dismiss($username, $repository, $pullRequest, $id) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals'); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index eb7f3e727dd..af0cf58efab 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -127,7 +127,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul ))); $this->apiVersion = $apiVersion ?: 'v3'; - $builder->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); + $builder->addHeaderValue('Accept', sprintf('application/vnd.github.%s+json', $this->apiVersion)); if ($enterpriseUrl) { $this->setEnterpriseUrl($enterpriseUrl); diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index f67c2c9dd08..7d2052498e6 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -157,6 +157,19 @@ public function addHeaders(array $headers) $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); } + /** + * @param string $header + * @param string $headerValue + */ + public function addHeaderValue($header, $headerValue) + { + if (!isset($this->headers[$header])) { + $this->headers[$header] = $headerValue; + } else { + $this->headers[$header] = array_merge((array)$this->headers[$header], array($headerValue)); + } + } + /** * Add a cache plugin to cache responses locally. * diff --git a/test/Github/Tests/Api/PullRequest/CommentsTest.php b/test/Github/Tests/Api/PullRequest/CommentsTest.php new file mode 100644 index 00000000000..a6213a168cc --- /dev/null +++ b/test/Github/Tests/Api/PullRequest/CommentsTest.php @@ -0,0 +1,495 @@ + 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + ], + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + ], + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/12/comments') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->all('octocat', 'Hello-World', 12)); + } + + /** + * @test + */ + public function shouldGetAllReviewComments() + { + $expectedValue = [ + [ + 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + ], + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + ], + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/comments') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->all('octocat', 'Hello-World')); + } + + /** + * @test + */ + public function shouldShowReviewComment() + { + $expectedValue = [ + 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + ], + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/comments/1') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->show('octocat', 'Hello-World', 1)); + } + + /** + * @test + */ + public function shouldCreateReviewComment() + { + $expectedValue = [ + 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + ], + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + ], + ], + ]; + $data = [ + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'path' => 'file1.txt', + 'position' => 4, + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/octocat/Hello-World/pulls/1/comments', $data) + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->create('octocat', 'Hello-World', 1, $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateReviewCommentWithoutCommitId() + { + $data = [ + 'path' => 'file1.txt', + 'position' => 4, + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->create('octocat', 'Hello-World', 1, $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateReviewCommentWithoutPath() + { + $data = [ + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'position' => 4, + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->create('octocat', 'Hello-World', 1, $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateReviewCommentWithoutPosition() + { + $data = [ + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'path' => 'file1.txt', + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->create('octocat', 'Hello-World', 1, $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateReviewCommentWithoutBody() + { + $data = [ + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'path' => 'file1.txt', + 'position' => 4, + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->create('octocat', 'Hello-World', 1, $data); + } + + /** + * @test + */ + public function shouldUpdateReviewComment() + { + $expectedValue = [ + 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + ], + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + ], + ], + ]; + $data = [ + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/octocat/Hello-World/pulls/comments/1', $data) + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->update('octocat', 'Hello-World', 1, $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotUpdateReviewCommentWithoutBody() + { + $expectedValue = [ + 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + ], + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + ], + ], + ]; + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('patch') + ; + + $this->assertSame($expectedValue, $api->update('octocat', 'Hello-World', 1, [])); + } + + /** + * @test + */ + public function shouldDeleteReviewComment() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/octocat/Hello-World/pulls/comments/1') + ; + + $api->remove('octocat', 'Hello-World', 1); + } + + protected function getApiClass() + { + return Comments::class; + } +} diff --git a/test/Github/Tests/Api/PullRequest/ReviewTest.php b/test/Github/Tests/Api/PullRequest/ReviewTest.php new file mode 100644 index 00000000000..54b8d55aafe --- /dev/null +++ b/test/Github/Tests/Api/PullRequest/ReviewTest.php @@ -0,0 +1,401 @@ + 80, + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following{/other_user}', + 'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}', + 'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false + ], + 'body' => 'Here is the body for the review.', + 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', + 'state' => 'APPROVED', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', + '_links' => [ + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + ], + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/12/reviews') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->all('octocat', 'Hello-World', 12)); + } + + /** + * @test + */ + public function shouldShowReview() + { + $expectedValue = [ + 'id' => 80, + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following{/other_user}', + 'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}', + 'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false + ], + 'body' => 'Here is the body for the review.', + 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', + 'state' => 'APPROVED', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', + '_links' => [ + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/12/reviews/80') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->show('octocat', 'Hello-World', 12, 80)); + } + + /** + * @test + */ + public function shouldDeleteReview() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/octocat/Hello-World/pulls/12/reviews/80') + ; + + $api->remove('octocat', 'Hello-World', 12, 80); + } + + /** + * @test + */ + public function shouldShowReviewComments() + { + $expectedValue = [ + [ + "url" => "https://api.github.com/repos/octocat/Hello-World/pulls/comments/1", + "id" => 1, + "pull_request_review_id" => 42, + "diff_hunk" => "@@ -16,33 +16,40 @@ public class Connection => IConnection...", + "path" => "file1.txt", + "position" => 1, + "original_position" => 4, + "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e", + "original_commit_id" => "9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840", + "user" => [ + "login" => "octocat", + "id" => 1, + "avatar_url" => "https://github.com/images/error/octocat_happy.gif", + "gravatar_id" => "", + "url" => "https://api.github.com/users/octocat", + "html_url" => "https://github.com/octocat", + "followers_url" => "https://api.github.com/users/octocat/followers", + "following_url" => "https://api.github.com/users/octocat/following[/other_user]", + "gists_url" => "https://api.github.com/users/octocat/gists[/gist_id]", + "starred_url" => "https://api.github.com/users/octocat/starred[/owner][/repo]", + "subscriptions_url" => "https://api.github.com/users/octocat/subscriptions", + "organizations_url" => "https://api.github.com/users/octocat/orgs", + "repos_url" => "https://api.github.com/users/octocat/repos", + "events_url" => "https://api.github.com/users/octocat/events[/privacy]", + "received_events_url" => "https://api.github.com/users/octocat/received_events", + "type" => "User", + "site_admin" => false, + ], + "body" => "Great stuff", + "created_at" => "2011-04-14T16:00:49Z", + "updated_at" => "2011-04-14T16:00:49Z", + "html_url" => "https://github.com/octocat/Hello-World/pull/1#discussion-diff-1", + "pull_request_url" => "https://api.github.com/repos/octocat/Hello-World/pulls/1", + "_links" => [ + "self" => [ + "href" => "https://api.github.com/repos/octocat/Hello-World/pulls/comments/1", + ], + "html" => [ + "href" => "https://github.com/octocat/Hello-World/pull/1#discussion-diff-1", + ], + "pull_request" => [ + "href" => "https://api.github.com/repos/octocat/Hello-World/pulls/1", + ], + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/1/reviews/42/comments') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->comments('octocat', 'Hello-World', 1, 42)); + } + + /** + * @test + */ + public function shouldCreateReviewComment() + { + $data = [ + 'event' => 'APPROVE', + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/octocat/Hello-World/pulls/12/reviews') + ; + + $api->create('octocat', 'Hello-World', 12, $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateReviewWithoutEvent() + { + $data = [ + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->create('octocat', 'Hello-World', 12, $data); + } + + /** + * @test + * @expectedException \Github\Exception\InvalidArgumentException + */ + public function shouldNotCreateReviewWithInvalidEvent() + { + $data = [ + 'event' => 'DISMISSED', + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->create('octocat', 'Hello-World', 12, $data); + } + + /** + * @test + */ + public function shouldSubmitReviewComment() + { + $expectedValue = [ + 'id' => 80, + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following{/other_user}', + 'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}', + 'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false + ], + 'body' => 'Here is the body for the review.', + 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', + 'state' => 'APPROVED', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', + '_links' => [ + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + ], + ], + ]; + $data = [ + 'event' => 'APPROVE', + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/octocat/Hello-World/pulls/12/reviews/80/events') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->submit('octocat', 'Hello-World', 12, 80, $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotSubmitReviewWithoutEvent() + { + $data = [ + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->submit('octocat', 'Hello-World', 12, 80, $data); + } + + /** + * @test + * @expectedException \Github\Exception\InvalidArgumentException + */ + public function shouldNotSubmitReviewWithInvalidEvent() + { + $data = [ + 'event' => 'DISMISSED', + 'body' => 'Nice change', + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->never()) + ->method('post') + ; + + $api->submit('octocat', 'Hello-World', 12, 80, $data); + } + + /** + * @test + */ + public function shouldDismissReview() + { + $expectedValue = [ + 'id' => 80, + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following{/other_user}', + 'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}', + 'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false + ], + 'body' => 'Here is the body for the review.', + 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', + 'state' => 'APPROVED', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', + '_links' => [ + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + ], + ], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/octocat/Hello-World/pulls/12/reviews/80/dismissals') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->dismiss('octocat', 'Hello-World', 12, 80)); + } + + protected function getApiClass() + { + return Review::class; + } +} diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 8bb3bcb1f72..672093f5cda 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -305,6 +305,16 @@ public function shouldGetCommentsApiObject() $this->assertInstanceOf(\Github\Api\PullRequest\Comments::class, $api->comments()); } + /** + * @test + */ + public function shouldGetReviewApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\PullRequest\Review::class, $api->reviews()); + } + /** * @return string */ From ae12dab1a9e77a5cb930e3d2b7be058459813043 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 7 Feb 2017 11:30:48 +0100 Subject: [PATCH 501/951] update the branch alias Since adding support for the pull request review API is a new feature the minor version needs to be incremented. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 62e44e009cc..b9595471044 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.1.x-dev" } } } From bf378705da33089c8ada59e992699e28d19cd2a7 Mon Sep 17 00:00:00 2001 From: Brandon Bloodgood Date: Thu, 9 Feb 2017 07:28:37 -0600 Subject: [PATCH 502/951] Add branch protection (#520) * Added branch protection * Updated method comments --- lib/Github/Api/Repo.php | 13 +++++ lib/Github/Api/Repository/Protection.php | 45 +++++++++++++++++ .../Tests/Api/Repository/ProtectionTest.php | 49 +++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 lib/Github/Api/Repository/Protection.php create mode 100644 test/Github/Tests/Api/Repository/ProtectionTest.php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 0285f44886a..94becd25d1a 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -9,6 +9,7 @@ use Github\Api\Repository\DeployKeys; use Github\Api\Repository\Downloads; use Github\Api\Repository\Projects; +use Github\Api\Repository\Protection; use Github\Api\Repository\Releases; use Github\Api\Repository\Forks; use Github\Api\Repository\Hooks; @@ -413,6 +414,18 @@ public function branches($username, $repository, $branch = null) return $this->get($url); } + /** + * Manage the protection of a repository branch. + * + * @link https://developer.github.com/v3/repos/branches/#get-branch-protection + * + * @return Protection + */ + public function protection() + { + return new Protection($this->client); + } + /** * Get the contributors of a repository. * diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php new file mode 100644 index 00000000000..6976870da13 --- /dev/null +++ b/lib/Github/Api/Repository/Protection.php @@ -0,0 +1,45 @@ + + */ +class Protection extends AbstractApi +{ + /** + * Retrieves configured protection for the provided branch + * + * @link https://developer.github.com/v3/repos/branches/#get-branch-protection + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch protection information + */ + public function show($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection'); + } + + /** + * Updates the repo's branch protection + * + * @link https://developer.github.com/v3/repos/branches/#update-branch-protection + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch protection information + * + * @return array The updated branch protection information + */ + public function update($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params); + } +} diff --git a/test/Github/Tests/Api/Repository/ProtectionTest.php b/test/Github/Tests/Api/Repository/ProtectionTest.php new file mode 100644 index 00000000000..48b59b268dd --- /dev/null +++ b/test/Github/Tests/Api/Repository/ProtectionTest.php @@ -0,0 +1,49 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldUpdateProtection() + { + $expectedValue = array('required_status_checks', 'required_pull_reqeust_reviews', 'restrictions'); + $data = array('required_status_checks' => null); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Repository\Protection::class; + } +} From 836050555ad386b3c464b7e987606a89d0e9c0e0 Mon Sep 17 00:00:00 2001 From: Tim Joosten Date: Sat, 11 Feb 2017 04:43:22 +0100 Subject: [PATCH 503/951] Fix typo change fom to from. In doc/issue/labels.md --- doc/issue/labels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 706beca660c..2b35848bccb 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -61,7 +61,7 @@ $client->api('issue')->labels()->replace('KnpLabs', 'php-github-api', 4, array(' Replace a label for an issue: by username, repo, issue number and array of labels. -### Remove all labels fom an issue +### Remove all labels from an issue > Requires [authentication](../security.md). From 6cb20db96309139150a4d15a09e37c86dbe53e57 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 13 Feb 2017 22:43:10 +0100 Subject: [PATCH 504/951] Fixed integration authentication example --- doc/security.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/security.md b/doc/security.md index e31adce4f8d..8eedf9e604c 100644 --- a/doc/security.md +++ b/doc/security.md @@ -54,6 +54,10 @@ The following sample code authenticates as an installation using [lcobucci/jwt]( to generate a JSON Web Token (JWT). ```php +use Lcobucci\JWT\Builder; +use Lcobucci\JWT\Signer\Key; +use Lcobucci\JWT\Signer\Rsa\Sha256; + $builder = new Github\HttpClient\Builder(new GuzzleClient()); $github = new Github\Client($builder, 'machine-man-preview'); @@ -61,7 +65,7 @@ $jwt = (new Builder) ->setIssuer($integrationId) ->setIssuedAt(time()) ->setExpiration(time() + 60) - ->sign(new Sha256(), (new Keychain)->getPrivateKey($pemPrivateKeyPath)) + ->sign(new Sha256(), new Key('file:///path/to/integration.private-key.pem')) ->getToken(); $github->authenticate($jwt, null, Github\Client::AUTH_JWT); From 6f89e35950beb32d62751b2128d5dc9fc3477b08 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 13 Feb 2017 22:37:53 +0100 Subject: [PATCH 505/951] Added missing api methods for the integrations installation api --- doc/integrations.md | 26 ++++++++ lib/Github/Api/Integrations.php | 56 +++++++++++++++++ lib/Github/Client.php | 2 + test/Github/Tests/Api/IntegrationTest.php | 73 +++++++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 test/Github/Tests/Api/IntegrationTest.php diff --git a/doc/integrations.md b/doc/integrations.md index 9e34e6a0b9e..f3b1c1e8c6c 100644 --- a/doc/integrations.md +++ b/doc/integrations.md @@ -13,3 +13,29 @@ To create an access token on behalf of a user with id 456 use: ```php $token = $client->api('integrations')->createInstallationToken(123, 456); ``` + +### Find all installations + +Find all installations for the authenticated integration. +```php +Installations = $client->api('integrations')->findInstallations(); +``` + +### List repositories + +List repositories that are accessible to the authenticated installation. +```php +$repositories = $client->api('integrations')->listRepositories(456); +``` + +### Add repository to installation +Add a single repository to an installation. +```php +$client->api('integrations')->addRepository(123); +``` + +### Remove repository from installation +Remove a single repository from an installation. +```php +$client->api('integrations')->removeRepository(123); +``` diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index f8cdadb00bc..7af6a093482 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -26,4 +26,60 @@ public function createInstallationToken($installationId, $userId = null) return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); } + + /** + * Find all installations for the authenticated integration. + * + * @link https://developer.github.com/v3/integrations/#find-installations + * + * @return array + */ + public function findInstallations() + { + return $this->get('/integration/installations'); + } + + /** + * List repositories that are accessible to the authenticated installation. + * + * @link https://developer.github.com/v3/integrations/installations/#list-repositories + * + * @param int $userId + * + * @return array + */ + public function listRepositories($userId) + { + return $this->get('/installation/repositories', ['user_id' => $userId]); + } + + /** + * Add a single repository to an installation. + * + * @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation + * + * @param int $installationId + * @param int $repositoryId + * + * @return array + */ + public function addRepository($installationId, $repositoryId) + { + return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + } + + /** + * Remove a single repository from an installation. + * + * @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation + * + * @param int $installationId + * @param int $repositoryId + * + * @return array + */ + public function removeRepository($installationId, $repositoryId) + { + return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 4d10da6af25..062cf998c95 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -27,6 +27,8 @@ * @method Api\GitData gitData() * @method Api\Gists gist() * @method Api\Gists gists() + * @method Api\Integrations integration() + * @method Api\Integrations integrations() * @method Api\Issue issue() * @method Api\Issue issues() * @method Api\Markdown markdown() diff --git a/test/Github/Tests/Api/IntegrationTest.php b/test/Github/Tests/Api/IntegrationTest.php new file mode 100644 index 00000000000..2ab5dc3be62 --- /dev/null +++ b/test/Github/Tests/Api/IntegrationTest.php @@ -0,0 +1,73 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/integration/installations') + ->willReturn($result); + + $this->assertEquals($result, $api->findInstallations()); + } + + /** + * @test + */ + public function shouldGetRepositoriesFromInstallation() + { + $result = ['repo1', 'repo2']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/installation/repositories', ['user_id' => '1234']) + ->willReturn($result); + + $this->assertEquals($result, $api->listRepositories('1234')); + } + + /** + * @test + */ + public function shouldAddRepositoryToInstallation() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/installations/1234/repositories/5678'); + + $api->addRepository('1234', '5678'); + } + + /** + * @test + */ + public function shouldRemoveRepositoryToInstallation() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/installations/1234/repositories/5678'); + + $api->removeRepository('1234', '5678'); + } + + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Integrations::class; + } +} From be18a9e500d161c5663e6d713e1a491aa66846f4 Mon Sep 17 00:00:00 2001 From: Emmet O'Grady Date: Thu, 23 Feb 2017 12:42:20 +0100 Subject: [PATCH 506/951] Bugfix: headers not being passed to request (#529) * Add IDE files to gitignore * Add failing UT to show bug * Fix bug: reset plugin when headers change * Remove IDEs from gitignore --- lib/Github/HttpClient/Builder.php | 3 +++ test/Github/Tests/HttpClient/BuilderTest.php | 24 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 7d2052498e6..5b742285bd9 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -168,6 +168,9 @@ public function addHeaderValue($header, $headerValue) } else { $this->headers[$header] = array_merge((array)$this->headers[$header], array($headerValue)); } + + $this->removePlugin(Plugin\HeaderAppendPlugin::class); + $this->addPlugin(new Plugin\HeaderAppendPlugin($this->headers)); } /** diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php index 3643dd292fa..dadfd4f44d8 100644 --- a/test/Github/Tests/HttpClient/BuilderTest.php +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -49,4 +49,28 @@ public function shouldAddHeaders() $client->addHeaders($headers); } + + /** + * @test + */ + public function appendingHeaderShouldAddAndRemovePlugin() + { + $expectedHeaders = [ + 'Accept' => 'application/vnd.github.v3', + ]; + + $client = $this->getMockBuilder(\Github\HttpClient\Builder::class) + ->setMethods(array('removePlugin', 'addPlugin')) + ->getMock(); + + $client->expects($this->once()) + ->method('removePlugin') + ->with(Plugin\HeaderAppendPlugin::class); + + $client->expects($this->once()) + ->method('addPlugin') + ->with(new Plugin\HeaderAppendPlugin($expectedHeaders)); + + $client->addHeaderValue('Accept', 'application/vnd.github.v3'); + } } From 0feb0760f1f04197ccfd02d377eddb0a31f26d5e Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 23 Mar 2017 09:15:40 +0100 Subject: [PATCH 507/951] Prepare for 2.1 (#542) --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e27839991..c7ba646f00b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,21 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 2.0.2 +## 2.1.0 + +### Added + +- Add support for retrieving a single notification info using his ID +- Add a function to get user organizations +- Added GraphQL support +- Add page variable to organization repo list (Organization::repositories()) +- Add support for pull request review. +- Add support for adding branch protection. ### Fixed - Bug with double slashes when using enterprise URL. +- Bug when headers not being passed to request (#529) ## 2.0.0 From 38301ccff12917aa89e0359c63d88098ce7ebbd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Benoist?= Date: Thu, 23 Mar 2017 09:36:09 +0100 Subject: [PATCH 508/951] Add ability to define parameters for /users/{user}/starred (#536) * Add ability to define parameter for /users/{user}/starred Following the documentation (https://developer.github.com/v3/activity/starring/#list-repositories-being-starred) we can define few parameters to the request: - page (was already available in the lib) - per_page - sort - direction * Typo in annotation --- lib/Github/Api/CurrentUser.php | 2 +- lib/Github/Api/User.php | 14 ++++++++++---- test/Github/Tests/Api/UserTest.php | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index dc2a877d7e3..742f5579774 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -112,7 +112,7 @@ public function teams() * * @param string $type role in the repository * @param string $sort sort by - * @param string $direction direction of sort, ask or desc + * @param string $direction direction of sort, asc or desc * * @return array */ diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 65702296f5e..c11716040d8 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -129,15 +129,21 @@ public function watched($username) * * @link http://developer.github.com/v3/activity/starring/ * - * @param string $username the username - * @param int $page the page number of the paginated result set + * @param string $username the username + * @param int $page the page number of the paginated result set + * @param int $perPage the number of results per page + * @param string $sort sort by (possible values: created, updated) + * @param string $direction direction of sort (possible values: asc, desc) * * @return array list of starred repositories */ - public function starred($username, $page = 1) + public function starred($username, $page = 1, $perPage = 30, $sort = 'created', $direction = 'desc') { return $this->get('/users/'.rawurlencode($username).'/starred', array( - 'page' => $page + 'page' => $page, + 'per_page' => $perPage, + 'sort' => $sort, + 'direction' => $direction, )); } diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 19f2e380e29..8e505cfd862 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -42,6 +42,7 @@ public function shouldGetUserOrganizations() $this->assertEquals($expectedArray, $api->organizations('l3l0')); } + public function shouldGetUserOrgs() { $expectedArray = array(array( @@ -61,6 +62,7 @@ public function shouldGetUserOrgs() $this->assertEquals($expectedArray, $api->orgs()); } + /** * @test */ @@ -131,6 +133,22 @@ public function shouldGetUserFollowers() $this->assertEquals($expectedArray, $api->followers('l3l0')); } + /** + * @test + */ + public function shouldGetStarredToRepositories() + { + $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/users/l3l0/starred', ['page' => 2, 'per_page' => 30, 'sort' => 'created', 'direction' => 'desc']) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->starred('l3l0', 2)); + } + /** * @test */ From adf8914fd6b396843f92eb085aab67e1a3c18bae Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 23 Mar 2017 09:47:22 +0100 Subject: [PATCH 509/951] Missing miscellaneous api endpoints (#534) --- doc/README.md | 4 ++ doc/miscellaneous/emojis.md | 8 +++ doc/miscellaneous/gitignore.md | 14 +++++ doc/miscellaneous/markdown.md | 14 +++++ lib/Github/Api/Miscellaneous/Emojis.php | 20 ++++++ lib/Github/Api/Miscellaneous/Gitignore.php | 34 +++++++++++ lib/Github/Client.php | 10 +++ .../Tests/Api/Miscellaneous/EmojisTest.php | 36 +++++++++++ .../Tests/Api/Miscellaneous/GitignoreTest.php | 61 +++++++++++++++++++ .../Api/{ => Miscellaneous}/MarkdownTest.php | 4 +- 10 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 doc/miscellaneous/emojis.md create mode 100644 doc/miscellaneous/gitignore.md create mode 100644 doc/miscellaneous/markdown.md create mode 100644 lib/Github/Api/Miscellaneous/Emojis.php create mode 100644 lib/Github/Api/Miscellaneous/Gitignore.php create mode 100644 test/Github/Tests/Api/Miscellaneous/EmojisTest.php create mode 100644 test/Github/Tests/Api/Miscellaneous/GitignoreTest.php rename test/Github/Tests/Api/{ => Miscellaneous}/MarkdownTest.php (96%) diff --git a/doc/README.md b/doc/README.md index 8cffeaaff07..04fcd7a3885 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,6 +14,10 @@ APIs: * [Issues](issues.md) * [Comments](issue/comments.md) * [Labels](issue/labels.md) +* Miscellaneous + * [Emojis](miscellaneous/emojis.md) + * [Gitignore](miscellaneous/gitignore.md) + * [Markdown](miscellaneous/markdown.md) * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) diff --git a/doc/miscellaneous/emojis.md b/doc/miscellaneous/emojis.md new file mode 100644 index 00000000000..0ba2045596e --- /dev/null +++ b/doc/miscellaneous/emojis.md @@ -0,0 +1,8 @@ +## Emojis API +[Back to the navigation](../README.md) + +### Lists all available emojis on GitHub. + +```php +$emojis = $client->api('emojis')->all(); +``` diff --git a/doc/miscellaneous/gitignore.md b/doc/miscellaneous/gitignore.md new file mode 100644 index 00000000000..181424f34ad --- /dev/null +++ b/doc/miscellaneous/gitignore.md @@ -0,0 +1,14 @@ +## Gitignore API +[Back to the navigation](../README.md) + +### Lists all available gitignore templates + +```php +$gitignoreTemplates = $client->api('gitignore')->all(); +``` + +### Get a single template + +```php +$gitignore = $client->api('gitignore')->show('C'); +``` diff --git a/doc/miscellaneous/markdown.md b/doc/miscellaneous/markdown.md new file mode 100644 index 00000000000..4f9ffecc179 --- /dev/null +++ b/doc/miscellaneous/markdown.md @@ -0,0 +1,14 @@ +## Markdown API +[Back to the navigation](../README.md) + +### Render an arbitrary Markdown document + +```php +$gitignoreTemplates = $client->api('markdown')->render('Hello world github/linguist#1 **cool**, and #1!', 'markdown'); +``` + +### Render a Markdown document in raw mode + +```php +$gitignore = $client->api('markdown')->renderRaw('path/to/file'); +``` diff --git a/lib/Github/Api/Miscellaneous/Emojis.php b/lib/Github/Api/Miscellaneous/Emojis.php new file mode 100644 index 00000000000..2a940f6dfb7 --- /dev/null +++ b/lib/Github/Api/Miscellaneous/Emojis.php @@ -0,0 +1,20 @@ +get('/emojis'); + } +} diff --git a/lib/Github/Api/Miscellaneous/Gitignore.php b/lib/Github/Api/Miscellaneous/Gitignore.php new file mode 100644 index 00000000000..c7306110ee5 --- /dev/null +++ b/lib/Github/Api/Miscellaneous/Gitignore.php @@ -0,0 +1,34 @@ +get('/gitignore/templates'); + } + + /** + * Get a single template. + * + * @link https://developer.github.com/v3/gitignore/#get-a-single-template + * + * @param string $template + * + * @return array + */ + public function show($template) + { + return $this->get('/gitignore/templates/' . rawurlencode($template)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 062cf998c95..ad282661d12 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -23,10 +23,12 @@ * @method Api\CurrentUser me() * @method Api\Enterprise ent() * @method Api\Enterprise enterprise() + * @method Api\Miscellaneous\Emojis emojis() * @method Api\GitData git() * @method Api\GitData gitData() * @method Api\Gists gist() * @method Api\Gists gists() + * @method Api\Miscellaneous\Gitignore gitignore() * @method Api\Integrations integration() * @method Api\Integrations integrations() * @method Api\Issue issue() @@ -177,6 +179,10 @@ public function api($name) $api = new Api\Enterprise($this); break; + case 'emojis': + $api = new Api\Miscellaneous\Emojis($this); + break; + case 'git': case 'git_data': case 'gitData': @@ -188,6 +194,10 @@ public function api($name) $api = new Api\Gists($this); break; + case 'gitignore': + $api = new Api\Miscellaneous\Gitignore($this); + break; + case 'integration': case 'integrations': $api = new Api\Integrations($this); diff --git a/test/Github/Tests/Api/Miscellaneous/EmojisTest.php b/test/Github/Tests/Api/Miscellaneous/EmojisTest.php new file mode 100644 index 00000000000..63bac291e94 --- /dev/null +++ b/test/Github/Tests/Api/Miscellaneous/EmojisTest.php @@ -0,0 +1,36 @@ + 'https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5', + '-1' => 'https://github.global.ssl.fastly.net/images/icons/emoji/-1.png?v5', + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/emojis') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @return string + */ + protected function getApiClass() + { + return Emojis::class; + } +} diff --git a/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php b/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php new file mode 100644 index 00000000000..9fbd0ef4fc4 --- /dev/null +++ b/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php @@ -0,0 +1,61 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/gitignore/templates') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetTemplate() + { + $expectedArray = array( + 'name' => 'C', + 'source' => "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a" + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/C') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('C')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return Gitignore::class; + } +} diff --git a/test/Github/Tests/Api/MarkdownTest.php b/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php similarity index 96% rename from test/Github/Tests/Api/MarkdownTest.php rename to test/Github/Tests/Api/Miscellaneous/MarkdownTest.php index 296a2778575..14cb9bf439a 100644 --- a/test/Github/Tests/Api/MarkdownTest.php +++ b/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php @@ -1,6 +1,8 @@ Date: Thu, 23 Mar 2017 10:07:21 +0100 Subject: [PATCH 510/951] Missing issues api endpoints (#533) --- doc/README.md | 2 + doc/issue/assignees.md | 28 +++++ doc/issue/labels.md | 6 + doc/issues.md | 12 ++ lib/Github/Api/Issue.php | 45 ++++++++ lib/Github/Api/Issue/Assignees.php | 83 ++++++++++++++ lib/Github/Api/Issue/Labels.php | 16 +++ test/Github/Tests/Api/Issue/AssigneesTest.php | 107 ++++++++++++++++++ test/Github/Tests/Api/Issue/LabelsTest.php | 16 +++ test/Github/Tests/Api/IssueTest.php | 30 +++++ 10 files changed, 345 insertions(+) create mode 100644 doc/issue/assignees.md create mode 100644 lib/Github/Api/Issue/Assignees.php create mode 100644 test/Github/Tests/Api/Issue/AssigneesTest.php diff --git a/doc/README.md b/doc/README.md index 04fcd7a3885..ba33a60c503 100644 --- a/doc/README.md +++ b/doc/README.md @@ -12,8 +12,10 @@ APIs: * [Comments](gists/comments.md) * [Integrations](integrations.md) * [Issues](issues.md) + * [Assignees](issue/assignees.md) * [Comments](issue/comments.md) * [Labels](issue/labels.md) + * [Milestones](issue/milestones.md) * Miscellaneous * [Emojis](miscellaneous/emojis.md) * [Gitignore](miscellaneous/gitignore.md) diff --git a/doc/issue/assignees.md b/doc/issue/assignees.md new file mode 100644 index 00000000000..035ea8ddcd7 --- /dev/null +++ b/doc/issue/assignees.md @@ -0,0 +1,28 @@ +## Issues / Assignees API +[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md) + +Wraps [GitHub Issue Assignees API](https://developer.github.com/v3/issues/assignees/). + +### List all available assignees + +```php +$assignees = $client->api('issue')->assignees()->listAvailable('KnpLabs', 'php-github-api'); +``` + +### Check if a user is an available assignee + +```php +$info = $client->api('issue')->assignees()->check('KnpLabs', 'php-github-api', 'test-user); +``` + +### Add assignee + +```php +$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]); +``` + +### Remove assignee + +```php +$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]); +``` diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 2b35848bccb..828726f96ed 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -12,6 +12,12 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api'); List all project labels by username and repo. Returns an array of project labels. +### Get a single label + +```php +$label = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api', 'label1'); +``` + ### Create a label ```php diff --git a/doc/issues.md b/doc/issues.md index e2804277d35..3f26bab5ad6 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -84,3 +84,15 @@ $client->api('issue')->all('KnpLabs', 'php-github-api', array('labels' => 'label ``` Returns an array of issues matching the given label. + +### Lock an issue discussion + +```php +$client->api('issue')->lock('KnpLabs', 'php-github-api', 4); +``` + +### Unlock an issue discussion + +```php +$client->api('issue')->unlock('KnpLabs', 'php-github-api', 4); +``` diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index f1f41d92ed1..4c30783473d 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Issue\Assignees; use Github\Api\Issue\Comments; use Github\Api\Issue\Events; use Github\Api\Issue\Labels; @@ -132,6 +133,38 @@ public function update($username, $repository, $id, array $params) return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params); } + /** + * Lock an issue. Users with push access can lock an issue's conversation. + * + * @link https://developer.github.com/v3/issues/#lock-an-issue + * + * @param string $username + * @param string $repository + * @param string $id + * + * @return string + */ + public function lock($username, $repository, $id) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock'); + } + + /** + * Unlock an issue. Users with push access can unlock an issue's conversation. + * + * @link https://developer.github.com/v3/issues/#lock-an-issue + * + * @param string $username + * @param string $repository + * @param string $id + * + * @return string + */ + public function unlock($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock'); + } + /** * List an issue comments. * @@ -179,4 +212,16 @@ public function milestones() { return new Milestones($this->client); } + + /** + * List all assignees. + * + * @link https://developer.github.com/v3/issues/assignees/ + * + * @return Assignees + */ + public function assignees() + { + return new Assignees($this->client); + } } diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php new file mode 100644 index 00000000000..f304f7ab05a --- /dev/null +++ b/lib/Github/Api/Issue/Assignees.php @@ -0,0 +1,83 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees', $parameters); + } + + /** + * Check to see if a particular user is an assignee for a repository. + * + * @link https://developer.github.com/v3/issues/assignees/#check-assignee + * + * @param string $username + * @param string $repository + * @param string $assignee + * + * @return array + */ + public function check($username, $repository, $assignee) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees/' . rawurlencode($assignee)); + } + + /** + * Add assignees to an Issue + * + * @link https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue + * + * @param string $username + * @param string $repository + * @param string $issue + * @param array $parameters + * + * @return string + * @throws MissingArgumentException + */ + public function add($username, $repository, $issue, array $parameters) + { + if (!isset($parameters['assignees'])) { + throw new MissingArgumentException('assignees'); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters); + } + + /** + * Remove assignees from an Issue + * + * @link https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue + * + * @param string $username + * @param string $repository + * @param string $issue + * @param array $parameters + * + * @return string + * @throws MissingArgumentException + */ + public function remove($username, $repository, $issue, array $parameters) + { + if (!isset($parameters['assignees'])) { + throw new MissingArgumentException('assignees'); + } + + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters); + } +} diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 8f27887acfb..fb0f52362e3 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -33,6 +33,22 @@ public function all($username, $repository, $issue = null) return $this->get($path); } + /** + * Get a single label. + * + * @link https://developer.github.com/v3/issues/labels/#get-a-single-label + * + * @param string $username + * @param string $repository + * @param string $label + * + * @return array + */ + public function show($username, $repository, $label) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); + } + /** * Create a label for a repository. * diff --git a/test/Github/Tests/Api/Issue/AssigneesTest.php b/test/Github/Tests/Api/Issue/AssigneesTest.php new file mode 100644 index 00000000000..a3cfe0f6066 --- /dev/null +++ b/test/Github/Tests/Api/Issue/AssigneesTest.php @@ -0,0 +1,107 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/knplabs/php-github-api/assignees'); + + $api->listAvailable('knplabs', 'php-github-api'); + } + + /** + * @test + */ + public function shouldCheckAssignee() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/knplabs/php-github-api/assignees/test-user'); + + $api->check('knplabs', 'php-github-api', 'test-user'); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotAddAssigneeMissingParameter() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->add('knplabs', 'php-github-api', 4, $data); + } + + /** + * @test + */ + public function shouldAddAssignee() + { + $data = array( + 'assignees' => array('test-user') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/knplabs/php-github-api/issues/4/assignees', $data); + + $api->add('knplabs', 'php-github-api', 4, $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotRemoveAssigneeMissingParameter() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('delete'); + + $api->remove('knplabs', 'php-github-api', 4, $data); + } + + /** + * @test + */ + public function shouldRemoveAssignee() + { + $data = array( + 'assignees' => array('test-user') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/knplabs/php-github-api/issues/4/assignees', $data); + + $api->remove('knplabs', 'php-github-api', 4, $data); + } + + /** + * @return string + */ + protected function getApiClass() + { + return Assignees::class; + } +} diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index e6be19d27c3..5be4e21254d 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -58,6 +58,22 @@ public function shouldCreateLabel() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } + /** + * @test + */ + public function shouldGetSingleLabel() + { + $expectedValue = array(array('name' => 'label1')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/labels/label1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'label1')); + } + /** * @test */ diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 242a650a3e7..a8a40835b39 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -242,6 +242,36 @@ public function shouldGetMilestonesApiObject() $this->assertInstanceOf(\Github\Api\Issue\Milestones::class, $api->milestones()); } + /** + * @test + */ + public function shouldLockIssue() + { + $parameters = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/knplabs/php-github-api/issues/1/lock', $parameters); + + $api->lock('knplabs', 'php-github-api', '1'); + } + + /** + * @test + */ + public function shouldUnlockIssue() + { + $parameters = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/knplabs/php-github-api/issues/1/lock', $parameters); + + $api->unlock('knplabs', 'php-github-api', '1'); + } + /** * @return string */ From 9f0cf3a1f7304cdd1f730233b5b4d38fdf3047a6 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sun, 26 Mar 2017 14:39:10 +0200 Subject: [PATCH 511/951] Add traffic (#548) * Create Traffic.php * Add Clones * Apply fixes from StyleCI [ci skip] [skip ci] * Add Traffic to Repo * Add Traffic * Apply fixes from StyleCI [ci skip] [skip ci] * list() -> referers() * Test skeleton * Apply fixes from StyleCI [ci skip] [skip ci] * Add per * Remove // * Fix Syntax Error * Add * Syntax * Add Tests --- lib/Github/Api/Repo.php | 6 ++ lib/Github/Api/Repository/Traffic.php | 63 +++++++++++++++ .../Tests/Api/Repository/TrafficTest.php | 79 +++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 lib/Github/Api/Repository/Traffic.php create mode 100644 test/Github/Tests/Api/Repository/TrafficTest.php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 94becd25d1a..b730158d67e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -16,6 +16,7 @@ use Github\Api\Repository\Labels; use Github\Api\Repository\Stargazers; use Github\Api\Repository\Statuses; +use Github\Api\Repository\Traffic; /** * Searching repositories, getting repository information @@ -562,4 +563,9 @@ public function projects() { return new Projects($this->client); } + + public function traffic() + { + return new Traffic($this->client); + } } diff --git a/lib/Github/Api/Repository/Traffic.php b/lib/Github/Api/Repository/Traffic.php new file mode 100644 index 00000000000..1e7d85bf5ce --- /dev/null +++ b/lib/Github/Api/Repository/Traffic.php @@ -0,0 +1,63 @@ + + */ +class Traffic extends AbstractApi +{ + /** + * @link https://developer.github.com/v3/repos/traffic/#list-referrers + * + * @param string $owner + * @param string $repository + * + * @return array + */ + public function referers($owner, $repository) + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/referrers'); + } + /** + * @link https://developer.github.com/v3/repos/traffic/#list-paths + * + * @param string $owner + * @param string $repository + * + * @return array + */ + public function paths($owner, $repository) + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/paths'); + } + /** + * @link https://developer.github.com/v3/repos/traffic/#views + * + * @param string $owner + * @param string $repository + * @param string|day $per + * + * @return array + */ + public function views($owner, $repository, $per = 'day') + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/views?per='.rawurlencode($per)); + } + /** + * @link https://developer.github.com/v3/repos/traffic/#clones + * + * @param string $owner + * @param string $repository + * @param string|day $per + * + * @return array + */ + public function clones($owner, $repository, $per = 'day') + { + return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/clones?per='.rawurlencode($per)); + } +} diff --git a/test/Github/Tests/Api/Repository/TrafficTest.php b/test/Github/Tests/Api/Repository/TrafficTest.php new file mode 100644 index 00000000000..5110c546240 --- /dev/null +++ b/test/Github/Tests/Api/Repository/TrafficTest.php @@ -0,0 +1,79 @@ + "github.com","count" => 112,"uniques" => 15]); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/repos/knplabs/php-github-api/traffic/popular/referrers') + ->will($this->returnValue($expectedValue)); + + $result = $api->referers('knplabs', 'php-github-api'); + + $this->assertEquals($expectedValue, $result); + } + + public function shouldgetPaths() + { + $expectedValue = json_encode(["path" => "/knplabs/php-github-api","title" => "KnpLabs/php-github-api: A simple PHP GitHub API client, Object Oriented, tested and documented. For 5.5+.","count" => 203,"uniques" => 54]); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/repos/knplabs/php-github-api/traffic/popular/paths') + ->will($this->returnValue($expectedValue)); + + $result = $api->paths('knplabs', 'php-github-api'); + + $this->assertEquals($expectedValue, $result); + } + + public function shouldgetViews() + { + $expectedValue = json_encode(["count" => 813,"uniques" => 61,"views" => [["timestamp" => "2017-03-12T00:00:00Z","count" => 40,"uniques" => 3]]]); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/repos/knplabs/php-github-api/traffic/views?per=day') + ->will($this->returnValue($expectedValue)); + + $result = $api->views('knplabs', 'php-github-api'); + + $this->assertEquals($expectedValue, $result); + } + + public function shouldgetClones() + { + $expectedValue = json_encode(["count" => 813,"uniques" => 61,"clones" => [["timestamp" => "2017-03-12T00:00:00Z","count" => 14,"uniques" => 8]]]); + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/repos/knplabs/php-github-api/traffic/clones?per=day') + ->will($this->returnValue($expectedValue)); + + $result = $api->clones('knplabs', 'php-github-api'); + + $this->assertEquals($expectedValue, $result); + } + + protected function getApiClass() + { + return \Github\Api\Repository\Traffic::class; + } +} From 0a0826b1f77c04cc59f896059d41ecd8140cb72e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 26 Mar 2017 14:42:10 +0200 Subject: [PATCH 512/951] Implement missing review request api (#547) --- doc/pull_request/review_request.md | 27 ++++++++ lib/Github/Api/PullRequest.php | 6 ++ lib/Github/Api/PullRequest/Review.php | 10 +++ lib/Github/Api/PullRequest/ReviewRequest.php | 66 +++++++++++++++++++ .../Api/PullRequest/ReviewRequestTest.php | 65 ++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 doc/pull_request/review_request.md create mode 100644 lib/Github/Api/PullRequest/ReviewRequest.php create mode 100644 test/Github/Tests/Api/PullRequest/ReviewRequestTest.php diff --git a/doc/pull_request/review_request.md b/doc/pull_request/review_request.md new file mode 100644 index 00000000000..5b27c21a6b0 --- /dev/null +++ b/doc/pull_request/review_request.md @@ -0,0 +1,27 @@ +## Pull Requests / Review Requests API +[Back to the "Pull Requests API"](../pull_requests.md) | [Back to the navigation](../README.md) + +The Pull Request Review API is currently available for developers to preview. +To access the API during the preview period, you must provide a custom media type in the Accept header: + +```php +$client->api('pull_request')->reviewRequests()->configure(); +``` + +### List all review requests + +```php +$reviewRequests = $client->api('pull_request')->reviewRequests()->all('twbs', 'bootstrap', 12); +``` + +### Create a review request + +```php +$client->api('pull_request')->reviewRequests()->create('twbs', 'bootstrap', 12, array('user1', 'user2')); +``` + +### Remove a review request + +```php +$client->api('pull_request')->reviewRequests()->remove('twbs', 'bootstrap', 12, array('user1', 'user2')); +``` diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 52cc77fe348..c732b362b09 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -4,6 +4,7 @@ use Github\Api\PullRequest\Comments; use Github\Api\PullRequest\Review; +use Github\Api\PullRequest\ReviewRequest; use Github\Exception\MissingArgumentException; /** @@ -71,6 +72,11 @@ public function reviews() return new Review($this->client); } + public function reviewRequests() + { + return new ReviewRequest($this->client); + } + /** * Create a pull request. * diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 8977bddf8dd..fdbf8d1e5bc 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -3,6 +3,7 @@ namespace Github\Api\PullRequest; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; @@ -14,6 +15,15 @@ */ class Review extends AbstractApi { + use AcceptHeaderTrait; + + public function configure() + { + $this->acceptHeaderValue = 'application/vnd.github.black-cat-preview+json'; + + return $this; + } + /** * Get a listing of a pull request's reviews by the username, repository and pull request number. * diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php new file mode 100644 index 00000000000..a8b454b93d3 --- /dev/null +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -0,0 +1,66 @@ +acceptHeaderValue = 'application/vnd.github.black-cat-preview+json'; + + return $this; + } + + /** + * @link https://developer.github.com/v3/pulls/review_requests/#list-review-requests + * + * @param string $username + * @param string $repository + * @param int $pullRequest + * @param array $params + * + * @return array + */ + public function all($username, $repository, $pullRequest, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', $params); + } + + /** + * @link https://developer.github.com/v3/pulls/review_requests/#create-a-review-request + * + * @param string $username + * @param string $repository + * @param int $pullRequest + * @param array $reviewers + * + * @return string + */ + public function create($username, $repository, $pullRequest, array $reviewers) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]); + } + + /** + * @link https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request + * + * @param string $username + * @param string $repository + * @param int $pullRequest + * @param array $reviewers + * + * @return string + */ + public function remove($username, $repository, $pullRequest, array $reviewers) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]); + } +} diff --git a/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php b/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php new file mode 100644 index 00000000000..f6d98cb3a77 --- /dev/null +++ b/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php @@ -0,0 +1,65 @@ + 80], + ['id' => 81], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->all('octocat', 'Hello-World', 12)); + } + + /** + * @test + */ + public function shouldCreateReviewRequest() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser']]) + ; + + $api->create('octocat', 'Hello-World', 12, ['testuser']); + } + + /** + * @test + */ + public function shouldDeleteReviewRequest() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser']]) + ; + + $api->remove('octocat', 'Hello-World', 12, ['testuser']); + } + + /** + * @return string + */ + protected function getApiClass() + { + return ReviewRequest::class; + } +} From 48bd26cbf33eff09de1fe64efbbb468d6ac25cc2 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 26 Mar 2017 14:44:08 +0200 Subject: [PATCH 513/951] Use parameters array instead of inline query param (#546) --- lib/Github/Api/User.php | 2 +- test/Github/Tests/Api/UserTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index c11716040d8..d4dc6bccbf6 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -40,7 +40,7 @@ public function all($id = null) return $this->get('/users'); } - return $this->get('/users?since=' . rawurldecode($id)); + return $this->get('/users', ['since' => rawurldecode($id)]); } /** diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 8e505cfd862..b93d62b3c03 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -82,6 +82,25 @@ public function shouldGetAllUsers() $this->assertEquals($expectedArray, $api->all()); } + /** + * @test + */ + public function shouldGetAllUsersSince() + { + $expectedArray = array( + array('id' => 3, 'username' => 'test3'), + array('id' => 4, 'username' => 'test4') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/users', ['since' => 2]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all(2)); + } + /** * @test */ From 8a6d6e9b58be1abe36e58791959337295dc221a0 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 26 Mar 2017 14:44:57 +0200 Subject: [PATCH 514/951] Added docs for response headers (#545) --- doc/README.md | 1 + doc/request_response_info.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 doc/request_response_info.md diff --git a/doc/README.md b/doc/README.md index ba33a60c503..ea20c6a6897 100644 --- a/doc/README.md +++ b/doc/README.md @@ -48,3 +48,4 @@ Additional features: * [Request any Route](request_any_route.md) * [Customize `php-github-api`](customize.md) * [Running and writing tests](testing.md) +* [Request / Response info](request_response_info.md) diff --git a/doc/request_response_info.md b/doc/request_response_info.md new file mode 100644 index 00000000000..880e7f85a22 --- /dev/null +++ b/doc/request_response_info.md @@ -0,0 +1,14 @@ +## Request / Response information +[Back to the navigation](README.md) + +### Get response headers + +Get the repsonse header for the latest request + +``` +$headers = $githubClient->getLastResponse()->getHeaders(); +//Example headers +$headers['X-RateLimit-Remaining']; +$headers['X-OAuth-Scopes']; +$headers['X-Accepted-OAuth-Scopes']; +``` From 9b66e473522163f2dc36a02f21918f75be70dd2f Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 26 Mar 2017 14:45:46 +0200 Subject: [PATCH 515/951] Chainable/fluent configure methods (#544) * Make chaining available in Stargazers Allows for: ```php $stargazers = $client->repo()->stargazers()->configure('star')->all('vuejs', 'vue'); ``` instead of ```php $stargazers = $client->repo()->stargazers(); $stargazers->configure('star'); $stargazers = $stargazers->all('vuejs', 'vue'); ``` * Make all configure methods chainable --- lib/Github/Api/GitData/Blobs.php | 4 ++++ lib/Github/Api/Issue/Comments.php | 4 ++++ lib/Github/Api/Project/AbstractProjectApi.php | 4 ++++ lib/Github/Api/Project/Cards.php | 4 ++++ lib/Github/Api/Project/Columns.php | 4 ++++ lib/Github/Api/Repository/Comments.php | 7 +++++++ lib/Github/Api/Repository/Stargazers.php | 4 ++++ 7 files changed, 31 insertions(+) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index b8abb415193..0cc980fef14 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -19,12 +19,16 @@ class Blobs extends AbstractApi * Configure the Accept header depending on the blob type. * * @param string|null $bodyType + * + * @return self */ public function configure($bodyType = null) { if ('raw' === $bodyType) { $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getApiVersion()); } + + return $this; } /** diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index e72b964f02e..c860c74d64e 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -20,6 +20,8 @@ class Comments extends AbstractApi * * @link https://developer.github.com/v3/issues/comments/#custom-media-types * @param string|null $bodyType + * + * @return self */ public function configure($bodyType = null) { @@ -28,6 +30,8 @@ public function configure($bodyType = null) } $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + + return $this; } /** diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php index 55bc733424f..b64f1ca19b1 100644 --- a/lib/Github/Api/Project/AbstractProjectApi.php +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -13,10 +13,14 @@ abstract class AbstractProjectApi extends AbstractApi * Configure the accept header for Early Access to the projects api * * @see https://developer.github.com/v3/repos/projects/#projects + * + * @return self */ public function configure() { $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + + return $this; } public function show($id, array $params = array()) diff --git a/lib/Github/Api/Project/Cards.php b/lib/Github/Api/Project/Cards.php index 65765b75907..61eca191040 100644 --- a/lib/Github/Api/Project/Cards.php +++ b/lib/Github/Api/Project/Cards.php @@ -14,10 +14,14 @@ class Cards extends AbstractApi * Configure the accept header for Early Access to the projects api * * @see https://developer.github.com/v3/repos/projects/#projects + * + * @return self */ public function configure() { $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + + return $this; } public function all($columnId, array $params = array()) diff --git a/lib/Github/Api/Project/Columns.php b/lib/Github/Api/Project/Columns.php index 16b9f25c327..76c555979bd 100644 --- a/lib/Github/Api/Project/Columns.php +++ b/lib/Github/Api/Project/Columns.php @@ -14,10 +14,14 @@ class Columns extends AbstractApi * Configure the accept header for Early Access to the projects api * * @see https://developer.github.com/v3/repos/projects/#projects + * + * return self */ public function configure() { $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + + return $this; } public function all($projectId, array $params = array()) diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index b1d9abe7cbe..2827ee8ad5f 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -15,6 +15,11 @@ class Comments extends AbstractApi { use AcceptHeaderTrait; + /** + * @param string|null $bodyType + * + * @return self + */ public function configure($bodyType = null) { switch ($bodyType) { @@ -35,6 +40,8 @@ public function configure($bodyType = null) } $this->acceptHeaderValue = $header; + + return $this; } public function all($username, $repository, $sha = null) diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index 9267dff4fbd..5a298b717db 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -20,12 +20,16 @@ class Stargazers extends AbstractApi * @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps * * @param string $bodyType + * + * @return self */ public function configure($bodyType = null) { if ('star' === $bodyType) { $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); } + + return $this; } public function all($username, $repository) From 8c5d3bbef78a8c7f7610a5b38a1a6eff1d2fb12e Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 27 Mar 2017 10:15:15 -0700 Subject: [PATCH 516/951] Add configure() support for issues (#532) * Add configure() support for issues Borrowed from issue comments, but changed the default bodyType to "raw" since the documentation indicates that is the default when no specific media type is passed: https://developer.github.com/v3/media/#comment-body-properties * add more configure methods to address missing custom media types - also fixes the Issue/Comments default configure value - also adds support for polaris-preview in PullRequest - also adds support for squirrel-girl-preview in PullRequest/Comments - replaces switch case with in_array in Repository/Comments to standardize * switch order of configure values for PullRequest and PullRequest/Comments Users would more commonly be interested in changing the bodyType rather than apiVersion Also, added missing @param values * update configure() to be chainable per #544 * revert existing bodyTypes that were defaulting to "full" instead of "raw" Per @Nyholm "I think the best solution is to accept that we made a mistake before by keep the default body type to full for the comments API. In general we should align with the docs. Making a new major release just for this fix is not a good solution. What we should do is to create a new issue suggesting this change and add that issue in a 3.0 milestone. So in short: Just change this back to full and I'll be happy to merge." --- lib/Github/Api/Gist/Comments.php | 22 ++++++++++++++++++ lib/Github/Api/Gists.php | 21 +++++++++++++++++ lib/Github/Api/Issue.php | 21 +++++++++++++++++ lib/Github/Api/PullRequest.php | 30 +++++++++++++++++++++++++ lib/Github/Api/PullRequest/Comments.php | 27 ++++++++++++++++++++++ lib/Github/Api/Repository/Comments.php | 22 +++++------------- lib/Github/Api/Repository/Contents.php | 22 ++++++++++++++++++ 7 files changed, 149 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 521e4d03bb4..e77428c1a53 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -3,6 +3,7 @@ namespace Github\Api\Gist; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://developer.github.com/v3/gists/comments/ @@ -10,6 +11,27 @@ */ class Comments extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/gists/comments/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('text', 'html', 'full'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * Get all comments for a gist. * diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 9710e6de683..c661dfebbc2 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -14,6 +14,27 @@ */ class Gists extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/gists/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('base64'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + + return $this; + } + public function all($type = null) { if (!in_array($type, array('public', 'starred'))) { diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 4c30783473d..fa79ffa63cc 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -19,6 +19,27 @@ */ class Issue extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/issues/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('text', 'html', 'full'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * List issues by username, repo and state. * diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index c732b362b09..a47509197c3 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -15,6 +15,36 @@ */ class PullRequest extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/pulls/#custom-media-types + * @param string|null $bodyType + * @param string|null $apiVersion + * + * @return self + */ + public function configure($bodyType = null, $apiVersion = null) + { + if (!in_array($apiVersion, array('polaris-preview'))) { + $apiVersion = $this->client->getApiVersion(); + } + + if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) { + $bodyType = 'raw'; + } + + if (!in_array($bodyType, array('diff', 'patch'))) { + $bodyType .= '+json'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * Get a listing of a project's pull requests by the username, repository and (optionally) state. * diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index b2de809ed7a..161c629909e 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -3,6 +3,7 @@ namespace Github\Api\PullRequest; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** @@ -11,6 +12,32 @@ */ class Comments extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/pulls/comments/#custom-media-types + * @param string|null $bodyType + * @param string|null @apiVersion + * + * @return self + */ + public function configure($bodyType = null, $apiVersion = null) + { + if (!in_array($apiVersion, array('squirrel-girl-preview'))) { + $apiVersion = $this->client->getApiVersion(); + } + + if (!in_array($bodyType, array('text', 'html', 'full'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $apiVersion, $bodyType); + + return $this; + } + public function all($username, $repository, $pullRequest = null) { if (null !== $pullRequest) { diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index 2827ee8ad5f..4e993720296 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -16,30 +16,20 @@ class Comments extends AbstractApi use AcceptHeaderTrait; /** + * Configure the body type. + * + * @link https://developer.github.com/v3/repos/comments/#custom-media-types * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - switch ($bodyType) { - case 'raw': - $header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getApiVersion()); - break; - - case 'text': - $header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getApiVersion()); - break; - - case 'html': - $header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getApiVersion()); - break; - - default: - $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getApiVersion()); + if (!in_array($bodyType, array('raw', 'text', 'html'))) { + $bodyType = 'full'; } - $this->acceptHeaderValue = $header; + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); return $this; } diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 064f68490ff..387413bb053 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -3,6 +3,7 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\InvalidArgumentException; use Github\Exception\ErrorException; use Github\Exception\MissingArgumentException; @@ -14,6 +15,27 @@ */ class Contents extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/repo/contents/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('html', 'object'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * Get content of README file in a repository. * From d26bc79b068fd5bc2aa37ab679c310430796322e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 28 Mar 2017 09:27:09 +0200 Subject: [PATCH 517/951] Use the new cache plugin factory method (#531) --- composer.json | 2 +- doc/README.md | 1 + doc/caching.md | 30 ++++++++++++++++++++++++++++++ lib/Github/HttpClient/Builder.php | 4 ++-- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 doc/caching.md diff --git a/composer.json b/composer.json index b9595471044..3e519ef5eeb 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", "php-http/client-common": "^1.3", - "php-http/cache-plugin": "^1.2" + "php-http/cache-plugin": "^1.3" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.5", diff --git a/doc/README.md b/doc/README.md index ea20c6a6897..20abcd6373a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -48,4 +48,5 @@ Additional features: * [Request any Route](request_any_route.md) * [Customize `php-github-api`](customize.md) * [Running and writing tests](testing.md) +* [Response caching](caching.md) * [Request / Response info](request_response_info.md) diff --git a/doc/caching.md b/doc/caching.md new file mode 100644 index 00000000000..a95f92e9eea --- /dev/null +++ b/doc/caching.md @@ -0,0 +1,30 @@ +## Response caching +[Back to the navigation](README.md) + +This example uses the PSR6 cache pool [redis-adapter](https://github.com/php-cache/redis-adapter). See http://www.php-cache.com/ for alternatives. + +```php +connect('127.0.0.1', 6379); +// Create a PSR6 cache pool +$pool = new RedisCachePool($client); + +$client = new \Github\Client(); +$client->addCache($pool); + +// Do some request + +// Stop using cache +$client->removeCache(); +``` + +Using cache, the client will get cached responses if resources haven't changed since last time, +**without** reaching the `X-Rate-Limit` [imposed by github](http://developer.github.com/v3/#rate-limiting). + diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 5b742285bd9..e42a5efe22e 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -176,12 +176,12 @@ public function addHeaderValue($header, $headerValue) /** * Add a cache plugin to cache responses locally. * - * @param CacheItemPoolInterface $cache + * @param CacheItemPoolInterface $cachePool * @param array $config */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { - $this->cachePlugin = new Plugin\CachePlugin($cachePool, $this->streamFactory, $config); + $this->cachePlugin = Plugin\CachePlugin::clientCache($cachePool, $this->streamFactory, $config); $this->httpClientModified = true; } From 80cb9e9f8441f0e80cb39557dfcebed19863a45d Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 28 Mar 2017 09:59:30 +0200 Subject: [PATCH 518/951] Added changelog for 2.2.0 (#552) * Added changelog for 2.2.0 * Fixed typo * Typo --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7ba646f00b..24e0186561f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.2.0 + +### Added + +- API support for Reviews. +- API support for Traffic. +- API support for issue Assignees. +- API support for Miscellaneous Gitignore and Emojis. +- Added endpoints for issue lock, unlock and issue label show. +- Added more parameters to `User::starred`. +- Fluid interface by allowing `configure()` to return `$this`. +- `configure()` support for issues API. + +### Fixed + +- Cache issue where some requests are not cached +- Issue with `User::all()` creates a query with double question marks. + ## 2.1.0 ### Added From 387d21e897c245dbb3e4f07bc754dcfddc1ea3cd Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 28 Mar 2017 10:18:25 +0200 Subject: [PATCH 519/951] Updated branch alias (#553) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e519ef5eeb..5b226cc70bb 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "2.3.x-dev" } } } From a6e9b065927ef724ff3b858cde834f3090a66387 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 8 Apr 2017 17:53:18 +0200 Subject: [PATCH 520/951] Renamed "functional" tests to "integration" tests (#564) --- phpunit.xml.dist | 2 +- test/Github/Tests/{Functional => Integration}/CommitTest.php | 4 ++-- test/Github/Tests/{Functional => Integration}/GistTest.php | 4 ++-- .../Tests/{Functional => Integration}/IssueCommentTest.php | 4 ++-- .../Github/Tests/{Functional => Integration}/MarkdownTest.php | 4 ++-- .../Tests/{Functional => Integration}/RateLimitTest.php | 4 ++-- .../Tests/{Functional => Integration}/RepoCommentTest.php | 4 ++-- test/Github/Tests/{Functional => Integration}/RepoTest.php | 4 ++-- .../Tests/{Functional => Integration}/ResultPagerTest.php | 4 ++-- test/Github/Tests/{Functional => Integration}/TestCase.php | 4 ++-- test/Github/Tests/{Functional => Integration}/UserTest.php | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) rename test/Github/Tests/{Functional => Integration}/CommitTest.php (97%) rename test/Github/Tests/{Functional => Integration}/GistTest.php (97%) rename test/Github/Tests/{Functional => Integration}/IssueCommentTest.php (98%) rename test/Github/Tests/{Functional => Integration}/MarkdownTest.php (94%) rename test/Github/Tests/{Functional => Integration}/RateLimitTest.php (86%) rename test/Github/Tests/{Functional => Integration}/RepoCommentTest.php (98%) rename test/Github/Tests/{Functional => Integration}/RepoTest.php (98%) rename test/Github/Tests/{Functional => Integration}/ResultPagerTest.php (95%) rename test/Github/Tests/{Functional => Integration}/TestCase.php (93%) rename test/Github/Tests/{Functional => Integration}/UserTest.php (98%) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 619d9706a7a..0f71eb3983d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,7 +19,7 @@ - functional + integration diff --git a/test/Github/Tests/Functional/CommitTest.php b/test/Github/Tests/Integration/CommitTest.php similarity index 97% rename from test/Github/Tests/Functional/CommitTest.php rename to test/Github/Tests/Integration/CommitTest.php index 4aec0b3cc60..8dcaa0d022e 100644 --- a/test/Github/Tests/Functional/CommitTest.php +++ b/test/Github/Tests/Integration/CommitTest.php @@ -1,9 +1,9 @@ Date: Fri, 14 Apr 2017 10:12:16 +0200 Subject: [PATCH 521/951] Make sure we vary on the Authorization header (#558) * Make sure we vary on the Authorization header * Updated name * Added Content-type * Allow us to test unreleased versions * Added functional tests * Reduced unneeded code * updateing deps * Do not use any php5.5+ code --- composer.json | 8 ++- lib/Github/HttpClient/Builder.php | 4 ++ test/Github/Tests/Functional/CacheTest.php | 68 ++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 test/Github/Tests/Functional/CacheTest.php diff --git a/composer.json b/composer.json index 5b226cc70bb..e5a0e106c83 100644 --- a/composer.json +++ b/composer.json @@ -24,17 +24,21 @@ "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", "php-http/client-common": "^1.3", - "php-http/cache-plugin": "^1.3" + "php-http/cache-plugin": "^1.4" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.5", "php-http/guzzle6-adapter": "^1.0", + "php-http/mock-client": "^1.0", "guzzlehttp/psr7": "^1.2", - "sllh/php-cs-fixer-styleci-bridge": "^1.3" + "sllh/php-cs-fixer-styleci-bridge": "^1.3", + "cache/array-adapter": "^0.4" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } }, + "minimum-stability": "dev", + "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "2.3.x-dev" diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index e42a5efe22e..d87a021c076 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -13,6 +13,7 @@ use Http\Message\RequestFactory; use Http\Message\StreamFactory; use Psr\Cache\CacheItemPoolInterface; +use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; /** * A builder that builds the API client. @@ -181,6 +182,9 @@ public function addHeaderValue($header, $headerValue) */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { + if (!isset($config['cache_key_generator'])) { + $config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept', 'Content-type']); + } $this->cachePlugin = Plugin\CachePlugin::clientCache($cachePool, $this->streamFactory, $config); $this->httpClientModified = true; } diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php new file mode 100644 index 00000000000..31c6f5a4f5d --- /dev/null +++ b/test/Github/Tests/Functional/CacheTest.php @@ -0,0 +1,68 @@ + + */ +class CacheTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + */ + public function shouldServeCachedResponse() + { + $mockClient = new \Http\Mock\Client(); + $mockClient->addResponse($this->getCurrentUserResponse('nyholm')); + $mockClient->addResponse($this->getCurrentUserResponse('octocat')); + + $github = Client::createWithHttpClient($mockClient); + $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); + + $github->authenticate('fake_token_aaa', Client::AUTH_HTTP_TOKEN); + $userA = $github->currentUser()->show(); + $this->assertEquals('nyholm', $userA['login']); + + $userB = $github->currentUser()->show(); + $this->assertEquals('nyholm', $userB['login'], 'Two request following each other should be cached.'); + } + /** + * @test + */ + public function shouldVaryOnAuthorization() + { + $mockClient = new \Http\Mock\Client(); + $mockClient->addResponse($this->getCurrentUserResponse('nyholm')); + $mockClient->addResponse($this->getCurrentUserResponse('octocat')); + + $github = Client::createWithHttpClient($mockClient); + $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); + + $github->authenticate('fake_token_aaa', Client::AUTH_HTTP_TOKEN); + $userA = $github->currentUser()->show(); + $this->assertEquals('nyholm', $userA['login']); + + $github->authenticate('fake_token_bbb', Client::AUTH_HTTP_TOKEN); + $userB = $github->currentUser()->show(); + $this->assertEquals('octocat', $userB['login'], 'We must vary on the Authorization header.'); + } + + private function getCurrentUserResponse($username) + { + $headers = [ + 'Content-Type' => 'application/json', + ]; + + $body = \GuzzleHttp\Psr7\stream_for(json_encode([ + 'login' => $username, + ])); + + return new Response(200, $headers, $body); + } +} From 65a205979ccf8911dff7e8c054c0039944e32d21 Mon Sep 17 00:00:00 2001 From: Josh Waihi Date: Fri, 14 Apr 2017 20:16:12 +1200 Subject: [PATCH 522/951] Allow userId to be an optional argument. (#556) --- lib/Github/Api/Integrations.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index 7af6a093482..0ab6768e036 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -23,7 +23,6 @@ public function createInstallationToken($installationId, $userId = null) if ($userId) { $parameters['user_id'] = $userId; } - return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); } @@ -48,9 +47,13 @@ public function findInstallations() * * @return array */ - public function listRepositories($userId) + public function listRepositories($userId = null) { - return $this->get('/installation/repositories', ['user_id' => $userId]); + $parameters = array(); + if ($userId) { + $parameters['user_id'] = $userId; + } + return $this->get('/installation/repositories', $parameters); } /** From ae43b2764c2c952e5a441c7a2e599a899a0ee47f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 14 Apr 2017 11:50:09 +0100 Subject: [PATCH 523/951] Reverted bad cs change (#567) * Reverted bad cs change * Update Integrations.php --- lib/Github/Api/Integrations.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index 0ab6768e036..ca797870e2a 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -23,6 +23,7 @@ public function createInstallationToken($installationId, $userId = null) if ($userId) { $parameters['user_id'] = $userId; } + return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); } @@ -53,6 +54,7 @@ public function listRepositories($userId = null) if ($userId) { $parameters['user_id'] = $userId; } + return $this->get('/installation/repositories', $parameters); } From 63325b7f419936664a6bf8301efc4a341a92481a Mon Sep 17 00:00:00 2001 From: Alex Slaughter Date: Fri, 14 Apr 2017 16:12:36 -0400 Subject: [PATCH 524/951] Add support for fetching statuses (#565) * Add support for fetching statuses * fix style ci * Add docs, add test, linter cleanup * Merge in master * Update language * Fix test --- lib/Github/Api/PullRequest.php | 23 ++++++++++- test/Github/Tests/Api/PullRequestTest.php | 50 ++++++++++++++++------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index a47509197c3..d88db8cf9c8 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -10,7 +10,8 @@ /** * API for accessing Pull Requests from your Git/Github repositories. * - * @link http://developer.github.com/v3/pulls/ + * @see http://developer.github.com/v3/pulls/ + * * @author Joseph Bielawski */ class PullRequest extends AbstractApi @@ -60,7 +61,7 @@ public function all($username, $repository, array $params = array()) { $parameters = array_merge(array( 'page' => 1, - 'per_page' => 30 + 'per_page' => 30, ), $params); return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); @@ -92,6 +93,24 @@ public function files($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files'); } + /** + * All statuses which are the statuses of its head branch. + * + * @see http://developer.github.com/v3/pulls/ + * + * @param string $username the username + * @param string $repository the repository + * @param string $id the ID of the pull request for which statuses are retrieved + * + * @return array array of statuses for the project + */ + public function status($username, $repository, $id) + { + $link = $this->show($username, $repository, $id)['_links']['statuses']['href']; + + return $this->get($link); + } + public function comments() { return new Comments($this->client); diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 672093f5cda..cfcc005599d 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -101,6 +101,28 @@ public function shouldShowFilesFromPullRequest() $this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15')); } + /** + * @test + */ + public function shouldShowStatusesFromPullRequest() + { + $expectedArray = array(array('id' => 'id', 'sha' => '123123')); + $expectedArray['_links']['statuses']['href'] = '/repos/ezsystems/ezpublish/pulls/15/statuses'; + + $api = $this->getApiMock(); + $api->expects($this->at(0)) + ->method('get') + ->with('/repos/ezsystems/ezpublish/pulls/15') + ->will($this->returnValue($expectedArray)); + + $api->expects($this->at(1)) + ->method('get') + ->with('/repos/ezsystems/ezpublish/pulls/15/statuses') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->status('ezsystems', 'ezpublish', '15')); + } + /** * @test */ @@ -187,10 +209,10 @@ public function shouldMergePullRequestWithMergeMethod() public function shouldCreatePullRequestUsingTitle() { $data = array( - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API' + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ); $api = $this->getApiMock(); @@ -207,9 +229,9 @@ public function shouldCreatePullRequestUsingTitle() public function shouldCreatePullRequestUsingIssueId() { $data = array( - 'base' => 'master', - 'head' => 'virtualtestbranch', - 'issue' => 25 + 'base' => 'master', + 'head' => 'virtualtestbranch', + 'issue' => 25, ); $api = $this->getApiMock(); @@ -227,9 +249,9 @@ public function shouldCreatePullRequestUsingIssueId() public function shouldNotCreatePullRequestWithoutBase() { $data = array( - 'head' => 'virtualtestbranch', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API' + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ); $api = $this->getApiMock(); @@ -246,9 +268,9 @@ public function shouldNotCreatePullRequestWithoutBase() public function shouldNotCreatePullRequestWithoutHead() { $data = array( - 'base' => 'master', + 'base' => 'master', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API' + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ); $api = $this->getApiMock(); @@ -265,8 +287,8 @@ public function shouldNotCreatePullRequestWithoutHead() public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { $data = array( - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', ); @@ -284,8 +306,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() public function shouldNotCreatePullRequestWithoutIssueIdOrTitle() { $data = array( - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', ); $api = $this->getApiMock(); From e306f0750277a89011d297326f5f308daffa0838 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 17 Apr 2017 23:13:14 -0700 Subject: [PATCH 525/951] The Merge methods API is now official (#562) * The Merge methods API is now official see: https://developer.github.com/changes/2017-04-07-end-merge-methods-api-preview/ this removes the apiVersion (that wasn't being used anyway..) also adds support for rebase mergeMethod per https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button Since this previously looked for the value to be bool, this is a breaking change * retain weird bool support for this value * let github throw errors instead * add back in $apiVersion to make it easier to handle preview versions in the future there are no preview versions now so checking against an empty array also had to fix the acceptHeaderValue to correctly use the variable * throw invalidargumentexception when trying to use invalid merge method * add missing use --- lib/Github/Api/PullRequest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index d88db8cf9c8..54bea84a8a2 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -5,6 +5,7 @@ use Github\Api\PullRequest\Comments; use Github\Api\PullRequest\Review; use Github\Api\PullRequest\ReviewRequest; +use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; /** @@ -29,7 +30,7 @@ class PullRequest extends AbstractApi */ public function configure($bodyType = null, $apiVersion = null) { - if (!in_array($apiVersion, array('polaris-preview'))) { + if (!in_array($apiVersion, array())) { $apiVersion = $this->client->getApiVersion(); } @@ -41,7 +42,7 @@ public function configure($bodyType = null, $apiVersion = null) $bodyType .= '+json'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $apiVersion, $bodyType); return $this; } @@ -182,6 +183,10 @@ public function merge($username, $repository, $id, $message, $sha, $mergeMethod $mergeMethod = $mergeMethod ? 'squash' : 'merge'; } + if (!in_array($mergeMethod, array('merge', 'squash', 'rebase'), true)) { + throw new InvalidArgumentException(sprintf('"$mergeMethod" must be one of ["merge", "squash", "rebase"] ("%s" given).', $mergeMethod)); + } + $params = array( 'commit_message' => $message, 'sha' => $sha, From 717bfa8ace2a965e738001092e0b4c4cf797937a Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Tue, 18 Apr 2017 10:30:22 -0700 Subject: [PATCH 526/951] add configure to branch protection for preview access (#568) --- lib/Github/Api/Repository/Protection.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 6976870da13..6e12410c2ce 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -3,6 +3,7 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://developer.github.com/v3/repos/branches/ @@ -10,6 +11,15 @@ */ class Protection extends AbstractApi { + use AcceptHeaderTrait; + + public function configure() + { + $this->acceptHeaderValue = 'application/vnd.github.loki-preview+json'; + + return $this; + } + /** * Retrieves configured protection for the provided branch * From 6a211e15216db23959cbb1af5776f261b9ed11d4 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Tue, 18 Apr 2017 11:09:35 -0700 Subject: [PATCH 527/951] add basic branch protection docs (#569) * add basic branch protection docs * example params for branch protection --- doc/README.md | 1 + doc/repo/protection.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 doc/repo/protection.md diff --git a/doc/README.md b/doc/README.md index 20abcd6373a..ebc64840d37 100644 --- a/doc/README.md +++ b/doc/README.md @@ -32,6 +32,7 @@ APIs: * [Repositories](repos.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) + * [Protection](repo/protection.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) * [Stargazers](repo/stargazers.md) diff --git a/doc/repo/protection.md b/doc/repo/protection.md new file mode 100644 index 00000000000..89a7fc550b3 --- /dev/null +++ b/doc/repo/protection.md @@ -0,0 +1,35 @@ +## Repo / Protection API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +The Protection API is currently available for developers to preview. +To access the API during the preview period, you must provide a custom media type in the Accept header: + +```php +$client->api('repo')->protection()->configure(); +``` + +### List all branch protection + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'master'); +``` + +### Update branch protection + +> Requires [authentication](../security.md). + +For the full list of parameters see https://developer.github.com/v3/repos/branches/#parameters-1 + +```php +$params = [ + 'required_status_checks' => null, + 'required_pull_request_reviews' => [ + 'include_admins' => true, + ], + 'enforce_admins' => true, + 'restrictions' => null, +]; +$protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'master', $params); +``` From 4d4a62820d0274c477c1765303f74254cc278097 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 18 Apr 2017 20:51:11 +0200 Subject: [PATCH 528/951] Changelog for 2.3.0 (#570) * Changelog for 2.3.0 * typo --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e0186561f..52431808950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.3.0 + +### Fixed + +- Issue where we serve the wrong cached response. We vary on authorization header now. + +### Added + +- `PullRequest::status` +- Throw InvalidArgumentException on `PullRequest::merge` when wrong merge method is used. +- Added `Protection::configure` + +### Changed + +- First argument to `Integrations::listRepositories()` is now optional. +- Moved tests from "functional" to "integration" + ## 2.2.0 ### Added From d88dbc667fcb944413fea8485793c0cf7ce7693c Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 18 Apr 2017 21:08:34 +0200 Subject: [PATCH 529/951] Update branch alias (#571) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5a0e106c83..f3b7e544f69 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "2.4.x-dev" } } } From 556f7d98e7e9e30a1f7753efe13fb60f4162b37e Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 24 Apr 2017 10:48:34 -0700 Subject: [PATCH 530/951] Fix milestone doc typo (#575) * fix typo in milestone doc page * change header text to be more clear now that github has the concept of "projects" it makes sense to not misuse that term here --- doc/issue/milestones.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/issue/milestones.md b/doc/issue/milestones.md index 25ead337894..e376d221fa6 100644 --- a/doc/issue/milestones.md +++ b/doc/issue/milestones.md @@ -3,7 +3,7 @@ Wraps [GitHub Issue Milestones API](http://developer.github.com/v3/issues/milestones/). -### List project milestones +### List milestones for a repository ```php $milestones = $client->api('issue')->milestones()->all('KnpLabs', 'php-github-api'); @@ -27,7 +27,7 @@ $milestone = $client->api('issue')->milestones()->create('KnpLabs', 'php-github- $milestone = $client->api('issue')->milestones()->update('KnpLabs', 'php-github-api', 123, array('title' => '3.0')); ``` -### Remove a milestonre +### Remove a milestone ```php $client->api('issue')->milestones()->remove('KnpLabs', 'php-github-api', 123); From 4729cecb521e65540cdc20588098c8193884d634 Mon Sep 17 00:00:00 2001 From: Andrey Astakhov Date: Wed, 3 May 2017 05:58:02 +0200 Subject: [PATCH 531/951] Add support for pagination and parameters in the pull request comments API. (#576) * Add support for pagination and parameters to review comments API. * Add doc blocks and links. --- lib/Github/Api/PullRequest/Comments.php | 73 ++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 161c629909e..18679ca133e 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -38,20 +38,64 @@ public function configure($bodyType = null, $apiVersion = null) return $this; } - public function all($username, $repository, $pullRequest = null) + /** + * Get a listing of a pull request's comments by the username, repository and pull request number + * or all repository comments by the username and repository. + * + * @link https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request + * @link https://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + * + * @param string $username the username + * @param string $repository the repository + * @param int|null $pullRequest the pull request number + * @param array $params a list of extra parameters. + * + * @return array + */ + public function all($username, $repository, $pullRequest = null, array $params = []) { if (null !== $pullRequest) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); } - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments'); + $parameters = array_merge([ + 'page' => 1, + 'per_page' => 30 + ], $params); + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments', $parameters); } + /** + * Get a single pull request comment by the username, repository and comment id. + * + * @link https://developer.github.com/v3/pulls/comments/#get-a-single-comment + * + * @param string $username the username + * @param string $repository the repository + * @param int $comment the comment id + * + * @return array + */ public function show($username, $repository, $comment) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); } + /** + * Create a pull request comment by the username, repository and pull request number. + * + * @link https://developer.github.com/v3/pulls/comments/#create-a-comment + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param array $params a list of extra parameters. + * + * @throws MissingArgumentException + * + * @return array + */ public function create($username, $repository, $pullRequest, array $params) { if (!isset($params['body'])) { @@ -66,6 +110,20 @@ public function create($username, $repository, $pullRequest, array $params) return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params); } + /** + * Update a pull request comment by the username, repository and comment id. + * + * @link https://developer.github.com/v3/pulls/comments/#edit-a-comment + * + * @param string $username the username + * @param string $repository the repository + * @param int $comment the comment id + * @param array $params a list of extra parameters. + * + * @throws MissingArgumentException + * + * @return array + */ public function update($username, $repository, $comment, array $params) { if (!isset($params['body'])) { @@ -75,6 +133,17 @@ public function update($username, $repository, $comment, array $params) return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment), $params); } + /** + * Delete a pull request comment by the username, repository and comment id. + * + * @link https://developer.github.com/v3/pulls/comments/#delete-a-comment + * + * @param string $username the username + * @param string $repository the repository + * @param int $comment the comment id + * + * @return string + */ public function remove($username, $repository, $comment) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); From 155bc011c980636e0968ba145c4519dd03286d6d Mon Sep 17 00:00:00 2001 From: Benoit Del Basso Date: Thu, 4 May 2017 16:35:30 +0800 Subject: [PATCH 532/951] Add the ability to fetch user installations (#577) * Add the ability to fetch user installations * fix style * tests and support for pagination * style fix --- lib/Github/Api/CurrentUser.php | 10 ++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 742f5579774..62bb8b33610 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -168,4 +168,14 @@ public function subscriptions() { return $this->get('/user/subscriptions'); } + + /** + * @link https://developer.github.com/v3/integrations/#list-installations-for-user + * + * @param array $params + */ + public function installations(array $params = array()) + { + return $this->get('/user/installations', array_merge(array('page' => 1), $params)); + } } diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 355c0498538..6a14f29d338 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -84,6 +84,22 @@ public function shouldGetWatchedRepositories() $this->assertEquals($expectedArray, $api->watched(1)); } + /** + * @test + */ + public function shouldGetInstallationsForUser() + { + $result = ['installation1', 'installation2']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/installations') + ->willReturn($result); + + $this->assertEquals($result, $api->installations()); + } + /** * @test */ From 5de0a80e0c5bfbe0fb17ef44f0147eea3a4d5db1 Mon Sep 17 00:00:00 2001 From: Benoit Del Basso Date: Thu, 4 May 2017 22:41:00 +0800 Subject: [PATCH 533/951] add the ability to fetch repositories for a specific installation and user --- doc/integrations.md | 14 +++++++++++++- lib/Github/Api/CurrentUser.php | 11 +++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 18 +++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/doc/integrations.md b/doc/integrations.md index f3b1c1e8c6c..6e7413dde1d 100644 --- a/doc/integrations.md +++ b/doc/integrations.md @@ -18,7 +18,13 @@ $token = $client->api('integrations')->createInstallationToken(123, 456); Find all installations for the authenticated integration. ```php -Installations = $client->api('integrations')->findInstallations(); +$installations = $client->api('integrations')->findInstallations(); +``` + +### Find installations for a user + +```php +$installations = $client->api('current_user')->installations(); ``` ### List repositories @@ -28,6 +34,12 @@ List repositories that are accessible to the authenticated installation. $repositories = $client->api('integrations')->listRepositories(456); ``` +### List repositories for a given installation and user + +``` +$repositories = $client->api('current_user')->repositoriesByInstallation(456); +``` + ### Add repository to installation Add a single repository to an installation. ```php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 62bb8b33610..53dfb0dc226 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -178,4 +178,15 @@ public function installations(array $params = array()) { return $this->get('/user/installations', array_merge(array('page' => 1), $params)); } + + /** + * @link https://developer.github.com/v3/integrations/installations/#list-repositories-accessible-to-the-user-for-an-installation + * + * @param string $installationId the ID of the Installation + * @param array $params + */ + public function repositoriesByInstallation($installationId, array $params = array()) + { + return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(array('page' => 1), $params)); + } } diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 6a14f29d338..b93d94ed1bd 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -87,7 +87,7 @@ public function shouldGetWatchedRepositories() /** * @test */ - public function shouldGetInstallationsForUser() + public function shouldGetInstallations() { $result = ['installation1', 'installation2']; @@ -100,6 +100,22 @@ public function shouldGetInstallationsForUser() $this->assertEquals($result, $api->installations()); } + /** + * @test + */ + public function shouldGetRepositoriesByInstallation() + { + $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/installations/42/repositories', array('page' => 1)) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->repositoriesByInstallation(42)); + } + /** * @test */ From b3b4db498909c1331bce184f29edaae7f941bc9c Mon Sep 17 00:00:00 2001 From: Luke Cousins Date: Mon, 8 May 2017 10:41:36 +0100 Subject: [PATCH 534/951] Allow getting repo info by id, not just user and repo name (#579) * Get repo details by id * Updating doc for showById * Adding note that this is an undocumented feature * Adding test for showById() * Stating undocumented in the docs too --- doc/repos.md | 8 ++++++++ lib/Github/Api/Repo.php | 17 +++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 55ebe1326cd..7c7d83be5c5 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -44,10 +44,18 @@ $repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_p ### Get extended information about a repository +Using the username of the repository owner and the repository name: + ```php $repo = $client->api('repo')->show('KnpLabs', 'php-github-api') ``` +Or by using the repository id (note that this is at time of writing an undocumented feature, see [here](https://github.com/piotrmurach/github/issues/283) and [here](https://github.com/piotrmurach/github/issues/282)): + +```php +$repo = $client->api('repo')->showById(123456) +``` + Returns an array of information about the specified repository. ### Get the repositories of a specific user diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b730158d67e..5dbe7b9444c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -150,6 +150,23 @@ public function show($username, $repository) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } + + /** + * Get extended information about a repository by its id. + * Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on. + * + * @link http://developer.github.com/v3/repos/ + * @link https://github.com/piotrmurach/github/issues/283 + * @link https://github.com/piotrmurach/github/issues/282 + * + * @param int $id the id of the repository + * + * @return array information about the repository + */ + public function showById($id) + { + return $this->get('/repositories/'.rawurlencode($id)); + } /** * Create repository. diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index cc2e9c8e52c..beb68c415d3 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -19,6 +19,22 @@ public function shouldShowRepository() $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api')); } + + /** + * @test + */ + public function shouldShowRepositoryById() + { + $expectedArray = array('id' => 123456, 'name' => 'repoName'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repositories/123456') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->showById(123456)); + } /** * @test From 25ea2644796039f5b325d950acb58f7133579dd1 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 9 May 2017 15:42:50 +0200 Subject: [PATCH 535/951] Add Integrations::configure (#581) * Add configure() * cs fixes * Hardcode header * cs fixes * Docblock fix --- lib/Github/Api/Integrations.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index ca797870e2a..9cb801d699a 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -2,12 +2,30 @@ namespace Github\Api; +use Github\Api\AcceptHeaderTrait; + /** * @link https://developer.github.com/v3/integrations/ * @author Nils Adermann */ class Integrations extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the accept header for Early Access to the integrations api + * + * @see https://developer.github.com/v3/integrations/ + * + * @return self + */ + public function configure() + { + $this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json'; + + return $this; + } + /** * Create an access token for an installation * From 7c2afd8d58d64a3d4e9da72d6c73a0930802113e Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Wed, 10 May 2017 05:23:52 -0700 Subject: [PATCH 536/951] Remove need to use configure() on PR review and review request (#584) --- doc/pull_request/review_request.md | 7 ------- lib/Github/Api/PullRequest/Review.php | 2 -- lib/Github/Api/PullRequest/ReviewRequest.php | 2 -- 3 files changed, 11 deletions(-) diff --git a/doc/pull_request/review_request.md b/doc/pull_request/review_request.md index 5b27c21a6b0..bed33a426c2 100644 --- a/doc/pull_request/review_request.md +++ b/doc/pull_request/review_request.md @@ -1,13 +1,6 @@ ## Pull Requests / Review Requests API [Back to the "Pull Requests API"](../pull_requests.md) | [Back to the navigation](../README.md) -The Pull Request Review API is currently available for developers to preview. -To access the API during the preview period, you must provide a custom media type in the Accept header: - -```php -$client->api('pull_request')->reviewRequests()->configure(); -``` - ### List all review requests ```php diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index fdbf8d1e5bc..40c8db83127 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -19,8 +19,6 @@ class Review extends AbstractApi public function configure() { - $this->acceptHeaderValue = 'application/vnd.github.black-cat-preview+json'; - return $this; } diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php index a8b454b93d3..8321fd27cac 100644 --- a/lib/Github/Api/PullRequest/ReviewRequest.php +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -14,8 +14,6 @@ class ReviewRequest extends AbstractApi public function configure() { - $this->acceptHeaderValue = 'application/vnd.github.black-cat-preview+json'; - return $this; } From eba0b92a4e23dd37abd75f99323a1b463b205d77 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 10 May 2017 15:37:39 +0200 Subject: [PATCH 537/951] Prepare for release 2.4.0 (#582) * Prepare for release 2.4.0 * Update CHANGELOG.md * Typo --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52431808950..14f8fd8e7b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.4.0 + +### Added + +- `Integrations::configure` to allow accessing early access program endpoints. +- Add support for pagination and parameters in the pull request comments +- Add the ability to fetch user installations (`CurrentUser::installations`) +- Allow getting repo info by id (`Repo::showById`) +- Allow fetching repositories for a specific installation and user (`CurrentUser::repositoriesByInstallation`) + +### Changed + +- `PullRequest\Review` and `PullRequest\ReviewRequest` is now part of the official API. No need to call `configure`. + ## 2.3.0 ### Fixed From 513e76772aa67e8f75cc9dc888123ae6a569d7ab Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 10 May 2017 16:17:17 +0200 Subject: [PATCH 538/951] Update branch alias (#585) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f3b7e544f69..06181293b35 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.4.x-dev" + "dev-master": "2.5.x-dev" } } } From 4962b5b7653178ee84106e4bdb2a83c974c6f91b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 15 May 2017 15:02:05 +0200 Subject: [PATCH 539/951] clarify changelog (#589) There's to different APIs that are easy to confuse. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f8fd8e7b9..e8225105d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- API support for Reviews. +- API support for Pull Request Review Requests. - API support for Traffic. - API support for issue Assignees. - API support for Miscellaneous Gitignore and Emojis. From baee5ccd35a0247dd85d6cdf47aa3cf1428e6e14 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:02:37 +0200 Subject: [PATCH 540/951] Update and rename Integrations.php to Apps.php --- lib/Github/Api/{Integrations.php => Apps.php} | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) rename lib/Github/Api/{Integrations.php => Apps.php} (60%) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Apps.php similarity index 60% rename from lib/Github/Api/Integrations.php rename to lib/Github/Api/Apps.php index 9cb801d699a..1ebce7218c3 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Apps.php @@ -5,27 +5,13 @@ use Github\Api\AcceptHeaderTrait; /** - * @link https://developer.github.com/v3/integrations/ + * @link https://developer.github.com/v3/apps/ * @author Nils Adermann */ -class Integrations extends AbstractApi +class Apps extends AbstractApi { use AcceptHeaderTrait; - /** - * Configure the accept header for Early Access to the integrations api - * - * @see https://developer.github.com/v3/integrations/ - * - * @return self - */ - public function configure() - { - $this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json'; - - return $this; - } - /** * Create an access token for an installation * @@ -48,19 +34,19 @@ public function createInstallationToken($installationId, $userId = null) /** * Find all installations for the authenticated integration. * - * @link https://developer.github.com/v3/integrations/#find-installations + * @link https://developer.github.com/v3/apps/#find-installations * * @return array */ public function findInstallations() { - return $this->get('/integration/installations'); + return $this->get('/app/installations'); } /** * List repositories that are accessible to the authenticated installation. * - * @link https://developer.github.com/v3/integrations/installations/#list-repositories + * @link https://developer.github.com/v3/apps/installations/#list-repositories * * @param int $userId * @@ -73,13 +59,13 @@ public function listRepositories($userId = null) $parameters['user_id'] = $userId; } - return $this->get('/installation/repositories', $parameters); + return $this->get('/app/repositories', $parameters); } /** * Add a single repository to an installation. * - * @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation + * @link https://developer.github.com/v3/apps/installations/#add-repository-to-installation * * @param int $installationId * @param int $repositoryId @@ -88,13 +74,13 @@ public function listRepositories($userId = null) */ public function addRepository($installationId, $repositoryId) { - return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->put('/app/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } /** * Remove a single repository from an installation. * - * @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation + * @link https://developer.github.com/v3/apps/installations/#remove-repository-from-installation * * @param int $installationId * @param int $repositoryId @@ -103,6 +89,6 @@ public function addRepository($installationId, $repositoryId) */ public function removeRepository($installationId, $repositoryId) { - return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->delete('/app/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } } From 53c433d815b235a6fd515104a8b32095ac5bc44f Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:05:19 +0200 Subject: [PATCH 541/951] Update Client.php --- lib/Github/Client.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ad282661d12..f8ae9c27d7a 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -29,8 +29,9 @@ * @method Api\Gists gist() * @method Api\Gists gists() * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Integrations integration() - * @method Api\Integrations integrations() + * @method Api\Apps integration() (deprecated) + * @method Api\Apps integrations() (deprecated) + * @method Api\Apps apps() * @method Api\Issue issue() * @method Api\Issue issues() * @method Api\Markdown markdown() @@ -200,7 +201,8 @@ public function api($name) case 'integration': case 'integrations': - $api = new Api\Integrations($this); + case 'apps': + $api = new Api\Apps($this); break; case 'issue': From 46da27158d1e47839ed4f2ad10b5cfc52e2e258a Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:07:01 +0200 Subject: [PATCH 542/951] Update tests --- .../Github/Tests/Api/{IntegrationTest.php => AppTest.php} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename test/Github/Tests/Api/{IntegrationTest.php => AppTest.php} (88%) diff --git a/test/Github/Tests/Api/IntegrationTest.php b/test/Github/Tests/Api/AppTest.php similarity index 88% rename from test/Github/Tests/Api/IntegrationTest.php rename to test/Github/Tests/Api/AppTest.php index 2ab5dc3be62..51679175725 100644 --- a/test/Github/Tests/Api/IntegrationTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -2,19 +2,19 @@ namespace Github\Tests\Api; -class IntegrationTest extends TestCase +class AppTest extends TestCase { /** * @test */ - public function shouldFindRepositoriesForIntegration() + public function shouldFindRepositoriesForApplication() { $result = ['installation1', 'installation2']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/integration/installations') + ->with('/app/installations') ->willReturn($result); $this->assertEquals($result, $api->findInstallations()); @@ -68,6 +68,6 @@ public function shouldRemoveRepositoryToInstallation() */ protected function getApiClass() { - return \Github\Api\Integrations::class; + return \Github\Api\Apps::class; } } From 8fa6ab06ffc294da0395332381beb59d8f7f6bda Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:07:53 +0200 Subject: [PATCH 543/951] Fix --- lib/Github/Api/Apps.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 1ebce7218c3..331206c21db 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -59,7 +59,7 @@ public function listRepositories($userId = null) $parameters['user_id'] = $userId; } - return $this->get('/app/repositories', $parameters); + return $this->get('/installation/repositories', $parameters); } /** From 62b16fc7797f8bf64e0aec7f4c7a25e87b28b3f2 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:10:41 +0200 Subject: [PATCH 544/951] Fix --- lib/Github/Api/Apps.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 331206c21db..1b27d96fdbe 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -74,7 +74,7 @@ public function listRepositories($userId = null) */ public function addRepository($installationId, $repositoryId) { - return $this->put('/app/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->put('/installation/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } /** From 1a0b96ddb8f7b1bcdde4ead992b6ff774d60a3fe Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:12:30 +0200 Subject: [PATCH 545/951] Fix --- lib/Github/Api/Apps.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 1b27d96fdbe..c4f5d490c36 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -74,7 +74,7 @@ public function listRepositories($userId = null) */ public function addRepository($installationId, $repositoryId) { - return $this->put('/installation/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } /** @@ -89,6 +89,6 @@ public function addRepository($installationId, $repositoryId) */ public function removeRepository($installationId, $repositoryId) { - return $this->delete('/app/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } } From 5a052f956a2c1dd01197b0cbb69da29971372d32 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:15:10 +0200 Subject: [PATCH 546/951] Keep BC --- lib/Github/Api/Apps.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index c4f5d490c36..ee452dd11c9 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -2,16 +2,25 @@ namespace Github\Api; -use Github\Api\AcceptHeaderTrait; - /** * @link https://developer.github.com/v3/apps/ * @author Nils Adermann */ class Apps extends AbstractApi { - use AcceptHeaderTrait; - + /** + * @deprecated + * Configure the accept header for Early Access to the integrations api (DEPRECATED) + * + * @see https://developer.github.com/v3/apps/ + * + * @return self + */ + public function configure() + { + return $this; + } + /** * Create an access token for an installation * From a0a1f0e3c134ba9898baa32df13d2cec5d275f83 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:18:21 +0200 Subject: [PATCH 547/951] Keep BC --- lib/Github/Api/Integrations.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/Github/Api/Integrations.php diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php new file mode 100644 index 00000000000..6ef459fe529 --- /dev/null +++ b/lib/Github/Api/Integrations.php @@ -0,0 +1,13 @@ + + */ +class Integrations extends Apps +{ + +} From aeba9694b0a3f1a3f3bad83dc53aa566295345be Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:19:20 +0200 Subject: [PATCH 548/951] StyleCI --- lib/Github/Api/Integrations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index 6ef459fe529..d575533b897 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -9,5 +9,4 @@ */ class Integrations extends Apps { - } From 78c873269485987d065c32e0c18e93230b888551 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:30:13 +0200 Subject: [PATCH 549/951] GraphQL Out of Beta --- lib/Github/Api/GraphQL.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 90974015463..448c59846b5 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -5,9 +5,9 @@ /** * GraphQL API. * - * Part of the Github API Early-Access Program + * Part of the Github v4 API * - * @link https://developer.github.com/early-access/graphql/ + * @link https://developer.github.com/v4/ * @author Miguel Piedrafita */ class GraphQL extends AbstractApi From 56814d0ea43a3bb157a74b52f22ee5f5e2942dd5 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 16:33:43 +0200 Subject: [PATCH 550/951] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ccdbdb0965..ab28d5dabb0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ For old version please check: A simple Object Oriented wrapper for GitHub API, written with PHP5. -Uses [GitHub API v3](http://developer.github.com/v3/). The object API is very similar to the RESTful API. +Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4](http://developer.github.com/v4). The object API (v3) is very similar to the RESTful API. ## Features @@ -114,5 +114,6 @@ See the [`doc` directory](doc/) for more detailed documentation. - Thanks to [Rolf van de Krol](http://github.com/rolfvandekrol) for his countless contributions. - Thanks to [Nicolas Pastorino](http://github.com/jeanvoye) for his contribution on the Pull Request API. - Thanks to [Edoardo Rivello](http://github.com/erivello) for his contribution on the Gists API. +- Thanks to [Miguel Piedrafita](https://github.com/m1guelpf) for his contribution to the v4 & Apps API. Thanks to GitHub for the high quality API and documentation. From 78a74223587904d113bb39211ff5a1ced42c4e79 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 18:19:10 +0200 Subject: [PATCH 551/951] Update docs index --- doc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/README.md b/doc/README.md index ebc64840d37..d6ab57637dd 100644 --- a/doc/README.md +++ b/doc/README.md @@ -2,6 +2,7 @@ Navigation ========== APIs: +* [Applications](apps.md) * [Authorizations](authorizations.md) * [Commits](commits.md) * Current User @@ -10,7 +11,6 @@ APIs: * [Enterprise](enterprise.md) * [Gists](gists.md) * [Comments](gists/comments.md) -* [Integrations](integrations.md) * [Issues](issues.md) * [Assignees](issue/assignees.md) * [Comments](issue/comments.md) From fb92df9cc5981ecad6dd1fef01da5f104d00e581 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 18:20:32 +0200 Subject: [PATCH 552/951] Update docs --- doc/{integrations.md => apps.md} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename doc/{integrations.md => apps.md} (59%) diff --git a/doc/integrations.md b/doc/apps.md similarity index 59% rename from doc/integrations.md rename to doc/apps.md index 6e7413dde1d..7cc9b45a17e 100644 --- a/doc/integrations.md +++ b/doc/apps.md @@ -1,24 +1,24 @@ -## Instegrations API +## Applications API [Back to the navigation](README.md) -Wraps [GitHub Integrations API](http://developer.github.com/v3/integrations/). +Wraps [GitHub Applications API](http://developer.github.com/v3/apps/). ### Create a new installation token For the installation id 123 use the following: ```php -$token = $client->api('integrations')->createInstallationToken(123); +$token = $client->api('apps')->createInstallationToken(123); ``` To create an access token on behalf of a user with id 456 use: ```php -$token = $client->api('integrations')->createInstallationToken(123, 456); +$token = $client->api('apps')->createInstallationToken(123, 456); ``` ### Find all installations -Find all installations for the authenticated integration. +Find all installations for the authenticated application. ```php -$installations = $client->api('integrations')->findInstallations(); +$installations = $client->api('apps')->findInstallations(); ``` ### Find installations for a user @@ -31,7 +31,7 @@ $installations = $client->api('current_user')->installations(); List repositories that are accessible to the authenticated installation. ```php -$repositories = $client->api('integrations')->listRepositories(456); +$repositories = $client->api('apps')->listRepositories(456); ``` ### List repositories for a given installation and user @@ -43,11 +43,11 @@ $repositories = $client->api('current_user')->repositoriesByInstallation(456); ### Add repository to installation Add a single repository to an installation. ```php -$client->api('integrations')->addRepository(123); +$client->api('apps')->addRepository(123); ``` ### Remove repository from installation Remove a single repository from an installation. ```php -$client->api('integrations')->removeRepository(123); +$client->api('apps')->removeRepository(123); ``` From 8b686a46b91d1c601747d19f055058444338ddcc Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 18:23:55 +0200 Subject: [PATCH 553/951] Add GraphQL to docs index --- doc/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/README.md b/doc/README.md index ebc64840d37..e961752f881 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,7 +1,10 @@ Navigation ========== -APIs: +v4 API: +* [GraphQL](graphql.md) + +v3 APIs: * [Authorizations](authorizations.md) * [Commits](commits.md) * Current User @@ -10,6 +13,7 @@ APIs: * [Enterprise](enterprise.md) * [Gists](gists.md) * [Comments](gists/comments.md) +* [GraphQL](graphql.md) * [Integrations](integrations.md) * [Issues](issues.md) * [Assignees](issue/assignees.md) From 26121e46f7daa14545a4d0f9a69d88050446a0d1 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 18:26:28 +0200 Subject: [PATCH 554/951] Add GraphQL Docs --- doc/graphql.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 doc/graphql.md diff --git a/doc/graphql.md b/doc/graphql.md new file mode 100644 index 00000000000..85def0f556b --- /dev/null +++ b/doc/graphql.md @@ -0,0 +1,10 @@ +## GraphQL API +[Back to the navigation](README.md) + +Wraps [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/). + +#### Execute a query + +```php +$rateLimits = $client->api('graphql')->execute($query); +``` From 5f4b52497042cffabb08940cdccb35d1f0a93581 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 19:10:59 +0200 Subject: [PATCH 555/951] Set header to accept v4 API --- lib/Github/Api/GraphQL.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 448c59846b5..d7ae1367348 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -2,6 +2,7 @@ namespace Github\Api; +use AcceptHeaderTrait; /** * GraphQL API. * @@ -12,6 +13,7 @@ */ class GraphQL extends AbstractApi { + use AcceptHeaderTrait; /** * @param string $query * @@ -19,6 +21,7 @@ class GraphQL extends AbstractApi */ public function execute($query) { + $this->acceptHeader = 'application/vnd.github.v4+json'; $params = array( 'query' => $query ); From 5f0660408970a7b62bd2d36cb1539317f4ec7b3c Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 22 May 2017 19:12:19 +0200 Subject: [PATCH 556/951] StyleCI --- lib/Github/Api/GraphQL.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index d7ae1367348..b6e4ca6e95b 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -3,6 +3,7 @@ namespace Github\Api; use AcceptHeaderTrait; + /** * GraphQL API. * @@ -21,7 +22,7 @@ class GraphQL extends AbstractApi */ public function execute($query) { - $this->acceptHeader = 'application/vnd.github.v4+json'; + $this->acceptHeader = 'application/vnd.github.v4+json'; $params = array( 'query' => $query ); From 3374868613c6dcb83bd1eddd5fce0a83bc65a931 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Mon, 22 May 2017 22:23:12 +0200 Subject: [PATCH 557/951] Fix link --- doc/repos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index 7c7d83be5c5..1eb24a278b7 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -30,7 +30,7 @@ Returns a list of repositories. #### Advanced search -You can filter the results by language. It takes the same values as the language drop down on [http://github.com/search](http://github). +You can filter the results by language. It takes the same values as the language drop down on [http://github.com/search](http://github.com/search). ```php $repos = $client->api('repo')->find('chess', array('language' => 'php')); From aa27c9c0b8af9ae3eea4457d79d3c71d286e7b0a Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 09:16:15 +0200 Subject: [PATCH 558/951] Add deprecation notice --- lib/Github/Api/Integrations.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index d575533b897..eda702087b1 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -2,8 +2,10 @@ namespace Github\Api; +@trigger_error('The '.__NAMESPACE__.'\Integrations class is deprecated. Use the '.__NAMESPACE__.'\Apps class instead.', E_USER_DEPRECATED); + /** - * @deprecated + * @deprecated Use the Apps class * @link https://developer.github.com/v3/apps/ * @author Nils Adermann */ From 66d5e1fa5248065bbb1561d279bc12d0d9e20a52 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 09:21:17 +0200 Subject: [PATCH 559/951] Remove deprecated class --- lib/Github/Api/Apps.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index ee452dd11c9..f1fe786a5c7 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -8,19 +8,6 @@ */ class Apps extends AbstractApi { - /** - * @deprecated - * Configure the accept header for Early Access to the integrations api (DEPRECATED) - * - * @see https://developer.github.com/v3/apps/ - * - * @return self - */ - public function configure() - { - return $this; - } - /** * Create an access token for an installation * From 8871411338c914a6ef9e3b93b53c1bb52444f8b9 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 09:23:40 +0200 Subject: [PATCH 560/951] Keep BC --- lib/Github/Api/Integrations.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index eda702087b1..ef6ed557d82 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -11,4 +11,16 @@ */ class Integrations extends Apps { + /** + * @deprecated + * Configure the accept header for Early Access to the integrations api (DEPRECATED) + * + * @see https://developer.github.com/v3/apps/ + * + * @return self + */ + public function configure() + { + return $this; + } } From 499d23ac84f2f2bb373ec6804e2bb54430b4a962 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 09:29:46 +0200 Subject: [PATCH 561/951] Keep BC --- lib/Github/Client.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index f8ae9c27d7a..db63d262de3 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -29,8 +29,8 @@ * @method Api\Gists gist() * @method Api\Gists gists() * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Apps integration() (deprecated) - * @method Api\Apps integrations() (deprecated) + * @method Api\Integrations integration() (deprecated) + * @method Api\Integrations integrations() (deprecated) * @method Api\Apps apps() * @method Api\Issue issue() * @method Api\Issue issues() @@ -201,6 +201,8 @@ public function api($name) case 'integration': case 'integrations': + $api = new Api\Integrations($this); + break case 'apps': $api = new Api\Apps($this); break; From afcf4aa3e4a32093baf562319cd6ad86f29fc53d Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 09:35:19 +0200 Subject: [PATCH 562/951] cs --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index db63d262de3..b9f6620e8a5 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -202,7 +202,7 @@ public function api($name) case 'integration': case 'integrations': $api = new Api\Integrations($this); - break + break; case 'apps': $api = new Api\Apps($this); break; From 849899e8331d10db711d3c3455576f3ab01b35b6 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 09:38:20 +0200 Subject: [PATCH 563/951] cs --- lib/Github/Api/GraphQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index b6e4ca6e95b..ca60aa70276 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -22,7 +22,7 @@ class GraphQL extends AbstractApi */ public function execute($query) { - $this->acceptHeader = 'application/vnd.github.v4+json'; + $this->acceptHeaderValue = 'application/vnd.github.v4+json'; $params = array( 'query' => $query ); From 04389748133cd714b6faf75eda073a3174395084 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 11:44:19 +0200 Subject: [PATCH 564/951] Wording --- lib/Github/Api/Apps.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index f1fe786a5c7..dc11ff0b3cf 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -28,7 +28,7 @@ public function createInstallationToken($installationId, $userId = null) } /** - * Find all installations for the authenticated integration. + * Find all installations for the authenticated application. * * @link https://developer.github.com/v3/apps/#find-installations * From 3c464dd360f30b74e81ab7128ac952e1e18e7978 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 12:06:18 +0200 Subject: [PATCH 565/951] Retry Travis build --- lib/Github/Api/Integrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index ef6ed557d82..bcf030e958f 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -12,7 +12,7 @@ class Integrations extends Apps { /** - * @deprecated + * @deprecated * Configure the accept header for Early Access to the integrations api (DEPRECATED) * * @see https://developer.github.com/v3/apps/ From bf113ef561164d31cddbd850b891590e8c24b6b1 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 12:12:57 +0200 Subject: [PATCH 566/951] StyleCI --- lib/Github/Api/Integrations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index bcf030e958f..ef6ed557d82 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -12,7 +12,7 @@ class Integrations extends Apps { /** - * @deprecated + * @deprecated * Configure the accept header for Early Access to the integrations api (DEPRECATED) * * @see https://developer.github.com/v3/apps/ From 08d95b474ab952e08ab5b0857d836c008221c55d Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Tue, 23 May 2017 22:00:42 +0200 Subject: [PATCH 567/951] Remove unused code --- lib/Github/Api/GraphQL.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index ca60aa70276..f1c0334a29a 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -2,8 +2,6 @@ namespace Github\Api; -use AcceptHeaderTrait; - /** * GraphQL API. * From 9631d2a87402568963e540c62cb222530cc1c5e1 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Wed, 24 May 2017 08:30:16 +0200 Subject: [PATCH 568/951] cs --- lib/Github/Api/GraphQL.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index f1c0334a29a..6a112099e4c 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -13,6 +13,7 @@ class GraphQL extends AbstractApi { use AcceptHeaderTrait; + /** * @param string $query * From 05c6e526d0757e2685460aea7996418a4ece3c47 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 25 May 2017 21:07:41 +0200 Subject: [PATCH 569/951] Updated 2.5.0 changelog (#596) --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8225105d0b..c1ff5332415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.5.0 (unreleased) + +### Added + +- Stable support for graphql api (V4) (#593) +- Stable support for apps (previously integrations) (#592) + +### Fixed + +- Incorrect link in repository search docs (#594) + ## 2.4.0 ### Added From 8ff540bcc524863ed75638a626ad054e4cbcdbe6 Mon Sep 17 00:00:00 2001 From: Fabien Bourigault Date: Thu, 1 Jun 2017 13:33:11 +0200 Subject: [PATCH 570/951] fix typo in comment --- lib/Github/HttpClient/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index d87a021c076..218749b43ae 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -60,7 +60,7 @@ class Builder private $plugins = []; /** - * This plugin is speacal treated because it has to be the very last plugin. + * This plugin is special treated because it has to be the very last plugin. * * @var Plugin\CachePlugin */ From e22d35319cc5ef3ea18fefe77b79676cca2ffeee Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 1 Jun 2017 21:24:47 +0200 Subject: [PATCH 571/951] Travis build config tweaks for hhvm (#600) * Travis build config tweaks for hhvm * Fixed typo in skipped test * Build config fixes to speed up the build --- .travis.yml | 13 +++++++++++-- test/Github/Tests/Api/Repository/AssetsTest.php | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7d4fd26b3c9..6831c07786c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,25 @@ language: php +cache: + directories: + - vendor + - $HOME/.composer/cache + php: - 5.5 - 5.6 - 7.0 - 7.1 - - hhvm + +matrix: + include: + - php: hhvm + dist: trusty sudo: false install: - - travis_retry composer install --no-interaction --prefer-source + - travis_retry composer install --no-interaction script: - vendor/bin/phpunit --verbose --coverage-text diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 353a3431640..5c49c682112 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -48,7 +48,7 @@ public function shouldCreateReleaseAsset() { if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) { return $this->markTestSkipped( - 'Asset upload support requires Server Name Indication. This is not supported be your PHP version.' + 'Asset upload support requires Server Name Indication. This is not supported by your PHP version.' ); } From f7be4c5724aa646588730485504de76b3b735b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Brala?= Date: Mon, 5 Jun 2017 14:28:43 +0200 Subject: [PATCH 572/951] Update README.md (#601) Typo `form` => `from` :) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab28d5dabb0..4b8fa59e33f 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Then run the following command to require the library: $ php composer.phar require knplabs/github-api php-http/guzzle6-adapter ``` -Why `php-http/guzzle6-adapter`? We are decoupled form any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md). +Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md). ## Using Laravel? From 59ba94c11d4786625c44eabb410d476b7ba01840 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 12 Jun 2017 09:56:48 -0700 Subject: [PATCH 573/951] add method to remove branch protection and doc example --- doc/repo/protection.md | 8 ++++++++ lib/Github/Api/Repository/Protection.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/doc/repo/protection.md b/doc/repo/protection.md index 89a7fc550b3..28ff7c2cb9f 100644 --- a/doc/repo/protection.md +++ b/doc/repo/protection.md @@ -33,3 +33,11 @@ $params = [ ]; $protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'master', $params); ``` + +### Remove branch protection + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->remove('twbs', 'bootstrap', 'master'); +``` diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 6e12410c2ce..33c68bf7960 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -52,4 +52,18 @@ public function update($username, $repository, $branch, array $params = array()) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params); } + + /** + * Remove the repo's branch protection + * + * @link https://developer.github.com/v3/repos/branches/#remove-branch-protection + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function remove($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection'); + } } From 5a5231e7a915c7bfcb13462a49e9e38378e48ecd Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 12 Jun 2017 12:00:07 -0700 Subject: [PATCH 574/951] unit test for remove branch protection method --- .../Tests/Api/Repository/ProtectionTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Github/Tests/Api/Repository/ProtectionTest.php b/test/Github/Tests/Api/Repository/ProtectionTest.php index 48b59b268dd..5b1fb62f17b 100644 --- a/test/Github/Tests/Api/Repository/ProtectionTest.php +++ b/test/Github/Tests/Api/Repository/ProtectionTest.php @@ -39,6 +39,22 @@ public function shouldUpdateProtection() $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'master', $data)); } + /** + * @test + */ + public function shouldRemoveProtection() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'master')); + } + /** * @return string */ From 2a8a22aeb8c694158f7ed07cf68707968a7dcac5 Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Sat, 24 Jun 2017 18:22:11 +0200 Subject: [PATCH 575/951] Added dismissal review mandatory "message" parameter --- lib/Github/Api/PullRequest/Review.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 40c8db83127..497a7d505eb 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -159,11 +159,22 @@ public function submit($username, $repository, $pullRequest, $id, array $params * @param string $repository the repository * @param int $pullRequest the pull request number * @param int $id the review id + * @param string $message a mandatory dismissal message * * @return array|string */ - public function dismiss($username, $repository, $pullRequest, $id) + public function dismiss($username, $repository, $pullRequest, $id, $message) { - return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals'); + if (empty($message)) { + throw new InvalidArgumentException(sprintf('"message" must be a valid string ("%s" given).', gettype($message))); + } + + if (!is_string($message)) { + throw new InvalidArgumentException('"message" is mandatory and cannot be empty'); + } + + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals', [ + 'message' => $message + ]); } } From d674e1da60658eb4556dfacb77676e0fd34b975a Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Sat, 24 Jun 2017 18:27:06 +0200 Subject: [PATCH 576/951] Ahhh the tests x) --- test/Github/Tests/Api/PullRequest/ReviewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/PullRequest/ReviewTest.php b/test/Github/Tests/Api/PullRequest/ReviewTest.php index 54b8d55aafe..441240ecfd3 100644 --- a/test/Github/Tests/Api/PullRequest/ReviewTest.php +++ b/test/Github/Tests/Api/PullRequest/ReviewTest.php @@ -391,7 +391,7 @@ public function shouldDismissReview() ->with('/repos/octocat/Hello-World/pulls/12/reviews/80/dismissals') ->willReturn($expectedValue); - $this->assertSame($expectedValue, $api->dismiss('octocat', 'Hello-World', 12, 80)); + $this->assertSame($expectedValue, $api->dismiss('octocat', 'Hello-World', 12, 80, 'Dismiss reason')); } protected function getApiClass() From 18e88bbbfcee4c3ec738daa1d2e2554bfde7ea73 Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Sat, 24 Jun 2017 18:37:22 +0200 Subject: [PATCH 577/951] Fixed flipped statement in Review API --- lib/Github/Api/PullRequest/Review.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 497a7d505eb..83182ad3c76 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -165,11 +165,11 @@ public function submit($username, $repository, $pullRequest, $id, array $params */ public function dismiss($username, $repository, $pullRequest, $id, $message) { - if (empty($message)) { + if (!is_string($message)) { throw new InvalidArgumentException(sprintf('"message" must be a valid string ("%s" given).', gettype($message))); } - if (!is_string($message)) { + if (empty($message)) { throw new InvalidArgumentException('"message" is mandatory and cannot be empty'); } From bed18bfc926e68260d5d95190187a9ee6c36f9b0 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Sun, 25 Jun 2017 21:54:36 +0200 Subject: [PATCH 578/951] Add a method to fetch repository events (#605) See [github documentation](https://developer.github.com/v3/activity/events/#list-repository-events). --- lib/Github/Api/Repo.php | 18 ++++++++++++++++-- test/Github/Tests/Api/RepoTest.php | 20 +++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 5dbe7b9444c..912a9c520bb 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -150,7 +150,7 @@ public function show($username, $repository) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } - + /** * Get extended information about a repository by its id. * Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on. @@ -580,9 +580,23 @@ public function projects() { return new Projects($this->client); } - + public function traffic() { return new Traffic($this->client); } + + /** + * @param string $username + * @param string $repository + * @param int $page + * + * @return array|string + * + * @see https://developer.github.com/v3/activity/events/#list-repository-events + */ + public function events($username, $repository, $page = 1) + { + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index beb68c415d3..d84f841009a 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -19,7 +19,7 @@ public function shouldShowRepository() $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api')); } - + /** * @test */ @@ -517,6 +517,24 @@ public function shouldGetCommitActivity() $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldGetRepositoryEvents() + { + $expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/events', array( + 'page' => 3, + )) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3)); + } + /** * @return string */ From 9486dcc4589a4791498f5d87c515be81264f0ac1 Mon Sep 17 00:00:00 2001 From: "Georges.L" Date: Sun, 25 Jun 2017 23:32:53 +0200 Subject: [PATCH 579/951] Added "reviews" documentation (#608) * Added "reviews" documentation * Fixed confusing terms "reviews requests" vs "reviews" * Updated "reviews" doc --- doc/pull_request/reviews.md | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 doc/pull_request/reviews.md diff --git a/doc/pull_request/reviews.md b/doc/pull_request/reviews.md new file mode 100644 index 00000000000..db61a03dde4 --- /dev/null +++ b/doc/pull_request/reviews.md @@ -0,0 +1,46 @@ +## Pull Requests / Reviews API +[Back to the "Pull Requests API"](../pull_requests.md) | [Back to the navigation](../README.md) + +### List all reviews + +```php +$reviewRequests = $client->api('pull_request')->reviews()->all('twbs', 'bootstrap', 12); +``` + +### Create a review + +```php +$client->api('pull_request')->reviews()->create('twbs', 'bootstrap', 12, array( + 'event' => 'APPROVE', // Accepted values: APPROVE, REQUEST_CHANGES, COMMENT, see https://developer.github.com/v3/pulls/reviews/#input-1 + 'body' => 'OK, looks good :)',// Optional, the review body text + 'commit_id' => $commitSha, // Optional, default value is HEAD sha +)); +``` + +### Get a review + +```php +$client->api('pull_request')->reviews()->show('twbs', 'bootstrap', 12, $reviewId); +``` + +### Get comment from a review + +```php +$client->api('pull_request')->reviews()->comments('twbs', 'bootstrap', 12, $reviewId); +``` + +### Dismiss a review +**This does not remove the review but dismisses the (dis)approval status of this one** + +Note: To dismiss a pull request review on a protected branch, you must be a +repository administrator or be included in the list of people or teams who can dismiss pull request reviews. + +```php +$client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $reviewId, 'Dismiss reason (mandatory)'); +``` + +### Remove a review + +```php +$client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $reviewId); +``` From 05b24ed592a61ea947b45d8d14cde25f9795fb2f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 26 Jun 2017 09:29:00 +0200 Subject: [PATCH 580/951] Prepare for 2.5.0 (#607) * Prepare for 2.5.0 * Added repo:events --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1ff5332415..d167e5c2a1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,20 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 2.5.0 (unreleased) +## 2.6.0 (unreleased) + +## 2.5.0 ### Added - Stable support for graphql api (V4) (#593) - Stable support for apps (previously integrations) (#592) +- `Repo::events()` ### Fixed - Incorrect link in repository search docs (#594) +- Added the required parameter `$message` on `Review::dismiss`. ## 2.4.0 From 30c7d5c01c5be444783d0ab762a015fb7cb4b3d4 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 26 Jun 2017 10:24:17 +0200 Subject: [PATCH 581/951] Update branch alias (#609) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 06181293b35..ef5f7770f2f 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.5.x-dev" + "dev-master": "2.6.x-dev" } } } From 37e2c303fa8ff7bd18bed9640813199a0c393503 Mon Sep 17 00:00:00 2001 From: Volodymyr Kublytskyi Date: Thu, 6 Jul 2017 17:14:50 +0300 Subject: [PATCH 582/951] Add support of GraphQL variables --- lib/Github/Api/GraphQL.php | 6 +++++- test/Github/Tests/Api/GraphQLTest.php | 29 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 6a112099e4c..ea9271030e7 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -16,15 +16,19 @@ class GraphQL extends AbstractApi /** * @param string $query + * @param array $variables * * @return array */ - public function execute($query) + public function execute($query, array $variables = null) { $this->acceptHeaderValue = 'application/vnd.github.v4+json'; $params = array( 'query' => $query ); + if (!empty($variables)) { + $params['variables'] = json_encode($variables); + } return $this->post('/graphql', $params); } diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index c209a733b75..e2f2d692c84 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -21,6 +21,35 @@ public function shouldTestGraphQL() $this->assertEquals('foo', $result); } + /** + * @test + */ + public function shouldSupportGraphQLVariables() + { + $api = $this->getApiMock(); + + $api->method('post') + ->with('/graphql', $this->arrayHasKey('variables')); + + $api->execute('bar', ['variable' => 'foo']); + } + + /** + * @test + */ + public function shouldJSONEncodeGraphQLVariables() + { + $api = $this->getApiMock(); + + $api->method('post') + ->with('/graphql', $this->equalTo([ + 'query'=>'bar', + 'variables' => '{"variable":"foo"}' + ])); + + $api->execute('bar', ['variable' => 'foo']); + } + protected function getApiClass() { return \Github\Api\GraphQL::class; From 5fc4032d1b5068af6f407fe962cfcabc8d3cba04 Mon Sep 17 00:00:00 2001 From: Volodymyr Kublytskyi Date: Thu, 6 Jul 2017 18:50:21 +0300 Subject: [PATCH 583/951] Add support of GraphQL variables - fixed default value to be same type if not specified --- lib/Github/Api/GraphQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index ea9271030e7..a71bea4c8ea 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -20,7 +20,7 @@ class GraphQL extends AbstractApi * * @return array */ - public function execute($query, array $variables = null) + public function execute($query, array $variables = array()) { $this->acceptHeaderValue = 'application/vnd.github.v4+json'; $params = array( From d0365b5b7f4b6ffa3a8b4b01507f7556b1743355 Mon Sep 17 00:00:00 2001 From: Volodymyr Kublytskyi Date: Fri, 7 Jul 2017 18:08:03 +0300 Subject: [PATCH 584/951] Document support of GraphQL variables --- CHANGELOG.md | 4 ++++ doc/graphql.md | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d167e5c2a1a..40b2dff1928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## 2.6.0 (unreleased) +### Added + +- Support for graphql api [variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) (#612) + ## 2.5.0 ### Added diff --git a/doc/graphql.md b/doc/graphql.md index 85def0f556b..89080b24227 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -8,3 +8,25 @@ Wraps [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/). ```php $rateLimits = $client->api('graphql')->execute($query); ``` + +#### Use variables + +[Variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) allow specifying of requested data without dynamical change of a query on a client side. + +```php +$query = <<<'QUERY' +query showOrganizationInfo ( + $organizationLogin: String! +) { + organization(login: $organizationLogin) { + name + url + } +} +QUERY; +$variables = [ + 'organizationLogin' => 'KnpLabs' +]; + +$orgInfo = $client->api('graphql')->execute($query, $variables); +``` \ No newline at end of file From d86475487ef11efcd23c08b2741543a5226f32d1 Mon Sep 17 00:00:00 2001 From: Cosmin Lupu Date: Thu, 13 Jul 2017 20:10:18 +0200 Subject: [PATCH 585/951] Added documentation for GitData API (#613) --- doc/README.md | 6 ++++++ doc/gitdata/blobs.md | 14 +++++++++++++ doc/gitdata/commits.md | 15 +++++++++++++ doc/gitdata/references.md | 44 +++++++++++++++++++++++++++++++++++++++ doc/gitdata/tags.md | 32 ++++++++++++++++++++++++++++ doc/gitdata/trees.md | 25 ++++++++++++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 doc/gitdata/blobs.md create mode 100644 doc/gitdata/commits.md create mode 100644 doc/gitdata/references.md create mode 100644 doc/gitdata/tags.md create mode 100644 doc/gitdata/trees.md diff --git a/doc/README.md b/doc/README.md index b1c99e97b22..772dbb3e645 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,6 +14,12 @@ v3 APIs: * [Enterprise](enterprise.md) * [Gists](gists.md) * [Comments](gists/comments.md) +* GitData + * [Blobs](gitdata/blobs.md) + * [Commits](gitdata/commits.md) + * [References](gitdata/references.md) + * [Tags](gitdata/tags.md) + * [Trees](gitdata/trees.md) * [GraphQL](graphql.md) * [Issues](issues.md) * [Assignees](issue/assignees.md) diff --git a/doc/gitdata/blobs.md b/doc/gitdata/blobs.md new file mode 100644 index 00000000000..78a79ac0810 --- /dev/null +++ b/doc/gitdata/blobs.md @@ -0,0 +1,14 @@ +## Blobs API +[Back to the navigation](../README.md) + +### Show a blob + +```php +$blob = $client->api('gitData')->blobs()->show('KnpLabs', 'php-github-api', '839e5185da9434753db47959bee16642bb4f2ce4'); +``` + +### Create a blob + +```php +$blob = $client->api('gitData')->blobs()->create('KnpLabs', 'php-github-api', ['content' => 'Test content', 'encoding' => 'utf-8']); +``` \ No newline at end of file diff --git a/doc/gitdata/commits.md b/doc/gitdata/commits.md new file mode 100644 index 00000000000..07584e49929 --- /dev/null +++ b/doc/gitdata/commits.md @@ -0,0 +1,15 @@ +## Commits API +[Back to the navigation](../README.md) + +### Show a commit + +```php +$commit = $client->api('gitData')->commits()->show('KnpLabs', 'php-github-api', '839e5185da9434753db47959bee16642bb4f2ce4'); +``` + +### Create a commit + +```php +$commitData = ['message' => 'Upgrading documentation', 'tree' => $treeSHA, 'parents' => [$parentCommitSHA]]; +$commit = $client->api('gitData')->commits()->create('KnpLabs', 'php-github-api', $commitData); +``` \ No newline at end of file diff --git a/doc/gitdata/references.md b/doc/gitdata/references.md new file mode 100644 index 00000000000..cc4ee25eb7c --- /dev/null +++ b/doc/gitdata/references.md @@ -0,0 +1,44 @@ +## References API +[Back to the navigation](../README.md) + + +### List all references +```php +$references = $client->api('gitData')->references()->all('KnpLabs', 'php-github-api'); +``` + +### Show a reference + +```php +$reference = $client->api('gitData')->references()->show('KnpLabs', 'php-github-api', 'heads/featureA'); +``` + +### Create a reference + +```php +$referenceData = ['ref' => 'refs/heads/featureA', 'sha' => '839e5185da9434753db47959bee16642bb4f2ce4']; +$reference = $client->api('gitData')->references()->create('KnpLabs', 'php-github-api', $referenceData); +``` + +### Update a reference + +```php +$referenceData = ['sha' => '839e5185da9434753db47959bee16642bb4f2ce4', 'force' => false ]; //Force is default false +$reference = $client->api('gitData')->references()->update('KnpLabs', 'php-github-api', 'heads/featureA', $referenceData); +``` + +### Delete a reference + +```php +$client->api('gitData')->references()->remove('KnpLabs', 'php-github-api', 'heads/featureA'); +``` + +### List all branches +```php +$references = $client->api('gitData')->references()->branches('KnpLabs', 'php-github-api'); +``` + +### List all tags +```php +$references = $client->api('gitData')->references()->tags('KnpLabs', 'php-github-api'); +``` \ No newline at end of file diff --git a/doc/gitdata/tags.md b/doc/gitdata/tags.md new file mode 100644 index 00000000000..36b323e5c74 --- /dev/null +++ b/doc/gitdata/tags.md @@ -0,0 +1,32 @@ +## Tags API +[Back to the navigation](../README.md) + +### Show all tags + +```php +$tags = $client->api('gitData')->tags()->all('KnpLabs', 'php-github-api'); +``` + +### Show a tag + +```php +$tag = $client->api('gitData')->tags()->show('KnpLabs', 'php-github-api', '839e5185da9434753db47959bee16642bb4f2ce4'); +``` + +### Create a tag + +```php +$tagData = [ + 'tag' => 'v0.0.1', + 'message' => 'initial version', + 'object' => 'c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c', + 'type' => 'commit', + 'tagger' => [ + 'name' => 'KnpLabs', + 'email' => 'hello@knplabs.com', + 'date' => '2017-06-17T14:53:35-07:00' + ] +]; + +$tag = $client->api('gitData')->tags()->create('KnpLabs', 'php-github-api', $tagData); +``` \ No newline at end of file diff --git a/doc/gitdata/trees.md b/doc/gitdata/trees.md new file mode 100644 index 00000000000..dcdd0b49c08 --- /dev/null +++ b/doc/gitdata/trees.md @@ -0,0 +1,25 @@ +## Trees API +[Back to the navigation](../README.md) + +### Show a tree + +```php +$tree = $client->api('gitData')->trees()->show('KnpLabs', 'php-github-api', '839e5185da9434753db47959bee16642bb4f2ce4'); +``` + +### Create a tree + +```php +$treeData = [ + 'base_tree' => '839e5185da9434753db47959bee16642bb4f2ce4', + 'tree' => [ + [ + 'path' => 'README.md', + 'mode' => '100644', + 'type' => 'blob', + 'content' => 'Updated Readme file' + ] + ] +]; +$tree = $client->api('gitData')->trees()->create('KnpLabs', 'php-github-api', $treeData); +``` \ No newline at end of file From b8e128d2a3a5b87aa0cd8ef3fdd966cd00daff9b Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Wed, 19 Jul 2017 23:12:08 -0700 Subject: [PATCH 586/951] add missing protection methods, docs and tests (#616) * add missing protection methods, docs and tests * fix style issues * fix failing test * update changelog --- CHANGELOG.md | 47 +-- doc/repo/protection.md | 230 +++++++++++ lib/Github/Api/Repository/Protection.php | 371 +++++++++++++++++ .../Tests/Api/Repository/ProtectionTest.php | 379 ++++++++++++++++++ 4 files changed, 1004 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40b2dff1928..fc9bad6dc3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Change Log -The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. ## 2.6.0 (unreleased) ### Added - Support for graphql api [variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) (#612) +- Added missing branch protection methods (#616) ## 2.5.0 @@ -25,7 +26,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- `Integrations::configure` to allow accessing early access program endpoints. +- `Integrations::configure` to allow accessing early access program endpoints. - Add support for pagination and parameters in the pull request comments - Add the ability to fetch user installations (`CurrentUser::installations`) - Allow getting repo info by id (`Repo::showById`) @@ -33,7 +34,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed -- `PullRequest\Review` and `PullRequest\ReviewRequest` is now part of the official API. No need to call `configure`. +- `PullRequest\Review` and `PullRequest\ReviewRequest` is now part of the official API. No need to call `configure`. ## 2.3.0 @@ -49,7 +50,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed -- First argument to `Integrations::listRepositories()` is now optional. +- First argument to `Integrations::listRepositories()` is now optional. - Moved tests from "functional" to "integration" ## 2.2.0 @@ -57,10 +58,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added - API support for Pull Request Review Requests. -- API support for Traffic. -- API support for issue Assignees. -- API support for Miscellaneous Gitignore and Emojis. -- Added endpoints for issue lock, unlock and issue label show. +- API support for Traffic. +- API support for issue Assignees. +- API support for Miscellaneous Gitignore and Emojis. +- Added endpoints for issue lock, unlock and issue label show. - Added more parameters to `User::starred`. - Fluid interface by allowing `configure()` to return `$this`. - `configure()` support for issues API. @@ -74,21 +75,21 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- Add support for retrieving a single notification info using his ID +- Add support for retrieving a single notification info using his ID - Add a function to get user organizations - Added GraphQL support - Add page variable to organization repo list (Organization::repositories()) -- Add support for pull request review. +- Add support for pull request review. - Add support for adding branch protection. ### Fixed -- Bug with double slashes when using enterprise URL. +- Bug with double slashes when using enterprise URL. - Bug when headers not being passed to request (#529) ## 2.0.0 -### Added +### Added - Support for JWT authentication - API for Organization\Members @@ -101,26 +102,26 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed -- `ApiLimitExceedException::__construct` has a new second parameter for the remaining API calls. -- First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to -`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: - +- `ApiLimitExceedException::__construct` has a new second parameter for the remaining API calls. +- First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to +`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: + ```php // Old way does not work: -$github = new Github\Client($httpClient); +$github = new Github\Client($httpClient); // New way will work: -$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); -$github = Github\Client::createWithHttpClient($httpClient); +$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); +$github = Github\Client::createWithHttpClient($httpClient); ``` -- Renamed the currentuser `DeployKeys` api class to `PublicKeys` to reflect to github api name. +- Renamed the currentuser `DeployKeys` api class to `PublicKeys` to reflect to github api name. ## 2.0.0-rc4 -### Added +### Added - HTTPlug to decouple from Guzzle -- `Github\Client::getLastResponse` was added +- `Github\Client::getLastResponse` was added - Support for PSR-6 cache - `Github\Client::addPlugin` and `Github\Client::removePlugin` - `Github\Client::getApiVersion` @@ -143,6 +144,6 @@ $github = Github\Client::createWithHttpClient($httpClient); - `Github/HttpClient/CachedHttpClient` was removed - All classes in `Github/HttpClient/Cache/*` were removed -## 1.7.1 +## 1.7.1 No change log before this version diff --git a/doc/repo/protection.md b/doc/repo/protection.md index 28ff7c2cb9f..6fed148096b 100644 --- a/doc/repo/protection.md +++ b/doc/repo/protection.md @@ -41,3 +41,233 @@ $protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'mas ```php $protection = $client->api('repo')->protection()->remove('twbs', 'bootstrap', 'master'); ``` + +### Get required status checks of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showStatusChecks('twbs', 'bootstrap', 'master'); +``` + +### Update required status checks of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'strict' => true, + 'contexts' => [ + 'continuous-integration/travis-ci', + ], +]; +$protection = $client->api('repo')->protection()->updateStatusChecks('twbs', 'bootstrap', 'master', $params); +``` + +### Remove required status checks of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->removeStatusChecks('twbs', 'bootstrap', 'master'); +``` + +### List required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showStatusChecksContexts('twbs', 'bootstrap', 'master'); +``` + +### Replace required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'continuous-integration/travis-ci', +]; +$protection = $client->api('repo')->protection()->replaceStatusChecksContexts('twbs', 'bootstrap', 'master', $params); +``` + +### Add required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'continuous-integration/jenkins', +]; +$protection = $client->api('repo')->protection()->addStatusChecksContexts('twbs', 'bootstrap', 'master', $params); +``` + +### Remove required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'continuous-integration/jenkins', +]; +$protection = $client->api('repo')->protection()->removeStatusChecksContexts('twbs', 'bootstrap', 'master', $params); +``` + +### Get pull request review enforcement of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showPullRequestReviewEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Update pull request review enforcement of protected branch + +> Requires [authentication](../security.md) with admin access and branch protection to be enabled. + +```php +$params = [ + 'dismissal_restrictions' => [ + 'users' => [ + 'octocat', + ], + 'teams' => [ + 'justice-league', + ], + ], + 'dismiss_stale_reviews' => true, + 'require_code_owner_reviews' => true, +]; +$protection = $client->api('repo')->protection()->updatePullRequestReviewEnforcement('twbs', 'bootstrap', 'master', $params); +``` + +### Remove pull request review enforcement of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->removePullRequestReviewEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Get admin enforcement of protected branch + + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showAdminEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Add admin enforcement of protected branch + +> Requires [authentication](../security.md) with admin access and branch protection to be enabled. + +```php +$protection = $client->api('repo')->protection()->addAdminEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Remove admin enforcement of protected branch + +> Requires [authentication](../security.md) with admin access and branch protection to be enabled. + +```php +$protection = $client->api('repo')->protection()->removeAdminEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Get restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->showRestrictions('twbs', 'bootstrap', 'master'); +``` + +### Remove restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->removeRestrictions('twbs', 'bootstrap', 'master'); +``` + +### List team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->showTeamRestrictions('twbs', 'bootstrap', 'master'); +``` + +### Replace team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'justice-league', +]; +$protection = $client->api('repo')->protection()->replaceTeamRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Add team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'justice-league', +]; +$protection = $client->api('repo')->protection()->addTeamRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Remove team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'octocats', +]; +$protection = $client->api('repo')->protection()->removeTeamRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### List user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->showUserRestrictions('twbs', 'bootstrap', 'master'); +``` + +### Replace user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'octocat', +]; +$protection = $client->api('repo')->protection()->replaceUserRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Add user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'octocat', +]; +$protection = $client->api('repo')->protection()->addUserRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Remove user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'defunkt', +]; +$protection = $client->api('repo')->protection()->removeUserRestrictions('twbs', 'bootstrap', 'master', $params); +``` diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 33c68bf7960..3c96e668933 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -66,4 +66,375 @@ public function remove($username, $repository, $branch) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection'); } + + /** + * Get required status checks of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The required status checks information + */ + public function showStatusChecks($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks'); + } + + /** + * Update required status checks of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks information + * + * @return array The updated branch status checks information + */ + public function updateStatusChecks($username, $repository, $branch, array $params = array()) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks', $params); + } + + /** + * Remove required status checks of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removeStatusChecks($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks'); + } + + /** + * List required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The required status checks contexts information + */ + public function showStatusChecksContexts($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts'); + } + + /** + * Replace required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information + * + * @return array The new branch status checks contexts information + */ + public function replaceStatusChecksContexts($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); + } + + /** + * Add required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information + * + * @return array The updated branch status checks contexts information + */ + public function addStatusChecksContexts($username, $repository, $branch, array $params = array()) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); + } + + /** + * Remove required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information + * + * @return array The updated branch status checks contexts information + */ + public function removeStatusChecksContexts($username, $repository, $branch, array $params = array()) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); + } + + /** + * Get pull request review enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The pull request review enforcement information + */ + public function showPullRequestReviewEnforcement($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews'); + } + + /** + * Update pull request review enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks information + * + * @return array The updated branch status checks information + */ + public function updatePullRequestReviewEnforcement($username, $repository, $branch, array $params = array()) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews', $params); + } + + /** + * Remove pull request review enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removePullRequestReviewEnforcement($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews'); + } + + /** + * Get admin enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The admin enforcement information + */ + public function showAdminEnforcement($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins'); + } + + /** + * Add admin enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The updated admin enforcement information + */ + public function addAdminEnforcement($username, $repository, $branch) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins'); + } + + /** + * Remove admin enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removeAdminEnforcement($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins'); + } + + /** + * Get restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch restrictions information + */ + public function showRestrictions($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions'); + } + + /** + * Remove restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removeRestrictions($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions'); + } + + /** + * List team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch team restrictions information + */ + public function showTeamRestrictions($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams'); + } + + /** + * Replace team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access + * + * @return array The new branch team restrictions information + */ + public function replaceTeamRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); + } + + /** + * Add team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access + * + * @return array The branch team restrictions information + */ + public function addTeamRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); + } + + /** + * Remove team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access + * + * @return array The updated branch team restrictions information + */ + public function removeTeamRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); + } + + /** + * List user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch user restrictions information + */ + public function showUserRestrictions($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users'); + } + + /** + * Replace user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access + * + * @return array The new branch user restrictions information + */ + public function replaceUserRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); + } + + /** + * Add user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access + * + * @return array The branch user restrictions information + */ + public function addUserRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); + } + + /** + * Remove user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access + * + * @return array The updated branch user restrictions information + */ + public function removeUserRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); + } } diff --git a/test/Github/Tests/Api/Repository/ProtectionTest.php b/test/Github/Tests/Api/Repository/ProtectionTest.php index 5b1fb62f17b..53f4e7ade69 100644 --- a/test/Github/Tests/Api/Repository/ProtectionTest.php +++ b/test/Github/Tests/Api/Repository/ProtectionTest.php @@ -55,6 +55,385 @@ public function shouldRemoveProtection() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'master')); } + /** + * @test + */ + public function shouldShowStatusChecks() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showStatusChecks('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldUpdateStatusChecks() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->updateStatusChecks('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveStatusChecks() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeStatusChecks('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowStatusChecksContexts() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showStatusChecksContexts('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldReplaceStatusChecksContexts() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->replaceStatusChecksContexts('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldAddStatusChecksContexts() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addStatusChecksContexts('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveStatusChecksContexts() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeStatusChecksContexts('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldShowPullRequestReviewEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_pull_request_reviews') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showPullRequestReviewEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldUpdatePullRequestReviewEnforcement() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_pull_request_reviews') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->updatePullRequestReviewEnforcement('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemovePullRequestReviewEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_pull_request_reviews') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removePullRequestReviewEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowAdminEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/enforce_admins') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showAdminEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldAddAdminEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/enforce_admins') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addAdminEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldRemoveAdminEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/enforce_admins') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeAdminEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldRemoveRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowTeamRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showTeamRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldReplaceTeamRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->replaceTeamRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldAddTeamRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addTeamRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveTeamRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeTeamRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldShowUserRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showUserRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldReplaceUserRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->replaceUserRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldAddUserRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addUserRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveUserRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeUserRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + /** * @return string */ From 9634720b3f91e8db450a51593f8b991ae5ec7540 Mon Sep 17 00:00:00 2001 From: Jeroen Herczeg Date: Fri, 21 Jul 2017 16:03:52 +0200 Subject: [PATCH 587/951] Minor fixes in example code --- doc/search.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/search.md b/doc/search.md index 77b6eb9816d..b798b934d35 100644 --- a/doc/search.md +++ b/doc/search.md @@ -15,7 +15,7 @@ Returns a list of repositories found by such criteria. ### Search code ```php -$repos = $client->api('search')->code('@todo language:php'); +$files = $client->api('search')->code('@todo language:php'); ``` Returns a list of files found by such criteria (containing "@todo" and language==php). @@ -23,7 +23,7 @@ Returns a list of files found by such criteria (containing "@todo" and language= ### Search issues ```php -$repos = $client->api('search')->issues('bug language:php'); +$issues = $client->api('search')->issues('bug language:php'); ``` Returns a list of issues found by such criteria. @@ -31,7 +31,7 @@ Returns a list of issues found by such criteria. ### Search users ```php -$repos = $client->api('search')->users('location:Amsterdam language:php'); +$users = $client->api('search')->users('location:Amsterdam language:php'); ``` Returns a list of users found by such criteria. @@ -42,7 +42,7 @@ You can sort results using 2-3 arguments. ```php $repos = $client->api('search')->repositories('...', 'created', 'asc'); -$repos = $client->api('search')->code('...........', 'indexed', 'desc'); -$repos = $client->api('search')->issues('.........', 'comments', 'asc'); -$repos = $client->api('search')->users('..........', 'followers', 'asc'); +$files = $client->api('search')->code('...........', 'indexed', 'desc'); +$issues = $client->api('search')->issues('.........', 'comments', 'asc'); +$users = $client->api('search')->users('..........', 'followers', 'asc'); ``` From 95ee6f6f5a038ac724797d4e1862b2e947bd6fe9 Mon Sep 17 00:00:00 2001 From: Jeroen Herczeg Date: Fri, 21 Jul 2017 16:08:48 +0200 Subject: [PATCH 588/951] Apply pr #618 to the master branch --- doc/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/README.md b/doc/README.md index b1c99e97b22..d7db629db1f 100644 --- a/doc/README.md +++ b/doc/README.md @@ -5,6 +5,7 @@ v4 API: * [GraphQL](graphql.md) v3 APIs: +* [Activity](activity.md) * [Applications](apps.md) * [Authorizations](authorizations.md) * [Commits](commits.md) @@ -20,6 +21,7 @@ v3 APIs: * [Comments](issue/comments.md) * [Labels](issue/labels.md) * [Milestones](issue/milestones.md) +* [Meta](meta.md) * Miscellaneous * [Emojis](miscellaneous/emojis.md) * [Gitignore](miscellaneous/gitignore.md) @@ -42,16 +44,15 @@ v3 APIs: * [Stargazers](repo/stargazers.md) * [Statuses](repo/statuses.md) * [Tags](repo/tags.md) +* [Search](search.md) * [Users](users.md) -* [Meta](meta.md) -* [Activity](activity.md) Additional features: -* [Pagination support](result_pager.md) * [Authentication & Security](security.md) -* [Request any Route](request_any_route.md) * [Customize `php-github-api`](customize.md) * [Running and writing tests](testing.md) * [Response caching](caching.md) * [Request / Response info](request_response_info.md) +* [Pagination support](result_pager.md) +* [Request any Route](request_any_route.md) From 8536135fda614a6aeb9660fa7f423b80a9a7c7db Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sat, 5 Aug 2017 10:09:18 +0200 Subject: [PATCH 589/951] Use "Install" instead of "Autoload" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b8fa59e33f..782a2cbef60 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] * [Guzzle](https://github.com/guzzle/guzzle) library, * (optional) PHPUnit to run tests. -## Autoload +## Install The new version of `php-github-api` using [Composer](http://getcomposer.org). The first step to use `php-github-api` is to download composer: From 22319eef7aac8a5c67c66c13626f6f9483d86811 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Thu, 10 Aug 2017 21:55:53 +0100 Subject: [PATCH 590/951] Add params to collaborators api calls (#623) * Add params to collaborators api calls https://developer.github.com/v3/repos/collaborators/#list-collaborators `GET /repos/:owner/:repo/collaborators` Params = `affiliation` https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator `PUT /repos/:owner/:repo/collaborators/:username` Params = `permission` * Add phpdoc to Collaborators api --- lib/Github/Api/Repository/Collaborators.php | 41 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index 116d8cc5a38..86812be9538 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -10,21 +10,54 @@ */ class Collaborators extends AbstractApi { - public function all($username, $repository) + /** + * @link https://developer.github.com/v3/repos/collaborators/#list-collaborators + * + * @param $username + * @param $repository + * @param array $params + * @return array|string + */ + public function all($username, $repository, array $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators', $params); } + /** + * @link https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator + * + * @param $username + * @param $repository + * @param $collaborator + * @return array|string + */ public function check($username, $repository, $collaborator) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } - public function add($username, $repository, $collaborator) + /** + * @link https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator + * + * @param $username + * @param $repository + * @param $collaborator + * @param array $params + * @return array|string + */ + public function add($username, $repository, $collaborator, array $params = []) { - return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator), $params); } + /** + * @link https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator + * + * @param $username + * @param $repository + * @param $collaborator + * @return array|string + */ public function remove($username, $repository, $collaborator) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); From 15dcea2efbd84e839cc1d311221cee9ae94ea211 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Thu, 24 Aug 2017 01:20:59 -0700 Subject: [PATCH 591/951] Issue body optional (#625) * remove body from being required when creating an issue * update test --- CHANGELOG.md | 1 + lib/Github/Api/Issue.php | 4 ++-- test/Github/Tests/Api/IssueTest.php | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc9bad6dc3f..f77faa1a6bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - Support for graphql api [variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) (#612) - Added missing branch protection methods (#616) +- Remove `body` as a required parameter when creating an issue (#624) ## 2.5.0 diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index fa79ffa63cc..1ec7e79e89c 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -129,8 +129,8 @@ public function show($username, $repository, $id) */ public function create($username, $repository, array $params) { - if (!isset($params['title'], $params['body'])) { - throw new MissingArgumentException(array('title', 'body')); + if (!isset($params['title'])) { + throw new MissingArgumentException(array('title')); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', $params); diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index a8a40835b39..5596f6be4de 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -105,17 +105,17 @@ public function shouldNotCreateIssueWithoutTitle() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ - public function shouldNotCreateIssueWithoutBody() + public function shouldCreateIssueWithoutBody() { $data = array( 'title' => 'some title' ); $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('post'); + $api->expects($this->once()) + ->method('post') + ->with('/repos/ornicar/php-github-api/issues', $data); $api->create('ornicar', 'php-github-api', $data); } From 89dafacd0a8960e34576a62137c43162655c81ee Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 28 Sep 2017 20:35:35 +0200 Subject: [PATCH 592/951] Add a helper fromFile function to get GraphQL queries from a file (#628) --- lib/Github/Api/GraphQL.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index a71bea4c8ea..eee542f3ad5 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -32,4 +32,15 @@ public function execute($query, array $variables = array()) return $this->post('/graphql', $params); } + + /** + * @param string $file + * @param array $variables + * + * @return array + */ + public function fromFile($file, array $variables = array()) + { + return $this->execute(file_get_contents($file), $variables); + } } From cacf6f38bf9e6c5242e2b6dc26a67c4791bc7751 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 30 Sep 2017 22:00:06 +0200 Subject: [PATCH 593/951] Updated changelog for next release (#630) --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f77faa1a6bb..d3bf0899055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,19 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 2.6.0 (unreleased) +## 2.6.0 ### Added - Support for graphql api [variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) (#612) - Added missing branch protection methods (#616) +- Helper function `fromFile ` to get GraphQL queries from a file (#628) +- Extra parameter `params` to collaborators api calls (#623) +- Documentation for GitData API (#613) + +### Fixed - Remove `body` as a required parameter when creating an issue (#624) +- Minor fixes in example code (#617) ## 2.5.0 From 23aaeda132a5dad120e74200ba4aed5148c79af8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 1 Oct 2017 13:55:30 +0200 Subject: [PATCH 594/951] Use composer 'autoload-dev' to setup autoload for phpunit tests --- composer.json | 3 +++ phpunit.xml.dist | 2 +- test/bootstrap.php | 18 ------------------ 3 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 test/bootstrap.php diff --git a/composer.json b/composer.json index ef5f7770f2f..dcbfb359e6d 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,9 @@ "autoload": { "psr-4": { "Github\\": "lib/Github/" } }, + "autoload-dev": { + "psr-4": { "Github\\Tests\\": "test/Github/Tests/"} + }, "minimum-stability": "dev", "prefer-stable": true, "extra": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0f71eb3983d..c390af0e017 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="test/bootstrap.php" + bootstrap="vendor/autoload.php" > diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index 416d08990eb..00000000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,18 +0,0 @@ -add('Github\Tests', __DIR__); - -return $loader; From 80a3329411fa5e980fbaeeaed40c8da1cb57db84 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 8 Oct 2017 17:39:23 +0200 Subject: [PATCH 595/951] Fixed incorrect docblock type --- lib/Github/Api/Repository/Traffic.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Traffic.php b/lib/Github/Api/Repository/Traffic.php index 1e7d85bf5ce..304dd899b0c 100644 --- a/lib/Github/Api/Repository/Traffic.php +++ b/lib/Github/Api/Repository/Traffic.php @@ -39,7 +39,7 @@ public function paths($owner, $repository) * * @param string $owner * @param string $repository - * @param string|day $per + * @param string $per * * @return array */ @@ -52,7 +52,7 @@ public function views($owner, $repository, $per = 'day') * * @param string $owner * @param string $repository - * @param string|day $per + * @param string $per * * @return array */ From d48b53bb09f7c8643576045e4dfdbd62759e4305 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 12 Oct 2017 19:55:44 -0700 Subject: [PATCH 596/951] Added string as a possible return type for methods (#635) --- lib/Github/Api/PullRequest.php | 2 +- lib/Github/Api/Repository/Contents.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 54bea84a8a2..df8a42f1109 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -77,7 +77,7 @@ public function all($username, $repository, array $params = array()) * @param string $repository the repository * @param string $id the ID of the pull request for which details are retrieved * - * @return array array of pull requests for the project + * @return array|string pull request details */ public function show($username, $repository, $id) { diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 387413bb053..6722bb3c7e0 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -64,7 +64,7 @@ public function readme($username, $repository, $reference = null) * @param null|string $path path to file or directory * @param null|string $reference reference to a branch or commit * - * @return array information for file | information for each item in directory + * @return array|string information for file | information for each item in directory */ public function show($username, $repository, $path = null, $reference = null) { From 13003af4d8f5abf8e55a8ad38a4eea4dfed5a513 Mon Sep 17 00:00:00 2001 From: Brandon Kelly Date: Thu, 12 Oct 2017 23:47:44 -0700 Subject: [PATCH 597/951] Fixed the @return type for Repo::readme() (#627) * Fixed the @return type for Repo::readme() * readme() can return an array if $format = v3+json --- lib/Github/Api/Repo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 912a9c520bb..9598d6d04ec 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -256,9 +256,9 @@ public function remove($username, $repository) * * @param string $username the user who owns the repository * @param string $repository the name of the repository - * @param string $format one of formats: "raw" or "html" + * @param string $format one of formats: "raw", "html", or "v3+json" * - * @return array the readme content + * @return string|array the readme content */ public function readme($username, $repository, $format = 'raw') { From 116322f2f94b1b93a5ef7eb7138b2d3ea0bc778c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 24 Oct 2017 20:48:54 -0700 Subject: [PATCH 598/951] Documented all $id parameters in API classes as int --- lib/Github/Api/CurrentUser/Notifications.php | 14 +++++++------- lib/Github/Api/CurrentUser/PublicKeys.php | 4 ++-- lib/Github/Api/Deployment.php | 4 ++-- lib/Github/Api/Issue.php | 8 ++++---- lib/Github/Api/PullRequest.php | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index ccc2af2aad5..0e9f4c2d278 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -75,8 +75,8 @@ public function markAsReadInRepository($username, $repository, array $params = a * * @link http://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read * - * @param string $id the notification number - * @param array $params + * @param int $id the notification number + * @param array $params * * @return array */ @@ -90,7 +90,7 @@ public function markAsRead($id, array $params) * * @link http://developer.github.com/v3/activity/notifications/#view-a-single-thread * - * @param string $id the notification number + * @param int $id the notification number * * @return array */ @@ -104,7 +104,7 @@ public function show($id) * * @link http://developer.github.com/v3/activity/notifications/#get-a-thread-subscription * - * @param string $id the notification number + * @param int $id the notification number * * @return array */ @@ -118,8 +118,8 @@ public function showSubscription($id) * * @link http://developer.github.com/v3/activity/notifications/#set-a-thread-subscription * - * @param string $id the notification number - * @param array $params + * @param int $id the notification number + * @param array $params * * @return array */ @@ -133,7 +133,7 @@ public function createSubscription($id, array $params) * * @link http://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription * - * @param string $id the notification number + * @param int $id the notification number * * @return array */ diff --git a/lib/Github/Api/CurrentUser/PublicKeys.php b/lib/Github/Api/CurrentUser/PublicKeys.php index 418e78b8639..a09a08305ac 100644 --- a/lib/Github/Api/CurrentUser/PublicKeys.php +++ b/lib/Github/Api/CurrentUser/PublicKeys.php @@ -28,7 +28,7 @@ public function all() * * @link https://developer.github.com/v3/users/keys/ * - * @param string $id + * @param int $id * * @return array */ @@ -62,7 +62,7 @@ public function create(array $params) * * @link https://developer.github.com/v3/users/keys/ * - * @param string $id + * @param int $id * * @return array */ diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 265be431b74..e7d4c95b5e2 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -68,8 +68,8 @@ public function create($username, $repository, array $params) * * @param string $username the username * @param string $repository the repository - * @param string $id the deployment number - * @param array $params The information about the deployment update. + * @param int $id the deployment number + * @param array $params The information about the deployment update. * Must include a "state" field of pending, success, error, or failure. * May also be given a target_url and description, ßee link for more details. * @return array information about the deployment diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 1ec7e79e89c..537f7b8ed00 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -104,7 +104,7 @@ public function org($organization, $state, array $params = array()) * * @param string $username the username * @param string $repository the repository - * @param string $id the issue number + * @param int $id the issue number * * @return array information about the issue */ @@ -143,7 +143,7 @@ public function create($username, $repository, array $params) * * @param string $username the username * @param string $repository the repository - * @param string $id the issue number + * @param int $id the issue number * @param array $params key=>value user attributes to update. * key can be title or body * @@ -161,7 +161,7 @@ public function update($username, $repository, $id, array $params) * * @param string $username * @param string $repository - * @param string $id + * @param int $id * * @return string */ @@ -177,7 +177,7 @@ public function lock($username, $repository, $id) * * @param string $username * @param string $repository - * @param string $id + * @param int $id * * @return string */ diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index df8a42f1109..89a48c7c9d3 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -75,7 +75,7 @@ public function all($username, $repository, array $params = array()) * * @param string $username the username * @param string $repository the repository - * @param string $id the ID of the pull request for which details are retrieved + * @param int $id the ID of the pull request for which details are retrieved * * @return array|string pull request details */ @@ -101,7 +101,7 @@ public function files($username, $repository, $id) * * @param string $username the username * @param string $repository the repository - * @param string $id the ID of the pull request for which statuses are retrieved + * @param int $id the ID of the pull request for which statuses are retrieved * * @return array array of statuses for the project */ From 69c1fa17d82cace7903ea593e1a69b57f1a2e5be Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 25 Oct 2017 20:34:44 +0100 Subject: [PATCH 599/951] Added missing newlines --- lib/Github/Client.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index b9f6620e8a5..d93c703e936 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -203,6 +203,7 @@ public function api($name) case 'integrations': $api = new Api\Integrations($this); break; + case 'apps': $api = new Api\Apps($this); break; @@ -225,6 +226,7 @@ public function api($name) case 'organizations': $api = new Api\Organization($this); break; + case 'org_project': case 'orgProject': case 'org_projects': @@ -284,6 +286,7 @@ public function api($name) case 'meta': $api = new Api\Meta($this); break; + case 'graphql': $api = new Api\GraphQL($this); break; From 1e9c33cc79533cf3a104df320be8735a0c0ab640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Barrera?= Date: Wed, 1 Nov 2017 11:30:40 +0000 Subject: [PATCH 600/951] Fix minor typo in protection.md The method called to update a branch's protection should be update not show --- doc/repo/protection.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/protection.md b/doc/repo/protection.md index 6fed148096b..9ba596dca1a 100644 --- a/doc/repo/protection.md +++ b/doc/repo/protection.md @@ -31,7 +31,7 @@ $params = [ 'enforce_admins' => true, 'restrictions' => null, ]; -$protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'master', $params); +$protection = $client->api('repo')->protection()->update('twbs', 'bootstrap', 'master', $params); ``` ### Remove branch protection From cac96bf141537ca63c2024299ad294c4437fe6e0 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 1 Oct 2017 12:30:15 +0200 Subject: [PATCH 601/951] Upgrade phpunit dependency to supported versions --- .travis.yml | 1 - CHANGELOG.md | 10 ++++++++++ README.md | 2 +- composer.json | 4 ++-- test/Github/Tests/Api/TestCase.php | 2 +- test/Github/Tests/ClientTest.php | 2 +- test/Github/Tests/Functional/CacheTest.php | 2 +- test/Github/Tests/HttpClient/BuilderTest.php | 2 +- .../Tests/HttpClient/Message/ResponseMediatorTest.php | 2 +- test/Github/Tests/Integration/TestCase.php | 2 +- test/Github/Tests/ResultPagerTest.php | 2 +- 11 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6831c07786c..55462cf4f90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ cache: - $HOME/.composer/cache php: - - 5.5 - 5.6 - 7.0 - 7.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index d3bf0899055..4174969f087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.7.0 (Unreleased) + +### Removed + +- Dropped support for php 5.5 + +### + +- Phpunit 6 compatibility + ## 2.6.0 ### Added diff --git a/README.md b/README.md index 782a2cbef60..6a25ad7dceb 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements -* PHP >= 5.5 +* PHP >= 5.6 * [Guzzle](https://github.com/guzzle/guzzle) library, * (optional) PHPUnit to run tests. diff --git a/composer.json b/composer.json index ef5f7770f2f..afe3e9d528b 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^5.5 || ^7.0", + "php": "^5.6 || ^7.0", "psr/http-message": "^1.0", "psr/cache": "^1.0", "php-http/httplug": "^1.1", @@ -27,7 +27,7 @@ "php-http/cache-plugin": "^1.4" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.5", + "phpunit/phpunit": "^5.5 || ^6.0", "php-http/guzzle6-adapter": "^1.0", "php-http/mock-client": "^1.0", "guzzlehttp/psr7": "^1.2", diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index c15228e63bb..c02e08bbde3 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -5,7 +5,7 @@ use Github\HttpClient\Builder; use ReflectionMethod; -abstract class TestCase extends \PHPUnit_Framework_TestCase +abstract class TestCase extends \PHPUnit\Framework\TestCase { /** * @return string diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 71ce371c353..3be0e3ba44e 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -12,7 +12,7 @@ use Http\Client\HttpClient; use Psr\Http\Message\RequestInterface; -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientTest extends \PHPUnit\Framework\TestCase { /** * @test diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index 31c6f5a4f5d..1af87ce63d6 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -11,7 +11,7 @@ * * @author Tobias Nyholm */ -class CacheTest extends \PHPUnit_Framework_TestCase +class CacheTest extends \PHPUnit\Framework\TestCase { /** * @test diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php index dadfd4f44d8..d04aa496bd8 100644 --- a/test/Github/Tests/HttpClient/BuilderTest.php +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -7,7 +7,7 @@ /** * @author Tobias Nyholm */ -class BuilderTest extends \PHPUnit_Framework_TestCase +class BuilderTest extends \PHPUnit\Framework\TestCase { /** * @test diff --git a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php index 2880f95fd28..d8f246c919d 100644 --- a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php +++ b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php @@ -8,7 +8,7 @@ /** * @author Tobias Nyholm */ -class ResponseMediatorTest extends \PHPUnit_Framework_TestCase +class ResponseMediatorTest extends \PHPUnit\Framework\TestCase { public function testGetContent() { diff --git a/test/Github/Tests/Integration/TestCase.php b/test/Github/Tests/Integration/TestCase.php index 13e88e37462..6f8e5815719 100644 --- a/test/Github/Tests/Integration/TestCase.php +++ b/test/Github/Tests/Integration/TestCase.php @@ -9,7 +9,7 @@ /** * @group integration */ -class TestCase extends \PHPUnit_Framework_TestCase +class TestCase extends \PHPUnit\Framework\TestCase { /** * @var Client diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index ee79058e79a..e72c1b3e092 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -18,7 +18,7 @@ * @author Mitchel Verschoof * @author Tobias Nyholm */ -class ResultPagerTest extends \PHPUnit_Framework_TestCase +class ResultPagerTest extends \PHPUnit\Framework\TestCase { /** * @test From 75772cbf7757a214e45c65c2f65746262f9bcffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kh=C3=A1nh=20C=C3=B4n?= Date: Mon, 6 Nov 2017 12:11:38 +0000 Subject: [PATCH 602/951] Change "knp-labs" to "KnpLabs" --- doc/repo/contents.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/repo/contents.md b/doc/repo/contents.md index ccc6c12d509..53c3fd20ede 100644 --- a/doc/repo/contents.md +++ b/doc/repo/contents.md @@ -4,53 +4,53 @@ ### Get a repository's README ```php -$readme = $client->api('repo')->contents()->readme('knp-labs', 'php-github-api', $reference); +$readme = $client->api('repo')->contents()->readme('KnpLabs', 'php-github-api', $reference); ``` ### Get information about a repository file or directory ```php -$fileInfo = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $reference); +$fileInfo = $client->api('repo')->contents()->show('KnpLabs', 'php-github-api', $path, $reference); ``` ### Check that a file or directory exists in the repository ```php -$fileExists = $client->api('repo')->contents()->exists('knp-labs', 'php-github-api', $path, $reference); +$fileExists = $client->api('repo')->contents()->exists('KnpLabs', 'php-github-api', $path, $reference); ``` ### Create a file ```php $committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); -$fileInfo = $client->api('repo')->contents()->create('knp-labs', 'php-github-api', $path, $content, $commitMessage, $branch, $committer); +$fileInfo = $client->api('repo')->contents()->create('KnpLabs', 'php-github-api', $path, $content, $commitMessage, $branch, $committer); ``` ### Update a file ```php $committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); -$oldFile = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $branch); +$oldFile = $client->api('repo')->contents()->show('KnpLabs', 'php-github-api', $path, $branch); -$fileInfo = $client->api('repo')->contents()->update('knp-labs', 'php-github-api', $path, $content, $commitMessage, $oldFile['sha'], $branch, $committer); +$fileInfo = $client->api('repo')->contents()->update('KnpLabs', 'php-github-api', $path, $content, $commitMessage, $oldFile['sha'], $branch, $committer); ``` ### Remove a file ```php $committer = array('name' => 'KnpLabs', 'email' => 'info@knplabs.com'); -$oldFile = $client->api('repo')->contents()->show('knp-labs', 'php-github-api', $path, $branch); +$oldFile = $client->api('repo')->contents()->show('KnpLabs', 'php-github-api', $path, $branch); -$fileInfo = $client->api('repo')->contents()->rm('knp-labs', 'php-github-api', $path, $commitMessage, $oldFile['sha'], $branch, $committer); +$fileInfo = $client->api('repo')->contents()->rm('KnpLabs', 'php-github-api', $path, $commitMessage, $oldFile['sha'], $branch, $committer); ``` ### Get repository archive ```php -$archive = $client->api('repo')->contents()->archive('knp-labs', 'php-github-api', $format, $reference); +$archive = $client->api('repo')->contents()->archive('KnpLabs', 'php-github-api', $format, $reference); ``` ### Download a file ```php -$fileContent = $client->api('repo')->contents()->download('knp-labs', 'php-github-api', $path, $reference); +$fileContent = $client->api('repo')->contents()->download('KnpLabs', 'php-github-api', $path, $reference); ``` From d2e04e52757e2ef21e9342a48e62ca60dae8497f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Votruba?= Date: Tue, 14 Nov 2017 08:27:45 +0100 Subject: [PATCH 603/951] README: drop outdated info, simplify install (#645) * README: drop outdated info, simplify install * README: remove tagging --- README.md | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6a25ad7dceb..d6a295449c3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,4 @@ -# PHP GitHub API 2.0 - -In 2.0 lib no longer uses guzzle 3.7, instead it has an HTTPlug abstraction layer. - -For old version please check: - -* [branch](https://github.com/KnpLabs/php-github-api/tree/1.7) -* [readme](https://github.com/KnpLabs/php-github-api/tree/1.7/README.md) -* [docs](https://github.com/KnpLabs/php-github-api/tree/1.7/doc) +# PHP GitHub API [![Build Status](https://travis-ci.org/KnpLabs/php-github-api.svg?branch=master)](https://travis-ci.org/KnpLabs/php-github-api) [![StyleCI](https://styleci.io/repos/3948501/shield?style=flat)](https://styleci.io/repos/3948501) @@ -17,7 +9,6 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Features -* Follows PSR-4 conventions and coding standard: autoload friendly * Light and fast thanks to lazy loading of API classes * Extensively tested and documented @@ -29,20 +20,15 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Install -The new version of `php-github-api` using [Composer](http://getcomposer.org). -The first step to use `php-github-api` is to download composer: +Via Composer: ```bash -$ curl -s http://getcomposer.org/installer | php -``` - -Then run the following command to require the library: -```bash -$ php composer.phar require knplabs/github-api php-http/guzzle6-adapter +$ composer require knplabs/github-api php-http/guzzle6-adapter ``` Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md). + ## Using Laravel? [Laravel GitHub](https://github.com/GrahamCampbell/Laravel-GitHub) by [Graham Campbell](https://github.com/GrahamCampbell) might interest you. @@ -53,7 +39,7 @@ Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client api('user')->repositories('ornicar'); @@ -69,7 +55,7 @@ This example uses the PSR6 cache pool [redis-adapter](https://github.com/php-cac Date: Wed, 15 Nov 2017 09:17:22 -0700 Subject: [PATCH 604/951] Correct Enterprise API documentation (issue #636) --- doc/enterprise.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/enterprise.md b/doc/enterprise.md index 7308d2dc1f2..5245fe7c3d8 100644 --- a/doc/enterprise.md +++ b/doc/enterprise.md @@ -12,10 +12,8 @@ In order to configure the client to point to a GitHub Enterprise installation, d // This file is generated by Composer require_once 'vendor/autoload.php'; -$client = new \Github\Client(); - -// Set the URL of your GitHub Enterprise installation -$client->setEnterpriseUrl('https://ghe.host'); +// Specify the URL of your GitHub Enterprise installation on client initialization +$client = new \Github\Client(null, null, 'https://ghe.host'); // Use the client as you would ordinarily $repositories = $client->api('user')->repositories('ornicar'); From 2c70a8eadb1fa75037ec60b65d413346a541be05 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 15 Nov 2017 17:33:43 +0000 Subject: [PATCH 605/951] set correct path to security.md --- doc/currentuser/publickeys.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/currentuser/publickeys.md b/doc/currentuser/publickeys.md index 5cfcf82b77e..f0eb72ad421 100644 --- a/doc/currentuser/publickeys.md +++ b/doc/currentuser/publickeys.md @@ -19,7 +19,7 @@ $key = $client->user()->keys()->show(1234); ### Add a public key to the authenticated user. -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $key = $client->user()->keys()->create(array('title' => 'key title', 'key' => 12345)); @@ -29,7 +29,7 @@ Adds a key with title 'key title' to the authenticated user and returns a the cr ### Remove a public key from the authenticated user. -> Requires [authentication](security.md). +> Requires [authentication](../security.md). ```php $client->user()->keys()->remove(12345); From 9bd650e4f5120ce5724d611dee8c41897d85e75a Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 27 Nov 2017 09:12:54 +0100 Subject: [PATCH 606/951] allow to set the requested page on all endpoints (#586) * allow to set the requested page on all endpoints At the moment it's not possible to request another page on all endpoints (search for example). With this change the requested `page` can be set the same way like the `per_page`. * private per page property * revert and private page --- lib/Github/Api/AbstractApi.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 6feff8ea2bb..19f8ce4d653 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -19,6 +19,13 @@ abstract class AbstractApi implements ApiInterface */ protected $client; + /** + * The requested page (GitHub pagination). + * + * @var null|int + */ + private $page; + /** * Number of items per page (GitHub pagination). * @@ -38,6 +45,24 @@ public function configure() { } + /** + * @return null|int + */ + public function getPage() + { + return $this->page; + } + + /** + * @param null|int $page + */ + public function setPage($page) + { + $this->page = (null === $page ? $page : (int) $page); + + return $this; + } + /** * @return null|int */ @@ -67,6 +92,9 @@ public function setPerPage($perPage) */ protected function get($path, array $parameters = array(), array $requestHeaders = array()) { + if (null !== $this->page && !isset($parameters['page'])) { + $parameters['page'] = $this->page; + } if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; } From 9bc5675de11a5a30d1f1cb31714f8d1a28a00d04 Mon Sep 17 00:00:00 2001 From: Wilhem Arthur Date: Fri, 8 Dec 2017 13:00:17 -0500 Subject: [PATCH 607/951] added request params and headers to user followers calls (#648) * added request params and headers to user followers calls * used shorthand array syntax * modified abstract api get method to use shorthand array syntax * Revert "modified abstract api get method to use shorthand array syntax" This reverts commit a3416c61e962073c75c3023c2b70d000115a5a25. * shorthand syntax for array --- lib/Github/Api/User.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index d4dc6bccbf6..856e86c17fa 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -88,12 +88,14 @@ public function orgs() * @link http://developer.github.com/v3/users/followers/ * * @param string $username the username + * @param array $parameters parameters for the query string + * @param array $requestHeaders additional headers to set in the request * * @return array list of followed users */ - public function following($username) + public function following($username, array $parameters = [], array $requestHeaders = []) { - return $this->get('/users/'.rawurlencode($username).'/following'); + return $this->get('/users/'.rawurlencode($username).'/following', $parameters, $requestHeaders); } /** @@ -102,12 +104,14 @@ public function following($username) * @link http://developer.github.com/v3/users/followers/ * * @param string $username the username + * @param array $parameters parameters for the query string + * @param array $requestHeaders additional headers to set in the request * * @return array list of following users */ - public function followers($username) + public function followers($username, array $parameters = [], array $requestHeaders = []) { - return $this->get('/users/'.rawurlencode($username).'/followers'); + return $this->get('/users/'.rawurlencode($username).'/followers', $parameters, $requestHeaders); } /** From f2b649098f87b944f7171104cf4122bfc024b10b Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 9 Dec 2017 23:15:33 +0100 Subject: [PATCH 608/951] Make method compatible with phpunit 5 and 6 --- test/Github/Tests/Api/Repository/ContentsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index e14b3785b46..be930ab1a00 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -67,13 +67,13 @@ public function getFailureStubsForExistsTest() } /** + * @param \PHPUnit_Framework_MockObject_Stub|\PHPUnit\Framework\MockObject\Stub\Exception + * * @test * @dataProvider getFailureStubsForExistsTest */ - public function shouldReturnFalseWhenFileIsNotFound(\PHPUnit_Framework_MockObject_Stub $failureStub) + public function shouldReturnFalseWhenFileIsNotFound($failureStub) { - $expectedValue = array('some-header' => 'value'); - $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') From 6af822c3ebc29f88a4f73eb33ca5610236e6bab2 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 9 Dec 2017 23:00:55 +0100 Subject: [PATCH 609/951] Missing issue timeline api --- doc/README.md | 1 + doc/issue/timeline.md | 17 +++++++++ lib/Github/Api/Issue.php | 13 +++++++ lib/Github/Api/Issue/Timeline.php | 33 ++++++++++++++++++ test/Github/Tests/Api/Issue/TimelineTest.php | 36 ++++++++++++++++++++ test/Github/Tests/Api/IssueTest.php | 10 ++++++ 6 files changed, 110 insertions(+) create mode 100644 doc/issue/timeline.md create mode 100644 lib/Github/Api/Issue/Timeline.php create mode 100644 test/Github/Tests/Api/Issue/TimelineTest.php diff --git a/doc/README.md b/doc/README.md index 2c351060190..00faee5a846 100644 --- a/doc/README.md +++ b/doc/README.md @@ -27,6 +27,7 @@ v3 APIs: * [Comments](issue/comments.md) * [Labels](issue/labels.md) * [Milestones](issue/milestones.md) + * [Timeline](issue/timeline.md) * [Meta](meta.md) * Miscellaneous * [Emojis](miscellaneous/emojis.md) diff --git a/doc/issue/timeline.md b/doc/issue/timeline.md new file mode 100644 index 00000000000..5b0760f92ee --- /dev/null +++ b/doc/issue/timeline.md @@ -0,0 +1,17 @@ +## Issues / Timeline API +[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md) + +Wraps [GitHub Issue Timeline API](http://developer.github.com/v3/issues/timeline/). + +This api is currently only available to developers in Early Access. To access the API during the Early Access period, +you must provide a custom media type in the Accept header. + +```php +$client->api('ìssue')->timeline()->configure(); +``` + +### List events for an issue + +```php +$events = $client->api('issue')->timeline()->all('KnpLabs', 'php-github-api', 123); +``` diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 537f7b8ed00..5a42d5cd4bd 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -7,6 +7,7 @@ use Github\Api\Issue\Events; use Github\Api\Issue\Labels; use Github\Api\Issue\Milestones; +use Github\Api\Issue\Timeline; use Github\Exception\MissingArgumentException; /** @@ -245,4 +246,16 @@ public function assignees() { return new Assignees($this->client); } + + /** + * List all events. + * + * @link https://developer.github.com/v3/issues/timeline/ + * + * @return Timeline + */ + public function timeline() + { + return new Timeline($this->client); + } } diff --git a/lib/Github/Api/Issue/Timeline.php b/lib/Github/Api/Issue/Timeline.php new file mode 100644 index 00000000000..1a076641024 --- /dev/null +++ b/lib/Github/Api/Issue/Timeline.php @@ -0,0 +1,33 @@ +acceptHeaderValue = 'application/vnd.github.mockingbird-preview'; + + return $this; + } + + /** + * Get all events for a specific issue. + * + * @link https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue + * @param string $username + * @param string $repository + * @param int $issue + * + * @return array + */ + public function all($username, $repository, $issue) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/timeline'); + } +} diff --git a/test/Github/Tests/Api/Issue/TimelineTest.php b/test/Github/Tests/Api/Issue/TimelineTest.php new file mode 100644 index 00000000000..43bd991f279 --- /dev/null +++ b/test/Github/Tests/Api/Issue/TimelineTest.php @@ -0,0 +1,36 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/issues/123/timeline', array()) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + } + + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Issue\Timeline::class; + } +} diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 5596f6be4de..545c5184be5 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -242,6 +242,16 @@ public function shouldGetMilestonesApiObject() $this->assertInstanceOf(\Github\Api\Issue\Milestones::class, $api->milestones()); } + /** + * @test + */ + public function shouldGetTimelineApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Issue\Timeline::class, $api->timeline()); + } + /** * @test */ From e2e991c37c063465aa1db20bf8b6efdc3ef98e63 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 9 Dec 2017 23:22:25 +0100 Subject: [PATCH 610/951] Add php 7.2 to the tested versions --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 55462cf4f90..6aa267626d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: php +sudo: false cache: directories: @@ -9,14 +10,13 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 matrix: include: - php: hhvm dist: trusty -sudo: false - install: - travis_retry composer install --no-interaction From c49e37870671676933bb275ede8d5a58d7ce1bf4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 11 Dec 2017 13:29:47 +0100 Subject: [PATCH 611/951] Do not prepend api/vX/ to the path if it already starts that way, e.g. pagination next URLs --- lib/Github/HttpClient/Plugin/PathPrepend.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index b3b840e1487..567bb156ed7 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -28,7 +28,9 @@ public function __construct($path) public function handleRequest(RequestInterface $request, callable $next, callable $first) { $currentPath = $request->getUri()->getPath(); - $uri = $request->getUri()->withPath($this->path.$currentPath); + if (strpos($currentPath, $this->path) !== 0) { + $uri = $request->getUri()->withPath($this->path.$currentPath); + } $request = $request->withUri($uri); From 633e0040ecedf191693862354de757593ad511fe Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Tue, 12 Dec 2017 17:06:05 -0200 Subject: [PATCH 612/951] Refactoring tests (#664) --- test/Github/Tests/Api/Repository/ContentsTest.php | 2 +- test/Github/Tests/Integration/RepoTest.php | 2 +- test/Github/Tests/ResultPagerTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index be930ab1a00..a8cc4098005 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -53,7 +53,7 @@ public function shouldReturnTrueWhenFileExists() ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) ->will($this->returnValue($response)); - $this->assertEquals(true, $api->exists('KnpLabs', 'php-github-api', 'composer.json')); + $this->assertTrue($api->exists('KnpLabs', 'php-github-api', 'composer.json')); } public function getFailureStubsForExistsTest() diff --git a/test/Github/Tests/Integration/RepoTest.php b/test/Github/Tests/Integration/RepoTest.php index 050c5575ab9..90328b909aa 100644 --- a/test/Github/Tests/Integration/RepoTest.php +++ b/test/Github/Tests/Integration/RepoTest.php @@ -21,7 +21,7 @@ public function shouldShowPRDiffIfHeaderIsPresent() $diff = $this->client->api('pull_request')->show('KnpLabs', 'php-github-api', '92'); - $this->assertTrue('string' === gettype($diff)); + $this->assertInternalType('string', $diff); } /** diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index e72c1b3e092..17be7278ffa 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -52,7 +52,7 @@ public function shouldGetAllResults() $paginator = new ResultPager($client); $result = $paginator->fetchAll($memberApi, $method, $parameters); - $this->assertEquals($amountLoops * count($content), count($result)); + $this->assertCount($amountLoops * count($content), $result); } /** @@ -94,7 +94,7 @@ public function shouldGetAllSearchResults() $paginator = new ResultPager($client); $result = $paginator->fetchAll($searchApi, $method, array('knplabs')); - $this->assertEquals($amountLoops * count($content['items']), count($result)); + $this->assertCount($amountLoops * count($content['items']), $result); } public function testFetch() From 3667cee456811238c4a31211e0340aa871defd68 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 12 Dec 2017 20:10:29 +0100 Subject: [PATCH 613/951] PathPrepend plugin: Only overwrite the request uri if it actually changed (#663) * PathPrepend plugin: Only overwrite the request uri if it actually changed * Add test for pathprepend http plugin * Formatting * Updated to phpunit6 --- lib/Github/HttpClient/Plugin/PathPrepend.php | 3 +- .../Tests/HttpClient/PathPrependTest.php | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/Github/Tests/HttpClient/PathPrependTest.php diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 567bb156ed7..2c91bf74f3b 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -30,10 +30,9 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $currentPath = $request->getUri()->getPath(); if (strpos($currentPath, $this->path) !== 0) { $uri = $request->getUri()->withPath($this->path.$currentPath); + $request = $request->withUri($uri); } - $request = $request->withUri($uri); - return $next($request); } } diff --git a/test/Github/Tests/HttpClient/PathPrependTest.php b/test/Github/Tests/HttpClient/PathPrependTest.php new file mode 100644 index 00000000000..dbd7905c739 --- /dev/null +++ b/test/Github/Tests/HttpClient/PathPrependTest.php @@ -0,0 +1,39 @@ + + */ +class PathPrependTest extends TestCase +{ + /** + * @dataProvider uris + */ + public function testPathIsPrepended($uri, $expectedPath) + { + $request = new Request('GET', $uri); + $plugin = new PathPrepend('/api/v3'); + + $newRequest = null; + $plugin->handleRequest($request, function ($request) use (&$newRequest) { + $newRequest = $request; + }, function () { + throw new \RuntimeException("Did not expect plugin to call first"); + }); + + $this->assertEquals($expectedPath, $newRequest->getUri()->getPath()); + } + + public static function uris() + { + return [ + ['http://example.com/foo/bar/api', '/api/v3/foo/bar/api'], + ['http://example.com/api/v3/foo/bar/api', '/api/v3/foo/bar/api'], + ]; + } +} From 4ffb1d389b40fd84dff5f5b12f2453abc1931c06 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 12 Dec 2017 20:35:34 +0100 Subject: [PATCH 614/951] Missing toggle primary email visibility api endpoint (#660) --- doc/README.md | 1 + doc/currentuser/emails.md | 35 +++++++++++++++++++ lib/Github/Api/CurrentUser/Emails.php | 24 +++++++++++++ .../Tests/Api/CurrentUser/EmailsTest.php | 16 +++++++++ 4 files changed, 76 insertions(+) create mode 100644 doc/currentuser/emails.md diff --git a/doc/README.md b/doc/README.md index 00faee5a846..f4e1d3421cb 100644 --- a/doc/README.md +++ b/doc/README.md @@ -10,6 +10,7 @@ v3 APIs: * [Authorizations](authorizations.md) * [Commits](commits.md) * Current User + * [Emails](currentuser/emails.md) * [Public keys](currentuser/publickeys.md) * [Memberships](currentuser/memberships.md) * [Enterprise](enterprise.md) diff --git a/doc/currentuser/emails.md b/doc/currentuser/emails.md new file mode 100644 index 00000000000..ef099f468d5 --- /dev/null +++ b/doc/currentuser/emails.md @@ -0,0 +1,35 @@ +## Current user / Emails API +[Back to the navigation](../README.md) + +Wraps [GitHub User Emails API](https://developer.github.com/v3/users/emails/#emails). + +> Requires [authentication](../security.md). + +### List email addresses for a user + +```php +$emails = $client->currentUser()->emails()->all(); +``` + +### List public email addresses for a user + +```php +$emails = $client->currentUser()->emails()->allPublic(); +``` + +### Add email address(es) + +```php +$emails = $client->currentUser()->emails()->add(['email1', 'email2']); +``` +### Delete email address(es) + +```php +$client->currentUser()->emails()->remove(['email1', 'email2']); +``` + +### Toggle primary email visibility + +```php +$primaryEmail = $client->currentUser()->emails()->toggleVisibility(); +``` diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index 8155301ed5d..98dae634efb 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -23,6 +23,18 @@ public function all() return $this->get('/user/emails'); } + /** + * List public email addresses for a user. + * + * @link https://developer.github.com/v3/users/emails/#list-public-email-addresses-for-a-user + * + * @return array + */ + public function allPublic() + { + return $this->get('/user/public_emails'); + } + /** * Adds one or more email for the authenticated user. * @@ -66,4 +78,16 @@ public function remove($emails) return $this->delete('/user/emails', $emails); } + + /** + * Toggle primary email visibility + * + * @link https://developer.github.com/v3/users/emails/#toggle-primary-email-visibility + * + * @return array + */ + public function toggleVisibility() + { + return $this->patch('/user/email/visibility'); + } } diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index cba52d12be3..cd15eb2c2ee 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -110,6 +110,22 @@ public function shouldNotAddEmailsWhenAreNotPass() $api->add(array()); } + /** + * @test + */ + public function shouldToggleVisibility() + { + $expectedValue = array('primary email info'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/user/email/visibility') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->toggleVisibility()); + } + /** * @return string */ From 1654be3be9aaed3f58a3087e2a91aea08cbcf41e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 12 Dec 2017 20:35:51 +0100 Subject: [PATCH 615/951] Missing search commits api endpoint (#659) --- doc/search.md | 7 +++++++ lib/Github/Api/Search.php | 21 +++++++++++++++++++++ test/Github/Tests/Api/SearchTest.php | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/doc/search.md b/doc/search.md index b798b934d35..0a674808001 100644 --- a/doc/search.md +++ b/doc/search.md @@ -34,6 +34,12 @@ Returns a list of issues found by such criteria. $users = $client->api('search')->users('location:Amsterdam language:php'); ``` +### Search commits + +```php +$commits = $client->api('search')->commits('repo:octocat/Spoon-Knife+css'); +``` + Returns a list of users found by such criteria. ### Sorting results @@ -45,4 +51,5 @@ $repos = $client->api('search')->repositories('...', 'created', 'asc'); $files = $client->api('search')->code('...........', 'indexed', 'desc'); $issues = $client->api('search')->issues('.........', 'comments', 'asc'); $users = $client->api('search')->users('..........', 'followers', 'asc'); +$commits = $client->api('search')->commits('..........', 'author-date', 'desc'); ``` diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 15e698ac970..857ef9eb7b9 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -10,6 +10,8 @@ */ class Search extends AbstractApi { + use AcceptHeaderTrait; + /** * Search repositories by filter (q). * @@ -73,4 +75,23 @@ public function users($q, $sort = 'updated', $order = 'desc') { return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); } + + /** + * Search commits by filter (q). + * + * @link https://developer.github.com/v3/search/#search-commits + * + * @param string $q the filter + * @param string $sort the sort field + * @param string $order sort order. asc/desc + * + * @return array + */ + public function commits($q, $sort = null, $order = 'desc') + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.cloak-preview'; + + return $this->get('/search/commits', array('q' => $q, 'sort' => $sort, 'order' => $order)); + } } diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index 69ec3e032eb..c67fc96171c 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -176,6 +176,26 @@ public function shouldSearchUsersRegardingSortAndOrder() ); } + /** + * @test + */ + public function shouldSearchCommitsRegardingSortAndOrder() + { + $expectedArray = ['total_count' => '0']; + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/search/commits', ['q' => 'query text', 'sort' => 'author-date', 'order' => 'asc']) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->commits('query text', 'author-date', 'asc') + ); + } + /** * @return string */ From 9acf27f181120adfe9b46573ece5faf473b06bda Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 12 Dec 2017 20:36:04 +0100 Subject: [PATCH 616/951] Mark legacy search methods as deprecated (#658) --- lib/Github/Api/Issue.php | 2 ++ lib/Github/Api/Repo.php | 2 ++ lib/Github/Api/User.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 5a42d5cd4bd..f77d4e4a22d 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -60,6 +60,8 @@ public function all($username, $repository, array $params = array()) /** * Search issues by username, repo, state and keyword. * + * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated + * * @link http://developer.github.com/v3/search/#search-issues * * @param string $username the username diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 9598d6d04ec..1578bc60b5b 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -31,6 +31,8 @@ class Repo extends AbstractApi /** * Search repositories by keyword. * + * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated + * * @link http://developer.github.com/v3/search/#search-repositories * * @param string $keyword the search query diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 856e86c17fa..570b3c0c719 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -14,6 +14,8 @@ class User extends AbstractApi /** * Search users by username. * + * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated + * * @link http://developer.github.com/v3/search/#search-users * * @param string $keyword the keyword to search From 1d4d360b5365b039aec75fe7e1405eac2f32a1de Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 12 Dec 2017 20:36:13 +0100 Subject: [PATCH 617/951] Missing code of conduct api endpoints (#656) --- doc/README.md | 1 + doc/miscellaneous/codeofconduct.md | 14 +++++ doc/repos.md | 6 +++ .../Api/Miscellaneous/CodeOfConduct.php | 44 +++++++++++++++ lib/Github/Api/Repo.php | 20 +++++++ lib/Github/Client.php | 4 ++ .../Api/Miscellaneous/CodeOfConductTest.php | 54 +++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 16 ++++++ 8 files changed, 159 insertions(+) create mode 100644 doc/miscellaneous/codeofconduct.md create mode 100644 lib/Github/Api/Miscellaneous/CodeOfConduct.php create mode 100644 test/Github/Tests/Api/Miscellaneous/CodeOfConductTest.php diff --git a/doc/README.md b/doc/README.md index f4e1d3421cb..a3334631fb5 100644 --- a/doc/README.md +++ b/doc/README.md @@ -31,6 +31,7 @@ v3 APIs: * [Timeline](issue/timeline.md) * [Meta](meta.md) * Miscellaneous + * [Code of conduct](miscellaneous/codeofconduct.md) * [Emojis](miscellaneous/emojis.md) * [Gitignore](miscellaneous/gitignore.md) * [Markdown](miscellaneous/markdown.md) diff --git a/doc/miscellaneous/codeofconduct.md b/doc/miscellaneous/codeofconduct.md new file mode 100644 index 00000000000..c47b3c49774 --- /dev/null +++ b/doc/miscellaneous/codeofconduct.md @@ -0,0 +1,14 @@ +## CodeOfConduct API +[Back to the navigation](../README.md) + +### Lists all code of conducts. + +```php +$codeOfConducts = $client->api('codeOfConduct')->all(); +``` + +### Get a code of conduct. + +```php +$codeOfConducts = $client->api('codeOfConduct')->show('contributor_covenant'); +``` diff --git a/doc/repos.md b/doc/repos.md index 1eb24a278b7..4fa2fb076d1 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -303,3 +303,9 @@ $milestones = $client->api('repo')->milestones('ornicar', 'php-github-api'); ``` Returns a list of milestones. + +### Get the contents of a repository's code of conduct + +```php +$codeOfConduct = $client->api('repo')->codeOfConduct('ornicar', 'php-github-api'); +``` diff --git a/lib/Github/Api/Miscellaneous/CodeOfConduct.php b/lib/Github/Api/Miscellaneous/CodeOfConduct.php new file mode 100644 index 00000000000..7d3c69ff469 --- /dev/null +++ b/lib/Github/Api/Miscellaneous/CodeOfConduct.php @@ -0,0 +1,44 @@ +acceptHeaderValue = 'application/vnd.github.scarlet-witch-preview+json'; + + return $this; + } + + /** + * List all codes of conduct. + * + * @link https://developer.github.com/v3/codes_of_conduct/#list-all-codes-of-conduct + * + * @return array + */ + public function all() + { + return $this->get('/codes_of_conduct'); + } + + /** + * Get an individual code of conduct + * + * @link https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct + * + * @param string $key + * + * @return array + */ + public function show($key) + { + return $this->get('/codes_of_conduct/' . rawurlencode($key)); + } +} diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 1578bc60b5b..e611599fa72 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -28,6 +28,8 @@ */ class Repo extends AbstractApi { + use AcceptHeaderTrait; + /** * Search repositories by keyword. * @@ -601,4 +603,22 @@ public function events($username, $repository, $page = 1) { return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]); } + + /** + * Get the contents of a repository's code of conduct + * + * @link https://developer.github.com/v3/codes_of_conduct/#get-the-contents-of-a-repositorys-code-of-conduct + * + * @param string $username + * @param string $repository + * + * @return array + */ + public function codeOfConduct($username, $repository) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.scarlet-witch-preview+json'; + + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/code_of_conduct'); + } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index d93c703e936..ea22b512a6c 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -23,6 +23,7 @@ * @method Api\CurrentUser me() * @method Api\Enterprise ent() * @method Api\Enterprise enterprise() + * @method Api\Miscellaneous\CodeOfConduct codeOfConduct() * @method Api\Miscellaneous\Emojis emojis() * @method Api\GitData git() * @method Api\GitData gitData() @@ -169,6 +170,9 @@ public function api($name) case 'currentUser': $api = new Api\CurrentUser($this); break; + case 'codeOfConduct': + $api = new Api\Miscellaneous\CodeOfConduct($this); + break; case 'deployment': case 'deployments': diff --git a/test/Github/Tests/Api/Miscellaneous/CodeOfConductTest.php b/test/Github/Tests/Api/Miscellaneous/CodeOfConductTest.php new file mode 100644 index 00000000000..0e07dea5752 --- /dev/null +++ b/test/Github/Tests/Api/Miscellaneous/CodeOfConductTest.php @@ -0,0 +1,54 @@ + 'CoC1'], + ['name' => 'CoC2'], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/codes_of_conduct') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetSingleCodeOfConducts() + { + $expectedArray = [ + 'name' => 'CoC', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/codes_of_conduct/contributor_covenant') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('contributor_covenant')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return CodeOfConduct::class; + } +} diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index d84f841009a..9ffd9986519 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -535,6 +535,22 @@ public function shouldGetRepositoryEvents() $this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3)); } + /** + * @test + */ + public function shouldGetRepositoryCodeOfConduct() + { + $expectedArray = array('name' => 'Contributor Covenant', 'url' => 'http://...'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/community/code_of_conduct') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->codeOfConduct('KnpLabs', 'php-github-api')); + } + /** * @return string */ From 95e66efbdeb28585d92d172f32e651dbdeb9dce9 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 12 Dec 2017 21:03:48 +0100 Subject: [PATCH 618/951] Missing repository topics api endpoints (#657) --- doc/repos.md | 12 ++++++++++ lib/Github/Api/Repo.php | 37 ++++++++++++++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 34 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 4fa2fb076d1..3c6526b759b 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -309,3 +309,15 @@ Returns a list of milestones. ```php $codeOfConduct = $client->api('repo')->codeOfConduct('ornicar', 'php-github-api'); ``` + +### List all topics for a repository + +```php +$topics = $client->api('repo')->topics('ornicar', 'php-github-api'); +``` + +### Replace all topics for a repository + +```php +$currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index e611599fa72..b00f12ded48 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -621,4 +621,41 @@ public function codeOfConduct($username, $repository) return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/code_of_conduct'); } + + /** + * List all topics for a repository + * + * @link https://developer.github.com/v3/repos/#list-all-topics-for-a-repository + * + * @param string $username + * @param string $repository + * + * @return array + */ + public function topics($username, $repository) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json'; + + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics'); + } + + /** + * Replace all topics for a repository + * + * @link https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository + * + * @param string $username + * @param string $repository + * @param array $topics + * + * @return array + */ + public function replaceTopics($username, $repository, array $topics) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json'; + + return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 9ffd9986519..24a4be1fe51 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -551,6 +551,40 @@ public function shouldGetRepositoryCodeOfConduct() $this->assertEquals($expectedArray, $api->codeOfConduct('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldGetRepositoryTopics() + { + $expectedArray = ['names' => ['octocat', 'atom', 'electron', 'API']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/topics') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->topics('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldReplaceRepositoryTopics() + { + $expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/topics', array( + 'names' => ['octocat', 'atom', 'electron', 'API'], + )) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API'])); + } + /** * @return string */ From d445f1eec4788763315c3c96a214db4e149f9deb Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 12 Dec 2017 21:14:04 +0100 Subject: [PATCH 619/951] Prepare for 2.7 release (#665) * Prepare for 2.7 release * Updated for new PRs * Add methods on deprecated classes * Adding Repo endpoints * typo --- CHANGELOG.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4174969f087..8ad5da91b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,38 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. -## 2.7.0 (Unreleased) +## 2.7.0 + +### Added + +- Phpunit 6 compatibility +- `Github\Api\AbstractApi::setPage()` to allow you to set the page on all endpoints. +- Support for query parameters and request headers on `Github\Api\User::following` and `Github\Api\User::followers` +- API endpoint `Github\Api\CurrentUser\Emails::allPublic()` +- API endpoint `Github\Api\Search::commits()` +- API endpoint `Github\Api\Miscellaneous\CodeOfConduct` +- API endpoint `Github\Api\Repo::topics()` +- API endpoint `Github\Api\Repo::replaceTopics()` + +### Fixed + +- Fixed bug in `PathPrepend` plugin where "api/vX" could be duplicated. + +### Changed + +- Improved documentation and doc blocks ### Removed - Dropped support for php 5.5 -### +### Deprecated -- Phpunit 6 compatibility +The following endpoints were deprecated by Github and are also deprecated in the client: + +- `Github\Api\Repo::find()` +- `Github\Api\User::find()` +- `Github\Api\Issue::find()` ## 2.6.0 From fdcf7a680a76d5b04406a7c93917f4cb1970b671 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 16 Dec 2017 23:01:05 +0100 Subject: [PATCH 620/951] Extend styleci config to check more code style rules --- .styleci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 731de4d858d..504456e7afa 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,4 +1,5 @@ -preset: psr2 +preset: recommended -enabled: - - return +disabled: + - align_double_arrow + - no_multiline_whitespace_before_semicolons From ead9bfdf14e7ac9011f35c8d6f51b4f02b9c97b1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 16 Dec 2017 23:10:21 +0100 Subject: [PATCH 621/951] Apply new code style fixes from styleci after extended config --- lib/Github/Api/AbstractApi.php | 14 +- lib/Github/Api/AcceptHeaderTrait.php | 23 +- lib/Github/Api/Apps.php | 7 +- lib/Github/Api/Authorizations.php | 5 +- lib/Github/Api/CurrentUser.php | 45 +-- lib/Github/Api/CurrentUser/Emails.php | 7 +- lib/Github/Api/CurrentUser/Followers.php | 7 +- lib/Github/Api/CurrentUser/Memberships.php | 4 +- lib/Github/Api/CurrentUser/Notifications.php | 9 +- lib/Github/Api/CurrentUser/PublicKeys.php | 3 +- lib/Github/Api/CurrentUser/Starring.php | 4 +- lib/Github/Api/CurrentUser/Watchers.php | 7 +- lib/Github/Api/Deployment.php | 49 +-- lib/Github/Api/Enterprise.php | 3 +- .../Api/Enterprise/ManagementConsole.php | 2 +- lib/Github/Api/Enterprise/Stats.php | 2 +- lib/Github/Api/Enterprise/UserAdmin.php | 2 +- lib/Github/Api/Gist/Comments.php | 8 +- lib/Github/Api/Gists.php | 8 +- lib/Github/Api/GitData.php | 1 + lib/Github/Api/GitData/Blobs.php | 7 +- lib/Github/Api/GitData/Commits.php | 7 +- lib/Github/Api/GitData/References.php | 11 +- lib/Github/Api/GitData/Tags.php | 9 +- lib/Github/Api/GitData/Trees.php | 11 +- lib/Github/Api/GraphQL.php | 19 +- lib/Github/Api/Integrations.php | 2 +- lib/Github/Api/Issue.php | 18 +- lib/Github/Api/Issue/Assignees.php | 14 +- lib/Github/Api/Issue/Comments.php | 17 +- lib/Github/Api/Issue/Events.php | 11 +- lib/Github/Api/Issue/Labels.php | 23 +- lib/Github/Api/Issue/Milestones.php | 31 +- lib/Github/Api/Issue/Timeline.php | 1 + lib/Github/Api/Markdown.php | 15 +- lib/Github/Api/Meta.php | 1 + .../Api/Miscellaneous/CodeOfConduct.php | 4 +- lib/Github/Api/Miscellaneous/Gitignore.php | 2 +- lib/Github/Api/Notification.php | 12 +- lib/Github/Api/Organization.php | 11 +- lib/Github/Api/Organization/Hooks.php | 22 +- lib/Github/Api/Organization/Members.php | 3 +- lib/Github/Api/Organization/Projects.php | 6 +- lib/Github/Api/Organization/Teams.php | 11 +- lib/Github/Api/Project/AbstractProjectApi.php | 6 +- lib/Github/Api/Project/Cards.php | 14 +- lib/Github/Api/Project/Columns.php | 18 +- lib/Github/Api/PullRequest.php | 27 +- lib/Github/Api/PullRequest/Comments.php | 10 +- lib/Github/Api/PullRequest/Review.php | 11 +- lib/Github/Api/RateLimit.php | 13 +- lib/Github/Api/Repo.php | 55 ++-- lib/Github/Api/Repository/Assets.php | 3 +- lib/Github/Api/Repository/Collaborators.php | 5 + lib/Github/Api/Repository/Comments.php | 4 +- lib/Github/Api/Repository/Commits.php | 5 +- lib/Github/Api/Repository/Contents.php | 44 +-- lib/Github/Api/Repository/DeployKeys.php | 5 +- lib/Github/Api/Repository/Downloads.php | 1 + lib/Github/Api/Repository/Forks.php | 9 +- lib/Github/Api/Repository/Hooks.php | 5 +- lib/Github/Api/Repository/Labels.php | 5 +- lib/Github/Api/Repository/Projects.php | 6 +- lib/Github/Api/Repository/Protection.php | 299 +++++++++--------- lib/Github/Api/Repository/Releases.php | 1 + lib/Github/Api/Repository/Stargazers.php | 3 +- lib/Github/Api/Repository/Statuses.php | 3 +- lib/Github/Api/Repository/Traffic.php | 6 +- lib/Github/Api/Search.php | 11 +- lib/Github/Api/User.php | 23 +- lib/Github/Client.php | 8 +- .../Exception/MissingArgumentException.php | 2 +- lib/Github/HttpClient/Builder.php | 4 +- .../HttpClient/Message/ResponseMediator.php | 13 +- .../HttpClient/Plugin/Authentication.php | 8 +- .../Plugin/GithubExceptionThrower.php | 12 +- lib/Github/ResultPager.php | 6 +- lib/Github/ResultPagerInterface.php | 4 +- test/Github/Tests/Api/AbstractApiTest.php | 62 ++-- test/Github/Tests/Api/AppTest.php | 1 - test/Github/Tests/Api/AuthorizationsTest.php | 14 +- .../Tests/Api/CurrentUser/DeployKeysTest.php | 14 +- .../Tests/Api/CurrentUser/EmailsTest.php | 28 +- .../Tests/Api/CurrentUser/FollowersTest.php | 8 +- .../Tests/Api/CurrentUser/MembershipsTest.php | 44 +-- .../Tests/Api/CurrentUser/StarringTest.php | 8 +- .../Tests/Api/CurrentUser/WatchersTest.php | 8 +- test/Github/Tests/Api/CurrentUserTest.php | 26 +- test/Github/Tests/Api/DeploymentTest.php | 10 +- .../Tests/Api/Enterprise/LicenseTest.php | 6 +- .../Api/Enterprise/ManagementConsoleTest.php | 8 +- .../Github/Tests/Api/Enterprise/StatsTest.php | 28 +- .../Tests/Api/Enterprise/UserAdminTest.php | 5 +- test/Github/Tests/Api/Gist/CommentsTest.php | 14 +- test/Github/Tests/Api/GistsTest.php | 56 ++-- test/Github/Tests/Api/GitData/BlobsTest.php | 16 +- test/Github/Tests/Api/GitData/CommitsTest.php | 12 +- .../Tests/Api/GitData/ReferencesTest.php | 26 +- test/Github/Tests/Api/GitData/TagsTest.php | 88 +++--- test/Github/Tests/Api/GitData/TreesTest.php | 94 +++--- test/Github/Tests/Api/GraphQLTest.php | 3 +- test/Github/Tests/Api/Issue/AssigneesTest.php | 16 +- test/Github/Tests/Api/Issue/CommentsTest.php | 20 +- test/Github/Tests/Api/Issue/EventsTest.php | 10 +- test/Github/Tests/Api/Issue/LabelsTest.php | 50 +-- .../Github/Tests/Api/Issue/MilestonesTest.php | 58 ++-- test/Github/Tests/Api/Issue/TimelineTest.php | 7 +- test/Github/Tests/Api/IssueTest.php | 64 ++-- test/Github/Tests/Api/MetaTest.php | 18 +- .../Tests/Api/Miscellaneous/EmojisTest.php | 4 +- .../Tests/Api/Miscellaneous/GitignoreTest.php | 13 +- .../Tests/Api/Miscellaneous/MarkdownTest.php | 22 +- test/Github/Tests/Api/NotificationTest.php | 20 +- .../Tests/Api/Organization/HooksTest.php | 20 +- .../Tests/Api/Organization/MembersTest.php | 6 +- .../Tests/Api/Organization/ProjectsTest.php | 8 +- .../Tests/Api/Organization/TeamsTest.php | 48 +-- test/Github/Tests/Api/OrganizationTest.php | 14 +- test/Github/Tests/Api/Project/CardsTest.php | 20 +- test/Github/Tests/Api/Project/ColumnsTest.php | 24 +- .../Github/Tests/Api/Project/ProjectsTest.php | 8 +- .../Tests/Api/PullRequest/CommentsTest.php | 1 - .../Tests/Api/PullRequest/ReviewTest.php | 102 +++--- test/Github/Tests/Api/PullRequestTest.php | 66 ++-- test/Github/Tests/Api/RateLimitTest.php | 20 +- test/Github/Tests/Api/RepoTest.php | 124 ++++---- .../Tests/Api/Repository/AssetsTest.php | 14 +- .../Api/Repository/CollaboratorsTest.php | 2 +- .../Tests/Api/Repository/CommentsTest.php | 24 +- .../Tests/Api/Repository/CommitsTest.php | 8 +- .../Tests/Api/Repository/ContentsTest.php | 80 ++--- .../Tests/Api/Repository/DeployKeysTest.php | 22 +- .../Tests/Api/Repository/DownloadsTest.php | 4 +- .../Github/Tests/Api/Repository/ForksTest.php | 14 +- .../Github/Tests/Api/Repository/HooksTest.php | 22 +- .../Tests/Api/Repository/LabelsTest.php | 22 +- .../Tests/Api/Repository/ProjectsTest.php | 8 +- .../Tests/Api/Repository/ProtectionTest.php | 76 ++--- .../Tests/Api/Repository/ReleasesTest.php | 20 +- .../Tests/Api/Repository/StargazersTest.php | 4 +- .../Tests/Api/Repository/StatusesTest.php | 38 +-- .../Tests/Api/Repository/TrafficTest.php | 9 +- test/Github/Tests/Api/SearchTest.php | 32 +- test/Github/Tests/Api/TestCase.php | 8 +- test/Github/Tests/Api/UserTest.php | 52 +-- test/Github/Tests/ClientTest.php | 85 +++-- test/Github/Tests/Functional/CacheTest.php | 1 + test/Github/Tests/HttpClient/BuilderTest.php | 8 +- .../Message/ResponseMediatorTest.php | 22 +- .../Tests/HttpClient/PathPrependTest.php | 2 +- test/Github/Tests/Integration/CommitTest.php | 16 +- .../Tests/Integration/IssueCommentTest.php | 21 +- .../Github/Tests/Integration/MarkdownTest.php | 8 +- .../Tests/Integration/RateLimitTest.php | 2 +- .../Tests/Integration/RepoCommentTest.php | 24 +- test/Github/Tests/Integration/RepoTest.php | 8 +- .../Tests/Integration/ResultPagerTest.php | 6 +- test/Github/Tests/Integration/UserTest.php | 2 +- test/Github/Tests/Mock/PaginatedResponse.php | 8 +- test/Github/Tests/ResultPagerTest.php | 23 +- 160 files changed, 1637 insertions(+), 1527 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 19f8ce4d653..135ac2b22be 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -90,7 +90,7 @@ public function setPerPage($perPage) * * @return array|string */ - protected function get($path, array $parameters = array(), array $requestHeaders = array()) + protected function get($path, array $parameters = [], array $requestHeaders = []) { if (null !== $this->page && !isset($parameters['page'])) { $parameters['page'] = $this->page; @@ -120,7 +120,7 @@ protected function get($path, array $parameters = array(), array $requestHeaders * * @return \Psr\Http\Message\ResponseInterface */ - protected function head($path, array $parameters = array(), array $requestHeaders = array()) + protected function head($path, array $parameters = [], array $requestHeaders = []) { if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { unset($parameters['ref']); @@ -140,7 +140,7 @@ protected function head($path, array $parameters = array(), array $requestHeader * * @return array|string */ - protected function post($path, array $parameters = array(), array $requestHeaders = array()) + protected function post($path, array $parameters = [], array $requestHeaders = []) { return $this->postRaw( $path, @@ -158,7 +158,7 @@ protected function post($path, array $parameters = array(), array $requestHeader * * @return array|string */ - protected function postRaw($path, $body, array $requestHeaders = array()) + protected function postRaw($path, $body, array $requestHeaders = []) { $response = $this->client->getHttpClient()->post( $path, @@ -178,7 +178,7 @@ protected function postRaw($path, $body, array $requestHeaders = array()) * * @return array|string */ - protected function patch($path, array $parameters = array(), array $requestHeaders = array()) + protected function patch($path, array $parameters = [], array $requestHeaders = []) { $response = $this->client->getHttpClient()->patch( $path, @@ -198,7 +198,7 @@ protected function patch($path, array $parameters = array(), array $requestHeade * * @return array|string */ - protected function put($path, array $parameters = array(), array $requestHeaders = array()) + protected function put($path, array $parameters = [], array $requestHeaders = []) { $response = $this->client->getHttpClient()->put( $path, @@ -218,7 +218,7 @@ protected function put($path, array $parameters = array(), array $requestHeaders * * @return array|string */ - protected function delete($path, array $parameters = array(), array $requestHeaders = array()) + protected function delete($path, array $parameters = [], array $requestHeaders = []) { $response = $this->client->getHttpClient()->delete( $path, diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php index 387a6e68be8..4a7e7a4668d 100644 --- a/lib/Github/Api/AcceptHeaderTrait.php +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -11,50 +11,51 @@ trait AcceptHeaderTrait { protected $acceptHeaderValue = null; - protected function get($path, array $parameters = array(), array $requestHeaders = array()) + protected function get($path, array $parameters = [], array $requestHeaders = []) { return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function head($path, array $parameters = array(), array $requestHeaders = array()) + protected function head($path, array $parameters = [], array $requestHeaders = []) { return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function post($path, array $parameters = array(), array $requestHeaders = array()) + protected function post($path, array $parameters = [], array $requestHeaders = []) { return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function postRaw($path, $body, array $requestHeaders = array()) + protected function postRaw($path, $body, array $requestHeaders = []) { return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders)); } - protected function patch($path, array $parameters = array(), array $requestHeaders = array()) + protected function patch($path, array $parameters = [], array $requestHeaders = []) { return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function put($path, array $parameters = array(), array $requestHeaders = array()) + protected function put($path, array $parameters = [], array $requestHeaders = []) { return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function delete($path, array $parameters = array(), array $requestHeaders = array()) + protected function delete($path, array $parameters = [], array $requestHeaders = []) { return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders)); } /** - * Append a new accept header on all requests + * Append a new accept header on all requests. + * * @return array */ - private function mergeHeaders(array $headers = array()) + private function mergeHeaders(array $headers = []) { - $default = array(); + $default = []; if ($this->acceptHeaderValue) { - $default = array('Accept' => $this->acceptHeaderValue); + $default = ['Accept' => $this->acceptHeaderValue]; } return array_merge($default, $headers); diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index dc11ff0b3cf..8ef0833875e 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -4,12 +4,13 @@ /** * @link https://developer.github.com/v3/apps/ + * * @author Nils Adermann */ class Apps extends AbstractApi { /** - * Create an access token for an installation + * Create an access token for an installation. * * @param int $installationId An integration installation id * @param int $userId An optional user id on behalf of whom the @@ -19,7 +20,7 @@ class Apps extends AbstractApi */ public function createInstallationToken($installationId, $userId = null) { - $parameters = array(); + $parameters = []; if ($userId) { $parameters['user_id'] = $userId; } @@ -50,7 +51,7 @@ public function findInstallations() */ public function listRepositories($userId = null) { - $parameters = array(); + $parameters = []; if ($userId) { $parameters['user_id'] = $userId; } diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index 5e6853fd773..fd8e9b23f50 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -6,6 +6,7 @@ * Creating, deleting and listing authorizations. * * @link http://developer.github.com/v3/oauth_authorizations/ + * * @author Evgeniy Guseletov */ class Authorizations extends AbstractApi @@ -36,13 +37,13 @@ public function show($clientId) * Create an authorization. * * @param array $params - * @param null $OTPCode + * @param null $OTPCode * * @return array */ public function create(array $params, $OTPCode = null) { - $headers = null === $OTPCode ? array() : array('X-GitHub-OTP' => $OTPCode); + $headers = null === $OTPCode ? [] : ['X-GitHub-OTP' => $OTPCode]; return $this->post('/authorizations', $params, $headers); } diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 53dfb0dc226..8718673746c 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -2,16 +2,17 @@ namespace Github\Api; -use Github\Api\CurrentUser\PublicKeys; use Github\Api\CurrentUser\Emails; use Github\Api\CurrentUser\Followers; use Github\Api\CurrentUser\Memberships; use Github\Api\CurrentUser\Notifications; -use Github\Api\CurrentUser\Watchers; +use Github\Api\CurrentUser\PublicKeys; use Github\Api\CurrentUser\Starring; +use Github\Api\CurrentUser\Watchers; /** * @link http://developer.github.com/v3/users/ + * * @author Joseph Bielawski * @author Felipe Valtl de Mello */ @@ -45,9 +46,9 @@ public function follow() public function followers($page = 1) { - return $this->get('/user/followers', array( - 'page' => $page - )); + return $this->get('/user/followers', [ + 'page' => $page, + ]); } /** @@ -58,9 +59,9 @@ public function followers($page = 1) * * @return array */ - public function issues(array $params = array(), $includeOrgIssues = true) + public function issues(array $params = [], $includeOrgIssues = true) { - return $this->get($includeOrgIssues ? '/issues' : '/user/issues', array_merge(array('page' => 1), $params)); + return $this->get($includeOrgIssues ? '/issues' : '/user/issues', array_merge(['page' => 1], $params)); } /** @@ -118,11 +119,11 @@ public function teams() */ public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc') { - return $this->get('/user/repos', array( + return $this->get('/user/repos', [ 'type' => $type, 'sort' => $sort, - 'direction' => $direction - )); + 'direction' => $direction, + ]); } /** @@ -138,9 +139,9 @@ public function watchers() */ public function watched($page = 1) { - return $this->get('/user/watched', array( - 'page' => $page - )); + return $this->get('/user/watched', [ + 'page' => $page, + ]); } /** @@ -156,9 +157,9 @@ public function starring() */ public function starred($page = 1) { - return $this->get('/user/starred', array( - 'page' => $page - )); + return $this->get('/user/starred', [ + 'page' => $page, + ]); } /** @@ -174,19 +175,19 @@ public function subscriptions() * * @param array $params */ - public function installations(array $params = array()) + public function installations(array $params = []) { - return $this->get('/user/installations', array_merge(array('page' => 1), $params)); + return $this->get('/user/installations', array_merge(['page' => 1], $params)); } /** * @link https://developer.github.com/v3/integrations/installations/#list-repositories-accessible-to-the-user-for-an-installation * - * @param string $installationId the ID of the Installation - * @param array $params + * @param string $installationId the ID of the Installation + * @param array $params */ - public function repositoriesByInstallation($installationId, array $params = array()) + public function repositoriesByInstallation($installationId, array $params = []) { - return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(array('page' => 1), $params)); + return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(['page' => 1], $params)); } } diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index 98dae634efb..15d4fad023e 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/users/emails/ + * * @author Joseph Bielawski */ class Emails extends AbstractApi @@ -49,7 +50,7 @@ public function allPublic() public function add($emails) { if (is_string($emails)) { - $emails = array($emails); + $emails = [$emails]; } elseif (0 === count($emails)) { throw new InvalidArgumentException(); } @@ -71,7 +72,7 @@ public function add($emails) public function remove($emails) { if (is_string($emails)) { - $emails = array($emails); + $emails = [$emails]; } elseif (0 === count($emails)) { throw new InvalidArgumentException(); } @@ -80,7 +81,7 @@ public function remove($emails) } /** - * Toggle primary email visibility + * Toggle primary email visibility. * * @link https://developer.github.com/v3/users/emails/#toggle-primary-email-visibility * diff --git a/lib/Github/Api/CurrentUser/Followers.php b/lib/Github/Api/CurrentUser/Followers.php index 19a8e2d37c8..52a712ca99e 100644 --- a/lib/Github/Api/CurrentUser/Followers.php +++ b/lib/Github/Api/CurrentUser/Followers.php @@ -6,6 +6,7 @@ /** * @link http://developer.github.com/v3/users/followers/ + * * @author Joseph Bielawski */ class Followers extends AbstractApi @@ -21,9 +22,9 @@ class Followers extends AbstractApi */ public function all($page = 1) { - return $this->get('/user/following', array( - 'page' => $page - )); + return $this->get('/user/following', [ + 'page' => $page, + ]); } /** diff --git a/lib/Github/Api/CurrentUser/Memberships.php b/lib/Github/Api/CurrentUser/Memberships.php index df87596c38a..da727397407 100644 --- a/lib/Github/Api/CurrentUser/Memberships.php +++ b/lib/Github/Api/CurrentUser/Memberships.php @@ -33,7 +33,7 @@ public function organization($organization) } /** - * Edit your organization membership + * Edit your organization membership. * * @link https://developer.github.com/v3/orgs/members/#edit-your-organization-membership * @@ -43,6 +43,6 @@ public function organization($organization) */ public function edit($organization) { - return $this->patch('/user/memberships/orgs/'.rawurlencode($organization), array('state' => 'active')); + return $this->patch('/user/memberships/orgs/'.rawurlencode($organization), ['state' => 'active']); } } diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index 0e9f4c2d278..36dfb57ef8f 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -6,6 +6,7 @@ /** * @link http://developer.github.com/v3/activity/notifications/ + * * @author Joseph Bielawski */ class Notifications extends AbstractApi @@ -19,7 +20,7 @@ class Notifications extends AbstractApi * * @return array */ - public function all(array $params = array()) + public function all(array $params = []) { return $this->get('/notifications', $params); } @@ -35,7 +36,7 @@ public function all(array $params = array()) * * @return array */ - public function allInRepository($username, $repository, array $params = array()) + public function allInRepository($username, $repository, array $params = []) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); } @@ -49,7 +50,7 @@ public function allInRepository($username, $repository, array $params = array()) * * @return array */ - public function markAsReadAll(array $params = array()) + public function markAsReadAll(array $params = []) { return $this->put('/notifications', $params); } @@ -65,7 +66,7 @@ public function markAsReadAll(array $params = array()) * * @return array */ - public function markAsReadInRepository($username, $repository, array $params = array()) + public function markAsReadInRepository($username, $repository, array $params = []) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/notifications', $params); } diff --git a/lib/Github/Api/CurrentUser/PublicKeys.php b/lib/Github/Api/CurrentUser/PublicKeys.php index a09a08305ac..706e14051ba 100644 --- a/lib/Github/Api/CurrentUser/PublicKeys.php +++ b/lib/Github/Api/CurrentUser/PublicKeys.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/users/keys/ + * * @author Joseph Bielawski */ class PublicKeys extends AbstractApi @@ -51,7 +52,7 @@ public function show($id) public function create(array $params) { if (!isset($params['title'], $params['key'])) { - throw new MissingArgumentException(array('title', 'key')); + throw new MissingArgumentException(['title', 'key']); } return $this->post('/user/keys', $params); diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index 39de729fe99..d823c0bf0f1 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -23,10 +23,10 @@ class Starring extends AbstractApi */ public function all($page = 1, $perPage = 30) { - return $this->get('/user/starred', array( + return $this->get('/user/starred', [ 'page' => $page, 'per_page' => $perPage, - )); + ]); } /** diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index a5a6d9b46f0..1ef35972c3f 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -6,6 +6,7 @@ /** * @link https://developer.github.com/v3/activity/watching/ + * * @author Joseph Bielawski * @revised Felipe Valtl de Mello */ @@ -22,9 +23,9 @@ class Watchers extends AbstractApi */ public function all($page = 1) { - return $this->get('/user/subscriptions', array( - 'page' => $page - )); + return $this->get('/user/subscriptions', [ + 'page' => $page, + ]); } /** diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index e7d4c95b5e2..a6e9bacd755 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -12,15 +12,17 @@ class Deployment extends AbstractApi { /** - * List deployments for a particular repository + * List deployments for a particular repository. + * * @link https://developer.github.com/v3/repos/deployments/#list-deployments * - * @param string $username the username of the user who owns the repository - * @param string $repository the name of the repository - * @param array $params query parameters to filter deployments by (see link) - * @return array the deployments requested + * @param string $username the username of the user who owns the repository + * @param string $repository the name of the repository + * @param array $params query parameters to filter deployments by (see link) + * + * @return array the deployments requested */ - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } @@ -41,22 +43,24 @@ public function show($username, $repository, $id) /** * Create a new deployment for the given username and repo. + * * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment * * Important: Once a deployment is created, it cannot be updated. Changes are indicated by creating new statuses. * @see updateStatus * - * @param string $username the username - * @param string $repository the repository - * @param array $params the new deployment data - * @return array information about the deployment + * @param string $username the username + * @param string $repository the repository + * @param array $params the new deployment data * * @throws MissingArgumentException + * + * @return array information about the deployment */ public function create($username, $repository, array $params) { if (!isset($params['ref'])) { - throw new MissingArgumentException(array('ref')); + throw new MissingArgumentException(['ref']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); @@ -64,22 +68,24 @@ public function create($username, $repository, array $params) /** * Updates a deployment by creating a new status update. + * * @link https://developer.github.com/v3/repos/deployments/#create-a-deployment-status * - * @param string $username the username + * @param string $username the username * @param string $repository the repository - * @param int $id the deployment number - * @param array $params The information about the deployment update. - * Must include a "state" field of pending, success, error, or failure. - * May also be given a target_url and description, ßee link for more details. - * @return array information about the deployment + * @param int $id the deployment number + * @param array $params The information about the deployment update. + * Must include a "state" field of pending, success, error, or failure. + * May also be given a target_url and description, ßee link for more details. * * @throws MissingArgumentException + * + * @return array information about the deployment */ public function updateStatus($username, $repository, $id, array $params) { if (!isset($params['state'])) { - throw new MissingArgumentException(array('state')); + throw new MissingArgumentException(['state']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); @@ -88,9 +94,10 @@ public function updateStatus($username, $repository, $id, array $params) /** * Gets all of the status updates tied to a given deployment. * - * @param string $username the username - * @param string $repository the repository - * @param int $id the deployment identifier + * @param string $username the username + * @param string $repository the repository + * @param int $id the deployment identifier + * * @return array the deployment statuses */ public function getStatuses($username, $repository, $id) diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index c23171a6614..3dbbee3ea2b 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -2,15 +2,16 @@ namespace Github\Api; +use Github\Api\Enterprise\License; use Github\Api\Enterprise\ManagementConsole; use Github\Api\Enterprise\Stats; -use Github\Api\Enterprise\License; use Github\Api\Enterprise\UserAdmin; /** * Getting information about a GitHub Enterprise instance. * * @link https://developer.github.com/v3/enterprise/ + * * @author Joseph Bielawski * @author Guillermo A. Fisher */ diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index bc25e53466f..f11c47643eb 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -72,6 +72,6 @@ public function keys($hash) */ protected function getWithLicenseHash($uri, $hash) { - return $this->get($uri, array('license_md5' => rawurlencode($hash))); + return $this->get($uri, ['license_md5' => rawurlencode($hash)]); } } diff --git a/lib/Github/Api/Enterprise/Stats.php b/lib/Github/Api/Enterprise/Stats.php index 7d3b1953892..78ba42565e9 100644 --- a/lib/Github/Api/Enterprise/Stats.php +++ b/lib/Github/Api/Enterprise/Stats.php @@ -123,6 +123,6 @@ public function all() */ public function show($type) { - return $this->get('/enterprise/stats/' . rawurlencode($type)); + return $this->get('/enterprise/stats/'.rawurlencode($type)); } } diff --git a/lib/Github/Api/Enterprise/UserAdmin.php b/lib/Github/Api/Enterprise/UserAdmin.php index 8f6ad10d91a..0cd55a38c53 100644 --- a/lib/Github/Api/Enterprise/UserAdmin.php +++ b/lib/Github/Api/Enterprise/UserAdmin.php @@ -17,7 +17,7 @@ class UserAdmin extends AbstractApi */ public function suspend($username) { - return $this->put('/users/'.rawurldecode($username).'/suspended', array('Content-Length' => 0)); + return $this->put('/users/'.rawurldecode($username).'/suspended', ['Content-Length' => 0]); } /** diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index e77428c1a53..0e022622ed8 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -7,6 +7,7 @@ /** * @link https://developer.github.com/v3/gists/comments/ + * * @author Kayla Daniels */ class Comments extends AbstractApi @@ -17,13 +18,14 @@ class Comments extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/gists/comments/#custom-media-types + * * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - if (!in_array($bodyType, array('text', 'html', 'full'))) { + if (!in_array($bodyType, ['text', 'html', 'full'])) { $bodyType = 'raw'; } @@ -67,7 +69,7 @@ public function show($gist, $comment) */ public function create($gist, $body) { - return $this->post('/gists/'.rawurlencode($gist).'/comments', array('body' => $body)); + return $this->post('/gists/'.rawurlencode($gist).'/comments', ['body' => $body]); } /** @@ -81,7 +83,7 @@ public function create($gist, $body) */ public function update($gist, $comment_id, $body) { - return $this->patch('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), array('body' => $body)); + return $this->patch('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), ['body' => $body]); } /** diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index c661dfebbc2..e6bdc430640 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -2,13 +2,14 @@ namespace Github\Api; -use Github\Exception\MissingArgumentException; use Github\Api\Gist\Comments; +use Github\Exception\MissingArgumentException; /** * Creating, editing, deleting and listing gists. * * @link http://developer.github.com/v3/gists/ + * * @author Joseph Bielawski * @author Edoardo Rivello */ @@ -20,13 +21,14 @@ class Gists extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/gists/#custom-media-types + * * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - if (!in_array($bodyType, array('base64'))) { + if (!in_array($bodyType, ['base64'])) { $bodyType = 'raw'; } @@ -37,7 +39,7 @@ public function configure($bodyType = null) public function all($type = null) { - if (!in_array($type, array('public', 'starred'))) { + if (!in_array($type, ['public', 'starred'])) { return $this->get('/gists'); } diff --git a/lib/Github/Api/GitData.php b/lib/Github/Api/GitData.php index 21395a8ba7a..d431b788704 100644 --- a/lib/Github/Api/GitData.php +++ b/lib/Github/Api/GitData.php @@ -12,6 +12,7 @@ * Getting full versions of specific files and trees in your Git repositories. * * @link http://developer.github.com/v3/git/ + * * @author Joseph Bielawski */ class GitData extends AbstractApi diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index 0cc980fef14..be68771d9bd 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -8,6 +8,7 @@ /** * @link http://developer.github.com/v3/git/blobs/ + * * @author Joseph Bielawski * @author Tobias Nyholm */ @@ -54,14 +55,14 @@ public function show($username, $repository, $sha) * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { if (!isset($params['content'], $params['encoding'])) { - throw new MissingArgumentException(array('content', 'encoding')); + throw new MissingArgumentException(['content', 'encoding']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs', $params); diff --git a/lib/Github/Api/GitData/Commits.php b/lib/Github/Api/GitData/Commits.php index e8d1bfe9d30..4205931f408 100644 --- a/lib/Github/Api/GitData/Commits.php +++ b/lib/Github/Api/GitData/Commits.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/git/commits/ + * * @author Joseph Bielawski */ class Commits extends AbstractApi @@ -32,14 +33,14 @@ public function show($username, $repository, $sha) * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { if (!isset($params['message'], $params['tree'], $params['parents'])) { - throw new MissingArgumentException(array('message', 'tree', 'parents')); + throw new MissingArgumentException(['message', 'tree', 'parents']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/commits', $params); diff --git a/lib/Github/Api/GitData/References.php b/lib/Github/Api/GitData/References.php index 906a6ffc117..c54c0c8aad0 100644 --- a/lib/Github/Api/GitData/References.php +++ b/lib/Github/Api/GitData/References.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/git/references/ + * * @author Joseph Bielawski */ class References extends AbstractApi @@ -73,14 +74,14 @@ public function show($username, $repository, $reference) * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { if (!isset($params['ref'], $params['sha'])) { - throw new MissingArgumentException(array('ref', 'sha')); + throw new MissingArgumentException(['ref', 'sha']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs', $params); @@ -94,9 +95,9 @@ public function create($username, $repository, array $params) * @param string $reference * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function update($username, $repository, $reference, array $params) { diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index d1caefe91f1..09f48bc0a80 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/git/tags/ + * * @author Joseph Bielawski */ class Tags extends AbstractApi @@ -45,14 +46,14 @@ public function show($username, $repository, $sha) * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { if (!isset($params['tag'], $params['message'], $params['object'], $params['type'])) { - throw new MissingArgumentException(array('tag', 'message', 'object', 'type')); + throw new MissingArgumentException(['tag', 'message', 'object', 'type']); } if (!isset($params['tagger'])) { @@ -60,7 +61,7 @@ public function create($username, $repository, array $params) } if (!isset($params['tagger']['name'], $params['tagger']['email'], $params['tagger']['date'])) { - throw new MissingArgumentException(array('tagger.name', 'tagger.email', 'tagger.date')); + throw new MissingArgumentException(['tagger.name', 'tagger.email', 'tagger.date']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/tags', $params); diff --git a/lib/Github/Api/GitData/Trees.php b/lib/Github/Api/GitData/Trees.php index 80885682232..d514d9f8205 100644 --- a/lib/Github/Api/GitData/Trees.php +++ b/lib/Github/Api/GitData/Trees.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/git/trees/ + * * @author Joseph Bielawski */ class Trees extends AbstractApi @@ -23,7 +24,7 @@ class Trees extends AbstractApi */ public function show($username, $repository, $sha, $recursive = false) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), $recursive ? array('recursive' => 1) : array()); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/trees/'.rawurlencode($sha), $recursive ? ['recursive' => 1] : []); } /** @@ -33,9 +34,9 @@ public function show($username, $repository, $sha, $recursive = false) * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { @@ -44,12 +45,12 @@ public function create($username, $repository, array $params) } if (!isset($params['tree'][0])) { - $params['tree'] = array($params['tree']); + $params['tree'] = [$params['tree']]; } foreach ($params['tree'] as $key => $tree) { if (!isset($tree['path'], $tree['mode'], $tree['type'])) { - throw new MissingArgumentException(array("tree.$key.path", "tree.$key.mode", "tree.$key.type")); + throw new MissingArgumentException(["tree.$key.path", "tree.$key.mode", "tree.$key.type"]); } // If `sha` is not set, `content` is required diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index eee542f3ad5..9d66b5123fb 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -8,38 +8,39 @@ * Part of the Github v4 API * * @link https://developer.github.com/v4/ + * * @author Miguel Piedrafita */ class GraphQL extends AbstractApi { use AcceptHeaderTrait; - + /** * @param string $query - * @param array $variables + * @param array $variables * * @return array */ - public function execute($query, array $variables = array()) + public function execute($query, array $variables = []) { $this->acceptHeaderValue = 'application/vnd.github.v4+json'; - $params = array( - 'query' => $query - ); + $params = [ + 'query' => $query, + ]; if (!empty($variables)) { $params['variables'] = json_encode($variables); } return $this->post('/graphql', $params); } - + /** * @param string $file - * @param array $variables + * @param array $variables * * @return array */ - public function fromFile($file, array $variables = array()) + public function fromFile($file, array $variables = []) { return $this->execute(file_get_contents($file), $variables); } diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php index ef6ed557d82..bd4f78a4f07 100644 --- a/lib/Github/Api/Integrations.php +++ b/lib/Github/Api/Integrations.php @@ -7,6 +7,7 @@ /** * @deprecated Use the Apps class * @link https://developer.github.com/v3/apps/ + * * @author Nils Adermann */ class Integrations extends Apps @@ -14,7 +15,6 @@ class Integrations extends Apps /** * @deprecated * Configure the accept header for Early Access to the integrations api (DEPRECATED) - * * @see https://developer.github.com/v3/apps/ * * @return self diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index f77d4e4a22d..9b7d1d043ed 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -26,13 +26,14 @@ class Issue extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/issues/#custom-media-types + * * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - if (!in_array($bodyType, array('text', 'html', 'full'))) { + if (!in_array($bodyType, ['text', 'html', 'full'])) { $bodyType = 'raw'; } @@ -52,16 +53,15 @@ public function configure($bodyType = null) * * @return array list of issues found */ - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(array('page' => 1), $params)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(['page' => 1], $params)); } /** * Search issues by username, repo, state and keyword. * * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * * @link http://developer.github.com/v3/search/#search-issues * * @param string $username the username @@ -73,7 +73,7 @@ public function all($username, $repository, array $params = array()) */ public function find($username, $repository, $state, $keyword) { - if (!in_array($state, array('open', 'closed'))) { + if (!in_array($state, ['open', 'closed'])) { $state = 'open'; } @@ -91,13 +91,13 @@ public function find($username, $repository, $state, $keyword) * * @return array list of issues found */ - public function org($organization, $state, array $params = array()) + public function org($organization, $state, array $params = []) { - if (!in_array($state, array('open', 'closed'))) { + if (!in_array($state, ['open', 'closed'])) { $state = 'open'; } - return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => 1, 'state' => $state), $params)); + return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => 1, 'state' => $state], $params)); } /** @@ -133,7 +133,7 @@ public function show($username, $repository, $id) public function create($username, $repository, array $params) { if (!isset($params['title'])) { - throw new MissingArgumentException(array('title')); + throw new MissingArgumentException(['title']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', $params); diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php index f304f7ab05a..31d6ac9d999 100644 --- a/lib/Github/Api/Issue/Assignees.php +++ b/lib/Github/Api/Issue/Assignees.php @@ -16,7 +16,7 @@ class Assignees extends AbstractApi * * @return array */ - public function listAvailable($username, $repository, array $parameters = array()) + public function listAvailable($username, $repository, array $parameters = []) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees', $parameters); } @@ -34,11 +34,11 @@ public function listAvailable($username, $repository, array $parameters = array( */ public function check($username, $repository, $assignee) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees/' . rawurlencode($assignee)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees/'.rawurlencode($assignee)); } /** - * Add assignees to an Issue + * Add assignees to an Issue. * * @link https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue * @@ -47,8 +47,9 @@ public function check($username, $repository, $assignee) * @param string $issue * @param array $parameters * - * @return string * @throws MissingArgumentException + * + * @return string */ public function add($username, $repository, $issue, array $parameters) { @@ -60,7 +61,7 @@ public function add($username, $repository, $issue, array $parameters) } /** - * Remove assignees from an Issue + * Remove assignees from an Issue. * * @link https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue * @@ -69,8 +70,9 @@ public function add($username, $repository, $issue, array $parameters) * @param string $issue * @param array $parameters * - * @return string * @throws MissingArgumentException + * + * @return string */ public function remove($username, $repository, $issue, array $parameters) { diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index c860c74d64e..a664d533274 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -8,6 +8,7 @@ /** * @link http://developer.github.com/v3/issues/comments/ + * * @author Joseph Bielawski * @author Tobias Nyholm */ @@ -19,13 +20,14 @@ class Comments extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/issues/comments/#custom-media-types + * * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - if (!in_array($bodyType, array('raw', 'text', 'html'))) { + if (!in_array($bodyType, ['raw', 'text', 'html'])) { $bodyType = 'full'; } @@ -38,6 +40,7 @@ public function configure($bodyType = null) * Get all comments for an issue. * * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + * * @param string $username * @param string $repository * @param int $issue @@ -47,15 +50,16 @@ public function configure($bodyType = null) */ public function all($username, $repository, $issue, $page = 1) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array( - 'page' => $page - )); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', [ + 'page' => $page, + ]); } /** * Get a comment for an issue. * * @link https://developer.github.com/v3/issues/comments/#get-a-single-comment + * * @param string $username * @param string $repository * @param int $comment @@ -71,12 +75,14 @@ public function show($username, $repository, $comment) * Create a comment for an issue. * * @link https://developer.github.com/v3/issues/comments/#create-a-comment + * * @param string $username * @param string $repository * @param int $issue * @param array $params * * @throws \Github\Exception\MissingArgumentException + * * @return array */ public function create($username, $repository, $issue, array $params) @@ -92,12 +98,14 @@ public function create($username, $repository, $issue, array $params) * Update a comment for an issue. * * @link https://developer.github.com/v3/issues/comments/#edit-a-comment + * * @param string $username * @param string $repository * @param int $comment * @param array $params * * @throws \Github\Exception\MissingArgumentException + * * @return array */ public function update($username, $repository, $comment, array $params) @@ -113,6 +121,7 @@ public function update($username, $repository, $comment, array $params) * Delete a comment for an issue. * * @link https://developer.github.com/v3/issues/comments/#delete-a-comment + * * @param string $username * @param string $repository * @param int $comment diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index adfcde83e5e..8b70ec79e09 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -6,6 +6,7 @@ /** * @link http://developer.github.com/v3/issues/events/ + * * @author Joseph Bielawski */ class Events extends AbstractApi @@ -14,10 +15,12 @@ class Events extends AbstractApi * Get all events for an issue. * * @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue + * * @param string $username * @param string $repository * @param int|null $issue * @param int $page + * * @return array */ public function all($username, $repository, $issue = null, $page = 1) @@ -28,18 +31,20 @@ public function all($username, $repository, $issue = null, $page = 1) $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events'; } - return $this->get($path, array( - 'page' => $page - )); + return $this->get($path, [ + 'page' => $page, + ]); } /** * Display an event for an issue. * * @link https://developer.github.com/v3/issues/events/#get-a-single-event + * * @param $username * @param $repository * @param $event + * * @return array */ public function show($username, $repository, $event) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index fb0f52362e3..1159e153ff0 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -8,6 +8,7 @@ /** * @link http://developer.github.com/v3/issues/labels/ + * * @author Joseph Bielawski */ class Labels extends AbstractApi @@ -16,6 +17,7 @@ class Labels extends AbstractApi * Get all labels for a repository or the labels for a specific issue. * * @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue + * * @param string $username * @param string $repository * @param int|null $issue @@ -53,13 +55,14 @@ public function show($username, $repository, $label) * Create a label for a repository. * * @link https://developer.github.com/v3/issues/labels/#create-a-label + * * @param string $username * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { @@ -77,6 +80,7 @@ public function create($username, $repository, array $params) * Delete a label for a repository. * * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue + * * @param string $username * @param string $repository * @param string $label @@ -89,9 +93,10 @@ public function deleteLabel($username, $repository, $label) } /** - * Edit a label for a repository + * Edit a label for a repository. * * @link https://developer.github.com/v3/issues/labels/#update-a-label + * * @param string $username * @param string $repository * @param string $label @@ -102,10 +107,10 @@ public function deleteLabel($username, $repository, $label) */ public function update($username, $repository, $label, $newName, $color) { - $params = array( + $params = [ 'name' => $newName, 'color' => $color, - ); + ]; return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); } @@ -114,6 +119,7 @@ public function update($username, $repository, $label, $newName, $color) * Add a label to an issue. * * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue + * * @param string $username * @param string $repository * @param int $issue @@ -126,7 +132,7 @@ public function update($username, $repository, $label, $newName, $color) public function add($username, $repository, $issue, $labels) { if (is_string($labels)) { - $labels = array($labels); + $labels = [$labels]; } elseif (0 === count($labels)) { throw new InvalidArgumentException(); } @@ -138,6 +144,7 @@ public function add($username, $repository, $issue, $labels) * Replace labels for an issue. * * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue + * * @param string $username * @param string $repository * @param int $issue @@ -151,9 +158,10 @@ public function replace($username, $repository, $issue, array $params) } /** - * Remove a label for an issue + * Remove a label for an issue. * * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue + * * @param string $username * @param string $repository * @param string $issue @@ -170,6 +178,7 @@ public function remove($username, $repository, $issue, $label) * Remove all labels from an issue. * * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue + * * @param string $username * @param string $repository * @param string $issue diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index c7ac0f4bd3f..11f0e94c6b1 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/issues/milestones/ + * * @author Joseph Bielawski */ class Milestones extends AbstractApi @@ -15,36 +16,38 @@ class Milestones extends AbstractApi * Get all milestones for a repository. * * @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository + * * @param string $username * @param string $repository * @param array $params * * @return array */ - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { - if (isset($params['state']) && !in_array($params['state'], array('open', 'closed', 'all'))) { + if (isset($params['state']) && !in_array($params['state'], ['open', 'closed', 'all'])) { $params['state'] = 'open'; } - if (isset($params['sort']) && !in_array($params['sort'], array('due_date', 'completeness'))) { + if (isset($params['sort']) && !in_array($params['sort'], ['due_date', 'completeness'])) { $params['sort'] = 'due_date'; } - if (isset($params['direction']) && !in_array($params['direction'], array('asc', 'desc'))) { + if (isset($params['direction']) && !in_array($params['direction'], ['asc', 'desc'])) { $params['direction'] = 'asc'; } - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array( + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge([ 'page' => 1, 'state' => 'open', 'sort' => 'due_date', - 'direction' => 'asc' - ), $params)); + 'direction' => 'asc', + ], $params)); } /** * Get a milestone for a repository. * * @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone + * * @param string $username * @param string $repository * @param int $id @@ -60,20 +63,21 @@ public function show($username, $repository, $id) * Create a milestone for a repository. * * @link https://developer.github.com/v3/issues/milestones/#create-a-milestone + * * @param string $username * @param string $repository * @param array $params * - * @return array - * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($username, $repository, array $params) { if (!isset($params['title'])) { throw new MissingArgumentException('title'); } - if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { + if (isset($params['state']) && !in_array($params['state'], ['open', 'closed'])) { $params['state'] = 'open'; } @@ -84,6 +88,7 @@ public function create($username, $repository, array $params) * Update a milestone for a repository. * * @link https://developer.github.com/v3/issues/milestones/#update-a-milestone + * * @param string $username * @param string $repository * @param int $id @@ -93,7 +98,7 @@ public function create($username, $repository, array $params) */ public function update($username, $repository, $id, array $params) { - if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { + if (isset($params['state']) && !in_array($params['state'], ['open', 'closed'])) { $params['state'] = 'open'; } @@ -104,6 +109,7 @@ public function update($username, $repository, $id, array $params) * Delete a milestone for a repository. * * @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone + * * @param string $username * @param string $repository * @param int $id @@ -116,9 +122,10 @@ public function remove($username, $repository, $id) } /** - * Get the labels of a milestone + * Get the labels of a milestone. * * @link https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone + * * @param string $username * @param string $repository * @param int $id diff --git a/lib/Github/Api/Issue/Timeline.php b/lib/Github/Api/Issue/Timeline.php index 1a076641024..c0f76f2f761 100644 --- a/lib/Github/Api/Issue/Timeline.php +++ b/lib/Github/Api/Issue/Timeline.php @@ -20,6 +20,7 @@ public function configure() * Get all events for a specific issue. * * @link https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue + * * @param string $username * @param string $repository * @param int $issue diff --git a/lib/Github/Api/Markdown.php b/lib/Github/Api/Markdown.php index 82d2ac55b6c..977b1d048e0 100644 --- a/lib/Github/Api/Markdown.php +++ b/lib/Github/Api/Markdown.php @@ -6,6 +6,7 @@ * Markdown Rendering API. * * @link http://developer.github.com/v3/markdown/ + * * @author Joseph Bielawski */ class Markdown extends AbstractApi @@ -19,14 +20,14 @@ class Markdown extends AbstractApi */ public function render($text, $mode = 'markdown', $context = null) { - if (!in_array($mode, array('gfm', 'markdown'))) { + if (!in_array($mode, ['gfm', 'markdown'])) { $mode = 'markdown'; } - $params = array( + $params = [ 'text' => $text, - 'mode' => $mode - ); + 'mode' => $mode, + ]; if (null !== $context && 'gfm' === $mode) { $params['context'] = $context; } @@ -41,8 +42,8 @@ public function render($text, $mode = 'markdown', $context = null) */ public function renderRaw($file) { - return $this->post('/markdown/raw', array( - 'file' => $file - )); + return $this->post('/markdown/raw', [ + 'file' => $file, + ]); } } diff --git a/lib/Github/Api/Meta.php b/lib/Github/Api/Meta.php index 076b3dc501e..0ec81f65ef9 100644 --- a/lib/Github/Api/Meta.php +++ b/lib/Github/Api/Meta.php @@ -6,6 +6,7 @@ * Getting GitHub service information. * * @link https://developer.github.com/v3/meta/ + * * @author Claude Dioudonnat */ class Meta extends AbstractApi diff --git a/lib/Github/Api/Miscellaneous/CodeOfConduct.php b/lib/Github/Api/Miscellaneous/CodeOfConduct.php index 7d3c69ff469..64bfaa8b420 100644 --- a/lib/Github/Api/Miscellaneous/CodeOfConduct.php +++ b/lib/Github/Api/Miscellaneous/CodeOfConduct.php @@ -29,7 +29,7 @@ public function all() } /** - * Get an individual code of conduct + * Get an individual code of conduct. * * @link https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct * @@ -39,6 +39,6 @@ public function all() */ public function show($key) { - return $this->get('/codes_of_conduct/' . rawurlencode($key)); + return $this->get('/codes_of_conduct/'.rawurlencode($key)); } } diff --git a/lib/Github/Api/Miscellaneous/Gitignore.php b/lib/Github/Api/Miscellaneous/Gitignore.php index c7306110ee5..c5f03e7e0e0 100644 --- a/lib/Github/Api/Miscellaneous/Gitignore.php +++ b/lib/Github/Api/Miscellaneous/Gitignore.php @@ -29,6 +29,6 @@ public function all() */ public function show($template) { - return $this->get('/gitignore/templates/' . rawurlencode($template)); + return $this->get('/gitignore/templates/'.rawurlencode($template)); } } diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index e8d5d8f7810..fbaed083518 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -10,6 +10,7 @@ * Important! You have to be authenticated to perform these methods * * @link https://developer.github.com/v3/activity/notifications/ + * * @author Dennis de Greef */ class Notification extends AbstractApi @@ -27,10 +28,10 @@ class Notification extends AbstractApi */ public function all($includingRead = false, $participating = false, DateTime $since = null) { - $parameters = array( + $parameters = [ 'all' => $includingRead, - 'participating' => $participating - ); + 'participating' => $participating, + ]; if ($since !== null) { $parameters['since'] = $since->format(DateTime::ISO8601); @@ -49,7 +50,7 @@ public function all($includingRead = false, $participating = false, DateTime $si */ public function markRead(DateTime $since = null) { - $parameters = array(); + $parameters = []; if ($since !== null) { $parameters['last_read_at'] = $since->format(DateTime::ISO8601); @@ -57,8 +58,9 @@ public function markRead(DateTime $since = null) $this->put('/notifications', $parameters); } + /** - * Gets a single notification using his ID + * Gets a single notification using his ID. * * @link https://developer.github.com/v3/activity/notifications/#view-a-single-thread * diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 077211a4987..49ca5c91f03 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -10,6 +10,7 @@ * Getting organization information and managing authenticated organization account information. * * @link http://developer.github.com/v3/orgs/ + * * @author Antoine Berranger * @author Joseph Bielawski */ @@ -57,10 +58,10 @@ public function update($organization, array $params) */ public function repositories($organization, $type = 'all', $page = 1) { - return $this->get('/orgs/'.rawurlencode($organization).'/repos', array( + return $this->get('/orgs/'.rawurlencode($organization).'/repos', [ 'type' => $type, 'page' => $page, - )); + ]); } /** @@ -92,12 +93,12 @@ public function teams() * * @param $organization * @param array $params - * @param int $page + * @param int $page * * @return array */ - public function issues($organization, array $params = array(), $page = 1) + public function issues($organization, array $params = [], $page = 1) { - return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(array('page' => $page), $params)); + return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => $page], $params)); } } diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index e137dee1ab7..b68a43bc3a6 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -11,7 +11,9 @@ class Hooks extends AbstractApi * List hooks. * * @link https://developer.github.com/v3/orgs/hooks/#list-hooks + * * @param string $organization + * * @return array */ public function all($organization) @@ -21,10 +23,12 @@ public function all($organization) /** * Get a single hook. + * * @link https://developer.github.com/v3/orgs/hooks/#get-single-hook * * @param string $organization * @param int $id + * * @return array */ public function show($organization, $id) @@ -36,15 +40,18 @@ public function show($organization, $id) * Create a hook. * * @link https://developer.github.com/v3/orgs/hooks/#create-a-hook + * * @param string $organization * @param array $params - * @return array + * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function create($organization, array $params) { if (!isset($params['name'], $params['config'])) { - throw new MissingArgumentException(array('name', 'config')); + throw new MissingArgumentException(['name', 'config']); } return $this->post('/orgs/'.rawurlencode($organization).'/hooks', $params); @@ -54,16 +61,19 @@ public function create($organization, array $params) * Edit a hook. * * @link https://developer.github.com/v3/orgs/hooks/#edit-a-hook + * * @param string $organization * @param int $id * @param array $params - * @return array + * * @throws \Github\Exception\MissingArgumentException + * + * @return array */ public function update($organization, $id, array $params) { if (!isset($params['config'])) { - throw new MissingArgumentException(array('config')); + throw new MissingArgumentException(['config']); } return $this->patch('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id), $params); @@ -73,8 +83,10 @@ public function update($organization, $id, array $params) * Ping a hook. * * @link https://developer.github.com/v3/orgs/hooks/#ping-a-hook + * * @param string $organization * @param int $id + * * @return null */ public function ping($organization, $id) @@ -86,8 +98,10 @@ public function ping($organization, $id) * Delete a hook. * * @link https://developer.github.com/v3/orgs/hooks/#delete-a-hook + * * @param string $organization * @param int $id + * * @return null */ public function remove($organization, $id) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 13bda339eb2..3639e3ba57d 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -6,13 +6,14 @@ /** * @link http://developer.github.com/v3/orgs/members/ + * * @author Joseph Bielawski */ class Members extends AbstractApi { public function all($organization, $type = null, $filter = 'all', $role = null) { - $parameters = array(); + $parameters = []; $path = '/orgs/'.rawurlencode($organization).'/'; if (null === $type) { $path .= 'members'; diff --git a/lib/Github/Api/Organization/Projects.php b/lib/Github/Api/Organization/Projects.php index dcff9c86c98..2bb7196e95a 100644 --- a/lib/Github/Api/Organization/Projects.php +++ b/lib/Github/Api/Organization/Projects.php @@ -7,15 +7,15 @@ class Projects extends AbstractProjectApi { - public function all($organization, array $params = array()) + public function all($organization, array $params = []) { - return $this->get('/orgs/'.rawurlencode($organization).'/projects', array_merge(array('page' => 1), $params)); + return $this->get('/orgs/'.rawurlencode($organization).'/projects', array_merge(['page' => 1], $params)); } public function create($organization, array $params) { if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); + throw new MissingArgumentException(['name']); } return $this->post('/orgs/'.rawurlencode($organization).'/projects', $params); diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index b6b0b72eb5e..401dbe4f116 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/orgs/teams/ + * * @author Joseph Bielawski */ class Teams extends AbstractApi @@ -22,9 +23,9 @@ public function create($organization, array $params) throw new MissingArgumentException('name'); } if (isset($params['repo_names']) && !is_array($params['repo_names'])) { - $params['repo_names'] = array($params['repo_names']); + $params['repo_names'] = [$params['repo_names']]; } - if (isset($params['permission']) && !in_array($params['permission'], array('pull', 'push', 'admin'))) { + if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) { $params['permission'] = 'pull'; } @@ -41,7 +42,7 @@ public function update($team, array $params) if (!isset($params['name'])) { throw new MissingArgumentException('name'); } - if (isset($params['permission']) && !in_array($params['permission'], array('pull', 'push', 'admin'))) { + if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) { $params['permission'] = 'pull'; } @@ -83,9 +84,9 @@ public function repository($team, $organization, $repository) return $this->get('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository)); } - public function addRepository($team, $organization, $repository, $params = array()) + public function addRepository($team, $organization, $repository, $params = []) { - if (isset($params['permission']) && !in_array($params['permission'], array('pull', 'push', 'admin'))) { + if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) { $params['permission'] = 'pull'; } diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php index b64f1ca19b1..15274d7dbc4 100644 --- a/lib/Github/Api/Project/AbstractProjectApi.php +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -10,7 +10,7 @@ abstract class AbstractProjectApi extends AbstractApi use AcceptHeaderTrait; /** - * Configure the accept header for Early Access to the projects api + * Configure the accept header for Early Access to the projects api. * * @see https://developer.github.com/v3/repos/projects/#projects * @@ -23,9 +23,9 @@ public function configure() return $this; } - public function show($id, array $params = array()) + public function show($id, array $params = []) { - return $this->get('/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params)); + return $this->get('/projects/'.rawurlencode($id), array_merge(['page' => 1], $params)); } public function update($id, array $params) diff --git a/lib/Github/Api/Project/Cards.php b/lib/Github/Api/Project/Cards.php index 61eca191040..758e7708b08 100644 --- a/lib/Github/Api/Project/Cards.php +++ b/lib/Github/Api/Project/Cards.php @@ -11,7 +11,7 @@ class Cards extends AbstractApi use AcceptHeaderTrait; /** - * Configure the accept header for Early Access to the projects api + * Configure the accept header for Early Access to the projects api. * * @see https://developer.github.com/v3/repos/projects/#projects * @@ -24,9 +24,9 @@ public function configure() return $this; } - public function all($columnId, array $params = array()) + public function all($columnId, array $params = []) { - return $this->get('/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params)); + return $this->get('/projects/columns/'.rawurlencode($columnId).'/cards', array_merge(['page' => 1], $params)); } public function show($id) @@ -36,12 +36,12 @@ public function show($id) public function create($columnId, array $params) { - return $this->post('/projects/columns/' . rawurlencode($columnId) . '/cards', $params); + return $this->post('/projects/columns/'.rawurlencode($columnId).'/cards', $params); } public function update($id, array $params) { - return $this->patch('/projects/columns/cards/' . rawurlencode($id), $params); + return $this->patch('/projects/columns/cards/'.rawurlencode($id), $params); } public function deleteCard($id) @@ -52,9 +52,9 @@ public function deleteCard($id) public function move($id, array $params) { if (!isset($params['position'])) { - throw new MissingArgumentException(array('position')); + throw new MissingArgumentException(['position']); } - return $this->post('/projects/columns/cards/' . rawurlencode($id) . '/moves', $params); + return $this->post('/projects/columns/cards/'.rawurlencode($id).'/moves', $params); } } diff --git a/lib/Github/Api/Project/Columns.php b/lib/Github/Api/Project/Columns.php index 76c555979bd..22e5cbafcb8 100644 --- a/lib/Github/Api/Project/Columns.php +++ b/lib/Github/Api/Project/Columns.php @@ -11,7 +11,7 @@ class Columns extends AbstractApi use AcceptHeaderTrait; /** - * Configure the accept header for Early Access to the projects api + * Configure the accept header for Early Access to the projects api. * * @see https://developer.github.com/v3/repos/projects/#projects * @@ -24,9 +24,9 @@ public function configure() return $this; } - public function all($projectId, array $params = array()) + public function all($projectId, array $params = []) { - return $this->get('/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params)); + return $this->get('/projects/'.rawurlencode($projectId).'/columns', array_merge(['page' => 1], $params)); } public function show($id) @@ -37,19 +37,19 @@ public function show($id) public function create($projectId, array $params) { if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); + throw new MissingArgumentException(['name']); } - return $this->post('/projects/' . rawurlencode($projectId) . '/columns', $params); + return $this->post('/projects/'.rawurlencode($projectId).'/columns', $params); } public function update($id, array $params) { if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); + throw new MissingArgumentException(['name']); } - return $this->patch('/projects/columns/' . rawurlencode($id), $params); + return $this->patch('/projects/columns/'.rawurlencode($id), $params); } public function deleteColumn($id) @@ -60,10 +60,10 @@ public function deleteColumn($id) public function move($id, array $params) { if (!isset($params['position'])) { - throw new MissingArgumentException(array('position')); + throw new MissingArgumentException(['position']); } - return $this->post('/projects/columns/' . rawurlencode($id) . '/moves', $params); + return $this->post('/projects/columns/'.rawurlencode($id).'/moves', $params); } public function cards() diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 89a48c7c9d3..933dd7b1a97 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -23,6 +23,7 @@ class PullRequest extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/pulls/#custom-media-types + * * @param string|null $bodyType * @param string|null $apiVersion * @@ -30,15 +31,15 @@ class PullRequest extends AbstractApi */ public function configure($bodyType = null, $apiVersion = null) { - if (!in_array($apiVersion, array())) { + if (!in_array($apiVersion, [])) { $apiVersion = $this->client->getApiVersion(); } - if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) { + if (!in_array($bodyType, ['text', 'html', 'full', 'diff', 'patch'])) { $bodyType = 'raw'; } - if (!in_array($bodyType, array('diff', 'patch'))) { + if (!in_array($bodyType, ['diff', 'patch'])) { $bodyType .= '+json'; } @@ -58,12 +59,12 @@ public function configure($bodyType = null, $apiVersion = null) * * @return array array of pull requests for the project */ - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { - $parameters = array_merge(array( + $parameters = array_merge([ 'page' => 1, 'per_page' => 30, - ), $params); + ], $params); return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } @@ -148,16 +149,16 @@ public function create($username, $repository, array $params) { // Two ways to create PR, using issue or title if (!isset($params['issue']) && !isset($params['title'])) { - throw new MissingArgumentException(array('issue', 'title')); + throw new MissingArgumentException(['issue', 'title']); } if (!isset($params['base'], $params['head'])) { - throw new MissingArgumentException(array('base', 'head')); + throw new MissingArgumentException(['base', 'head']); } // If `issue` is not sent, then `body` must be sent if (!isset($params['issue']) && !isset($params['body'])) { - throw new MissingArgumentException(array('issue', 'body')); + throw new MissingArgumentException(['issue', 'body']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params); @@ -165,7 +166,7 @@ public function create($username, $repository, array $params) public function update($username, $repository, $id, array $params) { - if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { + if (isset($params['state']) && !in_array($params['state'], ['open', 'closed'])) { $params['state'] = 'open'; } @@ -183,15 +184,15 @@ public function merge($username, $repository, $id, $message, $sha, $mergeMethod $mergeMethod = $mergeMethod ? 'squash' : 'merge'; } - if (!in_array($mergeMethod, array('merge', 'squash', 'rebase'), true)) { + if (!in_array($mergeMethod, ['merge', 'squash', 'rebase'], true)) { throw new InvalidArgumentException(sprintf('"$mergeMethod" must be one of ["merge", "squash", "rebase"] ("%s" given).', $mergeMethod)); } - $params = array( + $params = [ 'commit_message' => $message, 'sha' => $sha, 'merge_method' => $mergeMethod, - ); + ]; if (is_string($title)) { $params['commit_title'] = $title; diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 18679ca133e..183bfbe06ef 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -8,6 +8,7 @@ /** * @link http://developer.github.com/v3/pulls/comments/ + * * @author Joseph Bielawski */ class Comments extends AbstractApi @@ -18,6 +19,7 @@ class Comments extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/pulls/comments/#custom-media-types + * * @param string|null $bodyType * @param string|null @apiVersion * @@ -25,11 +27,11 @@ class Comments extends AbstractApi */ public function configure($bodyType = null, $apiVersion = null) { - if (!in_array($apiVersion, array('squirrel-girl-preview'))) { + if (!in_array($apiVersion, ['squirrel-girl-preview'])) { $apiVersion = $this->client->getApiVersion(); } - if (!in_array($bodyType, array('text', 'html', 'full'))) { + if (!in_array($bodyType, ['text', 'html', 'full'])) { $bodyType = 'raw'; } @@ -60,7 +62,7 @@ public function all($username, $repository, $pullRequest = null, array $params = $parameters = array_merge([ 'page' => 1, - 'per_page' => 30 + 'per_page' => 30, ], $params); return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments', $parameters); @@ -104,7 +106,7 @@ public function create($username, $repository, $pullRequest, array $params) // If `in_reply_to` is set, other options are not necessary anymore if (!isset($params['in_reply_to']) && !isset($params['commit_id'], $params['path'], $params['position'])) { - throw new MissingArgumentException(array('commit_id', 'path', 'position')); + throw new MissingArgumentException(['commit_id', 'path', 'position']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params); diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 83182ad3c76..04d5fb766ac 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -11,6 +11,7 @@ * API for accessing Pull Request Reviews from your Git/Github repositories. * * @link https://developer.github.com/v3/pulls/reviews/ + * * @author Christian Flothmann */ class Review extends AbstractApi @@ -38,7 +39,7 @@ public function all($username, $repository, $pullRequest, array $params = []) { $parameters = array_merge([ 'page' => 1, - 'per_page' => 30 + 'per_page' => 30, ], $params); return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $parameters); @@ -115,7 +116,7 @@ public function create($username, $repository, $pullRequest, array $params = []) throw new MissingArgumentException('event'); } - if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { + if (!in_array($params['event'], ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], true)) { throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); } @@ -143,7 +144,7 @@ public function submit($username, $repository, $pullRequest, $id, array $params throw new MissingArgumentException('event'); } - if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { + if (!in_array($params['event'], ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], true)) { throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); } @@ -159,7 +160,7 @@ public function submit($username, $repository, $pullRequest, $id, array $params * @param string $repository the repository * @param int $pullRequest the pull request number * @param int $id the review id - * @param string $message a mandatory dismissal message + * @param string $message a mandatory dismissal message * * @return array|string */ @@ -174,7 +175,7 @@ public function dismiss($username, $repository, $pullRequest, $id, $message) } return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals', [ - 'message' => $message + 'message' => $message, ]); } } diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index bfa42ae8288..ba5301dffd6 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -3,15 +3,16 @@ namespace Github\Api; /** - * Get rate limits + * Get rate limits. * * @link https://developer.github.com/v3/rate_limit/ + * * @author Jeff Finley */ class RateLimit extends AbstractApi { /** - * Get rate limits + * Get rate limits. * * @return array */ @@ -21,9 +22,9 @@ public function getRateLimits() } /** - * Get core rate limit + * Get core rate limit. * - * @return integer + * @return int */ public function getCoreLimit() { @@ -33,9 +34,9 @@ public function getCoreLimit() } /** - * Get search rate limit + * Get search rate limit. * - * @return integer + * @return int */ public function getSearchLimit() { diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b00f12ded48..cc2bc109972 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -8,12 +8,12 @@ use Github\Api\Repository\Contents; use Github\Api\Repository\DeployKeys; use Github\Api\Repository\Downloads; -use Github\Api\Repository\Projects; -use Github\Api\Repository\Protection; -use Github\Api\Repository\Releases; use Github\Api\Repository\Forks; use Github\Api\Repository\Hooks; use Github\Api\Repository\Labels; +use Github\Api\Repository\Projects; +use Github\Api\Repository\Protection; +use Github\Api\Repository\Releases; use Github\Api\Repository\Stargazers; use Github\Api\Repository\Statuses; use Github\Api\Repository\Traffic; @@ -23,6 +23,7 @@ * and managing repository information for authenticated users. * * @link http://developer.github.com/v3/repos/ + * * @author Joseph Bielawski * @author Thibault Duplessis */ @@ -34,7 +35,6 @@ class Repo extends AbstractApi * Search repositories by keyword. * * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * * @link http://developer.github.com/v3/search/#search-repositories * * @param string $keyword the search query @@ -42,9 +42,9 @@ class Repo extends AbstractApi * * @return array list of found repositories */ - public function find($keyword, array $params = array()) + public function find($keyword, array $params = []) { - return $this->get('/legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params)); + return $this->get('/legacy/repos/search/'.rawurlencode($keyword), array_merge(['start_page' => 1], $params)); } /** @@ -62,7 +62,7 @@ public function all($id = null) return $this->get('/repositories'); } - return $this->get('/repositories?since=' . rawurldecode($id)); + return $this->get('/repositories?since='.rawurldecode($id)); } /** @@ -135,9 +135,9 @@ public function participation($username, $repository) * * @return array list of organization repositories */ - public function org($organization, array $params = array()) + public function org($organization, array $params = []) { - return $this->get('/orgs/'.$organization.'/repos', array_merge(array('start_page' => 1), $params)); + return $this->get('/orgs/'.$organization.'/repos', array_merge(['start_page' => 1], $params)); } /** @@ -163,7 +163,7 @@ public function show($username, $repository) * @link https://github.com/piotrmurach/github/issues/283 * @link https://github.com/piotrmurach/github/issues/282 * - * @param int $id the id of the repository + * @param int $id the id of the repository * * @return array information about the repository */ @@ -204,7 +204,7 @@ public function create( ) { $path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos'; - $parameters = array( + $parameters = [ 'name' => $name, 'description' => $description, 'homepage' => $homepage, @@ -212,8 +212,8 @@ public function create( 'has_issues' => $hasIssues, 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, - 'auto_init' => $autoInit - ); + 'auto_init' => $autoInit, + ]; if ($organization && $teamId) { $parameters['team_id'] = $teamId; @@ -462,9 +462,9 @@ public function protection() */ public function contributors($username, $repository, $includingAnonymous = false) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', array( - 'anon' => $includingAnonymous ?: null - )); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contributors', [ + 'anon' => $includingAnonymous ?: null, + ]); } /** @@ -524,9 +524,9 @@ public function teams($username, $repository) */ public function watchers($username, $repository, $page = 1) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', array( - 'page' => $page - )); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', [ + 'page' => $page, + ]); } /** @@ -538,9 +538,9 @@ public function watchers($username, $repository, $page = 1) */ public function subscribers($username, $repository, $page = 1) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', array( - 'page' => $page - )); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/subscribers', [ + 'page' => $page, + ]); } /** @@ -558,10 +558,10 @@ public function subscribers($username, $repository, $page = 1) */ public function merge($username, $repository, $base, $head, $message = null) { - $parameters = array( + $parameters = [ 'base' => $base, 'head' => $head, - ); + ]; if (is_string($message)) { $parameters['commit_message'] = $message; @@ -573,6 +573,7 @@ public function merge($username, $repository, $base, $head, $message = null) /** * @param string $username * @param string $repository + * * @return array */ public function milestones($username, $repository) @@ -605,7 +606,7 @@ public function events($username, $repository, $page = 1) } /** - * Get the contents of a repository's code of conduct + * Get the contents of a repository's code of conduct. * * @link https://developer.github.com/v3/codes_of_conduct/#get-the-contents-of-a-repositorys-code-of-conduct * @@ -623,7 +624,7 @@ public function codeOfConduct($username, $repository) } /** - * List all topics for a repository + * List all topics for a repository. * * @link https://developer.github.com/v3/repos/#list-all-topics-for-a-repository * @@ -641,7 +642,7 @@ public function topics($username, $repository) } /** - * Replace all topics for a repository + * Replace all topics for a repository. * * @link https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository * diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 21b5a08cc5d..dbe6da2251a 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -8,6 +8,7 @@ /** * @link http://developer.github.com/v3/repos/releases/ + * * @author Evgeniy Guseletov */ class Assets extends AbstractApi @@ -73,7 +74,7 @@ public function create($username, $repository, $id, $name, $contentType, $conten // Asset creation requires a separate endpoint, uploads.github.com. // Change the base url for the HTTP client temporarily while we execute // this request. - $response = $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, array('Content-Type' => $contentType)); + $response = $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, ['Content-Type' => $contentType]); return $response; } diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index 86812be9538..b9467ed1949 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -6,6 +6,7 @@ /** * @link http://developer.github.com/v3/repos/collaborators/ + * * @author Joseph Bielawski */ class Collaborators extends AbstractApi @@ -16,6 +17,7 @@ class Collaborators extends AbstractApi * @param $username * @param $repository * @param array $params + * * @return array|string */ public function all($username, $repository, array $params = []) @@ -29,6 +31,7 @@ public function all($username, $repository, array $params = []) * @param $username * @param $repository * @param $collaborator + * * @return array|string */ public function check($username, $repository, $collaborator) @@ -43,6 +46,7 @@ public function check($username, $repository, $collaborator) * @param $repository * @param $collaborator * @param array $params + * * @return array|string */ public function add($username, $repository, $collaborator, array $params = []) @@ -56,6 +60,7 @@ public function add($username, $repository, $collaborator, array $params = []) * @param $username * @param $repository * @param $collaborator + * * @return array|string */ public function remove($username, $repository, $collaborator) diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index 4e993720296..53feb72cd31 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -8,6 +8,7 @@ /** * @link http://developer.github.com/v3/repos/comments/ + * * @author Joseph Bielawski * @author Tobias Nyholm */ @@ -19,13 +20,14 @@ class Comments extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/repos/comments/#custom-media-types + * * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - if (!in_array($bodyType, array('raw', 'text', 'html'))) { + if (!in_array($bodyType, ['raw', 'text', 'html'])) { $bodyType = 'full'; } diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 3aaa460d6c2..8195e4baf0f 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -6,6 +6,7 @@ /** * @link http://developer.github.com/v3/repos/commits/ + * * @author Joseph Bielawski */ class Commits extends AbstractApi @@ -17,12 +18,12 @@ public function all($username, $repository, array $params) public function compare($username, $repository, $base, $head, $mediaType = null) { - $headers = array(); + $headers = []; if (null !== $mediaType) { $headers['Accept'] = $mediaType; } - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), array(), $headers); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), [], $headers); } public function show($username, $repository, $sha) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 6722bb3c7e0..4c8124fb114 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -4,13 +4,14 @@ use Github\Api\AbstractApi; use Github\Api\AcceptHeaderTrait; -use Github\Exception\InvalidArgumentException; use Github\Exception\ErrorException; +use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; use Github\Exception\TwoFactorAuthenticationRequiredException; /** * @link http://developer.github.com/v3/repos/contents/ + * * @author Joseph Bielawski */ class Contents extends AbstractApi @@ -21,13 +22,14 @@ class Contents extends AbstractApi * Configure the body type. * * @link https://developer.github.com/v3/repo/contents/#custom-media-types + * * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - if (!in_array($bodyType, array('html', 'object'))) { + if (!in_array($bodyType, ['html', 'object'])) { $bodyType = 'raw'; } @@ -49,9 +51,9 @@ public function configure($bodyType = null) */ public function readme($username, $repository, $reference = null) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', array( - 'ref' => $reference - )); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', [ + 'ref' => $reference, + ]); } /** @@ -73,9 +75,9 @@ public function show($username, $repository, $path = null, $reference = null) $url .= '/'.rawurlencode($path); } - return $this->get($url, array( - 'ref' => $reference - )); + return $this->get($url, [ + 'ref' => $reference, + ]); } /** @@ -99,10 +101,10 @@ public function create($username, $repository, $path, $content, $message, $branc { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); - $parameters = array( + $parameters = [ 'content' => base64_encode($content), 'message' => $message, - ); + ]; if (null !== $branch) { $parameters['branch'] = $branch; @@ -110,7 +112,7 @@ public function create($username, $repository, $path, $content, $message, $branc if (null !== $committer) { if (!isset($committer['name'], $committer['email'])) { - throw new MissingArgumentException(array('name', 'email')); + throw new MissingArgumentException(['name', 'email']); } $parameters['committer'] = $committer; } @@ -137,9 +139,9 @@ public function exists($username, $repository, $path, $reference = null) } try { - $response = $this->head($url, array( - 'ref' => $reference - )); + $response = $this->head($url, [ + 'ref' => $reference, + ]); if ($response->getStatusCode() != 200) { return false; @@ -175,11 +177,11 @@ public function update($username, $repository, $path, $content, $message, $sha, { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); - $parameters = array( + $parameters = [ 'content' => base64_encode($content), 'message' => $message, 'sha' => $sha, - ); + ]; if (null !== $branch) { $parameters['branch'] = $branch; @@ -187,7 +189,7 @@ public function update($username, $repository, $path, $content, $message, $sha, if (null !== $committer) { if (!isset($committer['name'], $committer['email'])) { - throw new MissingArgumentException(array('name', 'email')); + throw new MissingArgumentException(['name', 'email']); } $parameters['committer'] = $committer; } @@ -216,10 +218,10 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); - $parameters = array( + $parameters = [ 'message' => $message, 'sha' => $sha, - ); + ]; if (null !== $branch) { $parameters['branch'] = $branch; @@ -227,7 +229,7 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null if (null !== $committer) { if (!isset($committer['name'], $committer['email'])) { - throw new MissingArgumentException(array('name', 'email')); + throw new MissingArgumentException(['name', 'email']); } $parameters['committer'] = $committer; } @@ -249,7 +251,7 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null */ public function archive($username, $repository, $format, $reference = null) { - if (!in_array($format, array('tarball', 'zipball'))) { + if (!in_array($format, ['tarball', 'zipball'])) { $format = 'tarball'; } diff --git a/lib/Github/Api/Repository/DeployKeys.php b/lib/Github/Api/Repository/DeployKeys.php index 2c25542dfc3..c6c8a2ce3b1 100644 --- a/lib/Github/Api/Repository/DeployKeys.php +++ b/lib/Github/Api/Repository/DeployKeys.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/repos/keys/ + * * @author Joseph Bielawski */ class DeployKeys extends AbstractApi @@ -24,7 +25,7 @@ public function show($username, $repository, $id) public function create($username, $repository, array $params) { if (!isset($params['title'], $params['key'])) { - throw new MissingArgumentException(array('title', 'key')); + throw new MissingArgumentException(['title', 'key']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys', $params); @@ -33,7 +34,7 @@ public function create($username, $repository, array $params) public function update($username, $repository, $id, array $params) { if (!isset($params['title'], $params['key'])) { - throw new MissingArgumentException(array('title', 'key')); + throw new MissingArgumentException(['title', 'key']); } return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params); diff --git a/lib/Github/Api/Repository/Downloads.php b/lib/Github/Api/Repository/Downloads.php index bfde5b3ea5e..ed4c42f27d4 100644 --- a/lib/Github/Api/Repository/Downloads.php +++ b/lib/Github/Api/Repository/Downloads.php @@ -6,6 +6,7 @@ /** * @link http://developer.github.com/v3/repos/downloads/ + * * @author Joseph Bielawski */ class Downloads extends AbstractApi diff --git a/lib/Github/Api/Repository/Forks.php b/lib/Github/Api/Repository/Forks.php index dbd4f3d3785..961dc64944a 100644 --- a/lib/Github/Api/Repository/Forks.php +++ b/lib/Github/Api/Repository/Forks.php @@ -6,20 +6,21 @@ /** * @link http://developer.github.com/v3/repos/forks/ + * * @author Joseph Bielawski */ class Forks extends AbstractApi { - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { - if (isset($params['sort']) && !in_array($params['sort'], array('newest', 'oldest', 'watchers'))) { + if (isset($params['sort']) && !in_array($params['sort'], ['newest', 'oldest', 'watchers'])) { $params['sort'] = 'newest'; } - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', array_merge(array('page' => 1), $params)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', array_merge(['page' => 1], $params)); } - public function create($username, $repository, array $params = array()) + public function create($username, $repository, array $params = []) { return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/forks', $params); } diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index a44a01a9f29..db67f40270e 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/repos/hooks/ + * * @author Joseph Bielawski */ class Hooks extends AbstractApi @@ -24,7 +25,7 @@ public function show($username, $repository, $id) public function create($username, $repository, array $params) { if (!isset($params['name'], $params['config'])) { - throw new MissingArgumentException(array('name', 'config')); + throw new MissingArgumentException(['name', 'config']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks', $params); @@ -33,7 +34,7 @@ public function create($username, $repository, array $params) public function update($username, $repository, $id, array $params) { if (!isset($params['config'])) { - throw new MissingArgumentException(array('config')); + throw new MissingArgumentException(['config']); } return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id), $params); diff --git a/lib/Github/Api/Repository/Labels.php b/lib/Github/Api/Repository/Labels.php index 34535e8e1c9..7829e551e25 100644 --- a/lib/Github/Api/Repository/Labels.php +++ b/lib/Github/Api/Repository/Labels.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/issues/labels/ + * * @author Joseph Bielawski */ class Labels extends AbstractApi @@ -24,7 +25,7 @@ public function show($username, $repository, $label) public function create($username, $repository, array $params) { if (!isset($params['name'], $params['color'])) { - throw new MissingArgumentException(array('name', 'color')); + throw new MissingArgumentException(['name', 'color']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); @@ -33,7 +34,7 @@ public function create($username, $repository, array $params) public function update($username, $repository, $label, array $params) { if (!isset($params['name'], $params['color'])) { - throw new MissingArgumentException(array('name', 'color')); + throw new MissingArgumentException(['name', 'color']); } return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); diff --git a/lib/Github/Api/Repository/Projects.php b/lib/Github/Api/Repository/Projects.php index 279a1d45f92..9db29f5578d 100644 --- a/lib/Github/Api/Repository/Projects.php +++ b/lib/Github/Api/Repository/Projects.php @@ -7,15 +7,15 @@ class Projects extends AbstractProjectApi { - public function all($username, $repository, array $params = array()) + public function all($username, $repository, array $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(array('page' => 1), $params)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(['page' => 1], $params)); } public function create($username, $repository, array $params) { if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); + throw new MissingArgumentException(['name']); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', $params); diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 3c96e668933..73d1e6b5897 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -7,6 +7,7 @@ /** * @link https://developer.github.com/v3/repos/branches/ + * * @author Brandon Bloodgood */ class Protection extends AbstractApi @@ -21,15 +22,15 @@ public function configure() } /** - * Retrieves configured protection for the provided branch + * Retrieves configured protection for the provided branch. * * @link https://developer.github.com/v3/repos/branches/#get-branch-protection * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The branch protection information + * @return array The branch protection information */ public function show($username, $repository, $branch) { @@ -37,30 +38,30 @@ public function show($username, $repository, $branch) } /** - * Updates the repo's branch protection + * Updates the repo's branch protection. * * @link https://developer.github.com/v3/repos/branches/#update-branch-protection * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The branch protection information + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch protection information * - * @return array The updated branch protection information + * @return array The updated branch protection information */ - public function update($username, $repository, $branch, array $params = array()) + public function update($username, $repository, $branch, array $params = []) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params); } /** - * Remove the repo's branch protection + * Remove the repo's branch protection. * * @link https://developer.github.com/v3/repos/branches/#remove-branch-protection * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch */ public function remove($username, $repository, $branch) { @@ -68,15 +69,15 @@ public function remove($username, $repository, $branch) } /** - * Get required status checks of protected branch + * Get required status checks of protected branch. * * @link https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The required status checks information + * @return array The required status checks information */ public function showStatusChecks($username, $repository, $branch) { @@ -84,30 +85,30 @@ public function showStatusChecks($username, $repository, $branch) } /** - * Update required status checks of protected branch + * Update required status checks of protected branch. * * @link https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The branch status checks information + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks information * - * @return array The updated branch status checks information + * @return array The updated branch status checks information */ - public function updateStatusChecks($username, $repository, $branch, array $params = array()) + public function updateStatusChecks($username, $repository, $branch, array $params = []) { return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks', $params); } /** - * Remove required status checks of protected branch + * Remove required status checks of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch */ public function removeStatusChecks($username, $repository, $branch) { @@ -115,15 +116,15 @@ public function removeStatusChecks($username, $repository, $branch) } /** - * List required status checks contexts of protected branch + * List required status checks contexts of protected branch. * * @link https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The required status checks contexts information + * @return array The required status checks contexts information */ public function showStatusChecksContexts($username, $repository, $branch) { @@ -131,66 +132,66 @@ public function showStatusChecksContexts($username, $repository, $branch) } /** - * Replace required status checks contexts of protected branch + * Replace required status checks contexts of protected branch. * * @link https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The branch status checks contexts information + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information * - * @return array The new branch status checks contexts information + * @return array The new branch status checks contexts information */ - public function replaceStatusChecksContexts($username, $repository, $branch, array $params = array()) + public function replaceStatusChecksContexts($username, $repository, $branch, array $params = []) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); } /** - * Add required status checks contexts of protected branch + * Add required status checks contexts of protected branch. * * @link https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The branch status checks contexts information + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information * - * @return array The updated branch status checks contexts information + * @return array The updated branch status checks contexts information */ - public function addStatusChecksContexts($username, $repository, $branch, array $params = array()) + public function addStatusChecksContexts($username, $repository, $branch, array $params = []) { return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); } /** - * Remove required status checks contexts of protected branch + * Remove required status checks contexts of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The branch status checks contexts information + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information * - * @return array The updated branch status checks contexts information + * @return array The updated branch status checks contexts information */ - public function removeStatusChecksContexts($username, $repository, $branch, array $params = array()) + public function removeStatusChecksContexts($username, $repository, $branch, array $params = []) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); } /** - * Get pull request review enforcement of protected branch + * Get pull request review enforcement of protected branch. * * @link https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The pull request review enforcement information + * @return array The pull request review enforcement information */ public function showPullRequestReviewEnforcement($username, $repository, $branch) { @@ -198,30 +199,30 @@ public function showPullRequestReviewEnforcement($username, $repository, $branch } /** - * Update pull request review enforcement of protected branch + * Update pull request review enforcement of protected branch. * * @link https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The branch status checks information + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks information * - * @return array The updated branch status checks information + * @return array The updated branch status checks information */ - public function updatePullRequestReviewEnforcement($username, $repository, $branch, array $params = array()) + public function updatePullRequestReviewEnforcement($username, $repository, $branch, array $params = []) { return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews', $params); } /** - * Remove pull request review enforcement of protected branch + * Remove pull request review enforcement of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch */ public function removePullRequestReviewEnforcement($username, $repository, $branch) { @@ -229,15 +230,15 @@ public function removePullRequestReviewEnforcement($username, $repository, $bran } /** - * Get admin enforcement of protected branch + * Get admin enforcement of protected branch. * * @link https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The admin enforcement information + * @return array The admin enforcement information */ public function showAdminEnforcement($username, $repository, $branch) { @@ -245,15 +246,15 @@ public function showAdminEnforcement($username, $repository, $branch) } /** - * Add admin enforcement of protected branch + * Add admin enforcement of protected branch. * * @link https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The updated admin enforcement information + * @return array The updated admin enforcement information */ public function addAdminEnforcement($username, $repository, $branch) { @@ -261,13 +262,13 @@ public function addAdminEnforcement($username, $repository, $branch) } /** - * Remove admin enforcement of protected branch + * Remove admin enforcement of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch */ public function removeAdminEnforcement($username, $repository, $branch) { @@ -275,15 +276,15 @@ public function removeAdminEnforcement($username, $repository, $branch) } /** - * Get restrictions of protected branch + * Get restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The branch restrictions information + * @return array The branch restrictions information */ public function showRestrictions($username, $repository, $branch) { @@ -291,13 +292,13 @@ public function showRestrictions($username, $repository, $branch) } /** - * Remove restrictions of protected branch + * Remove restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch */ public function removeRestrictions($username, $repository, $branch) { @@ -305,15 +306,15 @@ public function removeRestrictions($username, $repository, $branch) } /** - * List team restrictions of protected branch + * List team restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The branch team restrictions information + * @return array The branch team restrictions information */ public function showTeamRestrictions($username, $repository, $branch) { @@ -321,66 +322,66 @@ public function showTeamRestrictions($username, $repository, $branch) } /** - * Replace team restrictions of protected branch + * Replace team restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The list of team slugs with push access + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access * - * @return array The new branch team restrictions information + * @return array The new branch team restrictions information */ - public function replaceTeamRestrictions($username, $repository, $branch, array $params = array()) + public function replaceTeamRestrictions($username, $repository, $branch, array $params = []) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); } /** - * Add team restrictions of protected branch + * Add team restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The list of team slugs with push access + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access * - * @return array The branch team restrictions information + * @return array The branch team restrictions information */ - public function addTeamRestrictions($username, $repository, $branch, array $params = array()) + public function addTeamRestrictions($username, $repository, $branch, array $params = []) { return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); } /** - * Remove team restrictions of protected branch + * Remove team restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The list of team slugs with push access + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access * - * @return array The updated branch team restrictions information + * @return array The updated branch team restrictions information */ - public function removeTeamRestrictions($username, $repository, $branch, array $params = array()) + public function removeTeamRestrictions($username, $repository, $branch, array $params = []) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); } /** - * List user restrictions of protected branch + * List user restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch * - * @return array The branch user restrictions information + * @return array The branch user restrictions information */ public function showUserRestrictions($username, $repository, $branch) { @@ -388,52 +389,52 @@ public function showUserRestrictions($username, $repository, $branch) } /** - * Replace user restrictions of protected branch + * Replace user restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The list of user logins with push access + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access * - * @return array The new branch user restrictions information + * @return array The new branch user restrictions information */ - public function replaceUserRestrictions($username, $repository, $branch, array $params = array()) + public function replaceUserRestrictions($username, $repository, $branch, array $params = []) { return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); } /** - * Add user restrictions of protected branch + * Add user restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The list of user logins with push access + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access * - * @return array The branch user restrictions information + * @return array The branch user restrictions information */ - public function addUserRestrictions($username, $repository, $branch, array $params = array()) + public function addUserRestrictions($username, $repository, $branch, array $params = []) { return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); } /** - * Remove user restrictions of protected branch + * Remove user restrictions of protected branch. * * @link https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch * - * @param string $username The user who owns the repository - * @param string $repository The name of the repo - * @param string $branch The name of the branch - * @param array $params The list of user logins with push access + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access * - * @return array The updated branch user restrictions information + * @return array The updated branch user restrictions information */ - public function removeUserRestrictions($username, $repository, $branch, array $params = array()) + public function removeUserRestrictions($username, $repository, $branch, array $params = []) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); } diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 4d59318fe07..73fd080b42f 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/repos/releases/ + * * @author Matthew Simo * @author Evgeniy Guseletov */ diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index 5a298b717db..e71777741c7 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -7,6 +7,7 @@ /** * @link https://developer.github.com/v3/activity/starring/#list-stargazers + * * @author Nicolas Dupont * @author Tobias Nyholm */ @@ -15,7 +16,7 @@ class Stargazers extends AbstractApi use AcceptHeaderTrait; /** - * Configure the body type + * Configure the body type. * * @see https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps * diff --git a/lib/Github/Api/Repository/Statuses.php b/lib/Github/Api/Repository/Statuses.php index 728d1305f28..c62f4edd8b6 100644 --- a/lib/Github/Api/Repository/Statuses.php +++ b/lib/Github/Api/Repository/Statuses.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/repos/statuses/ + * * @author Joseph Bielawski */ class Statuses extends AbstractApi @@ -51,7 +52,7 @@ public function combined($username, $repository, $sha) * * @return array */ - public function create($username, $repository, $sha, array $params = array()) + public function create($username, $repository, $sha, array $params = []) { if (!isset($params['state'])) { throw new MissingArgumentException('state'); diff --git a/lib/Github/Api/Repository/Traffic.php b/lib/Github/Api/Repository/Traffic.php index 304dd899b0c..d5b550c8521 100644 --- a/lib/Github/Api/Repository/Traffic.php +++ b/lib/Github/Api/Repository/Traffic.php @@ -1,11 +1,12 @@ */ class Traffic extends AbstractApi @@ -22,6 +23,7 @@ public function referers($owner, $repository) { return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/referrers'); } + /** * @link https://developer.github.com/v3/repos/traffic/#list-paths * @@ -34,6 +36,7 @@ public function paths($owner, $repository) { return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/popular/paths'); } + /** * @link https://developer.github.com/v3/repos/traffic/#views * @@ -47,6 +50,7 @@ public function views($owner, $repository, $per = 'day') { return $this->get('/repos/'.rawurlencode($owner).'/'.rawurlencode($repository).'/traffic/views?per='.rawurlencode($per)); } + /** * @link https://developer.github.com/v3/repos/traffic/#clones * diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 857ef9eb7b9..dfc4c24718b 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -6,6 +6,7 @@ * Implement the Search API. * * @link https://developer.github.com/v3/search/ + * * @author Greg Payne */ class Search extends AbstractApi @@ -25,7 +26,7 @@ class Search extends AbstractApi */ public function repositories($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/repositories', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/repositories', ['q' => $q, 'sort' => $sort, 'order' => $order]); } /** @@ -41,7 +42,7 @@ public function repositories($q, $sort = 'updated', $order = 'desc') */ public function issues($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/issues', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/issues', ['q' => $q, 'sort' => $sort, 'order' => $order]); } /** @@ -57,7 +58,7 @@ public function issues($q, $sort = 'updated', $order = 'desc') */ public function code($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/code', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/code', ['q' => $q, 'sort' => $sort, 'order' => $order]); } /** @@ -73,7 +74,7 @@ public function code($q, $sort = 'updated', $order = 'desc') */ public function users($q, $sort = 'updated', $order = 'desc') { - return $this->get('/search/users', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/users', ['q' => $q, 'sort' => $sort, 'order' => $order]); } /** @@ -92,6 +93,6 @@ public function commits($q, $sort = null, $order = 'desc') //This api is in preview mode, so set the correct accept-header $this->acceptHeaderValue = 'application/vnd.github.cloak-preview'; - return $this->get('/search/commits', array('q' => $q, 'sort' => $sort, 'order' => $order)); + return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]); } } diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 570b3c0c719..2c3b807b9bf 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -6,6 +6,7 @@ * Searching users, getting user information. * * @link http://developer.github.com/v3/users/ + * * @author Joseph Bielawski * @author Thibault Duplessis */ @@ -15,7 +16,6 @@ class User extends AbstractApi * Search users by username. * * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * * @link http://developer.github.com/v3/search/#search-users * * @param string $keyword the keyword to search @@ -74,7 +74,7 @@ public function organizations($username) } /** - * Get user organizations + * Get user organizations. * * @link https://developer.github.com/v3/orgs/#list-your-organizations * @@ -84,14 +84,15 @@ public function orgs() { return $this->get('/user/orgs'); } + /** * Request the users that a specific user is following. * * @link http://developer.github.com/v3/users/followers/ * - * @param string $username the username - * @param array $parameters parameters for the query string - * @param array $requestHeaders additional headers to set in the request + * @param string $username the username + * @param array $parameters parameters for the query string + * @param array $requestHeaders additional headers to set in the request * * @return array list of followed users */ @@ -105,9 +106,9 @@ public function following($username, array $parameters = [], array $requestHeade * * @link http://developer.github.com/v3/users/followers/ * - * @param string $username the username - * @param array $parameters parameters for the query string - * @param array $requestHeaders additional headers to set in the request + * @param string $username the username + * @param array $parameters parameters for the query string + * @param array $requestHeaders additional headers to set in the request * * @return array list of following users */ @@ -145,12 +146,12 @@ public function watched($username) */ public function starred($username, $page = 1, $perPage = 30, $sort = 'created', $direction = 'desc') { - return $this->get('/users/'.rawurlencode($username).'/starred', array( + return $this->get('/users/'.rawurlencode($username).'/starred', [ 'page' => $page, 'per_page' => $perPage, 'sort' => $sort, 'direction' => $direction, - )); + ]); } /** @@ -241,6 +242,6 @@ public function keys($username) */ public function publicEvents($username) { - return $this->get('/users/'.rawurlencode($username) . '/events/public'); + return $this->get('/users/'.rawurlencode($username).'/events/public'); } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ea22b512a6c..8e2ea275502 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -3,8 +3,8 @@ namespace Github; use Github\Api\ApiInterface; -use Github\Exception\InvalidArgumentException; use Github\Exception\BadMethodCallException; +use Github\Exception\InvalidArgumentException; use Github\HttpClient\Builder; use Github\HttpClient\Plugin\Authentication; use Github\HttpClient\Plugin\GithubExceptionThrower; @@ -129,9 +129,9 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); $builder->addPlugin(new Plugin\RedirectPlugin()); $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); - $builder->addPlugin(new Plugin\HeaderDefaultsPlugin(array( + $builder->addPlugin(new Plugin\HeaderDefaultsPlugin([ 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', - ))); + ])); $this->apiVersion = $apiVersion ?: 'v3'; $builder->addHeaderValue('Accept', sprintf('application/vnd.github.%s+json', $this->apiVersion)); @@ -317,7 +317,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null throw new InvalidArgumentException('You need to specify authentication method!'); } - if (null === $authMethod && in_array($password, array(self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT))) { + if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT])) { $authMethod = $password; $password = null; } diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index 4a7e372e97c..96e217acde7 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -12,7 +12,7 @@ class MissingArgumentException extends ErrorException public function __construct($required, $code = 0, $previous = null) { if (is_string($required)) { - $required = array($required); + $required = [$required]; } parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code, $previous); diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 218749b43ae..fe9499b29e8 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -4,6 +4,7 @@ use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\Plugin; +use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; use Http\Client\Common\PluginClient; use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; @@ -13,7 +14,6 @@ use Http\Message\RequestFactory; use Http\Message\StreamFactory; use Psr\Cache\CacheItemPoolInterface; -use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; /** * A builder that builds the API client. @@ -167,7 +167,7 @@ public function addHeaderValue($header, $headerValue) if (!isset($this->headers[$header])) { $this->headers[$header] = $headerValue; } else { - $this->headers[$header] = array_merge((array)$this->headers[$header], array($headerValue)); + $this->headers[$header] = array_merge((array) $this->headers[$header], [$headerValue]); } $this->removePlugin(Plugin\HeaderAppendPlugin::class); diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index c841d21269d..6b944165f9f 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -33,11 +33,11 @@ public static function getContent(ResponseInterface $response) public static function getPagination(ResponseInterface $response) { if (!$response->hasHeader('Link')) { - return null; + return; } $header = self::getHeader($response, 'Link'); - $pagination = array(); + $pagination = []; foreach (explode(',', $header) as $link) { preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match); @@ -61,14 +61,15 @@ public static function getApiLimit(ResponseInterface $response) if (null !== $remainingCalls && 1 > $remainingCalls) { throw new ApiLimitExceedException($remainingCalls); } - + return $remainingCalls; } - + /** - * Get the value for a single header + * Get the value for a single header. + * * @param ResponseInterface $response - * @param string $name + * @param string $name * * @return string|null */ diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 9601eb12c67..920d65722c6 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -18,7 +18,7 @@ class Authentication implements Plugin private $password; private $method; - public function __construct($tokenOrLogin, $password = null, $method) + public function __construct($tokenOrLogin, $password, $method) { $this->tokenOrLogin = $tokenOrLogin; $this->password = $password; @@ -46,10 +46,10 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $uri = $request->getUri(); $query = $uri->getQuery(); - $parameters = array( + $parameters = [ 'client_id' => $this->tokenOrLogin, 'client_secret' => $this->password, - ); + ]; $query .= empty($query) ? '' : '&'; $query .= utf8_encode(http_build_query($parameters, '', '&')); @@ -62,7 +62,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $uri = $request->getUri(); $query = $uri->getQuery(); - $parameters = array('access_token' => $this->tokenOrLogin); + $parameters = ['access_token' => $this->tokenOrLogin]; $query .= empty($query) ? '' : '&'; $query .= utf8_encode(http_build_query($parameters, '', '&')); diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index cc9581e9c61..7d46fe9c2e5 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -2,14 +2,14 @@ namespace Github\HttpClient\Plugin; -use Http\Client\Common\Plugin; -use Psr\Http\Message\RequestInterface; -use Github\Exception\TwoFactorAuthenticationRequiredException; -use Github\HttpClient\Message\ResponseMediator; use Github\Exception\ApiLimitExceedException; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; +use Github\Exception\TwoFactorAuthenticationRequiredException; use Github\Exception\ValidationFailedException; +use Github\HttpClient\Message\ResponseMediator; +use Http\Client\Common\Plugin; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; /** @@ -33,7 +33,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); $reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); - + throw new ApiLimitExceedException($limit, $reset); } @@ -50,7 +50,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl if (400 == $response->getStatusCode()) { throw new ErrorException($content['message'], 400); } elseif (422 == $response->getStatusCode() && isset($content['errors'])) { - $errors = array(); + $errors = []; foreach ($content['errors'] as $error) { switch ($error['code']) { case 'missing': diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index b63ffd676ec..7e872d85925 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -57,7 +57,7 @@ public function getPagination() /** * {@inheritdoc} */ - public function fetch(ApiInterface $api, $method, array $parameters = array()) + public function fetch(ApiInterface $api, $method, array $parameters = []) { $result = $this->callApi($api, $method, $parameters); $this->postFetch(); @@ -68,7 +68,7 @@ public function fetch(ApiInterface $api, $method, array $parameters = array()) /** * {@inheritdoc} */ - public function fetchAll(ApiInterface $api, $method, array $parameters = array()) + public function fetchAll(ApiInterface $api, $method, array $parameters = []) { $isSearch = $api instanceof Search; @@ -187,6 +187,6 @@ protected function get($key) */ protected function callApi(ApiInterface $api, $method, array $parameters) { - return call_user_func_array(array($api, $method), $parameters); + return call_user_func_array([$api, $method], $parameters); } } diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 1130e8ec409..c5add903648 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -26,7 +26,7 @@ public function getPagination(); * * @return array returns the result of the Api::$method() call */ - public function fetch(ApiInterface $api, $method, array $parameters = array()); + public function fetch(ApiInterface $api, $method, array $parameters = []); /** * Fetch all results (pages) from an api call. @@ -39,7 +39,7 @@ public function fetch(ApiInterface $api, $method, array $parameters = array()); * * @return array returns a merge of the results of the Api::$method() call */ - public function fetchAll(ApiInterface $api, $method, array $parameters = array()); + public function fetchAll(ApiInterface $api, $method, array $parameters = []); /** * Method that performs the actual work to refresh the pagination property. diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 1c66a693ac7..e4ce3ae9171 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -12,16 +12,16 @@ class AbstractApiTest extends TestCase */ public function shouldPassGETRequestToClient() { - $expectedArray = array('value'); + $expectedArray = ['value']; - $httpClient = $this->getHttpMethodsMock(array('get')); + $httpClient = $this->getHttpMethodsMock(['get']); $httpClient ->expects($this->any()) ->method('get') - ->with('/path?param1=param1value', array('header1' => 'header1value')) + ->with('/path?param1=param1value', ['header1' => 'header1value']) ->will($this->returnValue($this->getPSR7Response($expectedArray))); $client = $this->getMockBuilder(\Github\Client::class) - ->setMethods(array('getHttpClient')) + ->setMethods(['getHttpClient']) ->getMock(); $client->expects($this->any()) ->method('getHttpClient') @@ -40,17 +40,17 @@ public function shouldPassGETRequestToClient() */ public function shouldPassPOSTRequestToClient() { - $expectedArray = array('value'); + $expectedArray = ['value']; - $httpClient = $this->getHttpMethodsMock(array('post')); + $httpClient = $this->getHttpMethodsMock(['post']); $httpClient ->expects($this->once()) ->method('post') - ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->with('/path', ['option1' => 'option1value'], json_encode(['param1' => 'param1value'])) ->will($this->returnValue($this->getPSR7Response($expectedArray))); $client = $this->getMockBuilder(\Github\Client::class) - ->setMethods(array('getHttpClient')) + ->setMethods(['getHttpClient']) ->getMock(); $client->expects($this->any()) ->method('getHttpClient') @@ -68,17 +68,17 @@ public function shouldPassPOSTRequestToClient() */ public function shouldPassPATCHRequestToClient() { - $expectedArray = array('value'); + $expectedArray = ['value']; - $httpClient = $this->getHttpMethodsMock(array('patch')); + $httpClient = $this->getHttpMethodsMock(['patch']); $httpClient ->expects($this->once()) ->method('patch') - ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->with('/path', ['option1' => 'option1value'], json_encode(['param1' => 'param1value'])) ->will($this->returnValue($this->getPSR7Response($expectedArray))); $client = $this->getMockBuilder(\Github\Client::class) - ->setMethods(array('getHttpClient')) + ->setMethods(['getHttpClient']) ->getMock(); $client->expects($this->any()) ->method('getHttpClient') @@ -96,17 +96,17 @@ public function shouldPassPATCHRequestToClient() */ public function shouldPassPUTRequestToClient() { - $expectedArray = array('value'); + $expectedArray = ['value']; - $httpClient = $this->getHttpMethodsMock(array('put')); + $httpClient = $this->getHttpMethodsMock(['put']); $httpClient ->expects($this->once()) ->method('put') - ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->with('/path', ['option1' => 'option1value'], json_encode(['param1' => 'param1value'])) ->will($this->returnValue($this->getPSR7Response($expectedArray))); $client = $this->getMockBuilder('Github\Client') - ->setMethods(array('getHttpClient')) + ->setMethods(['getHttpClient']) ->getMock(); $client->expects($this->any()) ->method('getHttpClient') @@ -124,23 +124,22 @@ public function shouldPassPUTRequestToClient() */ public function shouldPassDELETERequestToClient() { - $expectedArray = array('value'); + $expectedArray = ['value']; - $httpClient = $this->getHttpMethodsMock(array('delete')); + $httpClient = $this->getHttpMethodsMock(['delete']); $httpClient ->expects($this->once()) ->method('delete') - ->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value'))) + ->with('/path', ['option1' => 'option1value'], json_encode(['param1' => 'param1value'])) ->will($this->returnValue($this->getPSR7Response($expectedArray))); $client = $this->getMockBuilder('Github\Client') - ->setMethods(array('getHttpClient')) + ->setMethods(['getHttpClient']) ->getMock(); $client->expects($this->any()) ->method('getHttpClient') ->willReturn($httpClient); - $api = $this->getAbstractApiObject($client); $actual = $this->getMethod($api, 'delete') ->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['option1' => 'option1value']]); @@ -153,17 +152,17 @@ public function shouldPassDELETERequestToClient() */ public function shouldNotPassEmptyRefToClient() { - $expectedArray = array('value'); + $expectedArray = ['value']; - $httpClient = $this->getHttpMethodsMock(array('get')); + $httpClient = $this->getHttpMethodsMock(['get']); $httpClient ->expects($this->any()) ->method('get') - ->with('/path', array()) + ->with('/path', []) ->will($this->returnValue($this->getPSR7Response($expectedArray))); $client = $this->getMockBuilder(\Github\Client::class) - ->setMethods(array('getHttpClient')) + ->setMethods(['getHttpClient']) ->getMock(); $client->expects($this->any()) ->method('getHttpClient') @@ -177,6 +176,7 @@ public function shouldNotPassEmptyRefToClient() /** * @param $client + * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getAbstractApiObject($client) @@ -204,14 +204,15 @@ protected function getClientMock() } /** - * Return a HttpMethods client mock + * Return a HttpMethods client mock. * * @param array $methods + * * @return \Http\Client\Common\HttpMethodsClient */ - protected function getHttpMethodsMock(array $methods = array()) + protected function getHttpMethodsMock(array $methods = []) { - $methods = array_merge(array('sendRequest'), $methods); + $methods = array_merge(['sendRequest'], $methods); $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) ->disableOriginalConstructor() ->setMethods($methods) @@ -222,13 +223,14 @@ protected function getHttpMethodsMock(array $methods = array()) return $mock; } + /** * @return \Http\Client\HttpClient */ protected function getHttpClientMock() { $mock = $this->getMockBuilder(\Http\Client\HttpClient::class) - ->setMethods(array('sendRequest')) + ->setMethods(['sendRequest']) ->getMock(); $mock ->expects($this->any()) @@ -246,7 +248,7 @@ private function getPSR7Response($expectedArray) { return new Response( 200, - array('Content-Type' => 'application/json'), + ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($expectedArray)) ); } diff --git a/test/Github/Tests/Api/AppTest.php b/test/Github/Tests/Api/AppTest.php index 51679175725..75e028dbfcf 100644 --- a/test/Github/Tests/Api/AppTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -62,7 +62,6 @@ public function shouldRemoveRepositoryToInstallation() $api->removeRepository('1234', '5678'); } - /** * @return string */ diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php index 62ca0222c0c..a8170827484 100644 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -9,7 +9,7 @@ class AuthorizationsTest extends TestCase */ public function shouldGetAllAuthorizations() { - $expectedArray = array(array('id' => '123')); + $expectedArray = [['id' => '123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -26,7 +26,7 @@ public function shouldGetAllAuthorizations() public function shouldShowAuthorization() { $id = 123; - $expectedArray = array('id' => $id); + $expectedArray = ['id' => $id]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -42,9 +42,9 @@ public function shouldShowAuthorization() */ public function shouldAuthorization() { - $input = array( + $input = [ 'note' => '', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,9 +60,9 @@ public function shouldAuthorization() public function shouldUpdateAuthorization() { $id = 123; - $input = array( + $input = [ 'note' => '', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -93,7 +93,7 @@ public function shouldCheckAuthorization() { $id = 123; $token = 'abc'; - $expectedArray = array('id' => $id); + $expectedArray = ['id' => $id]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index bb03fa70339..7b1abd37923 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -9,7 +9,7 @@ class DeployKeysTest extends TestCase */ public function shouldShowKey() { - $expectedValue = array('id' => '12', 'key' => 'ssh-rsa ...'); + $expectedValue = ['id' => '12', 'key' => 'ssh-rsa ...']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,7 +25,7 @@ public function shouldShowKey() */ public function shouldGetKeys() { - $expectedValue = array(array('id' => '12', 'key' => 'ssh-rsa ...')); + $expectedValue = [['id' => '12', 'key' => 'ssh-rsa ...']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -41,8 +41,8 @@ public function shouldGetKeys() */ public function shouldCreateKey() { - $expectedValue = array('id' => '123', 'key' => 'ssh-rsa ...'); - $data = array('title' => 'my key', 'key' => 'ssh-rsa ...'); + $expectedValue = ['id' => '123', 'key' => 'ssh-rsa ...']; + $data = ['title' => 'my key', 'key' => 'ssh-rsa ...']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -59,7 +59,7 @@ public function shouldCreateKey() */ public function shouldNotCreateKeyWithoutTitleParam() { - $data = array('key' => 'ssh-rsa ...'); + $data = ['key' => 'ssh-rsa ...']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -74,7 +74,7 @@ public function shouldNotCreateKeyWithoutTitleParam() */ public function shouldNotCreateKeyWithoutKeyParam() { - $data = array('title' => 'my key'); + $data = ['title' => 'my key']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -88,7 +88,7 @@ public function shouldNotCreateKeyWithoutKeyParam() */ public function shouldRemoveKey() { - $expectedValue = array('some value'); + $expectedValue = ['some value']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index cd15eb2c2ee..2cc4c746712 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -9,7 +9,7 @@ class EmailsTest extends TestCase */ public function shouldGetEmails() { - $expectedValue = array(array('email@example.com')); + $expectedValue = [['email@example.com']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,12 +25,12 @@ public function shouldGetEmails() */ public function shouldRemoveEmail() { - $expectedValue = array('some value'); + $expectedValue = ['some value']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/user/emails', array('email@example.com')) + ->with('/user/emails', ['email@example.com']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->remove('email@example.com')); @@ -41,15 +41,15 @@ public function shouldRemoveEmail() */ public function shouldRemoveEmails() { - $expectedValue = array('some value'); + $expectedValue = ['some value']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/user/emails', array('email@example.com', 'email2@example.com')) + ->with('/user/emails', ['email@example.com', 'email2@example.com']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->remove(array('email@example.com', 'email2@example.com'))); + $this->assertEquals($expectedValue, $api->remove(['email@example.com', 'email2@example.com'])); } /** @@ -62,7 +62,7 @@ public function shouldNotRemoveEmailsWhenAreNotPass() $api->expects($this->any()) ->method('delete'); - $api->remove(array()); + $api->remove([]); } /** @@ -70,12 +70,12 @@ public function shouldNotRemoveEmailsWhenAreNotPass() */ public function shouldAddEmail() { - $expectedValue = array('some value'); + $expectedValue = ['some value']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/user/emails', array('email@example.com')) + ->with('/user/emails', ['email@example.com']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('email@example.com')); @@ -86,15 +86,15 @@ public function shouldAddEmail() */ public function shouldAddEmails() { - $expectedValue = array('some value'); + $expectedValue = ['some value']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/user/emails', array('email@example.com', 'email2@example.com')) + ->with('/user/emails', ['email@example.com', 'email2@example.com']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->add(array('email@example.com', 'email2@example.com'))); + $this->assertEquals($expectedValue, $api->add(['email@example.com', 'email2@example.com'])); } /** @@ -107,7 +107,7 @@ public function shouldNotAddEmailsWhenAreNotPass() $api->expects($this->any()) ->method('post'); - $api->add(array()); + $api->add([]); } /** @@ -115,7 +115,7 @@ public function shouldNotAddEmailsWhenAreNotPass() */ public function shouldToggleVisibility() { - $expectedValue = array('primary email info'); + $expectedValue = ['primary email info']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUser/FollowersTest.php b/test/Github/Tests/Api/CurrentUser/FollowersTest.php index 6ea021f201f..0ad32693008 100644 --- a/test/Github/Tests/Api/CurrentUser/FollowersTest.php +++ b/test/Github/Tests/Api/CurrentUser/FollowersTest.php @@ -9,10 +9,10 @@ class FollowersTest extends TestCase */ public function shouldGetFollowers() { - $expectedValue = array( - array('login' => 'l3l0'), - array('login' => 'cordoval') - ); + $expectedValue = [ + ['login' => 'l3l0'], + ['login' => 'cordoval'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php index 60edaa07e16..858e018cb42 100644 --- a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php +++ b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php @@ -9,28 +9,28 @@ class MembershipsTest extends TestCase */ public function shouldGetMemberships() { - $expectedValue = array( - array( - 'organization' => array( + $expectedValue = [ + [ + 'organization' => [ 'login' => 'octocat', 'id' => 1, - ), - 'user' => array( + ], + 'user' => [ 'login' => 'defunkt', 'id' => 3, - ), - ), - array( - 'organization' => array( + ], + ], + [ + 'organization' => [ 'login' => 'invitocat', 'id' => 2, - ), - 'user' => array( + ], + 'user' => [ 'login' => 'defunkt', 'id' => 3, - ), - ), - ); + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -46,16 +46,16 @@ public function shouldGetMemberships() */ public function shouldGetMembershipsForOrganization() { - $expectedValue = array( - 'organization' => array( + $expectedValue = [ + 'organization' => [ 'login' => 'invitocat', 'id' => 2, - ), - 'user' => array( + ], + 'user' => [ 'login' => 'defunkt', 'id' => 3, - ), - ); + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -71,9 +71,9 @@ public function shouldGetMembershipsForOrganization() */ public function shouldEditMembershipsForOrganization() { - $expectedValue = array( + $expectedValue = [ 'state' => 'active', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUser/StarringTest.php b/test/Github/Tests/Api/CurrentUser/StarringTest.php index 3cf8b7dae02..75c272b0008 100644 --- a/test/Github/Tests/Api/CurrentUser/StarringTest.php +++ b/test/Github/Tests/Api/CurrentUser/StarringTest.php @@ -9,10 +9,10 @@ class StarringTest extends TestCase */ public function shouldGetStarred() { - $expectedValue = array( - array('name' => 'l3l0/test'), - array('name' => 'cordoval/test') - ); + $expectedValue = [ + ['name' => 'l3l0/test'], + ['name' => 'cordoval/test'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index 79f8c9fee83..0347d02f3c0 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -9,10 +9,10 @@ class WatchersTest extends TestCase */ public function shouldGetWatchers() { - $expectedValue = array( - array('name' => 'l3l0/test'), - array('name' => 'cordoval/test') - ); + $expectedValue = [ + ['name' => 'l3l0/test'], + ['name' => 'cordoval/test'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index b93d94ed1bd..ace2301b650 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -9,7 +9,7 @@ class CurrentUserTest extends TestCase */ public function shouldShowCurrentUser() { - $expectedArray = array('id' => 1, 'username' => 'l3l0'); + $expectedArray = ['id' => 1, 'username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,15 +25,15 @@ public function shouldShowCurrentUser() */ public function shouldUpdateCurrentUserData() { - $expectedArray = array('id' => 1, 'username' => 'l3l0'); + $expectedArray = ['id' => 1, 'username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/user', array('value' => 'toChange')) + ->with('/user', ['value' => 'toChange']) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->update(array('value' => 'toChange'))); + $this->assertEquals($expectedArray, $api->update(['value' => 'toChange'])); } /** @@ -41,12 +41,12 @@ public function shouldUpdateCurrentUserData() */ public function shouldGetUserFollowers() { - $expectedArray = array(array('id' => 1, 'username' => 'l3l0test')); + $expectedArray = [['id' => 1, 'username' => 'l3l0test']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/user/followers', array('page' => 1)) + ->with('/user/followers', ['page' => 1]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->followers(1)); @@ -57,15 +57,15 @@ public function shouldGetUserFollowers() */ public function shouldGetIssuesAssignedToUser() { - $expectedArray = array(array('id' => 1, 'title' => 'issues')); + $expectedArray = [['id' => 1, 'title' => 'issues']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/issues', array('page' => 1, 'some' => 'param')) + ->with('/issues', ['page' => 1, 'some' => 'param']) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->issues(array('some' => 'param'))); + $this->assertEquals($expectedArray, $api->issues(['some' => 'param'])); } /** @@ -73,12 +73,12 @@ public function shouldGetIssuesAssignedToUser() */ public function shouldGetWatchedRepositories() { - $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/user/watched', array('page' => 1)) + ->with('/user/watched', ['page' => 1]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->watched(1)); @@ -105,12 +105,12 @@ public function shouldGetInstallations() */ public function shouldGetRepositoriesByInstallation() { - $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/user/installations/42/repositories', array('page' => 1)) + ->with('/user/installations/42/repositories', ['page' => 1]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositoriesByInstallation(42)); diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 0aab01db155..3c9a397855b 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -10,7 +10,7 @@ class DeploymentTest extends TestCase public function shouldCreateDeployment() { $api = $this->getApiMock(); - $deploymentData = array('ref' => 'fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9'); + $deploymentData = ['ref' => 'fd6a5f9e5a430dddae8d6a8ea378f913d3a766f9']; $api->expects($this->once()) ->method('post') ->with('/repos/KnpLabs/php-github-api/deployments', $deploymentData); @@ -37,7 +37,7 @@ public function shouldGetAllDeployments() public function shouldGetAllDeploymentsWithFilterParameters() { $api = $this->getApiMock(); - $filterData = array('foo' => 'bar', 'bar' => 'foo'); + $filterData = ['foo' => 'bar', 'bar' => 'foo']; $api->expects($this->once()) ->method('get') @@ -51,7 +51,7 @@ public function shouldGetAllDeploymentsWithFilterParameters() */ public function shouldShowProject() { - $expectedValue = array('id' => 123, 'ref' => 'master'); + $expectedValue = ['id' => 123, 'ref' => 'master']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -68,7 +68,7 @@ public function shouldShowProject() public function shouldCreateStatusUpdate() { $api = $this->getApiMock(); - $statusData = array('state' => 'pending', 'description' => 'waiting to start'); + $statusData = ['state' => 'pending', 'description' => 'waiting to start']; $api->expects($this->once()) ->method('post') @@ -84,7 +84,7 @@ public function shouldCreateStatusUpdate() public function shouldRejectStatusUpdateWithoutStateField() { $api = $this->getApiMock(); - $statusData = array('description' => 'waiting to start'); + $statusData = ['description' => 'waiting to start']; $api->updateStatus('KnpLabs', 'php-github-api', 1, $statusData); } diff --git a/test/Github/Tests/Api/Enterprise/LicenseTest.php b/test/Github/Tests/Api/Enterprise/LicenseTest.php index 798a362752f..b8d988a6146 100644 --- a/test/Github/Tests/Api/Enterprise/LicenseTest.php +++ b/test/Github/Tests/Api/Enterprise/LicenseTest.php @@ -11,14 +11,14 @@ class LicenseTest extends TestCase */ public function shouldShowLicenseInformation() { - $expectedArray = array( + $expectedArray = [ 'seats' => 1400, 'seats_used' => 1316, 'seats_available' => 84, 'kind' => 'standard', 'days_until_expiration' => 365, - 'expire_at' => '2016/02/06 12:41:52 -0600' - ); + 'expire_at' => '2016/02/06 12:41:52 -0600', + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php index df1b64ce743..fd1d2064f66 100644 --- a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -20,7 +20,7 @@ public function shouldShowConfigData() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/configcheck', array('license_md5' => $this->getLicenseHash())) + ->with('/setup/api/configcheck', ['license_md5' => $this->getLicenseHash()]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash())); @@ -58,7 +58,7 @@ public function shouldShowSettingsData() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/settings', array('license_md5' => $this->getLicenseHash())) + ->with('/setup/api/settings', ['license_md5' => $this->getLicenseHash()]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->settings($this->getLicenseHash())); @@ -77,7 +77,7 @@ public function shouldShowMaintenanceStatus() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/maintenance', array('license_md5' => $this->getLicenseHash())) + ->with('/setup/api/maintenance', ['license_md5' => $this->getLicenseHash()]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash())); @@ -97,7 +97,7 @@ public function shouldShowAuthorizedKeys() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/settings/authorized-keys', array('license_md5' => $this->getLicenseHash())) + ->with('/setup/api/settings/authorized-keys', ['license_md5' => $this->getLicenseHash()]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->keys($this->getLicenseHash())); } diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index fe902257e17..d3a8a89883a 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -36,7 +36,7 @@ public function shouldShowStatsByType($type) ->with(sprintf('/enterprise/stats/%s', $type)) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, call_user_func(array($api, $type))); + $this->assertEquals($expectedArray, call_user_func([$api, $type])); } /** @@ -44,19 +44,19 @@ public function shouldShowStatsByType($type) */ public function getTypes() { - return array( - array('issues'), - array('hooks'), - array('milestones'), - array('orgs'), - array('comments'), - array('pages'), - array('users'), - array('gists'), - array('pulls'), - array('repos'), - array('all') - ); + return [ + ['issues'], + ['hooks'], + ['milestones'], + ['orgs'], + ['comments'], + ['pages'], + ['users'], + ['gists'], + ['pulls'], + ['repos'], + ['all'], + ]; } /** diff --git a/test/Github/Tests/Api/Enterprise/UserAdminTest.php b/test/Github/Tests/Api/Enterprise/UserAdminTest.php index d9eddf8aa08..37b97a43447 100644 --- a/test/Github/Tests/Api/Enterprise/UserAdminTest.php +++ b/test/Github/Tests/Api/Enterprise/UserAdminTest.php @@ -1,4 +1,5 @@ getApiMock(); $api->expects($this->once()) @@ -25,7 +26,7 @@ public function shouldSuspendUser() */ public function shouldUnsuspendUser() { - $expectedArray = array(); + $expectedArray = []; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Gist/CommentsTest.php b/test/Github/Tests/Api/Gist/CommentsTest.php index 3a7fe8febd5..9f0b88fda9e 100644 --- a/test/Github/Tests/Api/Gist/CommentsTest.php +++ b/test/Github/Tests/Api/Gist/CommentsTest.php @@ -11,7 +11,7 @@ class CommentsTest extends TestCase */ public function shouldGetAllGistComments() { - $expectedValue = array(array('comment1data'), array('comment2data')); + $expectedValue = [['comment1data'], ['comment2data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllGistComments() */ public function shouldShowGistComment() { - $expectedValue = array('comment1'); + $expectedValue = ['comment1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,12 +43,12 @@ public function shouldShowGistComment() */ public function shouldCreateGistComment() { - $expectedValue = array('comment1data'); + $expectedValue = ['comment1data']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/gists/123/comments', array('body' => 'Test body')) + ->with('/gists/123/comments', ['body' => 'Test body']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('123', 'Test body')); @@ -59,8 +59,8 @@ public function shouldCreateGistComment() */ public function shouldUpdateGistComment() { - $expectedValue = array('comment1data'); - $data = array('body' => 'body test'); + $expectedValue = ['comment1data']; + $data = ['body' => 'body test']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -76,7 +76,7 @@ public function shouldUpdateGistComment() */ public function shouldRemoveComment() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 2a7a6464bbb..8e179693656 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -9,7 +9,7 @@ class GistsTest extends TestCase */ public function shouldGetStarredGists() { - $expectedArray = array(array('id' => '123')); + $expectedArray = [['id' => '123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,7 +25,7 @@ public function shouldGetStarredGists() */ public function shouldGetAllGists() { - $expectedArray = array(array('id' => '123')); + $expectedArray = [['id' => '123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -41,7 +41,7 @@ public function shouldGetAllGists() */ public function shouldShowGist() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -57,7 +57,7 @@ public function shouldShowGist() */ public function shouldShowCommits() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -83,7 +83,7 @@ public function shouldGetCommentsApiObject() */ public function shouldForkGist() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -99,7 +99,7 @@ public function shouldForkGist() */ public function shouldListGistForks() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -116,10 +116,10 @@ public function shouldListGistForks() */ public function shouldNotCreateGistWithoutFile() { - $input = array( + $input = [ 'description' => '', 'public' => false, - ); + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -133,7 +133,7 @@ public function shouldNotCreateGistWithoutFile() */ public function shouldCheckGist() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -149,7 +149,7 @@ public function shouldCheckGist() */ public function shouldStarGist() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -165,7 +165,7 @@ public function shouldStarGist() */ public function shouldUnstarGist() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -181,15 +181,15 @@ public function shouldUnstarGist() */ public function shouldCreateAnonymousGist() { - $input = array( + $input = [ 'description' => '', 'public' => false, - 'files' => array( - 'filename.txt' => array( - 'content' => 'content' - ) - ) - ); + 'files' => [ + 'filename.txt' => [ + 'content' => 'content', + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -204,18 +204,18 @@ public function shouldCreateAnonymousGist() */ public function shouldUpdateGist() { - $input = array( + $input = [ 'description' => 'jimbo', - 'files' => array( - 'filename.txt' => array( + 'files' => [ + 'filename.txt' => [ 'filename' => 'new_name.txt', - 'content' => 'content' - ), - 'filename_new.txt' => array( - 'content' => 'content new' - ) - ) - ); + 'content' => 'content', + ], + 'filename_new.txt' => [ + 'content' => 'content new', + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/GitData/BlobsTest.php b/test/Github/Tests/Api/GitData/BlobsTest.php index 4c96ba303a5..a871414f96b 100644 --- a/test/Github/Tests/Api/GitData/BlobsTest.php +++ b/test/Github/Tests/Api/GitData/BlobsTest.php @@ -9,7 +9,7 @@ class BlobsTest extends TestCase */ public function shouldShowBlob() { - $expectedValue = array('blob' => 'some data'); + $expectedValue = ['blob' => 'some data']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,15 +25,15 @@ public function shouldShowBlob() */ public function shouldShowRawBlob() { - $expectedValue = array('blob' => 'some data'); + $expectedValue = ['blob' => 'some data']; $client = $this->getMockBuilder('Github\Client') ->disableOriginalConstructor() ->getMock(); $api = $this->getMockBuilder($this->getApiClass()) - ->setMethods(array('configure', 'get')) - ->setConstructorArgs(array($client)) + ->setMethods(['configure', 'get']) + ->setConstructorArgs([$client]) ->getMock(); $api->expects($this->once()) ->method('configure') @@ -53,8 +53,8 @@ public function shouldShowRawBlob() */ public function shouldCreateBlob() { - $expectedValue = array('blob' => 'some data'); - $data = array('content' => 'some cotent', 'encoding' => 'utf8'); + $expectedValue = ['blob' => 'some data']; + $data = ['content' => 'some cotent', 'encoding' => 'utf8']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -71,7 +71,7 @@ public function shouldCreateBlob() */ public function shouldNotCreateBlobWithoutEncoding() { - $data = array('content' => 'some cotent'); + $data = ['content' => 'some cotent']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -86,7 +86,7 @@ public function shouldNotCreateBlobWithoutEncoding() */ public function shouldNotCreateBlobWithoutContent() { - $data = array('encoding' => 'utf8'); + $data = ['encoding' => 'utf8']; $api = $this->getApiMock(); $api->expects($this->never()) diff --git a/test/Github/Tests/Api/GitData/CommitsTest.php b/test/Github/Tests/Api/GitData/CommitsTest.php index 964956439cf..3d973c6ab59 100644 --- a/test/Github/Tests/Api/GitData/CommitsTest.php +++ b/test/Github/Tests/Api/GitData/CommitsTest.php @@ -9,7 +9,7 @@ class CommitsTest extends TestCase */ public function shouldShowCommitUsingSha() { - $expectedValue = array('sha' => '123', 'comitter'); + $expectedValue = ['sha' => '123', 'comitter']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,8 +25,8 @@ public function shouldShowCommitUsingSha() */ public function shouldCreateCommit() { - $expectedValue = array('sha' => '123', 'comitter'); - $data = array('message' => 'some message', 'tree' => 1234, 'parents' => array()); + $expectedValue = ['sha' => '123', 'comitter']; + $data = ['message' => 'some message', 'tree' => 1234, 'parents' => []]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldCreateCommit() */ public function shouldNotCreateCommitWithoutMessageParam() { - $data = array('tree' => 1234, 'parents' => array()); + $data = ['tree' => 1234, 'parents' => []]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -58,7 +58,7 @@ public function shouldNotCreateCommitWithoutMessageParam() */ public function shouldNotCreateCommitWithoutTreeParam() { - $data = array('message' => 'some message', 'parents' => array()); + $data = ['message' => 'some message', 'parents' => []]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -73,7 +73,7 @@ public function shouldNotCreateCommitWithoutTreeParam() */ public function shouldNotCreateCommitWithoutParentsParam() { - $data = array('message' => 'some message', 'tree' => '12334'); + $data = ['message' => 'some message', 'tree' => '12334']; $api = $this->getApiMock(); $api->expects($this->never()) diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 2c094492f2a..55a3fa0edd6 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -9,7 +9,7 @@ class ReferencesTest extends TestCase */ public function shouldNotEscapeSlashesInReferences() { - $expectedValue = array('reference' => 'some data'); + $expectedValue = ['reference' => 'some data']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,7 +25,7 @@ public function shouldNotEscapeSlashesInReferences() */ public function shouldShowReference() { - $expectedValue = array('reference' => 'some data'); + $expectedValue = ['reference' => 'some data']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -41,7 +41,7 @@ public function shouldShowReference() */ public function shouldRemoveReference() { - $expectedValue = array('reference' => 'some data'); + $expectedValue = ['reference' => 'some data']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -57,7 +57,7 @@ public function shouldRemoveReference() */ public function shouldGetAllRepoReferences() { - $expectedValue = array(array('reference' => 'some data')); + $expectedValue = [['reference' => 'some data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -73,7 +73,7 @@ public function shouldGetAllRepoReferences() */ public function shouldGetAllRepoBranches() { - $expectedValue = array(array('branch' => 'some data')); + $expectedValue = [['branch' => 'some data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -89,7 +89,7 @@ public function shouldGetAllRepoBranches() */ public function shouldGetAllRepoTags() { - $expectedValue = array(array('tag' => 'some data')); + $expectedValue = [['tag' => 'some data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -105,8 +105,8 @@ public function shouldGetAllRepoTags() */ public function shouldCreateReference() { - $expectedValue = array('reference' => 'some data'); - $data = array('ref' => '122', 'sha' => '1234'); + $expectedValue = ['reference' => 'some data']; + $data = ['ref' => '122', 'sha' => '1234']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -123,7 +123,7 @@ public function shouldCreateReference() */ public function shouldNotCreateReferenceWithoutShaParam() { - $data = array('ref' => '123'); + $data = ['ref' => '123']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -138,7 +138,7 @@ public function shouldNotCreateReferenceWithoutShaParam() */ public function shouldNotCreateReferenceWithoutRefsParam() { - $data = array('sha' => '1234'); + $data = ['sha' => '1234']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -152,8 +152,8 @@ public function shouldNotCreateReferenceWithoutRefsParam() */ public function shouldUpdateReference() { - $expectedValue = array('reference' => 'some data'); - $data = array('sha' => '12345sha'); + $expectedValue = ['reference' => 'some data']; + $data = ['sha' => '12345sha']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -170,7 +170,7 @@ public function shouldUpdateReference() */ public function shouldNoUpdateReferenceWithoutSha() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) diff --git a/test/Github/Tests/Api/GitData/TagsTest.php b/test/Github/Tests/Api/GitData/TagsTest.php index 8b109d0b9be..06543edeace 100644 --- a/test/Github/Tests/Api/GitData/TagsTest.php +++ b/test/Github/Tests/Api/GitData/TagsTest.php @@ -9,7 +9,7 @@ class TagsTest extends TestCase */ public function shouldShowTagUsingSha() { - $expectedValue = array('sha' => '123', 'comitter'); + $expectedValue = ['sha' => '123', 'comitter']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,7 +25,7 @@ public function shouldShowTagUsingSha() */ public function shouldGetAllTags() { - $expectedValue = array(array('sha' => '123', 'tagger')); + $expectedValue = [['sha' => '123', 'tagger']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -41,18 +41,18 @@ public function shouldGetAllTags() */ public function shouldCreateTag() { - $expectedValue = array('sha' => '123', 'comitter'); - $data = array( + $expectedValue = ['sha' => '123', 'comitter']; + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'object' => 'test', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', 'email' => 'leszek.prabucki@gmail.com', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -69,16 +69,16 @@ public function shouldCreateTag() */ public function shouldNotCreateTagWithoutMessageParam() { - $data = array( + $data = [ 'tag' => 'v2.2', 'object' => 'test', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', 'email' => 'leszek.prabucki@gmail.com', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -93,12 +93,12 @@ public function shouldNotCreateTagWithoutMessageParam() */ public function shouldNotCreateTagWithoutTaggerParam() { - $data = array( + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'object' => 'test', 'type' => 'unsigned', - ); + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -113,16 +113,16 @@ public function shouldNotCreateTagWithoutTaggerParam() */ public function shouldNotCreateTagWithoutTaggerNameParam() { - $data = array( + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'object' => 'test', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'email' => 'leszek.prabucki@gmail.com', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -137,16 +137,16 @@ public function shouldNotCreateTagWithoutTaggerNameParam() */ public function shouldNotCreateTagWithoutTaggerEmailParam() { - $data = array( + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'object' => 'test', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -161,16 +161,16 @@ public function shouldNotCreateTagWithoutTaggerEmailParam() */ public function shouldNotCreateTagWithoutTaggerDateParam() { - $data = array( + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'object' => 'test', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', 'email' => 'leszek.prabucki@gmail.com', - ) - ); + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -185,16 +185,16 @@ public function shouldNotCreateTagWithoutTaggerDateParam() */ public function shouldNotCreateTagWithoutTagParam() { - $data = array( + $data = [ 'message' => 'some message', 'object' => 'test', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', 'email' => 'leszek.prabucki@gmail.com', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -209,16 +209,16 @@ public function shouldNotCreateTagWithoutTagParam() */ public function shouldNotCreateTagWithoutObjectParam() { - $data = array( + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'type' => 'unsigned', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', 'email' => 'leszek.prabucki@gmail.com', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -233,16 +233,16 @@ public function shouldNotCreateTagWithoutObjectParam() */ public function shouldNotCreateTagWithoutTypeParam() { - $data = array( + $data = [ 'message' => 'some message', 'tag' => 'v2.2', 'object' => 'test', - 'tagger' => array( + 'tagger' => [ 'name' => 'l3l0', 'email' => 'leszek.prabucki@gmail.com', - 'date' => date('Y-m-d H:i:s') - ) - ); + 'date' => date('Y-m-d H:i:s'), + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index bd8db13f688..58ef5cef2a0 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -9,12 +9,12 @@ class TreesTest extends TestCase */ public function shouldShowTreeUsingSha() { - $expectedValue = array('sha' => '123', 'comitter'); + $expectedValue = ['sha' => '123', 'comitter']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/git/trees/123', array()) + ->with('/repos/KnpLabs/php-github-api/git/trees/123', []) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); @@ -25,23 +25,23 @@ public function shouldShowTreeUsingSha() */ public function shouldCreateTreeUsingSha() { - $expectedValue = array('sha' => '123', 'comitter'); - $data = array( - 'tree' => array( - array( + $expectedValue = ['sha' => '123', 'comitter']; + $data = [ + 'tree' => [ + [ 'path' => 'path', 'mode' => 'mode', 'type' => 'type', - 'sha' => '1234' - ), - array( + 'sha' => '1234', + ], + [ 'path' => 'htap', 'mode' => 'edom', 'type' => 'epyt', - 'sha' => '4321' - ), - ) - ); + 'sha' => '4321', + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -57,23 +57,23 @@ public function shouldCreateTreeUsingSha() */ public function shouldCreateTreeUsingContent() { - $expectedValue = array('sha' => '123', 'comitter'); - $data = array( - 'tree' => array( - array( + $expectedValue = ['sha' => '123', 'comitter']; + $data = [ + 'tree' => [ + [ 'path' => 'path', 'mode' => 'mode', 'type' => 'type', - 'content' => 'content' - ), - array( + 'content' => 'content', + ], + [ 'path' => 'htap', 'mode' => 'edom', 'type' => 'epyt', - 'content' => 'tnetnoc' - ), - ) - ); + 'content' => 'tnetnoc', + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -90,13 +90,13 @@ public function shouldCreateTreeUsingContent() */ public function shouldNotCreateTreeWithoutShaAndContentParam() { - $data = array( - 'tree' => array( + $data = [ + 'tree' => [ 'path' => 'path', 'mode' => 'mode', 'type' => 'type', - ) - ); + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -111,13 +111,13 @@ public function shouldNotCreateTreeWithoutShaAndContentParam() */ public function shouldNotCreateTreeWithoutPathParam() { - $data = array( - 'tree' => array( + $data = [ + 'tree' => [ 'mode' => 'mode', 'type' => 'type', - 'content' => 'content' - ) - ); + 'content' => 'content', + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -132,13 +132,13 @@ public function shouldNotCreateTreeWithoutPathParam() */ public function shouldNotCreateTreeWithoutModeParam() { - $data = array( - 'tree' => array( + $data = [ + 'tree' => [ 'path' => 'path', 'type' => 'type', - 'content' => 'content' - ) - ); + 'content' => 'content', + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -153,13 +153,13 @@ public function shouldNotCreateTreeWithoutModeParam() */ public function shouldNotCreateTreeWithoutTypeParam() { - $data = array( - 'tree' => array( + $data = [ + 'tree' => [ 'path' => 'path', 'mode' => 'mode', - 'content' => 'content' - ) - ); + 'content' => 'content', + ], + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -174,7 +174,7 @@ public function shouldNotCreateTreeWithoutTypeParam() */ public function shouldNotCreateTreeWithoutTreeParam() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -189,9 +189,9 @@ public function shouldNotCreateTreeWithoutTreeParam() */ public function shouldNotCreateTreeWhenTreeParamIsNotArray() { - $data = array( - 'tree' => '' - ); + $data = [ + 'tree' => '', + ]; $api = $this->getApiMock(); $api->expects($this->never()) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index e2f2d692c84..5faea997d3b 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -4,7 +4,6 @@ class GraphQLTest extends TestCase { - /** * @test */ @@ -44,7 +43,7 @@ public function shouldJSONEncodeGraphQLVariables() $api->method('post') ->with('/graphql', $this->equalTo([ 'query'=>'bar', - 'variables' => '{"variable":"foo"}' + 'variables' => '{"variable":"foo"}', ])); $api->execute('bar', ['variable' => 'foo']); diff --git a/test/Github/Tests/Api/Issue/AssigneesTest.php b/test/Github/Tests/Api/Issue/AssigneesTest.php index a3cfe0f6066..8777f0923b2 100644 --- a/test/Github/Tests/Api/Issue/AssigneesTest.php +++ b/test/Github/Tests/Api/Issue/AssigneesTest.php @@ -39,7 +39,7 @@ public function shouldCheckAssignee() */ public function shouldNotAddAssigneeMissingParameter() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -53,9 +53,9 @@ public function shouldNotAddAssigneeMissingParameter() */ public function shouldAddAssignee() { - $data = array( - 'assignees' => array('test-user') - ); + $data = [ + 'assignees' => ['test-user'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -71,7 +71,7 @@ public function shouldAddAssignee() */ public function shouldNotRemoveAssigneeMissingParameter() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -85,9 +85,9 @@ public function shouldNotRemoveAssigneeMissingParameter() */ public function shouldRemoveAssignee() { - $data = array( - 'assignees' => array('test-user') - ); + $data = [ + 'assignees' => ['test-user'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index daa7207c37f..51c67fe8f85 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -11,12 +11,12 @@ class CommentsTest extends TestCase */ public function shouldGetAllIssueComments() { - $expectedValue = array(array('comment1data'), array('comment2data')); + $expectedValue = [['comment1data'], ['comment2data']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/issues/123/comments', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/issues/123/comments', ['page' => 1]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); @@ -27,7 +27,7 @@ public function shouldGetAllIssueComments() */ public function shouldShowIssueComment() { - $expectedValue = array('comment1'); + $expectedValue = ['comment1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -44,7 +44,7 @@ public function shouldShowIssueComment() */ public function shouldNotCreateWithoutBody() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -58,8 +58,8 @@ public function shouldNotCreateWithoutBody() */ public function shouldCreateIssueComment() { - $expectedValue = array('comment1data'); - $data = array('body' => 'test body'); + $expectedValue = ['comment1data']; + $data = ['body' => 'test body']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -76,7 +76,7 @@ public function shouldCreateIssueComment() */ public function shouldNotUpdateWithoutBody() { - $data = array('somedata'); + $data = ['somedata']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -90,8 +90,8 @@ public function shouldNotUpdateWithoutBody() */ public function shouldUpdateIssueComment() { - $expectedValue = array('comment1data'); - $data = array('body' => 'body test'); + $expectedValue = ['comment1data']; + $data = ['body' => 'body test']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldUpdateIssueComment() */ public function shouldRemoveComment() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Issue/EventsTest.php b/test/Github/Tests/Api/Issue/EventsTest.php index 6e965c5ff22..37139936c63 100644 --- a/test/Github/Tests/Api/Issue/EventsTest.php +++ b/test/Github/Tests/Api/Issue/EventsTest.php @@ -11,12 +11,12 @@ class EventsTest extends TestCase */ public function shouldGetAllRepoIssuesEvents() { - $expectedValue = array(array('event1data'), array('event2data')); + $expectedValue = [['event1data'], ['event2data']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/issues/events', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/issues/events', ['page' => 1]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -27,12 +27,12 @@ public function shouldGetAllRepoIssuesEvents() */ public function shouldGetIssueEvents() { - $expectedValue = array(array('event1data'), array('event2data')); + $expectedValue = [['event1data'], ['event2data']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/issues/123/events', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/issues/123/events', ['page' => 1]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); @@ -43,7 +43,7 @@ public function shouldGetIssueEvents() */ public function shouldShowIssueEvent() { - $expectedValue = array('event1'); + $expectedValue = ['event1']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index 5be4e21254d..af8f14c67cb 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -11,15 +11,15 @@ class LabelsTest extends TestCase */ public function shouldGetProjectLabels() { - $expectedValue = array( - array('name' => 'l3l0repo'), - array('name' => 'other'), - ); + $expectedValue = [ + ['name' => 'l3l0repo'], + ['name' => 'other'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/labels', array()) + ->with('/repos/KnpLabs/php-github-api/labels', []) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -30,7 +30,7 @@ public function shouldGetProjectLabels() */ public function shouldGetAllIssueLabels() { - $expectedValue = array(array('name' => 'label')); + $expectedValue = [['name' => 'label']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -46,13 +46,13 @@ public function shouldGetAllIssueLabels() */ public function shouldCreateLabel() { - $expectedValue = array(array('name' => 'label', 'color' => 'FFFFFF')); - $data = array('name' => 'label'); + $expectedValue = [['name' => 'label', 'color' => 'FFFFFF']]; + $data = ['name' => 'label']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/labels', $data + array('color' => 'FFFFFF')) + ->with('/repos/KnpLabs/php-github-api/labels', $data + ['color' => 'FFFFFF']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); @@ -63,7 +63,7 @@ public function shouldCreateLabel() */ public function shouldGetSingleLabel() { - $expectedValue = array(array('name' => 'label1')); + $expectedValue = [['name' => 'label1']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -79,8 +79,8 @@ public function shouldGetSingleLabel() */ public function shouldCreateLabelWithColor() { - $expectedValue = array(array('name' => 'label', 'color' => '111111')); - $data = array('name' => 'label', 'color' => '111111'); + $expectedValue = [['name' => 'label', 'color' => '111111']]; + $data = ['name' => 'label', 'color' => '111111']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -96,7 +96,7 @@ public function shouldCreateLabelWithColor() */ public function shouldDeleteLabel() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -112,8 +112,8 @@ public function shouldDeleteLabel() */ public function shouldUpdateLabel() { - $expectedValue = array(array('name' => 'bar', 'color' => 'FFF')); - $data = array('name' => 'bar', 'color' => 'FFF'); + $expectedValue = [['name' => 'bar', 'color' => 'FFF']]; + $data = ['name' => 'bar', 'color' => 'FFF']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -129,7 +129,7 @@ public function shouldUpdateLabel() */ public function shouldRemoveLabel() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -145,12 +145,12 @@ public function shouldRemoveLabel() */ public function shouldAddOneLabel() { - $expectedValue = array('label' => 'somename'); + $expectedValue = ['label' => 'somename']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/issues/123/labels', array('labelname')) + ->with('/repos/KnpLabs/php-github-api/issues/123/labels', ['labelname']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->add('KnpLabs', 'php-github-api', 123, 'labelname')); @@ -161,15 +161,15 @@ public function shouldAddOneLabel() */ public function shouldAddManyLabels() { - $expectedValue = array('label' => 'somename'); + $expectedValue = ['label' => 'somename']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/issues/123/labels', array('labelname', 'labelname2')) + ->with('/repos/KnpLabs/php-github-api/issues/123/labels', ['labelname', 'labelname2']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->add('KnpLabs', 'php-github-api', 123, array('labelname', 'labelname2'))); + $this->assertEquals($expectedValue, $api->add('KnpLabs', 'php-github-api', 123, ['labelname', 'labelname2'])); } /** @@ -177,8 +177,8 @@ public function shouldAddManyLabels() */ public function shouldReplaceLabels() { - $expectedValue = array(array('label' => 'somename')); - $data = array('labels' => array('labelname')); + $expectedValue = [['label' => 'somename']]; + $data = ['labels' => ['labelname']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -199,7 +199,7 @@ public function shouldNotAddWhenDoNotHaveLabelsToAdd() $api->expects($this->any()) ->method('post'); - $api->add('KnpLabs', 'php-github-api', 123, array()); + $api->add('KnpLabs', 'php-github-api', 123, []); } /** @@ -207,7 +207,7 @@ public function shouldNotAddWhenDoNotHaveLabelsToAdd() */ public function shouldClearLabels() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Issue/MilestonesTest.php b/test/Github/Tests/Api/Issue/MilestonesTest.php index 74f7b50fcda..18963580b8a 100644 --- a/test/Github/Tests/Api/Issue/MilestonesTest.php +++ b/test/Github/Tests/Api/Issue/MilestonesTest.php @@ -11,12 +11,12 @@ class MilestonesTest extends TestCase */ public function shouldGetMilestones() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) + ->with('/repos/KnpLabs/php-github-api/milestones', ['page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -27,8 +27,8 @@ public function shouldGetMilestones() */ public function shouldCreateMilestone() { - $expectedValue = array(array('title' => 'milestone')); - $data = array('title' => 'milestone'); + $expectedValue = [['title' => 'milestone']]; + $data = ['title' => 'milestone']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -45,8 +45,8 @@ public function shouldCreateMilestone() */ public function shouldNotCreateMilestoneWithoutTitle() { - $expectedValue = array(array('title' => 'milestone')); - $data = array(); + $expectedValue = [['title' => 'milestone']]; + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -60,15 +60,15 @@ public function shouldNotCreateMilestoneWithoutTitle() */ public function shouldSetStateToOpenWhileCreationWhenStateParamNotRecognized() { - $expectedValue = array('title' => 'l3l0repo'); + $expectedValue = ['title' => 'l3l0repo']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/milestones', array('state' => 'open', 'title' => 'milestone')) + ->with('/repos/KnpLabs/php-github-api/milestones', ['state' => 'open', 'title' => 'milestone']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', array('state' => 'clos', 'title' => 'milestone'))); + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', ['state' => 'clos', 'title' => 'milestone'])); } /** @@ -76,13 +76,13 @@ public function shouldSetStateToOpenWhileCreationWhenStateParamNotRecognized() */ public function shouldUpdateMilestone() { - $expectedValue = array(array('title' => 'milestone')); - $data = array('title' => 'milestone'); + $expectedValue = [['title' => 'milestone']]; + $data = ['title' => 'milestone']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/KnpLabs/php-github-api/milestones/123', array('title' => 'milestone')) + ->with('/repos/KnpLabs/php-github-api/milestones/123', ['title' => 'milestone']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -93,8 +93,8 @@ public function shouldUpdateMilestone() */ public function shouldUpdateMilestoneWithClosedStatus() { - $expectedValue = array(array('title' => 'milestone')); - $data = array('title' => 'milestone', 'status' => 'closed'); + $expectedValue = [['title' => 'milestone']]; + $data = ['title' => 'milestone', 'status' => 'closed']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -110,13 +110,13 @@ public function shouldUpdateMilestoneWithClosedStatus() */ public function shouldSetStateToOpenWhileUpdateWhenStateParamNotRecognized() { - $expectedValue = array('title' => 'l3l0repo'); - $data = array('title' => 'milestone', 'state' => 'some'); + $expectedValue = ['title' => 'l3l0repo']; + $data = ['title' => 'milestone', 'state' => 'some']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/KnpLabs/php-github-api/milestones/123', array('state' => 'open', 'title' => 'milestone')) + ->with('/repos/KnpLabs/php-github-api/milestones/123', ['state' => 'open', 'title' => 'milestone']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); @@ -127,15 +127,15 @@ public function shouldSetStateToOpenWhileUpdateWhenStateParamNotRecognized() */ public function shouldSortByDueDateWhenSortParamNotRecognized() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) + ->with('/repos/KnpLabs/php-github-api/milestones', ['page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('sort' => 'completenes'))); + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', ['sort' => 'completenes'])); } /** @@ -143,15 +143,15 @@ public function shouldSortByDueDateWhenSortParamNotRecognized() */ public function shouldSetStateToOpenWhenStateParamNotRecognized() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) + ->with('/repos/KnpLabs/php-github-api/milestones', ['page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('state' => 'clos'))); + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', ['state' => 'clos'])); } /** @@ -159,15 +159,15 @@ public function shouldSetStateToOpenWhenStateParamNotRecognized() */ public function shouldSetDirectionToDescWhenDirectionParamNotRecognized() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/milestones', array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc')) + ->with('/repos/KnpLabs/php-github-api/milestones', ['page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'asc']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('direction' => 'asc'))); + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', ['direction' => 'asc'])); } /** @@ -175,7 +175,7 @@ public function shouldSetDirectionToDescWhenDirectionParamNotRecognized() */ public function shouldRemoveMilestones() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -191,7 +191,7 @@ public function shouldRemoveMilestones() */ public function shouldShowMilestone() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -207,7 +207,7 @@ public function shouldShowMilestone() */ public function shouldGetMilestoneLabels() { - $expectedValue = array(array('label'), array('label2')); + $expectedValue = [['label'], ['label2']]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Issue/TimelineTest.php b/test/Github/Tests/Api/Issue/TimelineTest.php index 43bd991f279..401219af32b 100644 --- a/test/Github/Tests/Api/Issue/TimelineTest.php +++ b/test/Github/Tests/Api/Issue/TimelineTest.php @@ -11,21 +11,20 @@ class TimelineTest extends TestCase */ public function shouldGetIssueEvents() { - $expectedValue = array( + $expectedValue = [ 'event1', 'event2', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/issues/123/timeline', array()) + ->with('/repos/KnpLabs/php-github-api/issues/123/timeline', []) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); } - /** * @return string */ diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 545c5184be5..2fed3618853 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -9,12 +9,12 @@ class IssueTest extends TestCase */ public function shouldGetIssues() { - $data = array( - 'state' => 'open' - ); - $sentData = $data + array( - 'page' => 1 - ); + $data = [ + 'state' => 'open', + ]; + $sentData = $data + [ + 'page' => 1, + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -29,19 +29,19 @@ public function shouldGetIssues() */ public function shouldGetIssuesUsingAdditionalParameters() { - $expectedArray = array(array('id' => '123')); - $data = array( + $expectedArray = [['id' => '123']]; + $data = [ 'state' => 'open', 'milestone' => '*', 'assignee' => 'l3l0', 'mentioned' => 'l3l0', 'labels' => 'bug,@high', 'sort' => 'created', - 'direction' => 'asc' - ); - $sentData = $data + array( - 'page' => 1 - ); + 'direction' => 'asc', + ]; + $sentData = $data + [ + 'page' => 1, + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -57,7 +57,7 @@ public function shouldGetIssuesUsingAdditionalParameters() */ public function shouldShowIssue() { - $expectedArray = array('id' => '123'); + $expectedArray = ['id' => '123']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -73,10 +73,10 @@ public function shouldShowIssue() */ public function shouldCreateIssue() { - $data = array( + $data = [ 'title' => 'some title', - 'body' => 'some body' - ); + 'body' => 'some body', + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -92,9 +92,9 @@ public function shouldCreateIssue() */ public function shouldNotCreateIssueWithoutTitle() { - $data = array( - 'body' => 'some body' - ); + $data = [ + 'body' => 'some body', + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -108,9 +108,9 @@ public function shouldNotCreateIssueWithoutTitle() */ public function shouldCreateIssueWithoutBody() { - $data = array( - 'title' => 'some title' - ); + $data = [ + 'title' => 'some title', + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -125,9 +125,9 @@ public function shouldCreateIssueWithoutBody() */ public function shouldCloseIssue() { - $data = array( + $data = [ 'state' => 'closed', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -142,9 +142,9 @@ public function shouldCloseIssue() */ public function shouldReOpenIssue() { - $data = array( + $data = [ 'state' => 'open', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -159,7 +159,7 @@ public function shouldReOpenIssue() */ public function shouldSearchOpenIssues() { - $expectedArray = array(array('id' => '123')); + $expectedArray = [['id' => '123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -175,7 +175,7 @@ public function shouldSearchOpenIssues() */ public function shouldSearchClosedIssues() { - $expectedArray = array(array('id' => '123')); + $expectedArray = [['id' => '123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -191,7 +191,7 @@ public function shouldSearchClosedIssues() */ public function shouldSearchOpenIssuesWhenStateNotRecognized() { - $expectedArray = array(array('id' => '123')); + $expectedArray = [['id' => '123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -257,7 +257,7 @@ public function shouldGetTimelineApiObject() */ public function shouldLockIssue() { - $parameters = array(); + $parameters = []; $api = $this->getApiMock(); $api->expects($this->once()) @@ -272,7 +272,7 @@ public function shouldLockIssue() */ public function shouldUnlockIssue() { - $parameters = array(); + $parameters = []; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/MetaTest.php b/test/Github/Tests/Api/MetaTest.php index 57e2cac8bac..9275e5a1f1b 100644 --- a/test/Github/Tests/Api/MetaTest.php +++ b/test/Github/Tests/Api/MetaTest.php @@ -9,15 +9,15 @@ class MetaTest extends TestCase */ public function shouldGetInformationService() { - $expectedArray = array( - 'hooks' => array( - '127.0.0.1/32' - ), - 'git' => array( - '127.0.0.1/32' - ), - 'verifiable_password_authentication' => true - ); + $expectedArray = [ + 'hooks' => [ + '127.0.0.1/32', + ], + 'git' => [ + '127.0.0.1/32', + ], + 'verifiable_password_authentication' => true, + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Miscellaneous/EmojisTest.php b/test/Github/Tests/Api/Miscellaneous/EmojisTest.php index 63bac291e94..b4408b80aa1 100644 --- a/test/Github/Tests/Api/Miscellaneous/EmojisTest.php +++ b/test/Github/Tests/Api/Miscellaneous/EmojisTest.php @@ -12,10 +12,10 @@ class EmojisTest extends TestCase */ public function shouldGetAllEmojis() { - $expectedArray = array( + $expectedArray = [ '+1' => 'https://github.global.ssl.fastly.net/images/icons/emoji/+1.png?v5', '-1' => 'https://github.global.ssl.fastly.net/images/icons/emoji/-1.png?v5', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php b/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php index 9fbd0ef4fc4..6a244adaef5 100644 --- a/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php +++ b/test/Github/Tests/Api/Miscellaneous/GitignoreTest.php @@ -2,7 +2,6 @@ namespace Github\Tests\Api\Miscellaneous; -use Github\Api\Miscellaneous\Emojis; use Github\Api\Miscellaneous\Gitignore; use Github\Tests\Api\TestCase; @@ -13,15 +12,15 @@ class GitignoreTest extends TestCase */ public function shouldGetAllTemplates() { - $expectedArray = array( + $expectedArray = [ 'Actionscript', 'Android', 'AppceleratorTitanium', 'Autotools', 'Bancha', 'C', - 'C++' - ); + 'C++', + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -37,10 +36,10 @@ public function shouldGetAllTemplates() */ public function shouldGetTemplate() { - $expectedArray = array( + $expectedArray = [ 'name' => 'C', - 'source' => "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a" - ); + 'source' => "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a", + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php b/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php index 14cb9bf439a..b327a1b83c8 100644 --- a/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php +++ b/test/Github/Tests/Api/Miscellaneous/MarkdownTest.php @@ -11,12 +11,12 @@ class MarkdownTest extends TestCase */ public function shouldRenderMarkdown() { - $input = 'Hello world github/linguist#1 **cool**, and #1!'; + $input = 'Hello world github/linguist#1 **cool**, and #1!'; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/markdown', array('text' => $input, 'mode' => 'markdown')); + ->with('/markdown', ['text' => $input, 'mode' => 'markdown']); $api->render($input); } @@ -26,12 +26,12 @@ public function shouldRenderMarkdown() */ public function shouldRenderMarkdownUsingGfmMode() { - $input = 'Hello world github/linguist#1 **cool**, and #1!'; + $input = 'Hello world github/linguist#1 **cool**, and #1!'; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/markdown', array('text' => $input, 'mode' => 'gfm')); + ->with('/markdown', ['text' => $input, 'mode' => 'gfm']); $api->render($input, 'gfm'); } @@ -41,12 +41,12 @@ public function shouldRenderMarkdownUsingGfmMode() */ public function shouldSetModeToMarkdownWhenIsNotRecognized() { - $input = 'Hello world github/linguist#1 **cool**, and #1!'; + $input = 'Hello world github/linguist#1 **cool**, and #1!'; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/markdown', array('text' => $input, 'mode' => 'markdown')); + ->with('/markdown', ['text' => $input, 'mode' => 'markdown']); $api->render($input, 'abc'); } @@ -56,17 +56,17 @@ public function shouldSetModeToMarkdownWhenIsNotRecognized() */ public function shouldSetContextOnlyForGfmMode() { - $input = 'Hello world github/linguist#1 **cool**, and #1!'; + $input = 'Hello world github/linguist#1 **cool**, and #1!'; $apiWithMarkdown = $this->getApiMock(); $apiWithMarkdown->expects($this->once()) ->method('post') - ->with('/markdown', array('text' => $input, 'mode' => 'markdown')); + ->with('/markdown', ['text' => $input, 'mode' => 'markdown']); $apiWithGfm = $this->getApiMock(); $apiWithGfm->expects($this->once()) ->method('post') - ->with('/markdown', array('text' => $input, 'mode' => 'gfm', 'context' => 'someContext')); + ->with('/markdown', ['text' => $input, 'mode' => 'gfm', 'context' => 'someContext']); $apiWithMarkdown->render($input, 'markdown', 'someContext'); $apiWithGfm->render($input, 'gfm', 'someContext'); @@ -77,12 +77,12 @@ public function shouldSetContextOnlyForGfmMode() */ public function shouldRenderRawFile() { - $file = 'file'; + $file = 'file'; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/markdown/raw', array('file' => $file)); + ->with('/markdown/raw', ['file' => $file]); $api->renderRaw($file); } diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index 0f2616996e2..5cbf7fabc11 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -11,10 +11,10 @@ class NotificationTest extends TestCase */ public function shouldGetNotifications() { - $parameters = array( + $parameters = [ 'all' => false, 'participating' => false, - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -31,11 +31,11 @@ public function shouldGetNotificationsSince() { $since = new DateTime('now'); - $parameters = array( + $parameters = [ 'all' => false, 'participating' => false, 'since' => $since->format(DateTime::ISO8601), - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -50,10 +50,10 @@ public function shouldGetNotificationsSince() */ public function shouldGetNotificationsIncludingAndParticipating() { - $parameters = array( + $parameters = [ 'all' => true, 'participating' => true, - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -68,7 +68,7 @@ public function shouldGetNotificationsIncludingAndParticipating() */ public function shouldMarkNotificationsAsRead() { - $parameters = array(); + $parameters = []; $api = $this->getApiMock(); $api->expects($this->once()) @@ -85,9 +85,9 @@ public function shouldMarkNotificationsAsReadForGivenDate() { $since = new DateTime('now'); - $parameters = array( + $parameters = [ 'last_read_at' => $since->format(DateTime::ISO8601), - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -96,7 +96,7 @@ public function shouldMarkNotificationsAsReadForGivenDate() $api->markRead($since); } - + public function shouldGetNotification() { $id = mt_rand(1, time()); diff --git a/test/Github/Tests/Api/Organization/HooksTest.php b/test/Github/Tests/Api/Organization/HooksTest.php index f61b4b54302..5c905ece70f 100644 --- a/test/Github/Tests/Api/Organization/HooksTest.php +++ b/test/Github/Tests/Api/Organization/HooksTest.php @@ -11,7 +11,7 @@ class HooksTest extends TestCase */ public function shouldGetAllOrganizationsHooks() { - $expectedValue = array(array('name' => 'hook')); + $expectedValue = [['name' => 'hook']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllOrganizationsHooks() */ public function shouldShowHook() { - $expectedValue = array('hook' => 'somename'); + $expectedValue = ['hook' => 'somename']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldShowHook() */ public function shouldRemoveHook() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,7 +60,7 @@ public function shouldRemoveHook() */ public function shouldNotCreateHookWithoutName() { - $data = array('config' => 'conf'); + $data = ['config' => 'conf']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -75,7 +75,7 @@ public function shouldNotCreateHookWithoutName() */ public function shouldNotCreateHookWithoutConfig() { - $data = array('name' => 'test'); + $data = ['name' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -89,8 +89,8 @@ public function shouldNotCreateHookWithoutConfig() */ public function shouldCreateHook() { - $expectedValue = array('hook' => 'somename'); - $data = array('name' => 'test', 'config' => 'someconfig'); + $expectedValue = ['hook' => 'somename']; + $data = ['name' => 'test', 'config' => 'someconfig']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldCreateHook() */ public function shouldNotUpdateHookWithoutConfig() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -121,8 +121,8 @@ public function shouldNotUpdateHookWithoutConfig() */ public function shouldUpdateHook() { - $expectedValue = array('hook' => 'somename'); - $data = array('config' => 'config'); + $expectedValue = ['hook' => 'somename']; + $data = ['config' => 'config']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Organization/MembersTest.php b/test/Github/Tests/Api/Organization/MembersTest.php index 19f072e14ef..58ff1ea3c08 100644 --- a/test/Github/Tests/Api/Organization/MembersTest.php +++ b/test/Github/Tests/Api/Organization/MembersTest.php @@ -11,7 +11,7 @@ class MembersTest extends TestCase */ public function shouldGetAllOrganizationMembers() { - $expectedValue = array(array('username' => 'l3l0')); + $expectedValue = [['username' => 'l3l0']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllOrganizationMembers() */ public function shouldGetPublicOrganizationMembers() { - $expectedValue = array(array('username' => 'l3l0')); + $expectedValue = [['username' => 'l3l0']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -123,7 +123,7 @@ public function shouldConcealOrganizationMembership() */ public function shouldShowOrganizationMember() { - $expectedValue = array('username' => 'l3l0'); + $expectedValue = ['username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Organization/ProjectsTest.php b/test/Github/Tests/Api/Organization/ProjectsTest.php index 1415949a343..8ac5bf52229 100644 --- a/test/Github/Tests/Api/Organization/ProjectsTest.php +++ b/test/Github/Tests/Api/Organization/ProjectsTest.php @@ -11,7 +11,7 @@ class ProjectsTest extends TestCase */ public function shouldGetAllRepositoryProjects() { - $expectedValue = array(array('name' => 'Test project 1')); + $expectedValue = [['name' => 'Test project 1']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -28,7 +28,7 @@ public function shouldGetAllRepositoryProjects() */ public function shouldNotCreateWithoutName() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -42,8 +42,8 @@ public function shouldNotCreateWithoutName() */ public function shouldCreateColumn() { - $expectedValue = array('project1data'); - $data = array('name' => 'Project 1'); + $expectedValue = ['project1data']; + $data = ['name' => 'Project 1']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 44cb781c8ce..4cff3609764 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -11,7 +11,7 @@ class TeamsTest extends TestCase */ public function shouldGetAllOrganizationTeams() { - $expectedValue = array(array('name' => 'KnpWorld'), array('name' => 'KnpFrance'), array('name' => 'KnpMontreal')); + $expectedValue = [['name' => 'KnpWorld'], ['name' => 'KnpFrance'], ['name' => 'KnpMontreal']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -59,7 +59,7 @@ public function shouldRemoveOrganizationTeam() */ public function shouldShowOrganizationTeam() { - $expectedValue = array('username' => 'l3l0'); + $expectedValue = ['username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -75,7 +75,7 @@ public function shouldShowOrganizationTeam() */ public function shouldGetTeamMembers() { - $expectedValue = array(array('username' => 'l3l0')); + $expectedValue = [['username' => 'l3l0']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -91,7 +91,7 @@ public function shouldGetTeamMembers() */ public function shouldAddTeamMembers() { - $expectedValue = array('username' => 'l3l0'); + $expectedValue = ['username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldAddTeamMembers() */ public function shouldRemoveTeamMembers() { - $expectedValue = array('username' => 'l3l0'); + $expectedValue = ['username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -123,7 +123,7 @@ public function shouldRemoveTeamMembers() */ public function shouldGetTeamRepositories() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -139,7 +139,7 @@ public function shouldGetTeamRepositories() */ public function shouldGetTeamRepository() { - $expectedValue = array('name' => 'l3l0repo'); + $expectedValue = ['name' => 'l3l0repo']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -155,7 +155,7 @@ public function shouldGetTeamRepository() */ public function shouldAddTeamRepository() { - $expectedValue = array('name' => 'l3l0repo'); + $expectedValue = ['name' => 'l3l0repo']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -171,7 +171,7 @@ public function shouldAddTeamRepository() */ public function shouldRemoveTeamRepository() { - $expectedValue = array('name' => 'l3l0repo'); + $expectedValue = ['name' => 'l3l0repo']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -188,7 +188,7 @@ public function shouldRemoveTeamRepository() */ public function shouldNotCreateTeamWithoutName() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -202,8 +202,8 @@ public function shouldNotCreateTeamWithoutName() */ public function shouldCreateOrganizationTeam() { - $expectedValue = array('name' => 'KnpWorld'); - $data = array('name' => 'KnpWorld'); + $expectedValue = ['name' => 'KnpWorld']; + $data = ['name' => 'KnpWorld']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -219,13 +219,13 @@ public function shouldCreateOrganizationTeam() */ public function shouldCreateOrganizationTeamWithRepoName() { - $expectedValue = array('name' => 'KnpWorld'); - $data = array('name' => 'KnpWorld', 'repo_names' => 'somerepo'); + $expectedValue = ['name' => 'KnpWorld']; + $data = ['name' => 'KnpWorld', 'repo_names' => 'somerepo']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/orgs/KnpLabs/teams', array('name' => 'KnpWorld', 'repo_names' => array('somerepo'))) + ->with('/orgs/KnpLabs/teams', ['name' => 'KnpWorld', 'repo_names' => ['somerepo']]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); @@ -236,13 +236,13 @@ public function shouldCreateOrganizationTeamWithRepoName() */ public function shouldCreateWithPullPermissionWhenPermissionParamNotRecognized() { - $expectedValue = array('name' => 'KnpWorld'); - $data = array('name' => 'KnpWorld', 'permission' => 'someinvalid'); + $expectedValue = ['name' => 'KnpWorld']; + $data = ['name' => 'KnpWorld', 'permission' => 'someinvalid']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/orgs/KnpLabs/teams', array('name' => 'KnpWorld', 'permission' => 'pull')) + ->with('/orgs/KnpLabs/teams', ['name' => 'KnpWorld', 'permission' => 'pull']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); @@ -254,7 +254,7 @@ public function shouldCreateWithPullPermissionWhenPermissionParamNotRecognized() */ public function shouldNotUpdateTeamWithoutName() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -268,8 +268,8 @@ public function shouldNotUpdateTeamWithoutName() */ public function shouldUpdateOrganizationTeam() { - $expectedValue = array('name' => 'KnpWorld'); - $data = array('name' => 'KnpWorld'); + $expectedValue = ['name' => 'KnpWorld']; + $data = ['name' => 'KnpWorld']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -285,13 +285,13 @@ public function shouldUpdateOrganizationTeam() */ public function shouldUpdateWithPullPermissionWhenPermissionParamNotRecognized() { - $expectedValue = array('name' => 'KnpWorld'); - $data = array('name' => 'KnpWorld', 'permission' => 'someinvalid'); + $expectedValue = ['name' => 'KnpWorld']; + $data = ['name' => 'KnpWorld', 'permission' => 'someinvalid']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/teams/KnpWorld', array('name' => 'KnpWorld', 'permission' => 'pull')) + ->with('/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull']) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 2090827655a..04f389c0337 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -9,7 +9,7 @@ class OrganizationTest extends TestCase */ public function shouldGetAllOrganizations() { - $expectedValue = array(array('login' => 'KnpLabs')); + $expectedValue = [['login' => 'KnpLabs']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,7 +25,7 @@ public function shouldGetAllOrganizations() */ public function shouldShowOrganization() { - $expectedArray = array('id' => 1, 'name' => 'KnpLabs'); + $expectedArray = ['id' => 1, 'name' => 'KnpLabs']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -41,15 +41,15 @@ public function shouldShowOrganization() */ public function shouldUpdateOrganization() { - $expectedArray = array('id' => 1, 'name' => 'KnpLabs'); + $expectedArray = ['id' => 1, 'name' => 'KnpLabs']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/orgs/KnpLabs', array('value' => 'toUpdate')) + ->with('/orgs/KnpLabs', ['value' => 'toUpdate']) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->update('KnpLabs', array('value' => 'toUpdate'))); + $this->assertEquals($expectedArray, $api->update('KnpLabs', ['value' => 'toUpdate'])); } /** @@ -57,12 +57,12 @@ public function shouldUpdateOrganization() */ public function shouldGetOrganizationRepositories() { - $expectedArray = array(array('id' => 1, 'username' => 'KnpLabs', 'name' => 'php-github-api')); + $expectedArray = [['id' => 1, 'username' => 'KnpLabs', 'name' => 'php-github-api']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/orgs/KnpLabs/repos', array('type' => 'all', 'page' => 1)) + ->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('KnpLabs')); diff --git a/test/Github/Tests/Api/Project/CardsTest.php b/test/Github/Tests/Api/Project/CardsTest.php index 0b68310274f..6195f1b3514 100644 --- a/test/Github/Tests/Api/Project/CardsTest.php +++ b/test/Github/Tests/Api/Project/CardsTest.php @@ -11,7 +11,7 @@ class CardsTest extends TestCase */ public function shouldGetAllColumnCards() { - $expectedValue = array(array('card1data'), array('card2data')); + $expectedValue = [['card1data'], ['card2data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllColumnCards() */ public function shouldShowCard() { - $expectedValue = array('card1'); + $expectedValue = ['card1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,8 +43,8 @@ public function shouldShowCard() */ public function shouldCreateCard() { - $expectedValue = array('card1data'); - $data = array('content_id' => '123', 'content_type' => 'Issue'); + $expectedValue = ['card1data']; + $data = ['content_id' => '123', 'content_type' => 'Issue']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,8 +60,8 @@ public function shouldCreateCard() */ public function shouldUpdateCard() { - $expectedValue = array('note1data'); - $data = array('note' => 'note test'); + $expectedValue = ['note1data']; + $data = ['note' => 'note test']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -77,7 +77,7 @@ public function shouldUpdateCard() */ public function shouldRemoveCard() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -94,7 +94,7 @@ public function shouldRemoveCard() */ public function shouldNotMoveWithoutPosition() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -108,8 +108,8 @@ public function shouldNotMoveWithoutPosition() */ public function shouldMoveCard() { - $expectedValue = array('card1'); - $data = array('position' => 'top'); + $expectedValue = ['card1']; + $data = ['position' => 'top']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Project/ColumnsTest.php b/test/Github/Tests/Api/Project/ColumnsTest.php index cb244623095..7ce3a1693f2 100644 --- a/test/Github/Tests/Api/Project/ColumnsTest.php +++ b/test/Github/Tests/Api/Project/ColumnsTest.php @@ -11,7 +11,7 @@ class ColumnsTest extends TestCase */ public function shouldGetAllProjectColumns() { - $expectedValue = array(array('column1data'), array('column2data')); + $expectedValue = [['column1data'], ['column2data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllProjectColumns() */ public function shouldShowColumn() { - $expectedValue = array('column1'); + $expectedValue = ['column1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -44,7 +44,7 @@ public function shouldShowColumn() */ public function shouldNotCreateWithoutName() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -58,8 +58,8 @@ public function shouldNotCreateWithoutName() */ public function shouldCreateColumn() { - $expectedValue = array('column1data'); - $data = array('name' => 'column 1'); + $expectedValue = ['column1data']; + $data = ['name' => 'column 1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -76,7 +76,7 @@ public function shouldCreateColumn() */ public function shouldNotUpdateWithoutName() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -90,8 +90,8 @@ public function shouldNotUpdateWithoutName() */ public function shouldUpdateColumn() { - $expectedValue = array('column1data'); - $data = array('name' => 'column 1 update'); + $expectedValue = ['column1data']; + $data = ['name' => 'column 1 update']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldUpdateColumn() */ public function shouldRemoveCard() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -124,7 +124,7 @@ public function shouldRemoveCard() */ public function shouldNotMoveWithoutPosition() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -138,8 +138,8 @@ public function shouldNotMoveWithoutPosition() */ public function shouldMoveCard() { - $expectedValue = array('card1'); - $data = array('position' => 'first'); + $expectedValue = ['card1']; + $data = ['position' => 'first']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Project/ProjectsTest.php b/test/Github/Tests/Api/Project/ProjectsTest.php index 3278b6b0ee1..0dc7e2645a5 100644 --- a/test/Github/Tests/Api/Project/ProjectsTest.php +++ b/test/Github/Tests/Api/Project/ProjectsTest.php @@ -12,7 +12,7 @@ class ProjectsTest extends TestCase */ public function shouldShowProject() { - $expectedValue = array('name' => 'Test project 1'); + $expectedValue = ['name' => 'Test project 1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -28,8 +28,8 @@ public function shouldShowProject() */ public function shouldUpdateProject() { - $expectedValue = array('project1data'); - $data = array('name' => 'Project 1 update'); + $expectedValue = ['project1data']; + $data = ['name' => 'Project 1 update']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -45,7 +45,7 @@ public function shouldUpdateProject() */ public function shouldRemoveProject() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/PullRequest/CommentsTest.php b/test/Github/Tests/Api/PullRequest/CommentsTest.php index a6213a168cc..872934260d1 100644 --- a/test/Github/Tests/Api/PullRequest/CommentsTest.php +++ b/test/Github/Tests/Api/PullRequest/CommentsTest.php @@ -3,7 +3,6 @@ namespace Github\Tests\Api\PullRequest; use Github\Api\PullRequest\Comments; -use Github\Api\PullRequest\ReviewComment; use Github\Tests\Api\TestCase; class CommentsTest extends TestCase diff --git a/test/Github/Tests/Api/PullRequest/ReviewTest.php b/test/Github/Tests/Api/PullRequest/ReviewTest.php index 441240ecfd3..24e212cde42 100644 --- a/test/Github/Tests/Api/PullRequest/ReviewTest.php +++ b/test/Github/Tests/Api/PullRequest/ReviewTest.php @@ -33,7 +33,7 @@ public function shouldGetAllReviewsForAPullRequest() 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', 'received_events_url' => 'https://api.github.com/users/octocat/received_events', 'type' => 'User', - 'site_admin' => false + 'site_admin' => false, ], 'body' => 'Here is the body for the review.', 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', @@ -42,10 +42,10 @@ public function shouldGetAllReviewsForAPullRequest() 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', '_links' => [ 'html' => [ - 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', ], 'pull_request' => [ - 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', ], ], ], @@ -85,7 +85,7 @@ public function shouldShowReview() 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', 'received_events_url' => 'https://api.github.com/users/octocat/received_events', 'type' => 'User', - 'site_admin' => false + 'site_admin' => false, ], 'body' => 'Here is the body for the review.', 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', @@ -94,10 +94,10 @@ public function shouldShowReview() 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', '_links' => [ 'html' => [ - 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', ], 'pull_request' => [ - 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', ], ], ]; @@ -133,48 +133,48 @@ public function shouldShowReviewComments() { $expectedValue = [ [ - "url" => "https://api.github.com/repos/octocat/Hello-World/pulls/comments/1", - "id" => 1, - "pull_request_review_id" => 42, - "diff_hunk" => "@@ -16,33 +16,40 @@ public class Connection => IConnection...", - "path" => "file1.txt", - "position" => 1, - "original_position" => 4, - "commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e", - "original_commit_id" => "9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840", - "user" => [ - "login" => "octocat", - "id" => 1, - "avatar_url" => "https://github.com/images/error/octocat_happy.gif", - "gravatar_id" => "", - "url" => "https://api.github.com/users/octocat", - "html_url" => "https://github.com/octocat", - "followers_url" => "https://api.github.com/users/octocat/followers", - "following_url" => "https://api.github.com/users/octocat/following[/other_user]", - "gists_url" => "https://api.github.com/users/octocat/gists[/gist_id]", - "starred_url" => "https://api.github.com/users/octocat/starred[/owner][/repo]", - "subscriptions_url" => "https://api.github.com/users/octocat/subscriptions", - "organizations_url" => "https://api.github.com/users/octocat/orgs", - "repos_url" => "https://api.github.com/users/octocat/repos", - "events_url" => "https://api.github.com/users/octocat/events[/privacy]", - "received_events_url" => "https://api.github.com/users/octocat/received_events", - "type" => "User", - "site_admin" => false, + 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', + 'id' => 1, + 'pull_request_review_id' => 42, + 'diff_hunk' => '@@ -16,33 +16,40 @@ public class Connection => IConnection...', + 'path' => 'file1.txt', + 'position' => 1, + 'original_position' => 4, + 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'original_commit_id' => '9c48853fa3dc5c1c3d6f1f1cd1f2743e72652840', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following[/other_user]', + 'gists_url' => 'https://api.github.com/users/octocat/gists[/gist_id]', + 'starred_url' => 'https://api.github.com/users/octocat/starred[/owner][/repo]', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events[/privacy]', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, ], - "body" => "Great stuff", - "created_at" => "2011-04-14T16:00:49Z", - "updated_at" => "2011-04-14T16:00:49Z", - "html_url" => "https://github.com/octocat/Hello-World/pull/1#discussion-diff-1", - "pull_request_url" => "https://api.github.com/repos/octocat/Hello-World/pulls/1", - "_links" => [ - "self" => [ - "href" => "https://api.github.com/repos/octocat/Hello-World/pulls/comments/1", + 'body' => 'Great stuff', + 'created_at' => '2011-04-14T16:00:49Z', + 'updated_at' => '2011-04-14T16:00:49Z', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', + '_links' => [ + 'self' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', ], - "html" => [ - "href" => "https://github.com/octocat/Hello-World/pull/1#discussion-diff-1", + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/1#discussion-diff-1', ], - "pull_request" => [ - "href" => "https://api.github.com/repos/octocat/Hello-World/pulls/1", + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/1', ], ], ], @@ -273,7 +273,7 @@ public function shouldSubmitReviewComment() 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', 'received_events_url' => 'https://api.github.com/users/octocat/received_events', 'type' => 'User', - 'site_admin' => false + 'site_admin' => false, ], 'body' => 'Here is the body for the review.', 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', @@ -282,10 +282,10 @@ public function shouldSubmitReviewComment() 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', '_links' => [ 'html' => [ - 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', ], 'pull_request' => [ - 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', ], ], ]; @@ -367,7 +367,7 @@ public function shouldDismissReview() 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', 'received_events_url' => 'https://api.github.com/users/octocat/received_events', 'type' => 'User', - 'site_admin' => false + 'site_admin' => false, ], 'body' => 'Here is the body for the review.', 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', @@ -376,10 +376,10 @@ public function shouldDismissReview() 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', '_links' => [ 'html' => [ - 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80' + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', ], 'pull_request' => [ - 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12' + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', ], ], ]; diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index cfcc005599d..a3486d1f301 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -9,7 +9,7 @@ class PullRequestTest extends TestCase */ public function shouldGetAllPullRequests() { - $expectedArray = array('pr1', 'pr2'); + $expectedArray = ['pr1', 'pr2']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,15 +25,15 @@ public function shouldGetAllPullRequests() */ public function shouldGetOpenPullRequests() { - $expectedArray = array('pr1', 'pr2'); + $expectedArray = ['pr1', 'pr2']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) + ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open', 'per_page' => 30, 'page' => 1]) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'open'))); + $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'open'])); } /** @@ -41,15 +41,15 @@ public function shouldGetOpenPullRequests() */ public function shouldGetClosedPullRequests() { - $expectedArray = array('pr1', 'pr2'); + $expectedArray = ['pr1', 'pr2']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) + ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed', 'per_page' => 30, 'page' => 1]) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', array('state' => 'closed'))); + $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'closed'])); } /** @@ -57,7 +57,7 @@ public function shouldGetClosedPullRequests() */ public function shouldShowPullRequest() { - $expectedArray = array('id' => 'id', 'sha' => '123123'); + $expectedArray = ['id' => 'id', 'sha' => '123123']; $api = $this->getApiMock(); @@ -74,7 +74,7 @@ public function shouldShowPullRequest() */ public function shouldShowCommitsFromPullRequest() { - $expectedArray = array(array('id' => 'id', 'sha' => '123123')); + $expectedArray = [['id' => 'id', 'sha' => '123123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -90,7 +90,7 @@ public function shouldShowCommitsFromPullRequest() */ public function shouldShowFilesFromPullRequest() { - $expectedArray = array(array('id' => 'id', 'sha' => '123123')); + $expectedArray = [['id' => 'id', 'sha' => '123123']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -106,7 +106,7 @@ public function shouldShowFilesFromPullRequest() */ public function shouldShowStatusesFromPullRequest() { - $expectedArray = array(array('id' => 'id', 'sha' => '123123')); + $expectedArray = [['id' => 'id', 'sha' => '123123']]; $expectedArray['_links']['statuses']['href'] = '/repos/ezsystems/ezpublish/pulls/15/statuses'; $api = $this->getApiMock(); @@ -128,15 +128,15 @@ public function shouldShowStatusesFromPullRequest() */ public function shouldUpdatePullRequests() { - $expectedArray = array('id' => 15, 'sha' => '123123'); + $expectedArray = ['id' => 15, 'sha' => '123123']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/ezsystems/ezpublish/pulls/15', array('state' => 'open', 'some' => 'param')) + ->with('/repos/ezsystems/ezpublish/pulls/15', ['state' => 'open', 'some' => 'param']) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', 15, array('state' => 'aa', 'some' => 'param'))); + $this->assertEquals($expectedArray, $api->update('ezsystems', 'ezpublish', 15, ['state' => 'aa', 'some' => 'param'])); } /** @@ -144,7 +144,7 @@ public function shouldUpdatePullRequests() */ public function shouldCheckIfPullRequestIsMerged() { - $expectedArray = array('some' => 'response'); + $expectedArray = ['some' => 'response']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -160,12 +160,12 @@ public function shouldCheckIfPullRequestIsMerged() */ public function shouldMergePullRequest() { - $expectedArray = array('some' => 'response'); + $expectedArray = ['some' => 'response']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'merge')) + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', ['commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'merge']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40))); @@ -176,12 +176,12 @@ public function shouldMergePullRequest() */ public function shouldMergePullRequestWithSquashAsBool() { - $expectedArray = array('some' => 'response'); + $expectedArray = ['some' => 'response']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'squash')) + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', ['commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'squash']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40), true)); @@ -192,12 +192,12 @@ public function shouldMergePullRequestWithSquashAsBool() */ public function shouldMergePullRequestWithMergeMethod() { - $expectedArray = array('some' => 'response'); + $expectedArray = ['some' => 'response']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/repos/ezsystems/ezpublish/pulls/15/merge', array('commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'rebase')) + ->with('/repos/ezsystems/ezpublish/pulls/15/merge', ['commit_message' => 'Merged something', 'sha' => str_repeat('A', 40), 'merge_method' => 'rebase']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->merge('ezsystems', 'ezpublish', 15, 'Merged something', str_repeat('A', 40), 'rebase')); @@ -208,12 +208,12 @@ public function shouldMergePullRequestWithMergeMethod() */ public function shouldCreatePullRequestUsingTitle() { - $data = array( + $data = [ 'base' => 'master', 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', 'body' => 'BODY: Testing pull-request creation from PHP Github API', - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -228,11 +228,11 @@ public function shouldCreatePullRequestUsingTitle() */ public function shouldCreatePullRequestUsingIssueId() { - $data = array( + $data = [ 'base' => 'master', 'head' => 'virtualtestbranch', 'issue' => 25, - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -248,11 +248,11 @@ public function shouldCreatePullRequestUsingIssueId() */ public function shouldNotCreatePullRequestWithoutBase() { - $data = array( + $data = [ 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', 'body' => 'BODY: Testing pull-request creation from PHP Github API', - ); + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -267,11 +267,11 @@ public function shouldNotCreatePullRequestWithoutBase() */ public function shouldNotCreatePullRequestWithoutHead() { - $data = array( + $data = [ 'base' => 'master', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', 'body' => 'BODY: Testing pull-request creation from PHP Github API', - ); + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -286,11 +286,11 @@ public function shouldNotCreatePullRequestWithoutHead() */ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { - $data = array( + $data = [ 'base' => 'master', 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - ); + ]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -305,10 +305,10 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() */ public function shouldNotCreatePullRequestWithoutIssueIdOrTitle() { - $data = array( + $data = [ 'base' => 'master', 'head' => 'virtualtestbranch', - ); + ]; $api = $this->getApiMock(); $api->expects($this->never()) diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index dbbc1d7e722..7ff78ca0de1 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -9,20 +9,20 @@ class RateLimitTest extends TestCase */ public function shouldReturnRateLimitArray() { - $expectedArray = array( - 'resources' => array( - 'core' => array( + $expectedArray = [ + 'resources' => [ + 'core' => [ 'limit' => 5000, 'remaining' => 4999, - 'reset' => 1372700873 - ), - 'search' => array( + 'reset' => 1372700873, + ], + 'search' => [ 'limit' => 30, 'remaining' => 18, - 'reset' => 1372697452 - ) - ) - ); + 'reset' => 1372697452, + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 24a4be1fe51..6fe7bd9d5f2 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -9,7 +9,7 @@ class RepoTest extends TestCase */ public function shouldShowRepository() { - $expectedArray = array('id' => 1, 'name' => 'repoName'); + $expectedArray = ['id' => 1, 'name' => 'repoName']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,7 +25,7 @@ public function shouldShowRepository() */ public function shouldShowRepositoryById() { - $expectedArray = array('id' => 123456, 'name' => 'repoName'); + $expectedArray = ['id' => 123456, 'name' => 'repoName']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -41,18 +41,18 @@ public function shouldShowRepositoryById() */ public function shouldSearchRepositories() { - $expectedArray = array( - array('id' => 1, 'name' => 'php'), - array('id' => 2, 'name' => 'php-cs') - ); + $expectedArray = [ + ['id' => 1, 'name' => 'php'], + ['id' => 2, 'name' => 'php-cs'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/legacy/repos/search/php', array('myparam' => 2, 'start_page' => 1)) + ->with('/legacy/repos/search/php', ['myparam' => 2, 'start_page' => 1]) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->find('php', array('myparam' => 2))); + $this->assertEquals($expectedArray, $api->find('php', ['myparam' => 2])); } /** @@ -60,18 +60,18 @@ public function shouldSearchRepositories() */ public function shouldPaginateFoundRepositories() { - $expectedArray = array( - array('id' => 3, 'name' => 'fork of php'), - array('id' => 4, 'name' => 'fork of php-cs') - ); + $expectedArray = [ + ['id' => 3, 'name' => 'fork of php'], + ['id' => 4, 'name' => 'fork of php-cs'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/legacy/repos/search/php', array('start_page' => 2)) + ->with('/legacy/repos/search/php', ['start_page' => 2]) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->find('php', array('start_page' => 2))); + $this->assertEquals($expectedArray, $api->find('php', ['start_page' => 2])); } /** @@ -79,12 +79,12 @@ public function shouldPaginateFoundRepositories() */ public function shouldGetAllRepositories() { - $expectedArray = array( - array('id' => 1, 'name' => 'dummy project'), - array('id' => 2, 'name' => 'awesome another project'), - array('id' => 3, 'name' => 'fork of php'), - array('id' => 4, 'name' => 'fork of php-cs'), - ); + $expectedArray = [ + ['id' => 1, 'name' => 'dummy project'], + ['id' => 2, 'name' => 'awesome another project'], + ['id' => 3, 'name' => 'fork of php'], + ['id' => 4, 'name' => 'fork of php-cs'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -100,12 +100,12 @@ public function shouldGetAllRepositories() */ public function shouldGetAllRepositoriesStartingIndex() { - $expectedArray = array( - array('id' => 1, 'name' => 'dummy project'), - array('id' => 2, 'name' => 'awesome another project'), - array('id' => 3, 'name' => 'fork of php'), - array('id' => 4, 'name' => 'fork of php-cs'), - ); + $expectedArray = [ + ['id' => 1, 'name' => 'dummy project'], + ['id' => 2, 'name' => 'awesome another project'], + ['id' => 3, 'name' => 'fork of php'], + ['id' => 4, 'name' => 'fork of php-cs'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -121,12 +121,12 @@ public function shouldGetAllRepositoriesStartingIndex() */ public function shouldCreateRepositoryUsingNameOnly() { - $expectedArray = array('id' => 1, 'name' => 'l3l0Repo'); + $expectedArray = ['id' => 1, 'name' => 'l3l0Repo']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/user/repos', array( + ->with('/user/repos', [ 'name' => 'l3l0Repo', 'description' => '', 'homepage' => '', @@ -134,8 +134,8 @@ public function shouldCreateRepositoryUsingNameOnly() 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false - )) + 'auto_init' => false, + ]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('l3l0Repo')); @@ -146,12 +146,12 @@ public function shouldCreateRepositoryUsingNameOnly() */ public function shouldCreateRepositoryForOrganization() { - $expectedArray = array('id' => 1, 'name' => 'KnpLabsRepo'); + $expectedArray = ['id' => 1, 'name' => 'KnpLabsRepo']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/orgs/KnpLabs/repos', array( + ->with('/orgs/KnpLabs/repos', [ 'name' => 'KnpLabsRepo', 'description' => '', 'homepage' => '', @@ -159,8 +159,8 @@ public function shouldCreateRepositoryForOrganization() 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false - )) + 'auto_init' => false, + ]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('KnpLabsRepo', '', '', true, 'KnpLabs')); @@ -171,12 +171,12 @@ public function shouldCreateRepositoryForOrganization() */ public function shouldGetRepositorySubscribers() { - $expectedArray = array(array('id' => 1, 'username' => 'l3l0')); + $expectedArray = [['id' => 1, 'username' => 'l3l0']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/subscribers', array('page' => 2)) + ->with('/repos/KnpLabs/php-github-api/subscribers', ['page' => 2]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->subscribers('KnpLabs', 'php-github-api', 2)); @@ -187,7 +187,7 @@ public function shouldGetRepositorySubscribers() */ public function shouldGetRepositoryTags() { - $expectedArray = array(array('sha' => 1234)); + $expectedArray = [['sha' => 1234]]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -203,7 +203,7 @@ public function shouldGetRepositoryTags() */ public function shouldGetRepositoryBranches() { - $expectedArray = array(array('sha' => 1234, 'name' => 'master')); + $expectedArray = [['sha' => 1234, 'name' => 'master']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -219,7 +219,7 @@ public function shouldGetRepositoryBranches() */ public function shouldGetRepositoryBranch() { - $expectedArray = array('sha' => 1234, 'name' => 'master'); + $expectedArray = ['sha' => 1234, 'name' => 'master']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -235,7 +235,7 @@ public function shouldGetRepositoryBranch() */ public function shouldGetRepositoryLanguages() { - $expectedArray = array('lang1', 'lang2'); + $expectedArray = ['lang1', 'lang2']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -251,7 +251,7 @@ public function shouldGetRepositoryLanguages() */ public function shouldGetRepositoryMilestones() { - $expectedArray = array('milestone1', 'milestone2'); + $expectedArray = ['milestone1', 'milestone2']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -267,12 +267,12 @@ public function shouldGetRepositoryMilestones() */ public function shouldGetContributorsExcludingAnonymousOnes() { - $expectedArray = array('contrib1', 'contrib2'); + $expectedArray = ['contrib1', 'contrib2']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/contributors', array('anon' => null)) + ->with('/repos/KnpLabs/php-github-api/contributors', ['anon' => null]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->contributors('KnpLabs', 'php-github-api', false)); @@ -283,12 +283,12 @@ public function shouldGetContributorsExcludingAnonymousOnes() */ public function shouldGetContributorsIncludingAnonymousOnes() { - $expectedArray = array('contrib1', 'contrib2'); + $expectedArray = ['contrib1', 'contrib2']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/contributors', array('anon' => true)) + ->with('/repos/KnpLabs/php-github-api/contributors', ['anon' => true]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->contributors('KnpLabs', 'php-github-api', true)); @@ -299,7 +299,7 @@ public function shouldGetContributorsIncludingAnonymousOnes() */ public function shouldGetRepositoryTeams() { - $expectedArray = array(array('id' => 1234), array('id' => 2345)); + $expectedArray = [['id' => 1234], ['id' => 2345]]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -315,12 +315,12 @@ public function shouldGetRepositoryTeams() */ public function shouldCreateUsingAllParams() { - $expectedArray = array('id' => 1, 'name' => 'l3l0Repo'); + $expectedArray = ['id' => 1, 'name' => 'l3l0Repo']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/user/repos', array( + ->with('/user/repos', [ 'name' => 'l3l0Repo', 'description' => 'test', 'homepage' => 'http://l3l0.eu', @@ -328,8 +328,8 @@ public function shouldCreateUsingAllParams() 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false - )) + 'auto_init' => false, + ]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->create('l3l0Repo', 'test', 'http://l3l0.eu', false)); @@ -340,15 +340,15 @@ public function shouldCreateUsingAllParams() */ public function shouldUpdate() { - $expectedArray = array('id' => 1, 'name' => 'l3l0Repo'); + $expectedArray = ['id' => 1, 'name' => 'l3l0Repo']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/l3l0Repo/test', array('description' => 'test', 'homepage' => 'http://l3l0.eu')) + ->with('/repos/l3l0Repo/test', ['description' => 'test', 'homepage' => 'http://l3l0.eu']) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->update('l3l0Repo', 'test', array('description' => 'test', 'homepage' => 'http://l3l0.eu'))); + $this->assertEquals($expectedArray, $api->update('l3l0Repo', 'test', ['description' => 'test', 'homepage' => 'http://l3l0.eu'])); } /** @@ -370,7 +370,7 @@ public function shouldDelete() */ public function shouldNotDelete() { - $expectedArray = array('message' => 'Not Found'); + $expectedArray = ['message' => 'Not Found']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -506,7 +506,7 @@ public function shouldGetReleasesApiObject() */ public function shouldGetCommitActivity() { - $expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400)); + $expectedArray = [['days' => [0, 3, 26, 20, 39, 1, 0], 'total' => 89, 'week' => 1336280400]]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -522,14 +522,14 @@ public function shouldGetCommitActivity() */ public function shouldGetRepositoryEvents() { - $expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent'); + $expectedArray = ['id' => 6122723754, 'type' => 'ForkEvent']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/events', array( + ->with('/repos/KnpLabs/php-github-api/events', [ 'page' => 3, - )) + ]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3)); @@ -540,7 +540,7 @@ public function shouldGetRepositoryEvents() */ public function shouldGetRepositoryCodeOfConduct() { - $expectedArray = array('name' => 'Contributor Covenant', 'url' => 'http://...'); + $expectedArray = ['name' => 'Contributor Covenant', 'url' => 'http://...']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -572,14 +572,14 @@ public function shouldGetRepositoryTopics() */ public function shouldReplaceRepositoryTopics() { - $expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent'); + $expectedArray = ['id' => 6122723754, 'type' => 'ForkEvent']; $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/repos/KnpLabs/php-github-api/topics', array( + ->with('/repos/KnpLabs/php-github-api/topics', [ 'names' => ['octocat', 'atom', 'electron', 'API'], - )) + ]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API'])); diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 5c49c682112..9341cb5ac99 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -11,7 +11,7 @@ class AssetsTest extends TestCase */ public function shouldGetAllReleaseAssets() { - $expectedValue = array(array('asset1data'), array('asset2data')); + $expectedValue = [['asset1data'], ['asset2data']]; $id = 76; $api = $this->getApiMock(); @@ -28,7 +28,7 @@ public function shouldGetAllReleaseAssets() */ public function shouldGetSingleReleaseAsset() { - $expectedValue = array('assetData'); + $expectedValue = ['assetData']; $assetId = 2; $api = $this->getApiMock(); @@ -60,7 +60,7 @@ public function shouldCreateReleaseAsset() $api = $this->getApiMock(); $api->expects($this->once()) ->method('postRaw') - ->with('https://uploads.github.com/repos/KnpLabs/php-github-api/releases/'. $releaseId .'/assets?name='.$name) + ->with('https://uploads.github.com/repos/KnpLabs/php-github-api/releases/'.$releaseId.'/assets?name='.$name) ->will($this->returnValue($body)); $this->assertEquals($body, $api->create('KnpLabs', 'php-github-api', $releaseId, $name, $contentType, $body)); @@ -71,9 +71,9 @@ public function shouldCreateReleaseAsset() */ public function shouldEditReleaseAsset() { - $expectedValue = array('assetUpdatedData'); + $expectedValue = ['assetUpdatedData']; $assetId = 5; - $data = array('name' => 'asset111_name_qweqwe'); + $data = ['name' => 'asset111_name_qweqwe']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -91,7 +91,7 @@ public function shouldEditReleaseAsset() public function shouldNotEditReleaseAssetWithoutName() { $assetId = 5; - $data = array('not_a_name' => 'just a value'); + $data = ['not_a_name' => 'just a value']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -105,7 +105,7 @@ public function shouldNotEditReleaseAssetWithoutName() */ public function shouldRemoveReleaseAsset() { - $expectedValue = array('assetUpdatedData'); + $expectedValue = ['assetUpdatedData']; $assetId = 5; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/CollaboratorsTest.php b/test/Github/Tests/Api/Repository/CollaboratorsTest.php index cbbacd1a94e..6683dba2bd0 100644 --- a/test/Github/Tests/Api/Repository/CollaboratorsTest.php +++ b/test/Github/Tests/Api/Repository/CollaboratorsTest.php @@ -11,7 +11,7 @@ class CollaboratorsTest extends TestCase */ public function shouldGetAllRepositoryCollaborators() { - $expectedValue = array(array('username' => 'l3l0')); + $expectedValue = [['username' => 'l3l0']]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/CommentsTest.php b/test/Github/Tests/Api/Repository/CommentsTest.php index 0924dbb1606..b573d3735c3 100644 --- a/test/Github/Tests/Api/Repository/CommentsTest.php +++ b/test/Github/Tests/Api/Repository/CommentsTest.php @@ -11,7 +11,7 @@ class CommentsTest extends TestCase */ public function shouldGetAllRepositoryComments() { - $expectedValue = array(array('comment1data'), array('comment2data')); + $expectedValue = [['comment1data'], ['comment2data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllRepositoryComments() */ public function shouldGetSpecificCommitRepositoryComments() { - $expectedValue = array(array('comment1data'), array('comment2data')); + $expectedValue = [['comment1data'], ['comment2data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldGetSpecificCommitRepositoryComments() */ public function shouldShowComment() { - $expectedValue = array('comment1'); + $expectedValue = ['comment1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,7 +60,7 @@ public function shouldShowComment() */ public function shouldNotCreateWithoutBody() { - $data = array('line' => 53, 'path' => 'test.php', 'position' => 2); + $data = ['line' => 53, 'path' => 'test.php', 'position' => 2]; $api = $this->getApiMock(); $api->expects($this->never()) @@ -74,8 +74,8 @@ public function shouldNotCreateWithoutBody() */ public function shouldCreateRepositoryCommitComment() { - $expectedValue = array('comment1data'); - $data = array('body' => 'test body', 'line' => 53, 'path' => 'test.php', 'position' => 2); + $expectedValue = ['comment1data']; + $data = ['body' => 'test body', 'line' => 53, 'path' => 'test.php', 'position' => 2]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -91,8 +91,8 @@ public function shouldCreateRepositoryCommitComment() */ public function shouldCreateRepositoryCommitCommentWithoutLine() { - $expectedValue = array('comment1data'); - $data = array('body' => 'body', 'path' => 'test.php', 'position' => 2); + $expectedValue = ['comment1data']; + $data = ['body' => 'body', 'path' => 'test.php', 'position' => 2]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -113,7 +113,7 @@ public function shouldNotUpdateWithoutBody() $api->expects($this->never()) ->method('patch'); - $api->update('KnpLabs', 'php-github-api', 'commitSHA123456', array()); + $api->update('KnpLabs', 'php-github-api', 'commitSHA123456', []); } /** @@ -121,8 +121,8 @@ public function shouldNotUpdateWithoutBody() */ public function shouldUpdateComment() { - $expectedValue = array('comment1data'); - $data = array('body' => 'body test'); + $expectedValue = ['comment1data']; + $data = ['body' => 'body test']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -138,7 +138,7 @@ public function shouldUpdateComment() */ public function shouldRemoveComment() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/CommitsTest.php b/test/Github/Tests/Api/Repository/CommitsTest.php index 727b39f4a18..25ef2536a1c 100644 --- a/test/Github/Tests/Api/Repository/CommitsTest.php +++ b/test/Github/Tests/Api/Repository/CommitsTest.php @@ -11,8 +11,8 @@ class CommitsTest extends TestCase */ public function shouldGetAllRepositoryCommits() { - $expectedValue = array('commit' => array(), 'comitter'); - $data = array('sha' => 'v3'); + $expectedValue = ['commit' => [], 'comitter']; + $data = ['sha' => 'v3']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -28,7 +28,7 @@ public function shouldGetAllRepositoryCommits() */ public function shouldCompareTwoCommits() { - $expectedValue = array('someCompareChanges'); + $expectedValue = ['someCompareChanges']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -44,7 +44,7 @@ public function shouldCompareTwoCommits() */ public function shouldShowCommitUsingSha() { - $expectedValue = array('sha' => '123', 'comitter'); + $expectedValue = ['sha' => '123', 'comitter']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index a8cc4098005..12fa01d44ef 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -2,8 +2,8 @@ namespace Github\Tests\Api\Repository; -use Github\Tests\Api\TestCase; use Github\Exception\TwoFactorAuthenticationRequiredException; +use Github\Tests\Api\TestCase; use GuzzleHttp\Psr7\Response; class ContentsTest extends TestCase @@ -18,7 +18,7 @@ public function shouldShowContentForGivenPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', ['ref' => null]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); @@ -34,7 +34,7 @@ public function shouldShowReadme() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/readme', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/readme', ['ref' => null]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->readme('KnpLabs', 'php-github-api')); @@ -50,7 +50,7 @@ public function shouldReturnTrueWhenFileExists() $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') - ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/composer.json', ['ref' => null]) ->will($this->returnValue($response)); $this->assertTrue($api->exists('KnpLabs', 'php-github-api', 'composer.json')); @@ -60,10 +60,10 @@ public function getFailureStubsForExistsTest() { $response = new Response(403); - return array( - array($this->throwException(new \ErrorException())), - array($this->returnValue($response)) - ); + return [ + [$this->throwException(new \ErrorException())], + [$this->returnValue($response)], + ]; } /** @@ -77,7 +77,7 @@ public function shouldReturnFalseWhenFileIsNotFound($failureStub) $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') - ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/composer.json', ['ref' => null]) ->will($failureStub); $this->assertFalse($api->exists('KnpLabs', 'php-github-api', 'composer.json')); @@ -92,7 +92,7 @@ public function shouldBubbleTwoFactorAuthenticationRequiredExceptionsWhenCheckin $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') - ->with('/repos/KnpLabs/php-github-api/contents/composer.json', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/composer.json', ['ref' => null]) ->will($this->throwException(new TwoFactorAuthenticationRequiredException(0))); $api->exists('KnpLabs', 'php-github-api', 'composer.json'); @@ -103,17 +103,17 @@ public function shouldBubbleTwoFactorAuthenticationRequiredExceptionsWhenCheckin */ public function shouldCreateNewFile() { - $expectedArray = array('content' => 'some data'); - $content = ' 'committer name', 'email' => 'email@example.com'); - $parameters = array( + $expectedArray = ['content' => 'some data']; + $content = ' 'committer name', 'email' => 'email@example.com']; + $parameters = [ 'content' => base64_encode($content), 'message' => $message, 'committer' => $committer, 'branch' => $branch, - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -131,8 +131,8 @@ public function shouldCreateNewFile() */ public function shouldThrowExceptionWhenCreateNewFileWithInvalidCommitter() { - $committer = array('invalid_key' => 'some data'); - $api = $this->getApiMock(); + $committer = ['invalid_key' => 'some data']; + $api = $this->getApiMock(); $api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, $committer); } @@ -141,19 +141,19 @@ public function shouldThrowExceptionWhenCreateNewFileWithInvalidCommitter() */ public function shouldUpdateFile() { - $expectedArray = array('content' => 'some data'); - $content = ' 'committer name', 'email' => 'email@example.com'); - $parameters = array( + $expectedArray = ['content' => 'some data']; + $content = ' 'committer name', 'email' => 'email@example.com']; + $parameters = [ 'content' => base64_encode($content), 'message' => $message, 'committer' => $committer, 'branch' => $branch, 'sha' => $sha, - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -171,8 +171,8 @@ public function shouldUpdateFile() */ public function shouldThrowExceptionWhenUpdateFileWithInvalidCommitter() { - $committer = array('invalid_key' => 'some data'); - $api = $this->getApiMock(); + $committer = ['invalid_key' => 'some data']; + $api = $this->getApiMock(); $api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, null, $committer); } @@ -181,17 +181,17 @@ public function shouldThrowExceptionWhenUpdateFileWithInvalidCommitter() */ public function shouldDeleteFile() { - $expectedArray = array('content' => 'some data'); - $message = 'a commit message'; - $sha = 'a sha'; - $branch = 'master'; - $committer = array('name' => 'committer name', 'email' => 'email@example.com'); - $parameters = array( + $expectedArray = ['content' => 'some data']; + $message = 'a commit message'; + $sha = 'a sha'; + $branch = 'master'; + $committer = ['name' => 'committer name', 'email' => 'email@example.com']; + $parameters = [ 'message' => $message, 'committer' => $committer, 'branch' => $branch, 'sha' => $sha, - ); + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -209,8 +209,8 @@ public function shouldDeleteFile() */ public function shouldThrowExceptionWhenDeleteFileWithInvalidCommitter() { - $committer = array('invalid_key' => 'some data'); - $api = $this->getApiMock(); + $committer = ['invalid_key' => 'some data']; + $api = $this->getApiMock(); $api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'a commit message', null, null, $committer); } @@ -292,7 +292,7 @@ public function shouldDownloadForGivenPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', array('ref' => null)) + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', ['ref' => null]) ->will($this->returnValue($getValue)); $this->assertEquals($expectedValue, $api->download('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); @@ -312,7 +312,7 @@ public function shouldDownloadForSpacedPath() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/mads379/scala.tmbundle/contents/Syntaxes%2FSimple%20Build%20Tool.tmLanguage', array('ref' => null)) + ->with('/repos/mads379/scala.tmbundle/contents/Syntaxes%2FSimple%20Build%20Tool.tmLanguage', ['ref' => null]) ->will($this->returnValue($getValue)); $this->assertEquals($expectedValue, $api->download('mads379', 'scala.tmbundle', 'Syntaxes/Simple Build Tool.tmLanguage')); diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index 557d259f483..f26c83c08e4 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -11,7 +11,7 @@ class DeployKeysTest extends TestCase */ public function shouldGetAllRepositoryDeployKeys() { - $expectedValue = array(array('name' => 'key')); + $expectedValue = [['name' => 'key']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllRepositoryDeployKeys() */ public function shouldShowDeployKey() { - $expectedValue = array('key' => 'somename'); + $expectedValue = ['key' => 'somename']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldShowDeployKey() */ public function shouldRemoveDeployKey() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,7 +60,7 @@ public function shouldRemoveDeployKey() */ public function shouldNotCreateDeployKeyWithoutName() { - $data = array('config' => 'conf'); + $data = ['config' => 'conf']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -75,7 +75,7 @@ public function shouldNotCreateDeployKeyWithoutName() */ public function shouldNotCreateDeployKeyWithoutColor() { - $data = array('name' => 'test'); + $data = ['name' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -89,8 +89,8 @@ public function shouldNotCreateDeployKeyWithoutColor() */ public function shouldCreateDeployKey() { - $expectedValue = array('key' => 'somename'); - $data = array('title' => 'test', 'key' => 'ssh-rsa 1231234232'); + $expectedValue = ['key' => 'somename']; + $data = ['title' => 'test', 'key' => 'ssh-rsa 1231234232']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldCreateDeployKey() */ public function shouldNotUpdateDeployKeyWithoutTitle() { - $data = array('key' => 'ssh-rsa 12323213'); + $data = ['key' => 'ssh-rsa 12323213']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -122,7 +122,7 @@ public function shouldNotUpdateDeployKeyWithoutTitle() */ public function shouldNotUpdateDeployKeyWithoutKey() { - $data = array('title' => 'test'); + $data = ['title' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -136,8 +136,8 @@ public function shouldNotUpdateDeployKeyWithoutKey() */ public function shouldUpdateDeployKey() { - $expectedValue = array('key' => 'somename'); - $data = array('title' => 'test', 'key' => 'ssh-rsa 12312312321...'); + $expectedValue = ['key' => 'somename']; + $data = ['title' => 'test', 'key' => 'ssh-rsa 12312312321...']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/DownloadsTest.php b/test/Github/Tests/Api/Repository/DownloadsTest.php index 33fe2b4b277..f73b71491e4 100644 --- a/test/Github/Tests/Api/Repository/DownloadsTest.php +++ b/test/Github/Tests/Api/Repository/DownloadsTest.php @@ -11,7 +11,7 @@ class DownloadsTest extends TestCase */ public function shouldGetAllRepositoryDownloads() { - $expectedValue = array(array('download')); + $expectedValue = [['download']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllRepositoryDownloads() */ public function shouldShowRepositoryDownload() { - $expectedValue = array('download'); + $expectedValue = ['download']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/ForksTest.php b/test/Github/Tests/Api/Repository/ForksTest.php index 36912fd93df..fbc6eb67212 100644 --- a/test/Github/Tests/Api/Repository/ForksTest.php +++ b/test/Github/Tests/Api/Repository/ForksTest.php @@ -11,12 +11,12 @@ class ForksTest extends TestCase */ public function shouldGetForks() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/forks', array('page' => 1)) + ->with('/repos/KnpLabs/php-github-api/forks', ['page' => 1]) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); @@ -27,8 +27,8 @@ public function shouldGetForks() */ public function shouldCreateFork() { - $expectedValue = array(array('name' => 'l3l0repo')); - $data = array('someparam'); + $expectedValue = [['name' => 'l3l0repo']]; + $data = ['someparam']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -44,15 +44,15 @@ public function shouldCreateFork() */ public function shouldSortByNewestWhenSortParamNotRecognized() { - $expectedValue = array(array('name' => 'l3l0repo')); + $expectedValue = [['name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/forks', array('page' => 1, 'sort' => 'newest')) + ->with('/repos/KnpLabs/php-github-api/forks', ['page' => 1, 'sort' => 'newest']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', array('sort' => 'oldes'))); + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', ['sort' => 'oldes'])); } /** diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index 6b5447d762e..6571d04496d 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -11,7 +11,7 @@ class HooksTest extends TestCase */ public function shouldGetAllRepositoryHooks() { - $expectedValue = array(array('name' => 'hook')); + $expectedValue = [['name' => 'hook']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllRepositoryHooks() */ public function shouldShowHook() { - $expectedValue = array('hook' => 'somename'); + $expectedValue = ['hook' => 'somename']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldShowHook() */ public function shouldRemoveHook() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,7 +60,7 @@ public function shouldRemoveHook() */ public function shouldNotCreateHookWithoutName() { - $data = array('config' => 'conf'); + $data = ['config' => 'conf']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -75,7 +75,7 @@ public function shouldNotCreateHookWithoutName() */ public function shouldNotCreateHookWithoutColor() { - $data = array('name' => 'test'); + $data = ['name' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -89,8 +89,8 @@ public function shouldNotCreateHookWithoutColor() */ public function shouldCreateHook() { - $expectedValue = array('hook' => 'somename'); - $data = array('name' => 'test', 'config' => 'someconfig'); + $expectedValue = ['hook' => 'somename']; + $data = ['name' => 'test', 'config' => 'someconfig']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldCreateHook() */ public function shouldNotUpdateHookWithoutConfig() { - $data = array('name' => 'test'); + $data = ['name' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -121,8 +121,8 @@ public function shouldNotUpdateHookWithoutConfig() */ public function shouldUpdateHook() { - $expectedValue = array('hook' => 'somename'); - $data = array('name' => 'test', 'config' => 'config'); + $expectedValue = ['hook' => 'somename']; + $data = ['name' => 'test', 'config' => 'config']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -138,7 +138,7 @@ public function shouldUpdateHook() */ public function shouldTestHook() { - $expectedValue = array(array('name' => 'hook')); + $expectedValue = [['name' => 'hook']]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index b7be0312b66..df9f03844ec 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -11,7 +11,7 @@ class LabelsTest extends TestCase */ public function shouldGetAllRepositoryLabelss() { - $expectedValue = array(array('name' => 'label')); + $expectedValue = [['name' => 'label']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllRepositoryLabelss() */ public function shouldShowLabel() { - $expectedValue = array('label' => 'somename'); + $expectedValue = ['label' => 'somename']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldShowLabel() */ public function shouldRemoveLabel() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,7 +60,7 @@ public function shouldRemoveLabel() */ public function shouldNotCreateLabelWithoutName() { - $data = array('color' => 'red'); + $data = ['color' => 'red']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -75,7 +75,7 @@ public function shouldNotCreateLabelWithoutName() */ public function shouldNotCreateLabelWithoutColor() { - $data = array('name' => 'test'); + $data = ['name' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -89,8 +89,8 @@ public function shouldNotCreateLabelWithoutColor() */ public function shouldCreateLabel() { - $expectedValue = array('label' => 'somename'); - $data = array('name' => 'test', 'color' => 'red'); + $expectedValue = ['label' => 'somename']; + $data = ['name' => 'test', 'color' => 'red']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -107,7 +107,7 @@ public function shouldCreateLabel() */ public function shouldNotUpdateLabelWithoutName() { - $data = array('color' => 'red'); + $data = ['color' => 'red']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -122,7 +122,7 @@ public function shouldNotUpdateLabelWithoutName() */ public function shouldNotUpdateLabelWithoutColor() { - $data = array('name' => 'test'); + $data = ['name' => 'test']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -136,8 +136,8 @@ public function shouldNotUpdateLabelWithoutColor() */ public function shouldUpdateLabel() { - $expectedValue = array('label' => 'somename'); - $data = array('name' => 'test', 'color' => 'red'); + $expectedValue = ['label' => 'somename']; + $data = ['name' => 'test', 'color' => 'red']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/ProjectsTest.php b/test/Github/Tests/Api/Repository/ProjectsTest.php index 2b0c50d2cf0..1c0b0f2ce4c 100644 --- a/test/Github/Tests/Api/Repository/ProjectsTest.php +++ b/test/Github/Tests/Api/Repository/ProjectsTest.php @@ -11,7 +11,7 @@ class ProjectsTest extends TestCase */ public function shouldGetAllRepositoryProjects() { - $expectedValue = array(array('name' => 'Test project 1')); + $expectedValue = [['name' => 'Test project 1']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -28,7 +28,7 @@ public function shouldGetAllRepositoryProjects() */ public function shouldNotCreateWithoutName() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -42,8 +42,8 @@ public function shouldNotCreateWithoutName() */ public function shouldCreateColumn() { - $expectedValue = array('project1data'); - $data = array('name' => 'Project 1'); + $expectedValue = ['project1data']; + $data = ['name' => 'Project 1']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/ProtectionTest.php b/test/Github/Tests/Api/Repository/ProtectionTest.php index 53f4e7ade69..f4f711dce74 100644 --- a/test/Github/Tests/Api/Repository/ProtectionTest.php +++ b/test/Github/Tests/Api/Repository/ProtectionTest.php @@ -11,7 +11,7 @@ class ProtectionTest extends TestCase */ public function shouldShowProtection() { - $expectedValue = array('required_status_checks', 'required_pull_reqeust_reviews', 'restrictions'); + $expectedValue = ['required_status_checks', 'required_pull_reqeust_reviews', 'restrictions']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,8 +27,8 @@ public function shouldShowProtection() */ public function shouldUpdateProtection() { - $expectedValue = array('required_status_checks', 'required_pull_reqeust_reviews', 'restrictions'); - $data = array('required_status_checks' => null); + $expectedValue = ['required_status_checks', 'required_pull_reqeust_reviews', 'restrictions']; + $data = ['required_status_checks' => null]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -44,7 +44,7 @@ public function shouldUpdateProtection() */ public function shouldRemoveProtection() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -60,7 +60,7 @@ public function shouldRemoveProtection() */ public function shouldShowStatusChecks() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -76,8 +76,8 @@ public function shouldShowStatusChecks() */ public function shouldUpdateStatusChecks() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -93,7 +93,7 @@ public function shouldUpdateStatusChecks() */ public function shouldRemoveStatusChecks() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -109,7 +109,7 @@ public function shouldRemoveStatusChecks() */ public function shouldShowStatusChecksContexts() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -125,8 +125,8 @@ public function shouldShowStatusChecksContexts() */ public function shouldReplaceStatusChecksContexts() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -142,8 +142,8 @@ public function shouldReplaceStatusChecksContexts() */ public function shouldAddStatusChecksContexts() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -159,8 +159,8 @@ public function shouldAddStatusChecksContexts() */ public function shouldRemoveStatusChecksContexts() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -176,7 +176,7 @@ public function shouldRemoveStatusChecksContexts() */ public function shouldShowPullRequestReviewEnforcement() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -192,8 +192,8 @@ public function shouldShowPullRequestReviewEnforcement() */ public function shouldUpdatePullRequestReviewEnforcement() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -209,7 +209,7 @@ public function shouldUpdatePullRequestReviewEnforcement() */ public function shouldRemovePullRequestReviewEnforcement() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -225,7 +225,7 @@ public function shouldRemovePullRequestReviewEnforcement() */ public function shouldShowAdminEnforcement() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -241,7 +241,7 @@ public function shouldShowAdminEnforcement() */ public function shouldAddAdminEnforcement() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -257,7 +257,7 @@ public function shouldAddAdminEnforcement() */ public function shouldRemoveAdminEnforcement() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -273,7 +273,7 @@ public function shouldRemoveAdminEnforcement() */ public function shouldShowRestrictions() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -289,7 +289,7 @@ public function shouldShowRestrictions() */ public function shouldRemoveRestrictions() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -305,7 +305,7 @@ public function shouldRemoveRestrictions() */ public function shouldShowTeamRestrictions() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -321,8 +321,8 @@ public function shouldShowTeamRestrictions() */ public function shouldReplaceTeamRestrictions() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -338,8 +338,8 @@ public function shouldReplaceTeamRestrictions() */ public function shouldAddTeamRestrictions() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -355,8 +355,8 @@ public function shouldAddTeamRestrictions() */ public function shouldRemoveTeamRestrictions() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -372,7 +372,7 @@ public function shouldRemoveTeamRestrictions() */ public function shouldShowUserRestrictions() { - $expectedValue = array('someOutput'); + $expectedValue = ['someOutput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -388,8 +388,8 @@ public function shouldShowUserRestrictions() */ public function shouldReplaceUserRestrictions() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -405,8 +405,8 @@ public function shouldReplaceUserRestrictions() */ public function shouldAddUserRestrictions() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -422,8 +422,8 @@ public function shouldAddUserRestrictions() */ public function shouldRemoveUserRestrictions() { - $expectedValue = array('someOutput'); - $data = array('someInput'); + $expectedValue = ['someOutput']; + $data = ['someInput']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index 64b164cb237..297ee283a08 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -11,7 +11,7 @@ class ReleasesTest extends TestCase */ public function shouldGetLatestRelease() { - $expectedValue = array('latest_release_data'); + $expectedValue = ['latest_release_data']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetLatestRelease() */ public function shouldGetReleaseByTag() { - $expectedValue = array('latest_release_data'); + $expectedValue = ['latest_release_data']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -47,7 +47,7 @@ public function shouldGetReleaseByTag() */ public function shouldGetAllRepositoryReleases() { - $expectedValue = array(array('release1data'), array('release2data')); + $expectedValue = [['release1data'], ['release2data']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -63,7 +63,7 @@ public function shouldGetAllRepositoryReleases() */ public function shouldGetSingleRepositoryRelease() { - $expectedValue = array('releaseData'); + $expectedValue = ['releaseData']; $id = 331; $api = $this->getApiMock(); @@ -80,8 +80,8 @@ public function shouldGetSingleRepositoryRelease() */ public function shouldCreateRepositoryRelease() { - $expectedValue = array('newReleaseData'); - $data = array('tag_name' => '1.1'); + $expectedValue = ['newReleaseData']; + $data = ['tag_name' => '1.1']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -98,7 +98,7 @@ public function shouldCreateRepositoryRelease() */ public function shouldNotCreateRepositoryReleaseWithoutTagName() { - $data = array('not_a_tag_name' => '1.1'); + $data = ['not_a_tag_name' => '1.1']; $api = $this->getApiMock(); $api->expects($this->never()) @@ -112,9 +112,9 @@ public function shouldNotCreateRepositoryReleaseWithoutTagName() */ public function shouldEditRepositoryRelease() { - $expectedValue = array('updatedData'); + $expectedValue = ['updatedData']; $id = 332; - $data = array('some' => 'thing'); + $data = ['some' => 'thing']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -130,7 +130,7 @@ public function shouldEditRepositoryRelease() */ public function shouldRemoveRepositoryRelease() { - $expectedValue = array('deleted'); + $expectedValue = ['deleted']; $id = 333; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/StargazersTest.php b/test/Github/Tests/Api/Repository/StargazersTest.php index ef5e5d6d5f8..0552100556c 100644 --- a/test/Github/Tests/Api/Repository/StargazersTest.php +++ b/test/Github/Tests/Api/Repository/StargazersTest.php @@ -11,7 +11,7 @@ class StargazersTest extends TestCase */ public function shouldGetAllRepositoryStargazers() { - $expectedValue = array(array('login' => 'nidup')); + $expectedValue = [['login' => 'nidup']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -27,7 +27,7 @@ public function shouldGetAllRepositoryStargazers() */ public function shouldGetAllRepositoryStargazersWithAlternativeResponse() { - $expectedValue = array(array('starred_at' => '2013-10-01T13:22:01Z', 'user' => array('login' => 'nidup'))); + $expectedValue = [['starred_at' => '2013-10-01T13:22:01Z', 'user' => ['login' => 'nidup']]]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php index 9b64708d452..f286d79aa51 100644 --- a/test/Github/Tests/Api/Repository/StatusesTest.php +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -11,10 +11,10 @@ class StatusesTest extends TestCase */ public function shouldShowCommitStatuses() { - $expectedValue = array( - array('state' => 'success', 'context' => 'Travis'), - array('state' => 'pending', 'context' => 'Travis') - ); + $expectedValue = [ + ['state' => 'success', 'context' => 'Travis'], + ['state' => 'pending', 'context' => 'Travis'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -30,21 +30,21 @@ public function shouldShowCommitStatuses() */ public function shouldShowCombinedCommitStatuses() { - $expectedValue = array( - array( + $expectedValue = [ + [ 'state' => 'success', - 'statuses' => array( - array( + 'statuses' => [ + [ 'state' => 'success', - 'context' => 'Travis' - ), - array( + 'context' => 'Travis', + ], + [ 'state' => 'success', - 'context' => 'Jenkins' - ) - ) - ) - ); + 'context' => 'Jenkins', + ], + ], + ], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -61,7 +61,7 @@ public function shouldShowCombinedCommitStatuses() */ public function shouldNotCreateWithoutStatus() { - $data = array(); + $data = []; $api = $this->getApiMock(); $api->expects($this->never()) @@ -75,8 +75,8 @@ public function shouldNotCreateWithoutStatus() */ public function shouldCreateCommitStatus() { - $expectedValue = array('state' => 'success'); - $data = array('state' => 'success'); + $expectedValue = ['state' => 'success']; + $data = ['state' => 'success']; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/Repository/TrafficTest.php b/test/Github/Tests/Api/Repository/TrafficTest.php index 5110c546240..f13a71ace1b 100644 --- a/test/Github/Tests/Api/Repository/TrafficTest.php +++ b/test/Github/Tests/Api/Repository/TrafficTest.php @@ -4,13 +4,12 @@ class TrafficTest extends TestCase { - /** * @test */ public function shouldgetReferers() { - $expectedValue = json_encode(["referrer" => "github.com","count" => 112,"uniques" => 15]); + $expectedValue = json_encode(['referrer' => 'github.com', 'count' => 112, 'uniques' => 15]); $api = $this->getApiMock(); @@ -26,7 +25,7 @@ public function shouldgetReferers() public function shouldgetPaths() { - $expectedValue = json_encode(["path" => "/knplabs/php-github-api","title" => "KnpLabs/php-github-api: A simple PHP GitHub API client, Object Oriented, tested and documented. For 5.5+.","count" => 203,"uniques" => 54]); + $expectedValue = json_encode(['path' => '/knplabs/php-github-api', 'title' => 'KnpLabs/php-github-api: A simple PHP GitHub API client, Object Oriented, tested and documented. For 5.5+.', 'count' => 203, 'uniques' => 54]); $api = $this->getApiMock(); @@ -42,7 +41,7 @@ public function shouldgetPaths() public function shouldgetViews() { - $expectedValue = json_encode(["count" => 813,"uniques" => 61,"views" => [["timestamp" => "2017-03-12T00:00:00Z","count" => 40,"uniques" => 3]]]); + $expectedValue = json_encode(['count' => 813, 'uniques' => 61, 'views' => [['timestamp' => '2017-03-12T00:00:00Z', 'count' => 40, 'uniques' => 3]]]); $api = $this->getApiMock(); @@ -58,7 +57,7 @@ public function shouldgetViews() public function shouldgetClones() { - $expectedValue = json_encode(["count" => 813,"uniques" => 61,"clones" => [["timestamp" => "2017-03-12T00:00:00Z","count" => 14,"uniques" => 8]]]); + $expectedValue = json_encode(['count' => 813, 'uniques' => 61, 'clones' => [['timestamp' => '2017-03-12T00:00:00Z', 'count' => 14, 'uniques' => 8]]]); $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index c67fc96171c..60ebb6cd3e1 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -9,7 +9,7 @@ class SearchTest extends TestCase */ public function shouldSearchRepositoriesByQuery() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -17,7 +17,7 @@ public function shouldSearchRepositoriesByQuery() ->method('get') ->with( '/search/repositories', - array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ['q' => 'query text', 'sort' => 'updated', 'order' => 'desc'] ) ->will($this->returnValue($expectedArray)); @@ -29,7 +29,7 @@ public function shouldSearchRepositoriesByQuery() */ public function shouldSearchRepositoriesRegardingSortAndOrder() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -37,7 +37,7 @@ public function shouldSearchRepositoriesRegardingSortAndOrder() ->method('get') ->with( '/search/repositories', - array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ['q' => 'query text', 'sort' => 'created', 'order' => 'asc'] ) ->will($this->returnValue($expectedArray)); @@ -52,7 +52,7 @@ public function shouldSearchRepositoriesRegardingSortAndOrder() */ public function shouldSearchIssuesByQuery() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -60,7 +60,7 @@ public function shouldSearchIssuesByQuery() ->method('get') ->with( '/search/issues', - array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ['q' => 'query text', 'sort' => 'updated', 'order' => 'desc'] ) ->will($this->returnValue($expectedArray)); @@ -72,7 +72,7 @@ public function shouldSearchIssuesByQuery() */ public function shouldSearchIssuesRegardingSortAndOrder() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -80,7 +80,7 @@ public function shouldSearchIssuesRegardingSortAndOrder() ->method('get') ->with( '/search/issues', - array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ['q' => 'query text', 'sort' => 'created', 'order' => 'asc'] ) ->will($this->returnValue($expectedArray)); @@ -95,7 +95,7 @@ public function shouldSearchIssuesRegardingSortAndOrder() */ public function shouldSearchCodeByQuery() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -103,7 +103,7 @@ public function shouldSearchCodeByQuery() ->method('get') ->with( '/search/code', - array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ['q' => 'query text', 'sort' => 'updated', 'order' => 'desc'] ) ->will($this->returnValue($expectedArray)); @@ -115,7 +115,7 @@ public function shouldSearchCodeByQuery() */ public function shouldSearchCodeRegardingSortAndOrder() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -123,7 +123,7 @@ public function shouldSearchCodeRegardingSortAndOrder() ->method('get') ->with( '/search/code', - array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ['q' => 'query text', 'sort' => 'created', 'order' => 'asc'] ) ->will($this->returnValue($expectedArray)); @@ -138,7 +138,7 @@ public function shouldSearchCodeRegardingSortAndOrder() */ public function shouldSearchUsersByQuery() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -146,7 +146,7 @@ public function shouldSearchUsersByQuery() ->method('get') ->with( '/search/users', - array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') + ['q' => 'query text', 'sort' => 'updated', 'order' => 'desc'] ) ->will($this->returnValue($expectedArray)); @@ -158,7 +158,7 @@ public function shouldSearchUsersByQuery() */ public function shouldSearchUsersRegardingSortAndOrder() { - $expectedArray = array(array('total_count' => '0')); + $expectedArray = [['total_count' => '0']]; $api = $this->getApiMock(); @@ -166,7 +166,7 @@ public function shouldSearchUsersRegardingSortAndOrder() ->method('get') ->with( '/search/users', - array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') + ['q' => 'query text', 'sort' => 'created', 'order' => 'asc'] ) ->will($this->returnValue($expectedArray)); diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index c02e08bbde3..512a8fc4d87 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -2,7 +2,6 @@ namespace Github\Tests\Api; -use Github\HttpClient\Builder; use ReflectionMethod; abstract class TestCase extends \PHPUnit\Framework\TestCase @@ -18,7 +17,7 @@ abstract protected function getApiClass(); protected function getApiMock() { $httpClient = $this->getMockBuilder(\Http\Client\HttpClient::class) - ->setMethods(array('sendRequest')) + ->setMethods(['sendRequest']) ->getMock(); $httpClient ->expects($this->any()) @@ -27,14 +26,15 @@ protected function getApiMock() $client = \Github\Client::createWithHttpClient($httpClient); return $this->getMockBuilder($this->getApiClass()) - ->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head')) - ->setConstructorArgs(array($client)) + ->setMethods(['get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head']) + ->setConstructorArgs([$client]) ->getMock(); } /** * @param object $object * @param string $methodName + * * @return ReflectionMethod */ protected function getMethod($object, $methodName) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index b93d62b3c03..fa56225fd1f 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -9,7 +9,7 @@ class UserTest extends TestCase */ public function shouldShowUser() { - $expectedArray = array('id' => 1, 'username' => 'l3l0'); + $expectedArray = ['id' => 1, 'username' => 'l3l0']; $api = $this->getApiMock(); $api->expects($this->once()) @@ -25,14 +25,14 @@ public function shouldShowUser() */ public function shouldGetUserOrganizations() { - $expectedArray = array(array( + $expectedArray = [[ 'id' => 202732, 'url' => 'https://api.github.com/orgs/KnpLabs', 'repos_url' => 'https://api.github.com/orgs/KnpLabs/repos', 'events_url' => 'https://api.github.com/orgs/KnpLabs/events', 'members_url' => 'https://api.github.com/orgs/KnpLabs/members{/member}', - 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}' - )); + 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}', + ]]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -45,14 +45,14 @@ public function shouldGetUserOrganizations() public function shouldGetUserOrgs() { - $expectedArray = array(array( + $expectedArray = [[ 'id' => 202732, 'url' => 'https://api.github.com/orgs/KnpLabs', 'repos_url' => 'https://api.github.com/orgs/KnpLabs/repos', 'events_url' => 'https://api.github.com/orgs/KnpLabs/events', 'members_url' => 'https://api.github.com/orgs/KnpLabs/members{/member}', - 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}' - )); + 'public_members_url' => 'https://api.github.com/orgs/KnpLabs/public_members{/member}', + ]]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -68,10 +68,10 @@ public function shouldGetUserOrgs() */ public function shouldGetAllUsers() { - $expectedArray = array( - array('id' => 1, 'username' => 'l3l0'), - array('id' => 2, 'username' => 'l3l0test') - ); + $expectedArray = [ + ['id' => 1, 'username' => 'l3l0'], + ['id' => 2, 'username' => 'l3l0test'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -87,10 +87,10 @@ public function shouldGetAllUsers() */ public function shouldGetAllUsersSince() { - $expectedArray = array( - array('id' => 3, 'username' => 'test3'), - array('id' => 4, 'username' => 'test4') - ); + $expectedArray = [ + ['id' => 3, 'username' => 'test3'], + ['id' => 4, 'username' => 'test4'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -106,10 +106,10 @@ public function shouldGetAllUsersSince() */ public function shouldSearchUsers() { - $expectedArray = array( - array('id' => 1, 'username' => 'l3l0'), - array('id' => 2, 'username' => 'l3l0test') - ); + $expectedArray = [ + ['id' => 1, 'username' => 'l3l0'], + ['id' => 2, 'username' => 'l3l0test'], + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -125,7 +125,7 @@ public function shouldSearchUsers() */ public function shouldGetFollowingUsers() { - $expectedArray = array(array('id' => 1, 'username' => 'l3l0test')); + $expectedArray = [['id' => 1, 'username' => 'l3l0test']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -141,7 +141,7 @@ public function shouldGetFollowingUsers() */ public function shouldGetUserFollowers() { - $expectedArray = array(array('id' => 1, 'username' => 'l3l0test')); + $expectedArray = [['id' => 1, 'username' => 'l3l0test']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -157,7 +157,7 @@ public function shouldGetUserFollowers() */ public function shouldGetStarredToRepositories() { - $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -173,7 +173,7 @@ public function shouldGetStarredToRepositories() */ public function shouldGetSubscriptionsToRepositories() { - $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -189,12 +189,12 @@ public function shouldGetSubscriptionsToRepositories() */ public function shouldGetUserRepositories() { - $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/users/l3l0/repos', array('type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc')) + ->with('/users/l3l0/repos', ['type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('l3l0')); @@ -220,7 +220,7 @@ public function shouldGetMyRepositories() */ public function shouldGetUserGists() { - $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 3be0e3ba44e..b92abe0599b 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -8,7 +8,6 @@ use Github\HttpClient\Builder; use Github\HttpClient\Plugin\Authentication; use GuzzleHttp\Psr7\Response; -use Http\Client\Common\Plugin; use Http\Client\HttpClient; use Psr\Http\Message\RequestInterface; @@ -44,7 +43,7 @@ public function shouldPassHttpClientInterfaceToConstructor() public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) - ->setMethods(array('addPlugin', 'removePlugin')) + ->setMethods(['addPlugin', 'removePlugin']) ->disableOriginalConstructor() ->getMock(); $builder->expects($this->once()) @@ -67,12 +66,12 @@ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $me public function getAuthenticationFullData() { - return array( - array('login', 'password', Client::AUTH_HTTP_PASSWORD), - array('token', null, Client::AUTH_HTTP_TOKEN), - array('token', null, Client::AUTH_URL_TOKEN), - array('client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID), - ); + return [ + ['login', 'password', Client::AUTH_HTTP_PASSWORD], + ['token', null, Client::AUTH_HTTP_TOKEN], + ['token', null, Client::AUTH_URL_TOKEN], + ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID], + ]; } /** @@ -82,7 +81,7 @@ public function getAuthenticationFullData() public function shouldAuthenticateUsingGivenParameters($token, $method) { $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) - ->setMethods(array('addPlugin', 'removePlugin')) + ->setMethods(['addPlugin', 'removePlugin']) ->getMock(); $builder->expects($this->once()) ->method('addPlugin') @@ -105,10 +104,10 @@ public function shouldAuthenticateUsingGivenParameters($token, $method) public function getAuthenticationPartialData() { - return array( - array('token', Client::AUTH_HTTP_TOKEN), - array('token', Client::AUTH_URL_TOKEN), - ); + return [ + ['token', Client::AUTH_HTTP_TOKEN], + ['token', Client::AUTH_URL_TOKEN], + ]; } /** @@ -166,47 +165,47 @@ public function shouldNotGetMagicApiInstance() public function getApiClassesProvider() { - return array( - array('user', Api\User::class), - array('users', Api\User::class), + return [ + ['user', Api\User::class], + ['users', Api\User::class], - array('me', Api\CurrentUser::class), - array('current_user', Api\CurrentUser::class), - array('currentUser', Api\CurrentUser::class), + ['me', Api\CurrentUser::class], + ['current_user', Api\CurrentUser::class], + ['currentUser', Api\CurrentUser::class], - array('git', Api\GitData::class), - array('git_data', Api\GitData::class), - array('gitData', Api\GitData::class), + ['git', Api\GitData::class], + ['git_data', Api\GitData::class], + ['gitData', Api\GitData::class], - array('gist', Api\Gists::class), - array('gists', Api\Gists::class), + ['gist', Api\Gists::class], + ['gists', Api\Gists::class], - array('issue', Api\Issue::class), - array('issues', Api\Issue::class), + ['issue', Api\Issue::class], + ['issues', Api\Issue::class], - array('markdown', Api\Markdown::class), + ['markdown', Api\Markdown::class], - array('organization', Api\Organization::class), - array('organizations', Api\Organization::class), + ['organization', Api\Organization::class], + ['organizations', Api\Organization::class], - array('repo', Api\Repo::class), - array('repos', Api\Repo::class), - array('repository', Api\Repo::class), - array('repositories', Api\Repo::class), + ['repo', Api\Repo::class], + ['repos', Api\Repo::class], + ['repository', Api\Repo::class], + ['repositories', Api\Repo::class], - array('search', Api\Search::class), + ['search', Api\Search::class], - array('pr', Api\PullRequest::class), - array('pullRequest', Api\PullRequest::class), - array('pull_request', Api\PullRequest::class), - array('pullRequests', Api\PullRequest::class), - array('pull_requests', Api\PullRequest::class), + ['pr', Api\PullRequest::class], + ['pullRequest', Api\PullRequest::class], + ['pull_request', Api\PullRequest::class], + ['pullRequests', Api\PullRequest::class], + ['pull_requests', Api\PullRequest::class], - array('authorization', Api\Authorizations::class), - array('authorizations', Api\Authorizations::class), + ['authorization', Api\Authorizations::class], + ['authorizations', Api\Authorizations::class], - array('meta', Api\Meta::class) - ); + ['meta', Api\Meta::class], + ]; } /** diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index 1af87ce63d6..6fd190dbca8 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -32,6 +32,7 @@ public function shouldServeCachedResponse() $userB = $github->currentUser()->show(); $this->assertEquals('nyholm', $userB['login'], 'Two request following each other should be cached.'); } + /** * @test */ diff --git a/test/Github/Tests/HttpClient/BuilderTest.php b/test/Github/Tests/HttpClient/BuilderTest.php index d04aa496bd8..33d21025f0e 100644 --- a/test/Github/Tests/HttpClient/BuilderTest.php +++ b/test/Github/Tests/HttpClient/BuilderTest.php @@ -15,7 +15,7 @@ class BuilderTest extends \PHPUnit\Framework\TestCase public function shouldClearHeaders() { $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) - ->setMethods(array('addPlugin', 'removePlugin')) + ->setMethods(['addPlugin', 'removePlugin']) ->getMock(); $builder->expects($this->once()) ->method('addPlugin') @@ -33,10 +33,10 @@ public function shouldClearHeaders() */ public function shouldAddHeaders() { - $headers = array('header1', 'header2'); + $headers = ['header1', 'header2']; $client = $this->getMockBuilder(\Github\HttpClient\Builder::class) - ->setMethods(array('addPlugin', 'removePlugin')) + ->setMethods(['addPlugin', 'removePlugin']) ->getMock(); $client->expects($this->once()) ->method('addPlugin') @@ -60,7 +60,7 @@ public function appendingHeaderShouldAddAndRemovePlugin() ]; $client = $this->getMockBuilder(\Github\HttpClient\Builder::class) - ->setMethods(array('removePlugin', 'addPlugin')) + ->setMethods(['removePlugin', 'addPlugin']) ->getMock(); $client->expects($this->once()) diff --git a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php index d8f246c919d..c14eac8a297 100644 --- a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php +++ b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php @@ -12,10 +12,10 @@ class ResponseMediatorTest extends \PHPUnit\Framework\TestCase { public function testGetContent() { - $body = array('foo' => 'bar'); + $body = ['foo' => 'bar']; $response = new Response( 200, - array('Content-Type'=>'application/json'), + ['Content-Type'=>'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($body)) ); @@ -30,7 +30,7 @@ public function testGetContentNotJson() $body = 'foobar'; $response = new Response( 200, - array(), + [], \GuzzleHttp\Psr7\stream_for($body) ); @@ -38,14 +38,14 @@ public function testGetContentNotJson() } /** - * Make sure we return the body if we have invalid json + * Make sure we return the body if we have invalid json. */ public function testGetContentInvalidJson() { $body = 'foobar'; $response = new Response( 200, - array('Content-Type'=>'application/json'), + ['Content-Type'=>'application/json'], \GuzzleHttp\Psr7\stream_for($body) ); @@ -54,22 +54,22 @@ public function testGetContentInvalidJson() public function testGetPagination() { - $header = <<; rel="first", ; rel="next", ; rel="prev", ; rel="last", TEXT; - $pagination = array( + $pagination = [ 'first' => 'http://github.com', 'next' => 'http://github.com', 'prev' => 'http://github.com', - 'last' => 'http://github.com' - ); + 'last' => 'http://github.com', + ]; // response mock - $response = new Response(200, array('link'=>$header)); + $response = new Response(200, ['link'=>$header]); $result = ResponseMediator::getPagination($response); $this->assertEquals($pagination, $result); @@ -80,7 +80,7 @@ public function testGetHeader() $header = 'application/json'; $response = new Response( 200, - array('Content-Type'=> $header) + ['Content-Type'=> $header] ); $this->assertEquals($header, ResponseMediator::getHeader($response, 'content-type')); diff --git a/test/Github/Tests/HttpClient/PathPrependTest.php b/test/Github/Tests/HttpClient/PathPrependTest.php index dbd7905c739..fdfe180980a 100644 --- a/test/Github/Tests/HttpClient/PathPrependTest.php +++ b/test/Github/Tests/HttpClient/PathPrependTest.php @@ -23,7 +23,7 @@ public function testPathIsPrepended($uri, $expectedPath) $plugin->handleRequest($request, function ($request) use (&$newRequest) { $newRequest = $request; }, function () { - throw new \RuntimeException("Did not expect plugin to call first"); + throw new \RuntimeException('Did not expect plugin to call first'); }); $this->assertEquals($expectedPath, $newRequest->getUri()->getPath()); diff --git a/test/Github/Tests/Integration/CommitTest.php b/test/Github/Tests/Integration/CommitTest.php index 8dcaa0d022e..2134bab2f65 100644 --- a/test/Github/Tests/Integration/CommitTest.php +++ b/test/Github/Tests/Integration/CommitTest.php @@ -13,11 +13,11 @@ class CommitTest extends TestCase public function shouldRetrieveCommitsForRepositoryBranch() { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $branch = 'master'; + $repo = 'php-github-api'; + $branch = 'master'; - $commits = $this->client->api('repo')->commits()->all($username, $repo, array('sha' => $branch)); - $commit = array_pop($commits); + $commits = $this->client->api('repo')->commits()->all($username, $repo, ['sha' => $branch]); + $commit = array_pop($commits); $this->assertArrayHasKey('url', $commit); $this->assertArrayHasKey('committer', $commit); @@ -32,7 +32,7 @@ public function shouldRetrieveCommitsForRepositoryBranch() public function shouldRetrieveCommitBySha() { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $commit = $this->client->api('repo')->commits()->show($username, $repo, '6df3adf5bd16745299c6429e163265daed430fa1'); @@ -50,10 +50,10 @@ public function shouldRetrieveCommitBySha() public function shouldRetrieveCommitsForFile() { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $branch = 'master'; + $repo = 'php-github-api'; + $branch = 'master'; - $commits = $this->client->api('repo')->commits()->all($username, $repo, array('sha' => $branch, 'path' => 'composer.json')); + $commits = $this->client->api('repo')->commits()->all($username, $repo, ['sha' => $branch, 'path' => 'composer.json']); $commit = array_pop($commits); $this->assertArrayHasKey('url', $commit); diff --git a/test/Github/Tests/Integration/IssueCommentTest.php b/test/Github/Tests/Integration/IssueCommentTest.php index d035182151a..3db9ce8bb46 100644 --- a/test/Github/Tests/Integration/IssueCommentTest.php +++ b/test/Github/Tests/Integration/IssueCommentTest.php @@ -13,11 +13,11 @@ class IssueCommentTest extends TestCase public function shouldRetrieveCommentsForIssue() { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $issue = 13; + $repo = 'php-github-api'; + $issue = 13; $comments = $this->client->api('issue')->comments()->all($username, $repo, $issue); - $comment = array_pop($comments); + $comment = array_pop($comments); $this->assertArrayHasKey('id', $comment); $this->assertArrayHasKey('url', $comment); @@ -36,7 +36,7 @@ public function shouldRetrieveCommentsForIssue() public function shouldRetrieveSingleComment($commentId) { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $comment = $this->client->api('issue')->comments()->show($username, $repo, $commentId); @@ -54,9 +54,9 @@ public function shouldRetrieveSingleComment($commentId) public function shouldCreateCommentForIssue() { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $issue = 13; - $params = array('body' => '%'); + $repo = 'php-github-api'; + $issue = 13; + $params = ['body' => '%']; $comment = $this->client->api('issue')->comments()->create($username, $repo, $issue, $params); @@ -69,6 +69,7 @@ public function shouldCreateCommentForIssue() return $comment['id']; } + /** * @test * @depends shouldCreateCommentForIssue @@ -76,8 +77,8 @@ public function shouldCreateCommentForIssue() public function shouldUpdateCommentByCommentId($commentId) { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $params = array('body' => 'test update'); + $repo = 'php-github-api'; + $params = ['body' => 'test update']; $comment = $this->client->api('issue')->comments()->update($username, $repo, $commentId, $params); @@ -98,7 +99,7 @@ public function shouldUpdateCommentByCommentId($commentId) public function shouldRemoveCommentByCommentId($commentId) { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $this->client->api('issue')->comments()->remove($username, $repo, $commentId); } diff --git a/test/Github/Tests/Integration/MarkdownTest.php b/test/Github/Tests/Integration/MarkdownTest.php index fa4f413a3da..1dd956019fe 100644 --- a/test/Github/Tests/Integration/MarkdownTest.php +++ b/test/Github/Tests/Integration/MarkdownTest.php @@ -17,15 +17,15 @@ public function shouldRetrieveParsedMarkdownContent() /** @var Markdown $api */ $api = $this->client->api('markdown'); - $input = 'Hello world github/linguist#1 **cool**, and #1!'; + $input = 'Hello world github/linguist#1 **cool**, and #1!'; $output = '

Hello world github/linguist#1 cool, and #1!

'; - $html = $api->render($input); + $html = $api->render($input); $this->assertEquals($output, $html); - $input = 'Hello world KnpLabs/KnpBundles#1 **cool**, and #1!'; + $input = 'Hello world KnpLabs/KnpBundles#1 **cool**, and #1!'; $output = '

Hello world KnpLabs/KnpBundles#1 cool, and #1!

'; - $html = $api->render($input, 'gfm', 'KnpLabs/KnpMenu'); + $html = $api->render($input, 'gfm', 'KnpLabs/KnpMenu'); $this->assertEquals($output, $html); } diff --git a/test/Github/Tests/Integration/RateLimitTest.php b/test/Github/Tests/Integration/RateLimitTest.php index d0f0015f2c0..64599e7c679 100644 --- a/test/Github/Tests/Integration/RateLimitTest.php +++ b/test/Github/Tests/Integration/RateLimitTest.php @@ -15,6 +15,6 @@ public function shouldRetrievedRateLimits() $response = $this->client->api('rate_limit')->getRateLimits(); $this->assertArrayHasKey('resources', $response); - $this->assertArraySubset(array('resources' => array('core' => array('limit' => 60))), $response); + $this->assertArraySubset(['resources' => ['core' => ['limit' => 60]]], $response); } } diff --git a/test/Github/Tests/Integration/RepoCommentTest.php b/test/Github/Tests/Integration/RepoCommentTest.php index a6447e8a0df..b2d5dec528a 100644 --- a/test/Github/Tests/Integration/RepoCommentTest.php +++ b/test/Github/Tests/Integration/RepoCommentTest.php @@ -13,10 +13,10 @@ class RepoCommentTest extends TestCase public function shouldRetrieveComments() { $username = 'fabpot'; - $repo = 'Twig'; + $repo = 'Twig'; $comments = $this->client->api('repo')->comments()->all($username, $repo); - $comment = array_pop($comments); + $comment = array_pop($comments); $this->assertArrayHasKey('line', $comment); $this->assertArrayHasKey('body', $comment); @@ -32,11 +32,11 @@ public function shouldRetrieveComments() public function shouldRetrieveCommentsForCommit() { $username = 'fabpot'; - $repo = 'Twig'; - $sha = '3506cfad1d946f4a87e8c55849a18044efe2d5dc'; + $repo = 'Twig'; + $sha = '3506cfad1d946f4a87e8c55849a18044efe2d5dc'; $comments = $this->client->api('repo')->comments()->all($username, $repo, $sha); - $comment = array_pop($comments); + $comment = array_pop($comments); $this->assertArrayHasKey('line', $comment); $this->assertArrayHasKey('body', $comment); @@ -52,9 +52,9 @@ public function shouldRetrieveCommentsForCommit() public function shouldCreateCommentForCommit() { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $sha = '22655813eb54e7d4e21545e396f919bcd245b50d'; - $params = array('body' => '%'); + $repo = 'php-github-api'; + $sha = '22655813eb54e7d4e21545e396f919bcd245b50d'; + $params = ['body' => '%']; $comment = $this->client->api('repo')->comments()->create($username, $repo, $sha, $params); @@ -75,7 +75,7 @@ public function shouldCreateCommentForCommit() public function shouldShowCommentByCommentId($commentId) { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $comment = $this->client->api('repo')->comments()->show($username, $repo, $commentId); @@ -96,8 +96,8 @@ public function shouldShowCommentByCommentId($commentId) public function shouldUpdateCommentByCommentId($commentId) { $username = 'KnpLabs'; - $repo = 'php-github-api'; - $params = array('body' => 'test update'); + $repo = 'php-github-api'; + $params = ['body' => 'test update']; $comment = $this->client->api('repo')->comments()->update($username, $repo, $commentId, $params); @@ -118,7 +118,7 @@ public function shouldUpdateCommentByCommentId($commentId) public function shouldRemoveCommentByCommentId($commentId) { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $this->client->api('repo')->comments()->remove($username, $repo, $commentId); } diff --git a/test/Github/Tests/Integration/RepoTest.php b/test/Github/Tests/Integration/RepoTest.php index 90328b909aa..076175f2523 100644 --- a/test/Github/Tests/Integration/RepoTest.php +++ b/test/Github/Tests/Integration/RepoTest.php @@ -13,10 +13,10 @@ class RepoTest extends TestCase public function shouldShowPRDiffIfHeaderIsPresent() { $this->client->addHeaders( - array('Accept' => sprintf( + ['Accept' => sprintf( 'application/vnd.github.%s.diff', $this->client->getApiVersion() - )) + )] ); $diff = $this->client->api('pull_request')->show('KnpLabs', 'php-github-api', '92'); @@ -66,7 +66,7 @@ public function shouldNotDecodeRawBlob() public function shouldRetrieveContributorsList() { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $contributors = $this->client->api('repo')->contributors($username, $repo); $contributor = array_pop($contributors); @@ -85,7 +85,7 @@ public function shouldRetrieveContributorsList() public function shouldShowRepo() { $username = 'KnpLabs'; - $repo = 'php-github-api'; + $repo = 'php-github-api'; $repo = $this->client->api('repo')->show($username, $repo); diff --git a/test/Github/Tests/Integration/ResultPagerTest.php b/test/Github/Tests/Integration/ResultPagerTest.php index d533d2ac952..447c52913ed 100644 --- a/test/Github/Tests/Integration/ResultPagerTest.php +++ b/test/Github/Tests/Integration/ResultPagerTest.php @@ -19,11 +19,11 @@ public function shouldPaginateGetRequests() $pager = $this->createPager(); - $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); + $repositories = $pager->fetch($repositoriesApi, 'repositories', ['KnpLabs']); $this->assertCount(10, $repositories); $repositoriesApi->setPerPage(20); - $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); + $repositories = $pager->fetch($repositoriesApi, 'repositories', ['KnpLabs']); $this->assertCount(20, $repositories); } @@ -47,7 +47,7 @@ public function shouldGetAllResultsFromSearchApi() $pager = $this->createPager(); - $users = $pager->fetch($searchApi, 'users', array('location:Kyiv')); + $users = $pager->fetch($searchApi, 'users', ['location:Kyiv']); $this->assertCount(10, $users); } diff --git a/test/Github/Tests/Integration/UserTest.php b/test/Github/Tests/Integration/UserTest.php index 41a14ac424f..d08f1d643a2 100644 --- a/test/Github/Tests/Integration/UserTest.php +++ b/test/Github/Tests/Integration/UserTest.php @@ -36,7 +36,7 @@ public function shouldShowUserData() */ public function shouldNotUpdateUserWithoutAuthorization() { - $this->client->api('current_user')->update(array('email' => 'leszek.prabucki@gmail.com')); + $this->client->api('current_user')->update(['email' => 'leszek.prabucki@gmail.com']); } /** diff --git a/test/Github/Tests/Mock/PaginatedResponse.php b/test/Github/Tests/Mock/PaginatedResponse.php index 13d2e815fc0..4586de402ec 100644 --- a/test/Github/Tests/Mock/PaginatedResponse.php +++ b/test/Github/Tests/Mock/PaginatedResponse.php @@ -16,18 +16,18 @@ class PaginatedResponse extends Response public function __construct($loopCount, array $content = []) { $this->loopCount = $loopCount; - $this->content = $content; + $this->content = $content; - parent::__construct(200, array('Content-Type'=>'application/json'), \GuzzleHttp\Psr7\stream_for(json_encode($content))); + parent::__construct(200, ['Content-Type'=>'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($content))); } public function getHeader($header) { if ($header === 'Link') { if ($this->loopCount > 1) { - $header = array(sprintf('; rel="next"', $this->loopCount)); + $header = [sprintf('; rel="next"', $this->loopCount)]; } else { - $header = array('; rel="prev"'); + $header = ['; rel="prev"']; } $this->loopCount--; diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 17be7278ffa..a105a84f054 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -2,11 +2,8 @@ namespace Github\Tests; -use Github\Api\Organization; use Github\Api\Organization\Members; use Github\Api\Search; -use Github\Client; -use Github\HttpClient\Builder; use Github\ResultPager; use Github\Tests\Mock\PaginatedResponse; use Http\Client\HttpClient; @@ -28,12 +25,12 @@ class ResultPagerTest extends \PHPUnit\Framework\TestCase public function shouldGetAllResults() { $amountLoops = 3; - $content = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + $content = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; $response = new PaginatedResponse($amountLoops, $content); // httpClient mock $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) - ->setMethods(array('sendRequest')) + ->setMethods(['sendRequest']) ->getMock(); $httpClientMock ->expects($this->exactly($amountLoops)) @@ -46,7 +43,7 @@ public function shouldGetAllResults() $memberApi = new Members($client); $method = 'all'; - $parameters = array('netwerven'); + $parameters = ['netwerven']; // Run fetchAll on result paginator $paginator = new ResultPager($client); @@ -72,15 +69,15 @@ public function shouldGetAllSearchResults() { $amountLoops = 3; - $content = array( + $content = [ 'total_count' => 12, - 'items' => array(1, 2, 3, 4) - ); + 'items' => [1, 2, 3, 4], + ]; $response = new PaginatedResponse($amountLoops, $content); // httpClient mock $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) - ->setMethods(array('sendRequest')) + ->setMethods(['sendRequest']) ->getMock(); $httpClientMock ->expects($this->exactly($amountLoops)) @@ -92,7 +89,7 @@ public function shouldGetAllSearchResults() $searchApi = new Search($client); $method = 'users'; $paginator = new ResultPager($client); - $result = $paginator->fetchAll($searchApi, $method, array('knplabs')); + $result = $paginator->fetchAll($searchApi, $method, ['knplabs']); $this->assertCount($amountLoops * count($content['items']), $result); } @@ -101,13 +98,13 @@ public function testFetch() { $result = 'foo'; $method = 'bar'; - $parameters = array('baz'); + $parameters = ['baz']; $api = $this->getMockBuilder(\Github\Api\ApiInterface::class) ->getMock(); $paginator = $this->getMockBuilder(\Github\ResultPager::class) ->disableOriginalConstructor() - ->setMethods(array('callApi', 'postFetch')) + ->setMethods(['callApi', 'postFetch']) ->getMock(); $paginator->expects($this->once()) ->method('callApi') From 719a37ed1edaf6fde7de7cc9973fab05a0ca73e6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 28 Dec 2017 06:05:34 +0000 Subject: [PATCH 622/951] Fixed branch alias (#667) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4ac1988eeb3..157da0f348a 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.6.x-dev" + "dev-master": "2.7.x-dev" } } } From 5419b5e894e4dd92c43536c790d4d48ad93a8f78 Mon Sep 17 00:00:00 2001 From: Joseph Mancuso Date: Mon, 8 Jan 2018 06:44:57 -0500 Subject: [PATCH 623/951] Added repository documentation to current user (#671) * created currentuser repositories documentation * Added code example to current users repo docs * changed email variable to repository variable * added parameter default and GitHub API link * added possible values --- doc/currentuser/repositories.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doc/currentuser/repositories.md diff --git a/doc/currentuser/repositories.md b/doc/currentuser/repositories.md new file mode 100644 index 00000000000..fe1ec702e63 --- /dev/null +++ b/doc/currentuser/repositories.md @@ -0,0 +1,30 @@ +## Current user / Repo API +[Back to the navigation](../README.md) + +> Requires [authentication](../security.md). + +### List repositories that are accessible to the authenticated user. + +```php +$repositories = $client->currentUser()->repositories(); +``` + +This includes repositories owned by the authenticated user, repositories where the authenticated user is a collaborator, and repositories that the authenticated user has access to through an organization membership. + +There are three values that can be passed into the `repositories` method: `type`, `sort` and `direction` + +| Parameters | Default | Possible Values | +| ------------- |-------------| -------------------------------------------- | +| type | `owner` | `all`, `owner`, `public`, `private`, `member` +| sort | `full_name` | `created`, `updated`, `pushed`, `full_name` +| direction | `asc` | `asc`, `desc` + +> See https://developer.github.com/v3/repos/#list-your-repositories for possible values and additional information + +#### Code Example: + +```php +$client = new \Github\Client(); +$client->authenticate($github_token, null, \Github\Client::AUTH_HTTP_TOKEN); +$client->currentUser()->repositories(); +``` From 2e1da6dc62194218344f32aa68e0ef6c6ee39344 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 13 Jan 2018 11:24:41 +0100 Subject: [PATCH 624/951] Change create issue example to avoid test issues in the repository --- doc/issues.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/issues.md b/doc/issues.md index 3f26bab5ad6..317f4babebe 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -38,10 +38,10 @@ Returns an array of information about the issue. > Requires [authentication](security.md). ```php -$client->api('issue')->create('KnpLabs', 'php-github-api', array('title' => 'The issue title', 'body' => 'The issue body')); +$client->api('issue')->create('KnpLabs', 'php-github-api-example', array('title' => 'The issue title', 'body' => 'The issue body')); ``` -Creates a new issue in the repo "php-github-api" of the user "KnpLabs". The issue is assigned to the authenticated user. +Creates a new issue in the repo "php-github-api-example" (the repository in this example does not exist) of the user "KnpLabs". The issue is assigned to the authenticated user. Returns an array of information about the issue. ### Close an issue From b86a36c00f0b902ead31a1b65bd431dadb96bc18 Mon Sep 17 00:00:00 2001 From: Patrik Csak Date: Sun, 4 Feb 2018 15:47:01 -0800 Subject: [PATCH 625/951] Fix return type --- lib/Github/Api/Repository/Contents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 6722bb3c7e0..ab68516f919 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -245,7 +245,7 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null * @param string $format format of archive: tarball or zipball * @param null|string $reference reference to a branch or commit * - * @return array information for archives + * @return string repository archive binary data */ public function archive($username, $repository, $format, $reference = null) { From 0c2639b383ef198a5239e673faa5617293cf0706 Mon Sep 17 00:00:00 2001 From: David Wattier Date: Mon, 12 Feb 2018 10:31:02 +0100 Subject: [PATCH 626/951] Typo fix on assignee documentation --- doc/issue/assignees.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/issue/assignees.md b/doc/issue/assignees.md index 035ea8ddcd7..d03524ae24d 100644 --- a/doc/issue/assignees.md +++ b/doc/issue/assignees.md @@ -12,17 +12,17 @@ $assignees = $client->api('issue')->assignees()->listAvailable('KnpLabs', 'php-g ### Check if a user is an available assignee ```php -$info = $client->api('issue')->assignees()->check('KnpLabs', 'php-github-api', 'test-user); +$info = $client->api('issue')->assignees()->check('KnpLabs', 'php-github-api', 'test-user'); ``` ### Add assignee ```php -$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]); +$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user']); ``` ### Remove assignee ```php -$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]); +$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user']); ``` From cbfecb301af67e8bd365146eedccdef45f736bb1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 16 Feb 2018 09:14:48 +0100 Subject: [PATCH 627/951] Missing use statement in security example --- doc/security.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/security.md b/doc/security.md index 8eedf9e604c..b762e8b9523 100644 --- a/doc/security.md +++ b/doc/security.md @@ -54,6 +54,7 @@ The following sample code authenticates as an installation using [lcobucci/jwt]( to generate a JSON Web Token (JWT). ```php +use Http\Adapter\Guzzle6\Client as GuzzleClient; use Lcobucci\JWT\Builder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Rsa\Sha256; From 556d9783bb800c8446cff09ef78ca2b6cfb8aab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20T=C3=B3th?= Date: Mon, 19 Feb 2018 13:08:26 +0100 Subject: [PATCH 628/951] Add collaborator permission call (#678) * Add collaborator permission call * Add docs for permission() call --- doc/repos.md | 18 +++++++++++++----- lib/Github/Api/Repository/Collaborators.php | 12 ++++++++++++ .../Tests/Api/Repository/CollaboratorsTest.php | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/doc/repos.md b/doc/repos.md index 3c6526b759b..8835ccf87b2 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -27,7 +27,6 @@ $repos = $client->api('repo')->find('symfony'); ``` Returns a list of repositories. - #### Advanced search You can filter the results by language. It takes the same values as the language drop down on [http://github.com/search](http://github.com/search). @@ -179,20 +178,29 @@ Returns a list of the collaborators for the 'reponame' repository. ### Add a collaborator to a repository ```php -$client->api('repo')->collaborators()->add('username', 'reponame', 'KnpLabs'); +$client->api('repo')->collaborators()->add('username', 'reponame', 'collaborator'); ``` -Adds the 'username' user as collaborator to the 'reponame' repository. +Adds the 'collaborator' user as collaborator to the 'reponame' repository. ### Remove a collaborator from a repository > Requires [authentication](security.md). ```php -$client->api('repo')->collaborators()->remove('username', 'reponame', 'KnpLabs'); +$client->api('repo')->collaborators()->remove('username', 'reponame', 'collaborator'); ``` -Remove the 'username' collaborator from the 'reponame' repository. +Remove the 'collaborator' collaborator from the 'reponame' repository. + +### Get the permissions of a collaborator for a repository + +```php +$permissions = $client->api('repo')->collaborators()->permission('username', 'reponame', 'collaborator'); +``` + +Returns the permissions of 'collaborator' collaborator for the 'reponame' repository. + ### Watch and unwatch a repository diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index b9467ed1949..b15109dd4f5 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -67,4 +67,16 @@ public function remove($username, $repository, $collaborator) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator)); } + + /** + * @link https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level + * @param $username + * @param $repository + * @param $collaborator + * @return array|string + */ + public function permission($username, $repository, $collaborator) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator).'/permission'); + } } diff --git a/test/Github/Tests/Api/Repository/CollaboratorsTest.php b/test/Github/Tests/Api/Repository/CollaboratorsTest.php index 6683dba2bd0..03b8c11d22a 100644 --- a/test/Github/Tests/Api/Repository/CollaboratorsTest.php +++ b/test/Github/Tests/Api/Repository/CollaboratorsTest.php @@ -70,6 +70,22 @@ public function shouldRemoveRepositoryCollaborator() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0')); } + /** + * @test + */ + public function shouldGetRepositoryCollaboratorPermission() + { + $expectedValue = array(array('permission' => 'admin', 'user' => 'l3l0')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/collaborators/l3l0/permission') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->permission('KnpLabs', 'php-github-api', 'l3l0')); + } + /** * @return string */ From b716e03f9cd6d259599891806a210290eecd565a Mon Sep 17 00:00:00 2001 From: Adam Campbell Date: Sun, 25 Feb 2018 14:20:41 -0600 Subject: [PATCH 629/951] Add missing parameters for User/CurrentUser Repositories (#684) * Add missing parameters for User/CurrentUser Repositories * Make some StyleCI fixes to User and CurrentUser classes * Some unrelated StyleCI fixes... ? --- lib/Github/Api/CurrentUser.php | 12 ++++++++---- lib/Github/Api/Repository/Collaborators.php | 2 ++ lib/Github/Api/User.php | 14 +++++++++----- .../Tests/Api/Repository/CollaboratorsTest.php | 2 +- test/Github/Tests/Api/UserTest.php | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 8718673746c..1ed98a65eae 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -111,18 +111,22 @@ public function teams() /** * @link http://developer.github.com/v3/repos/#list-your-repositories * - * @param string $type role in the repository - * @param string $sort sort by - * @param string $direction direction of sort, asc or desc + * @param string $type role in the repository + * @param string $sort sort by + * @param string $direction direction of sort, asc or desc + * @param string $visibility visibility of repository + * @param string $affiliation relationship to repository * * @return array */ - public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc') + public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = 'all', $affiliation = 'owner,collaborator,organization_member') { return $this->get('/user/repos', [ 'type' => $type, 'sort' => $sort, 'direction' => $direction, + 'visibility' => $visibility, + 'affiliation' => $affiliation, ]); } diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index b15109dd4f5..34411884624 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -70,9 +70,11 @@ public function remove($username, $repository, $collaborator) /** * @link https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level + * * @param $username * @param $repository * @param $collaborator + * * @return array|string */ public function permission($username, $repository, $collaborator) diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 2c3b807b9bf..c4414c56c75 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -173,19 +173,23 @@ public function subscriptions($username) * * @link https://developer.github.com/v3/repos/#list-user-repositories * - * @param string $username the username - * @param string $type role in the repository - * @param string $sort sort by - * @param string $direction direction of sort, asc or desc + * @param string $username the username + * @param string $type role in the repository + * @param string $sort sort by + * @param string $direction direction of sort, asc or desc + * @param string $visibility visibility of repository + * @param string $affiliation relationship to repository * * @return array list of the user repositories */ - public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc') + public function repositories($username, $type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = 'all', $affiliation = 'owner,collaborator,organization_member') { return $this->get('/users/'.rawurlencode($username).'/repos', [ 'type' => $type, 'sort' => $sort, 'direction' => $direction, + 'visibility' => $visibility, + 'affiliation' => $affiliation, ]); } diff --git a/test/Github/Tests/Api/Repository/CollaboratorsTest.php b/test/Github/Tests/Api/Repository/CollaboratorsTest.php index 03b8c11d22a..8bf57d96791 100644 --- a/test/Github/Tests/Api/Repository/CollaboratorsTest.php +++ b/test/Github/Tests/Api/Repository/CollaboratorsTest.php @@ -75,7 +75,7 @@ public function shouldRemoveRepositoryCollaborator() */ public function shouldGetRepositoryCollaboratorPermission() { - $expectedValue = array(array('permission' => 'admin', 'user' => 'l3l0')); + $expectedValue = [['permission' => 'admin', 'user' => 'l3l0']]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index fa56225fd1f..0c9eea62b9d 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -194,7 +194,7 @@ public function shouldGetUserRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/users/l3l0/repos', ['type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc']) + ->with('/users/l3l0/repos', ['type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc', 'visibility' => 'all', 'affiliation' => 'owner,collaborator,organization_member']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('l3l0')); From a173d54b1141c526d556feb59da7903a41156ddf Mon Sep 17 00:00:00 2001 From: Andrea Giannantonio Date: Tue, 6 Mar 2018 09:54:17 +0100 Subject: [PATCH 630/951] Pimp the readme with badge poser! (#686) * Pimp the readme with badge poser! * Override badge license with Monthly Downloads --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d6a295449c3..fc021e16c2c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ [![Build Status](https://travis-ci.org/KnpLabs/php-github-api.svg?branch=master)](https://travis-ci.org/KnpLabs/php-github-api) [![StyleCI](https://styleci.io/repos/3948501/shield?style=flat)](https://styleci.io/repos/3948501) +[![Latest Stable Version](https://poser.pugx.org/knplabs/github-api/v/stable)](https://packagist.org/packages/knplabs/github-api) +[![Total Downloads](https://poser.pugx.org/knplabs/github-api/downloads)](https://packagist.org/packages/knplabs/github-api) +[![Latest Unstable Version](https://poser.pugx.org/knplabs/github-api/v/unstable)](https://packagist.org/packages/knplabs/github-api) +[![Monthly Downloads](https://poser.pugx.org/knplabs/github-api/d/monthly)](https://packagist.org/packages/knplabs/github-api) +[![Daily Downloads](https://poser.pugx.org/knplabs/github-api/d/daily)](https://packagist.org/packages/knplabs/github-api) A simple Object Oriented wrapper for GitHub API, written with PHP5. From d6669e81b24887d664b1a291b1ee63ccd04f0653 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 8 Mar 2018 11:19:43 +0100 Subject: [PATCH 631/951] Allow data about our plugin to show up in Symfony debug toolbar (#687) * Allow data about our plugin to show up in Symfony webdebug bar * Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- lib/Github/HttpClient/Builder.php | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ad5da91b84..a1a4c427fb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.8.0 + +### Added + +- Allow our HTTP plugins to show up in the Symfony web profiler page. + ## 2.7.0 ### Added diff --git a/composer.json b/composer.json index 157da0f348a..6ad8173d1bc 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "php-http/httplug": "^1.1", "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.3", + "php-http/client-common": "^1.6", "php-http/cache-plugin": "^1.4" }, "require-dev": { diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index fe9499b29e8..e1c2050b2c6 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -6,6 +6,7 @@ use Http\Client\Common\Plugin; use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; use Http\Client\Common\PluginClient; +use Http\Client\Common\PluginClientFactory; use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; @@ -102,7 +103,7 @@ public function getHttpClient() } $this->pluginClient = new HttpMethodsClient( - new PluginClient($this->httpClient, $plugins), + (new PluginClientFactory())->createClient($this->httpClient, $plugins), $this->requestFactory ); } From 0f245db3602e4f22cf4c1ef96c66a96c5bce0935 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 8 Mar 2018 10:20:48 +0000 Subject: [PATCH 632/951] Corrected branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6ad8173d1bc..9b320a7eff7 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.7.x-dev" + "dev-master": "2.8.x-dev" } } } From 629de05f2059f79459d63814dae57039b8860201 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 9 Mar 2018 19:09:42 +0100 Subject: [PATCH 633/951] Updated requirements (#689) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc021e16c2c..86bcb041e31 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements * PHP >= 5.6 -* [Guzzle](https://github.com/guzzle/guzzle) library, +* A [HTTP client](https://packagist.org/providers/php-http/client-implementation) +* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation) * (optional) PHPUnit to run tests. ## Install From 8b9ac127688c36a10737fcbc8e10bba4882ba40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lio?= Date: Sun, 11 Mar 2018 00:12:48 -0300 Subject: [PATCH 634/951] Typo --- doc/currentuser/memberships.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/currentuser/memberships.md b/doc/currentuser/memberships.md index 989766bc254..53ee81eb96e 100644 --- a/doc/currentuser/memberships.md +++ b/doc/currentuser/memberships.md @@ -8,7 +8,7 @@ Wraps [GitHub Issue Comments API](https://developer.github.com/v3/orgs/members/# > Requires [authentication](../security.md). ```php -$memberships = $client->user()->memberships()->all(); +$memberships = $client->currentUser()->memberships()->all(); ``` Returns an array of your memberships in all organizations you are part of. @@ -18,7 +18,7 @@ Returns an array of your memberships in all organizations you are part of. > Requires [authentication](../security.md). ```php -$membership = $client->user()->memberships()->organization('KnpLabs'); +$membership = $client->currentUser()->memberships()->organization('KnpLabs'); ``` * `KnpLabs` : the organization @@ -29,7 +29,7 @@ Returns an array of one membership in a specific organization. > Requires [authentication](../security.md). ```php -$membership = $client->user()->memberships()->edit('KnpLabs'); +$membership = $client->currentUser()->memberships()->edit('KnpLabs'); ``` * `KnpLabs` : the organization From bf264fe07b34eca56539c7c4f0b24fff637bf9b5 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 17 Mar 2018 17:27:40 +0000 Subject: [PATCH 635/951] Fixed phpdoc typo (#695) * Fixed phpdoc typo * Update Builder.php --- lib/Github/HttpClient/Builder.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index e1c2050b2c6..6a635b2df41 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -5,7 +5,6 @@ use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\Plugin; use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; -use Http\Client\Common\PluginClient; use Http\Client\Common\PluginClientFactory; use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; @@ -34,7 +33,7 @@ class Builder /** * A HTTP client with all our plugins. * - * @var PluginClient + * @var HttpMethodsClient */ private $pluginClient; From 92f4207f3a653a70a03591adffde48d7fb1168f3 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 18 Mar 2018 19:32:05 +0100 Subject: [PATCH 636/951] Added check to avoid github 422 error --- lib/Github/Api/CurrentUser.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 1ed98a65eae..0c858b078b4 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -119,15 +119,25 @@ public function teams() * * @return array */ - public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = 'all', $affiliation = 'owner,collaborator,organization_member') + public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = null, $affiliation = null) { - return $this->get('/user/repos', [ + $params = [ 'type' => $type, 'sort' => $sort, 'direction' => $direction, - 'visibility' => $visibility, - 'affiliation' => $affiliation, - ]); + ]; + + if (null !== $visibility) { + unset($params['type']); + $params['visibility'] = $visibility; + } + + if (null !== $affiliation) { + unset($params['type']); + $params['affiliation'] = $affiliation; + } + + return $this->get('/user/repos', $params); } /** From f1be6755e06d055058e06d9227f9ba0c7b430d28 Mon Sep 17 00:00:00 2001 From: TVke Date: Thu, 22 Mar 2018 10:26:11 +0100 Subject: [PATCH 637/951] Replace use of depricated api to the correct one --- doc/security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/security.md b/doc/security.md index b762e8b9523..200c98176c2 100644 --- a/doc/security.md +++ b/doc/security.md @@ -71,6 +71,6 @@ $jwt = (new Builder) $github->authenticate($jwt, null, Github\Client::AUTH_JWT); -$token = $github->api('integrations')->createInstallationToken($installationId); +$token = $github->api('apps')->createInstallationToken($installationId); $github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); ``` From ae25782535f9d648a8f3ac6e095293c3dcb3b822 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 23 Mar 2018 15:54:52 +0100 Subject: [PATCH 638/951] Missing changelog items to prepare 2.8 release --- CHANGELOG.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a4c427fb8..12af198c91b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,22 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- Allow our HTTP plugins to show up in the Symfony web profiler page. +- Allow our HTTP plugins to show up in the Symfony web profiler page. (#687) +- Repository documentation to current user (#671) +- Add collaborator permission call (#678) +- Add missing parameters for User/CurrentUser Repositories (#684) +- Pimp the readme with badge poser (#686) + +### Fixed + +- Typo in assignee documentation +- Missing use statement in security example +- Fixed phpdoc typo (#695) +- Replace use of deprecated api to the correct one in the security docs (#697) + +### Changed + +- Updated requirements in readme (#689) ## 2.7.0 From 504609363777693ed30d224e3aa7edd217f8b0f3 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Sun, 25 Mar 2018 16:42:58 +0200 Subject: [PATCH 639/951] Add the repository transfer endpoint (#699) * Add the repository transfer endpoint * cs * Add tests * cs * Fix tests * typo * Update changelog * Update documentation * CamelCase * Doc fix --- CHANGELOG.md | 6 ++++++ doc/repos.md | 11 +++++++++++ lib/Github/Api/Repo.php | 20 ++++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 19 +++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12af198c91b..d4e16eeb7e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.9.0 + +### Added + +- API endpoint `Github\Api\Repo::transfer()` + ## 2.8.0 ### Added diff --git a/doc/repos.md b/doc/repos.md index 8835ccf87b2..d6abe19a0fe 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -329,3 +329,14 @@ $topics = $client->api('repo')->topics('ornicar', 'php-github-api'); ```php $currentTopics = $client->api('repo')->replaceTopics('ornicar', 'php-github-api', ['new', 'topics']); ``` + +### Transfer a repo to another user + +```php +$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github'); +``` +You can optionally assign some teams by passing an array with their ID's if you're transferring the repo to an organization: + +```php +$repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index cc2bc109972..c0c54a95f15 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -659,4 +659,24 @@ public function replaceTopics($username, $repository, array $topics) return $this->put('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/topics', ['names' => $topics]); } + + /** + * Transfer a repository. + * + * @link https://developer.github.com/v3/repos/#transfer-a-repository + * + * @param string $username + * @param string $repository + * @param string $newOwner + * @param array $teamId + * + * @return array + */ + public function transfer($username, $repository, $newOwner, $teamId = []) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.nightshade-preview+json'; + + return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 6fe7bd9d5f2..b82468e2731 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -585,6 +585,25 @@ public function shouldReplaceRepositoryTopics() $this->assertEquals($expectedArray, $api->replaceTopics('KnpLabs', 'php-github-api', ['octocat', 'atom', 'electron', 'API'])); } + /** + * @test + */ + public function shouldTransferRepository() + { + $expectedArray = ['id' => 1, 'name' => 'php-github-api']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/transfer', [ + 'new_owner' => 'github', + 'team_id' => [1234, 1235], + ]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->transfer('KnpLabs', 'php-github-api', 'github', [1234, 1235])); + } + /** * @return string */ From 44dc8571437e5b4a6fd10726bdc396e217498fd7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 25 Mar 2018 15:59:28 +0100 Subject: [PATCH 640/951] Fixed branch alias (#700) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9b320a7eff7..9c96c716a3f 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.8.x-dev" + "dev-master": "2.9.x-dev" } } } From f17c158af84f9b3c7279e5ca9dc4329d69e6d3ed Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 25 Mar 2018 19:56:39 +0100 Subject: [PATCH 641/951] Added the ability to mark a single thread as read (#693) * Added the ability to mark a single thread as read * Added test for markThreadRead * Fixed phpdoc * Updated notification docs --- doc/notification.md | 13 +++++++++++-- lib/Github/Api/Notification.php | 17 +++++++++++++++-- test/Github/Tests/Api/NotificationTest.php | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/doc/notification.md b/doc/notification.md index b47c1d5f7c3..ad022cad835 100644 --- a/doc/notification.md +++ b/doc/notification.md @@ -37,9 +37,18 @@ $client->api('notification')->markRead(new DateTime('2015/01/01')); Marks all notifications as read up until the current date, unless a date is given -## Get a single notification using his ID +### Mark a thread as read using its ID + +```php +$client->api('notification')->markThreadRead($id); +``` + +Marks a single thread as read using its ID. + +### Get a single thread using its ID ```php $client->api('notification')->id($id); ``` -Retrieves single notification data using his ID. + +Retrieves single thread's data using its ID. diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index fbaed083518..1759f26132c 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -41,7 +41,8 @@ public function all($includingRead = false, $participating = false, DateTime $si } /** - * Marks all notifications as read from the current date + * Marks all notifications as read from the current date. + * * Optionally give DateTime to mark as read before that date. * * @link https://developer.github.com/v3/activity/notifications/#mark-as-read @@ -60,7 +61,19 @@ public function markRead(DateTime $since = null) } /** - * Gets a single notification using his ID. + * Mark a single thread as read using its ID. + * + * @link https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read + * + * @param int $id + */ + public function markThreadRead($id) + { + $this->patch('/notifications/threads/'.$id); + } + + /** + * Gets a single thread using its ID. * * @link https://developer.github.com/v3/activity/notifications/#view-a-single-thread * diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index 5cbf7fabc11..e34dc171ced 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -97,6 +97,20 @@ public function shouldMarkNotificationsAsReadForGivenDate() $api->markRead($since); } + /** + * @test + */ + public function shouldMarkThreadAsRead() + { + $id = mt_rand(1, time()); + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/notifications/threads/'.$id); + + $api->markThreadRead($id); + } + public function shouldGetNotification() { $id = mt_rand(1, time()); From bc8deedd0b6a439ffbd8d339d276bed01c6b9e98 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 30 Mar 2018 22:08:58 +0100 Subject: [PATCH 642/951] Make sure per page is always restored --- lib/Github/ResultPager.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 7e872d85925..30d1ba4671f 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -78,26 +78,28 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = []) // set parameters per_page to GitHub max to minimize number of requests $api->setPerPage(100); - $result = $this->callApi($api, $method, $parameters); - $this->postFetch(); + try { + $result = $this->callApi($api, $method, $parameters); + $this->postFetch(); - if ($isSearch) { - $result = isset($result['items']) ? $result['items'] : $result; - } + if ($isSearch) { + $result = isset($result['items']) ? $result['items'] : $result; + } - while ($this->hasNext()) { - $next = $this->fetchNext(); + while ($this->hasNext()) { + $next = $this->fetchNext(); - if ($isSearch) { - $result = array_merge($result, $next['items']); - } else { - $result = array_merge($result, $next); + if ($isSearch) { + $result = array_merge($result, $next['items']); + } else { + $result = array_merge($result, $next); + } } + } finally { + // restore the perPage + $api->setPerPage($perPage); } - // restore the perPage - $api->setPerPage($perPage); - return $result; } From 857a4673f7fa364c560d039f0952ff72419c8aa9 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 30 Mar 2018 22:14:43 +0100 Subject: [PATCH 643/951] Can't inherit doc when the method is not present on the parent --- lib/Github/ResultPager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 7e872d85925..4b58a2ff5a4 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -158,7 +158,7 @@ public function fetchLast() } /** - * {@inheritdoc} + * @param string $key */ protected function has($key) { @@ -166,7 +166,7 @@ protected function has($key) } /** - * {@inheritdoc} + * @param string $key */ protected function get($key) { From 43ec535a7799dc5837879bbb4210774165e61495 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 30 Mar 2018 22:04:28 +0000 Subject: [PATCH 644/951] Fixed syntax error in phpdoc (#701) * Fixed syntax error in phpdoc * Corrected phpdoc indentation --- lib/Github/ResultPager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index b5db6a0cf4d..24f2a32f135 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -182,8 +182,8 @@ protected function get($key) /** * @param ApiInterface $api - * @param $method - * @param array $parameters + * @param string $method + * @param array $parameters * * @return mixed */ From edd2c9c25a33d611c929d542f9fe7903fc1e9943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B8egh?= <22152591+BenjaminHoegh@users.noreply.github.com> Date: Sat, 21 Apr 2018 15:33:08 +0200 Subject: [PATCH 645/951] Added resource link Added a resource link to help user find out what the different variables contains --- doc/repo/contents.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/repo/contents.md b/doc/repo/contents.md index 53c3fd20ede..756a5785316 100644 --- a/doc/repo/contents.md +++ b/doc/repo/contents.md @@ -1,6 +1,11 @@ ## Repo / Contents API [Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +--- + +You can read about references [here](https://developer.github.com/v3/git/refs/). + + ### Get a repository's README ```php From 6fbcd188048e060ac7ad63826b03a0ce85d8d775 Mon Sep 17 00:00:00 2001 From: TVke Date: Mon, 23 Apr 2018 11:23:54 +0200 Subject: [PATCH 646/951] Add more clearity about variables --- doc/security.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/security.md b/doc/security.md index 200c98176c2..9a9778c1407 100644 --- a/doc/security.md +++ b/doc/security.md @@ -23,7 +23,7 @@ and guess what should contain `$password`. The `$method` can contain one of the The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`, `Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in -`$username` variable (`$password` is omitted in this particular case). For the +`$usernameOrToken` variable (`$password` is omitted in this particular case). For the `Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID` `$usernameOrToken` should contain your client ID, and `$password` should contain client secret. @@ -47,7 +47,7 @@ Note however that GitHub describes this method as deprecated. In most case you s To authenticate as an integration you need to supply a JSON Web Token with `Github\Client::AUTH_JWT` to request and installation access token which is then usable with `Github\Client::AUTH_HTTP_TOKEN`. [Github´s integration -authentication docs](https://developer.github.com/early-access/integrations/authentication/) describe the flow in detail. +authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail. It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. The following sample code authenticates as an installation using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.2.0) @@ -74,3 +74,6 @@ $github->authenticate($jwt, null, Github\Client::AUTH_JWT); $token = $github->api('apps')->createInstallationToken($installationId); $github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); ``` + +The `$integrationId` you can find in the about section of your github app. +The `$installationId` you can find by installing the app and using the id in the url. \ No newline at end of file From d94da3d80c1074cb04a30076e4ba2e50c58d07b1 Mon Sep 17 00:00:00 2001 From: Mike Milano Date: Sun, 15 Jul 2018 11:09:07 -0700 Subject: [PATCH 647/951] Search topics implementation (#718) * Added API support for searching by topic. * Added accept header for preview mode. * Fixed parameter definition style. --- lib/Github/Api/Search.php | 17 +++++++++++++++++ test/Github/Tests/Api/SearchTest.php | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index dfc4c24718b..84626ae32db 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -95,4 +95,21 @@ public function commits($q, $sort = null, $order = 'desc') return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]); } + + /** + * Search commits by filter (q). + * + * @link https://developer.github.com/v3/search/#search-topics + * + * @param string $q the filter + * + * @return array + */ + public function topics($q) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json'; + + return $this->get('/search/topics', ['q' => $q]); + } } diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index 60ebb6cd3e1..a44c7b7499e 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -196,6 +196,26 @@ public function shouldSearchCommitsRegardingSortAndOrder() ); } + /** + * @test + */ + public function shouldSearchTopics() + { + $expectedArray = ['total_count' => '0']; + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/search/topics', ['q' => 'query text']) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->topics('query text') + ); + } + /** * @return string */ From e471b8e495820adb433d7e55c0429008e34ba7c1 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 22 Jul 2018 10:22:50 -0700 Subject: [PATCH 648/951] Added changelog for 2.9 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4e16eeb7e8..451268caf91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added - API endpoint `Github\Api\Repo::transfer()` +- API endpoint `Github\Api\Notification::markThreadRead()` +- API endpoint `Github\Api\Search::topics()` + +### Fixed + +- Make sure to always reset the "per page" in `Github\ResultPager::fetchAll()`. ## 2.8.0 From a1e207d7411190a68c4e8e78bacb42a36a4b1e9a Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Tue, 24 Jul 2018 22:39:14 +0300 Subject: [PATCH 649/951] Add comment about `Key` constructor argument --- doc/security.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/security.md b/doc/security.md index 9a9778c1407..afc1adeef52 100644 --- a/doc/security.md +++ b/doc/security.md @@ -66,6 +66,7 @@ $jwt = (new Builder) ->setIssuer($integrationId) ->setIssuedAt(time()) ->setExpiration(time() + 60) + // `file://` prefix for file path or file contents itself ->sign(new Sha256(), new Key('file:///path/to/integration.private-key.pem')) ->getToken(); @@ -76,4 +77,4 @@ $github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); ``` The `$integrationId` you can find in the about section of your github app. -The `$installationId` you can find by installing the app and using the id in the url. \ No newline at end of file +The `$installationId` you can find by installing the app and using the id in the url. From 96b4ff0ac656e489dc018651cf0c300a76cae9d1 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Sat, 4 Aug 2018 18:58:01 +0100 Subject: [PATCH 650/951] Allow unspecified `event` when creating review (#723) * Allow unspecified `event` when creating review Documentation for `event` in "Create a pull request review" states that "By leaving this blank, you set the review action state to `PENDING`, which means you will need to submit the pull request review when you are ready." This means that omitting `event` is perfectly legal. * Fix review creation test case Since we now allow `event` to be missing, adjust the test case to expect POST request to be made. --- lib/Github/Api/PullRequest/Review.php | 6 +----- test/Github/Tests/Api/PullRequest/ReviewTest.php | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 04d5fb766ac..f9795de0531 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -112,11 +112,7 @@ public function comments($username, $repository, $pullRequest, $id) */ public function create($username, $repository, $pullRequest, array $params = []) { - if (!isset($params['event'])) { - throw new MissingArgumentException('event'); - } - - if (!in_array($params['event'], ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], true)) { + if (array_key_exists('event', $params) && !in_array($params['event'], ['APPROVE', 'REQUEST_CHANGES', 'COMMENT'], true)) { throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); } diff --git a/test/Github/Tests/Api/PullRequest/ReviewTest.php b/test/Github/Tests/Api/PullRequest/ReviewTest.php index 24e212cde42..56c875a09a7 100644 --- a/test/Github/Tests/Api/PullRequest/ReviewTest.php +++ b/test/Github/Tests/Api/PullRequest/ReviewTest.php @@ -212,9 +212,8 @@ public function shouldCreateReviewComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ - public function shouldNotCreateReviewWithoutEvent() + public function shouldCreatePendingReviewWithoutEvent() { $data = [ 'body' => 'Nice change', @@ -222,8 +221,9 @@ public function shouldNotCreateReviewWithoutEvent() $api = $this->getApiMock(); $api - ->expects($this->never()) + ->expects($this->once()) ->method('post') + ->with('/repos/octocat/Hello-World/pulls/12/reviews') ; $api->create('octocat', 'Hello-World', 12, $data); From ba3f7deb2af21591ae68b490d0da13cff0e365ae Mon Sep 17 00:00:00 2001 From: Steven Yung Date: Mon, 6 Aug 2018 12:19:20 +0200 Subject: [PATCH 651/951] Add support for "before" parameter on Notification API (#724) * Add support for "before" parameter on Notification API add support for "before" paramaters on Notification API add NotificationTest@shouldGetNotificationsBefore * fix styling --- lib/Github/Api/Notification.php | 6 +++++- test/Github/Tests/Api/NotificationTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 1759f26132c..0d73d6076c7 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -26,7 +26,7 @@ class Notification extends AbstractApi * * @return array array of notifications */ - public function all($includingRead = false, $participating = false, DateTime $since = null) + public function all($includingRead = false, $participating = false, DateTime $since = null, DateTime $before = null) { $parameters = [ 'all' => $includingRead, @@ -37,6 +37,10 @@ public function all($includingRead = false, $participating = false, DateTime $si $parameters['since'] = $since->format(DateTime::ISO8601); } + if ($before !== null) { + $parameters['before'] = $before->format(DateTime::ISO8601); + } + return $this->get('/notifications', $parameters); } diff --git a/test/Github/Tests/Api/NotificationTest.php b/test/Github/Tests/Api/NotificationTest.php index e34dc171ced..7ef3e64ba45 100644 --- a/test/Github/Tests/Api/NotificationTest.php +++ b/test/Github/Tests/Api/NotificationTest.php @@ -45,6 +45,27 @@ public function shouldGetNotificationsSince() $api->all(false, false, $since); } + /** + * @test + */ + public function shouldGetNotificationsBefore() + { + $before = new DateTime('now'); + + $parameters = [ + 'all' => false, + 'participating' => false, + 'before' => $before->format(DateTime::ISO8601), + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/notifications', $parameters); + + $api->all(false, false, null, $before); + } + /** * @test */ From 15d0116010494ba3868d3c33ffbd92b22a57339d Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Tue, 28 Aug 2018 09:19:27 -0400 Subject: [PATCH 652/951] Adjust: installationn access token endpoint --- lib/Github/Api/Apps.php | 4 +++- test/Github/Tests/Api/AppTest.php | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 8ef0833875e..1467d2aaf43 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -16,6 +16,8 @@ class Apps extends AbstractApi * @param int $userId An optional user id on behalf of whom the * token will be requested * + * @link https://developer.github.com/v3/apps/#create-a-new-installation-token + * * @return array token and token metadata */ public function createInstallationToken($installationId, $userId = null) @@ -25,7 +27,7 @@ public function createInstallationToken($installationId, $userId = null) $parameters['user_id'] = $userId; } - return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); + return $this->post('/app/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); } /** diff --git a/test/Github/Tests/Api/AppTest.php b/test/Github/Tests/Api/AppTest.php index 75e028dbfcf..446ebf5d72f 100644 --- a/test/Github/Tests/Api/AppTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -4,6 +4,26 @@ class AppTest extends TestCase { + /** + * @test + */ + public function shouldCreateInstallationTokenForInstallation() + { + $result = [ + 'token' => 'v1.1f699f1069f60xxx', + 'expires_at' => '2016-07-11T22:14:10Z', + ]; + $installationId = 'installation1'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/app/installations/'.$installationId.'/access_tokens', []) + ->willReturn($result); + + $this->assertEquals($result, $api->createInstallationToken($installationId)); + } + /** * @test */ From a507ef6783bdb0292923928b368eb71afdbcc41b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 29 Aug 2018 18:56:14 +1200 Subject: [PATCH 653/951] Fix "get single label" example and add correct example for getting issue's labels --- doc/issue/labels.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 828726f96ed..4a9964f4402 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -15,7 +15,7 @@ Returns an array of project labels. ### Get a single label ```php -$label = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api', 'label1'); +$label = $client->api('issue')->labels()->show('KnpLabs', 'php-github-api', 'label1'); ``` ### Create a label @@ -57,6 +57,12 @@ Add a label to the issue by username, repo, issue number label name and. If the the system, it will be created. Returns an array of the issue labels. +### Get all labels for an issue + +```php +$label = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api', 4); +``` + ### Replace all labels for an issue > Requires [authentication](../security.md). From 48b4a7877a7d67199349fc062f1ce95a549e8224 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 2 Sep 2018 13:39:21 +0200 Subject: [PATCH 654/951] Check for BC breaks --- .travis.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6aa267626d5..07916214473 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,13 @@ language: php sudo: false cache: - directories: - - vendor - - $HOME/.composer/cache + directories: + - vendor + - $HOME/.composer/cache + +env: + global: + - TEST_COMMAND="vendor/bin/phpunit --verbose --coverage-text" php: - 5.6 @@ -16,9 +20,15 @@ matrix: include: - php: hhvm dist: trusty + - php: 7.2 + name: Backward compatibillity check + env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./vendor/bin/roave-backward-compatibility-check" + +before_install: + - if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; install: - travis_retry composer install --no-interaction script: - - vendor/bin/phpunit --verbose --coverage-text + - $TEST_COMMAND From c60cc216502a0b225fe52007067bd738017f7be4 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Sun, 2 Sep 2018 13:45:20 +0200 Subject: [PATCH 655/951] FIX GraphQL test warnings when they do not assert anything --- test/Github/Tests/Api/GraphQLTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index 5faea997d3b..042cb014a50 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -27,7 +27,8 @@ public function shouldSupportGraphQLVariables() { $api = $this->getApiMock(); - $api->method('post') + $api->expects($this->once()) + ->method('post') ->with('/graphql', $this->arrayHasKey('variables')); $api->execute('bar', ['variable' => 'foo']); @@ -40,7 +41,8 @@ public function shouldJSONEncodeGraphQLVariables() { $api = $this->getApiMock(); - $api->method('post') + $api->expects($this->once()) + ->method('post') ->with('/graphql', $this->equalTo([ 'query'=>'bar', 'variables' => '{"variable":"foo"}', From 3acc9843356ba2996108d8b70f02e8c7d33751cb Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 3 Sep 2018 22:50:39 +0200 Subject: [PATCH 656/951] Prepare 2.10.0 release --- CHANGELOG.md | 16 ++++++++++++++++ composer.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 451268caf91..fc4b55abaca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.10.0 + +### Added + +- Support for "before" parameter on Notification API (#724) + +### Changed + +- Allow unspecified `event` when creating review (#723) + +### Fixed + +- Adjust: installationn access token endpoint (#731) +- Fixed "get single label" example and add correct example for getting issue's labels (#732) +- Add comment about `Key` constructor argument (#722) + ## 2.9.0 ### Added diff --git a/composer.json b/composer.json index 9c96c716a3f..bfb6f79a8a2 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.9.x-dev" + "dev-master": "2.10.x-dev" } } } From 15100182b2ca389869861e3f636f3c7c6df4133a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 5 Sep 2018 19:31:47 +0200 Subject: [PATCH 657/951] Removed deprecated package because it is not working --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 9c96c716a3f..903a0365bad 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,6 @@ "php-http/guzzle6-adapter": "^1.0", "php-http/mock-client": "^1.0", "guzzlehttp/psr7": "^1.2", - "sllh/php-cs-fixer-styleci-bridge": "^1.3", "cache/array-adapter": "^0.4" }, "autoload": { From e91aba462179cdcc0f142a02131dbbc395a4c95a Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 5 Sep 2018 19:34:37 +0200 Subject: [PATCH 658/951] Added new php_cs conf --- .php_cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.php_cs b/.php_cs index 49ee926957e..83782b0f551 100644 --- a/.php_cs +++ b/.php_cs @@ -1,14 +1,14 @@ in(__DIR__); -use SLLH\StyleCIBridge\ConfigBridge; +$config = PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ -$config = ConfigBridge::create(); -$config->setUsingCache(true); - -if (method_exists($config, 'setRiskyAllowed')) { - $config->setRiskyAllowed(true); -} + ]) + ->setFinder($finder) +; return $config; From 6e9759c978d24550887f5593b6f1b27a3099f644 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 5 Sep 2018 20:13:29 +0200 Subject: [PATCH 659/951] Convert the assignee parameter to array --- lib/Github/Api/Issue/Assignees.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php index 31d6ac9d999..1e5e0b727a1 100644 --- a/lib/Github/Api/Issue/Assignees.php +++ b/lib/Github/Api/Issue/Assignees.php @@ -57,6 +57,12 @@ public function add($username, $repository, $issue, array $parameters) throw new MissingArgumentException('assignees'); } + if (!is_array($parameters['assignees'])) { + @trigger_error(sprintf('Passing the "assignees" parameter as a string in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array of strings instead', __METHOD__), E_USER_DEPRECATED); + + $parameters['assignees'] = [$parameters['assignees']]; + } + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters); } From 7995b7445a162a1d16eb7b9d4111ef0fac78f31f Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 5 Sep 2018 21:04:16 +0200 Subject: [PATCH 660/951] Prepare 2.10.1 release --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4b55abaca..d370a032502 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.10.1 + +### Fixed + +- Convert the assignee parameter to array to avoid getting a 422 error on github (#738) +- Fix GraphQL test warnings when they do not assert anything (#735) + +### Changed + +- Check for BC breaks during the travis build (#734) + ## 2.10.0 ### Added From 74d6231d02c8bc7cc06f40e732b9100e571f220b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 5 Sep 2018 21:50:06 +0200 Subject: [PATCH 661/951] MINOR Add structured Limit objects for rate limiting API, deprecate getRateLimits() (#733) * MINOR Add structured Limit objects for rate limiting API, deprecate getRateLimits() This adds structured link objects for each of the rate limiting resources that is returned from GitHub, including adding GraphQL. The previous methods are still backwards compatible and working, but are now deprecated in favour of the new methods. * Bump deprecation point to 2.11 --- doc/rate_limits.md | 20 ++-- lib/Github/Api/RateLimit.php | 75 ++++++++++++-- .../Api/RateLimit/RateLimitResource.php | 61 ++++++++++++ test/Github/Tests/Api/RateLimitTest.php | 99 +++++++++++++++---- .../Tests/Integration/RateLimitTest.php | 14 +++ 5 files changed, 235 insertions(+), 34 deletions(-) create mode 100644 lib/Github/Api/RateLimit/RateLimitResource.php diff --git a/doc/rate_limits.md b/doc/rate_limits.md index d64e91be39c..4ae826999f9 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -1,23 +1,31 @@ ## Rate Limit API [Back to the navigation](README.md) -Get Rate Limit -Wraps [GitHub Rate Limit API](http://developer.github.com/v3/rate_limit/). +Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com/v3/rate_limit/). -#### Get All Rate Limits. +#### Get All Rate Limits ```php -$rateLimits = $client->api('rate_limit')->getRateLimits(); +/** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits +$rateLimits = $client->api('rate_limit')->getLimits(); ``` #### Get Core Rate Limit ```php -$coreLimit = $client->api('rate_limit')->getCoreLimit(); +$coreLimit = $client->api('rate_limit')->getResource('core')->getLimit(); +$remaining = $client->api('rate_limit')->getResource('core')->getRemaining(); +$reset = $client->api('rate_limit')->getResource('core')->getReset(); ``` #### Get Search Rate Limit ```php -$searchLimit = $client->api('rate_limit')->getSearchLimit(); +$searchLimit = $client->api('rate_limit')->getResource('search')->getLimit(); +``` + +#### Get GraphQL Rate Limit + +```php +$searchLimit = $client->api('rate_limit')->getResource('graphql')->getLimit(); ``` diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index ba5301dffd6..e05508998e9 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -2,6 +2,8 @@ namespace Github\Api; +use Github\Api\RateLimit\RateLimitResource; + /** * Get rate limits. * @@ -12,36 +14,93 @@ class RateLimit extends AbstractApi { /** - * Get rate limits. + * @var RateLimitResource[] + */ + protected $resources = []; + + /** + * Get rate limits data in an array. + * + * @deprecated since 2.11.0 Use `->getResources()` instead * * @return array */ public function getRateLimits() { - return $this->get('/rate_limit'); + return $this->fetchLimits(); + } + + /** + * Gets the rate limit resource objects. + * + * @return RateLimitResource[] + */ + public function getResources() + { + $this->fetchLimits(); + + return $this->resources; + } + + /** + * Returns a rate limit resource object by the given name. + * + * @param string $name + * + * @return RateLimitResource|false + */ + public function getResource($name) + { + // Fetch once per instance + if (empty($this->resources)) { + $this->fetchLimits(); + } + + if (!isset($this->resources[$name])) { + return false; + } + + return $this->resources[$name]; + } + + /** + * Returns the data directly from the GitHub API endpoint. + * + * @return array + */ + protected function fetchLimits() + { + $result = $this->get('/rate_limit') ?: []; + + // Assemble Limit instances + foreach ($result['resources'] as $resourceName => $resource) { + $this->resources[$resourceName] = new RateLimitResource($resourceName, $resource); + } + + return $result; } /** * Get core rate limit. * + * @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead + * * @return int */ public function getCoreLimit() { - $response = $this->getRateLimits(); - - return $response['resources']['core']['limit']; + return $this->getResource('core')->getLimit(); } /** * Get search rate limit. * + * @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead + * * @return int */ public function getSearchLimit() { - $response = $this->getRateLimits(); - - return $response['resources']['search']['limit']; + return $this->getResource('search')->getLimit(); } } diff --git a/lib/Github/Api/RateLimit/RateLimitResource.php b/lib/Github/Api/RateLimit/RateLimitResource.php new file mode 100644 index 00000000000..5c7cd692c9c --- /dev/null +++ b/lib/Github/Api/RateLimit/RateLimitResource.php @@ -0,0 +1,61 @@ +name = $name; + $this->limit = $data['limit']; + $this->remaining = $data['remaining']; + $this->reset = $data['reset']; + } + + /** + * The name of the Limit, e.g. "core", "graphql", "search". + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The rate limit amount. + * + * @return int + */ + public function getLimit() + { + return $this->limit; + } + + /** + * Number of requests remaining in time period before hitting the rate limit. + * + * @return int + */ + public function getRemaining() + { + return $this->remaining; + } + + /** + * Timestamp for when the rate limit will be reset. + * + * @return int + */ + public function getReset() + { + return $this->reset; + } +} diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index 7ff78ca0de1..1c3a1f3c3dd 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -2,35 +2,94 @@ namespace Github\Tests\Api; +use Github\Api\RateLimit; + class RateLimitTest extends TestCase { /** - * @test + * Used for common assertions in each test. + * + * @var array */ - public function shouldReturnRateLimitArray() - { - $expectedArray = [ - 'resources' => [ - 'core' => [ - 'limit' => 5000, - 'remaining' => 4999, - 'reset' => 1372700873, - ], - 'search' => [ - 'limit' => 30, - 'remaining' => 18, - 'reset' => 1372697452, - ], + protected $expectedArray = [ + 'resources' => [ + 'core' => [ + 'limit' => 5000, + 'remaining' => 4999, + 'reset' => 1372700873, + ], + 'search' => [ + 'limit' => 30, + 'remaining' => 18, + 'reset' => 1372697452, + ], + 'graphql' => [ + 'limit' => 5000, + 'remaining' => 4030, + 'reset' => 1372697452, ], - ]; + ], + ]; + + /** + * @var RateLimit + */ + protected $api; + + /** + * Used to construct common expectations for the API input data in each unit test. + * + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); - $api = $this->getApiMock(); - $api->expects($this->once()) + $this->api = $this->getApiMock(); + $this->api->expects($this->once()) ->method('get') ->with('/rate_limit') - ->will($this->returnValue($expectedArray)); + ->will($this->returnValue($this->expectedArray)); + } - $this->assertEquals($expectedArray, $api->getRateLimits()); + /** + * @test + */ + public function shouldReturnRateLimitArray() + { + $this->assertSame($this->expectedArray, $this->api->getRateLimits()); + } + + /** + * @test + */ + public function shouldReturnArrayOfLimitInstances() + { + $this->assertContainsOnlyInstancesOf(RateLimit\RateLimitResource::class, $this->api->getResources()); + } + + /** + * @test + */ + public function shouldReturnRemainingGraphQLRequests() + { + $this->assertSame(4030, $this->api->getResource('graphql')->getRemaining()); + } + + /** + * @test + */ + public function shouldReturnResetForSearch() + { + $this->assertSame(1372697452, $this->api->getResource('search')->getReset()); + } + + /** + * @test + */ + public function shouldReturnFalseWhenResourceIsNotFound() + { + $this->assertFalse($this->api->getResource('non-exitent')); } /** diff --git a/test/Github/Tests/Integration/RateLimitTest.php b/test/Github/Tests/Integration/RateLimitTest.php index 64599e7c679..c4b5a521645 100644 --- a/test/Github/Tests/Integration/RateLimitTest.php +++ b/test/Github/Tests/Integration/RateLimitTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Integration; +use Github\Api\RateLimit\RateLimitResource; + /** * @group integration */ @@ -17,4 +19,16 @@ public function shouldRetrievedRateLimits() $this->assertArrayHasKey('resources', $response); $this->assertArraySubset(['resources' => ['core' => ['limit' => 60]]], $response); } + + /** + * @test + */ + public function shouldRetrieveRateLimitsAndReturnLimitInstances() + { + $response = $this->client->api('rate_limit')->getLimits(); + + $this->assertInternalType('array', $response); + $this->assertContainsOnlyInstancesOf(RateLimitResource::class, $response); + $this->assertEquals(60, $response->getLimit('core')->getLimit()); + } } From be3c5f33058d19ae8eff2766777c173825b6e48e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 5 Sep 2018 21:53:11 +0200 Subject: [PATCH 662/951] Bump branch alias for upcoming 2.11.0 release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d3641f472a0..4c1fcea4e9d 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.10.x-dev" + "dev-master": "2.11.x-dev" } } } From c9c742f745c6f468440a968af5afd4a850108c6c Mon Sep 17 00:00:00 2001 From: Antonio Tajuelo Date: Thu, 6 Sep 2018 09:33:11 +0200 Subject: [PATCH 663/951] Added support for getting star creation timestamps in activity/starring endpoint (#729) * Added support for getting star creation timestamps https://developer.github.com/v3/activity/starring/#list-stargazers * Fixed style * Updated docs for including starred creation date --- doc/activity.md | 9 +++++++++ lib/Github/Api/CurrentUser/Starring.php | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/doc/activity.md b/doc/activity.md index 81b35d47973..7cad30ef5f7 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -31,6 +31,15 @@ $activity = $client->api('current_user')->starring()->all(); ``` Returns an array of starred repos. +### Get repos that a authenticated user has starred with creation date + +Support for getting the star creation timestamp in the response, using the custom `Accept: application/vnd.github.v3.star+json` header. + +```php +$activity = $client->api('current_user')->starring()->configure('star')->all(); +``` +Returns an array of starred repos, including the `created_at` attribute for every star. + ### Check if authenticated user has starred a specific repo ```php diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index d823c0bf0f1..5fb6435f1f6 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -3,6 +3,7 @@ namespace Github\Api\CurrentUser; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://developer.github.com/v3/activity/starring/ @@ -11,6 +12,26 @@ */ class Starring extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @see https://developer.github.com/v3/activity/starring/#list-stargazers + * + * @param string $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if ('star' === $bodyType) { + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); + } + + return $this; + } + /** * List repositories starred by the authenticated user. * From ac67ff066bf430eddc504b2c4b6c30a27ae4066d Mon Sep 17 00:00:00 2001 From: Robert Dezso Date: Sun, 16 Sep 2018 14:49:02 +0200 Subject: [PATCH 664/951] Added support for Miscellaneous Licenses (#744) * Added support for Miscellaneous Licenses * Class fix --- doc/README.md | 1 + doc/miscellaneous/licenses.md | 14 +++++ lib/Github/Api/Miscellaneous/Licenses.php | 34 ++++++++++++ lib/Github/Client.php | 5 ++ .../Tests/Api/Miscellaneous/LicensesTest.php | 54 +++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 doc/miscellaneous/licenses.md create mode 100644 lib/Github/Api/Miscellaneous/Licenses.php create mode 100644 test/Github/Tests/Api/Miscellaneous/LicensesTest.php diff --git a/doc/README.md b/doc/README.md index a3334631fb5..c4c3562df9b 100644 --- a/doc/README.md +++ b/doc/README.md @@ -34,6 +34,7 @@ v3 APIs: * [Code of conduct](miscellaneous/codeofconduct.md) * [Emojis](miscellaneous/emojis.md) * [Gitignore](miscellaneous/gitignore.md) + * [Licenses](miscellaneous/licenses.md) * [Markdown](miscellaneous/markdown.md) * [Organization](organization.md) * [Members](organization/members.md) diff --git a/doc/miscellaneous/licenses.md b/doc/miscellaneous/licenses.md new file mode 100644 index 00000000000..c533f7ffda0 --- /dev/null +++ b/doc/miscellaneous/licenses.md @@ -0,0 +1,14 @@ +## Licenses API +[Back to the navigation](../README.md) + +### Lists all licenses. + +```php +$licenses = $client->api('licenses')->all(); +``` + +### Get a license. + +```php +$license = $client->api('licenses')->show('gpl-2.0'); +``` diff --git a/lib/Github/Api/Miscellaneous/Licenses.php b/lib/Github/Api/Miscellaneous/Licenses.php new file mode 100644 index 00000000000..f8e55782a89 --- /dev/null +++ b/lib/Github/Api/Miscellaneous/Licenses.php @@ -0,0 +1,34 @@ +get('/licenses'); + } + + /** + * Get an individual license by its license key. + * + * @link https://developer.github.com/v3/licenses/#get-an-individual-license + * + * @param string $license + * + * @return array + */ + public function show($license) + { + return $this->get('/licenses/'.rawurlencode($license)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 8e2ea275502..c6a904a14cc 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -25,6 +25,7 @@ * @method Api\Enterprise enterprise() * @method Api\Miscellaneous\CodeOfConduct codeOfConduct() * @method Api\Miscellaneous\Emojis emojis() + * @method Api\Miscellaneous\Licenses licenses() * @method Api\GitData git() * @method Api\GitData gitData() * @method Api\Gists gist() @@ -221,6 +222,10 @@ public function api($name) $api = new Api\Markdown($this); break; + case 'licenses': + $api = new Api\Miscellaneous\Licenses($this); + break; + case 'notification': case 'notifications': $api = new Api\Notification($this); diff --git a/test/Github/Tests/Api/Miscellaneous/LicensesTest.php b/test/Github/Tests/Api/Miscellaneous/LicensesTest.php new file mode 100644 index 00000000000..ed504c9b4aa --- /dev/null +++ b/test/Github/Tests/Api/Miscellaneous/LicensesTest.php @@ -0,0 +1,54 @@ + 'mit'], + ['key' => 'apache-2.0'], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/licenses') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetSingleLicenses() + { + $expectedArray = [ + 'key' => 'gpl-2.0', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/licenses/gpl-2.0') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('gpl-2.0')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return Licenses::class; + } +} From 9a565debd5d6cc3a73805374305ce4e5b489f851 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 23 Sep 2018 16:09:36 +0200 Subject: [PATCH 665/951] Fix of PHP version in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86bcb041e31..481609ca25a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Monthly Downloads](https://poser.pugx.org/knplabs/github-api/d/monthly)](https://packagist.org/packages/knplabs/github-api) [![Daily Downloads](https://poser.pugx.org/knplabs/github-api/d/daily)](https://packagist.org/packages/knplabs/github-api) -A simple Object Oriented wrapper for GitHub API, written with PHP5. +A simple Object Oriented wrapper for GitHub API, written with PHP. Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4](http://developer.github.com/v4). The object API (v3) is very similar to the RESTful API. From efe3850f8ce40802c977030eb606c2147916899b Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 13 Oct 2018 22:54:40 +0200 Subject: [PATCH 666/951] Added missing has_projects parameter to repo create --- lib/Github/Api/Repo.php | 5 ++++- test/Github/Tests/Api/RepoTest.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index c0c54a95f15..c8e6a24d631 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -187,6 +187,7 @@ public function showById($id) * @param bool $hasDownloads `true` to enable downloads for this repository, `false` to disable them * @param int $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. * @param bool $autoInit `true` to create an initial commit with empty README, `false` for no initial commit + * @param bool $hasProjects `true` to enable projects for this repository or false to disable them. * * @return array returns repository data */ @@ -200,7 +201,8 @@ public function create( $hasWiki = false, $hasDownloads = false, $teamId = null, - $autoInit = false + $autoInit = false, + $hasProjects = true ) { $path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos'; @@ -213,6 +215,7 @@ public function create( 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, 'auto_init' => $autoInit, + 'has_projects' => $hasProjects, ]; if ($organization && $teamId) { diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index b82468e2731..3ddf7cf8054 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -135,6 +135,7 @@ public function shouldCreateRepositoryUsingNameOnly() 'has_wiki' => false, 'has_downloads' => false, 'auto_init' => false, + 'has_projects' => true, ]) ->will($this->returnValue($expectedArray)); @@ -160,6 +161,7 @@ public function shouldCreateRepositoryForOrganization() 'has_wiki' => false, 'has_downloads' => false, 'auto_init' => false, + 'has_projects' => true, ]) ->will($this->returnValue($expectedArray)); @@ -329,6 +331,7 @@ public function shouldCreateUsingAllParams() 'has_wiki' => false, 'has_downloads' => false, 'auto_init' => false, + 'has_projects' => true, ]) ->will($this->returnValue($expectedArray)); From 7e07e4a62d614f39b023e54d7d22176316e0fd26 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 14 Oct 2018 14:34:37 +0200 Subject: [PATCH 667/951] Allow symlink to files to be downloaded (#751) --- lib/Github/Api/Repository/Contents.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 64346e62f65..ae1b0693772 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -276,8 +276,8 @@ public function download($username, $repository, $path, $reference = null) { $file = $this->show($username, $repository, $path, $reference); - if (!isset($file['type']) || 'file' !== $file['type']) { - throw new InvalidArgumentException(sprintf('Path "%s" is not a file.', $path)); + if (!isset($file['type']) || !in_array($file['type'], ['file', 'symlink'], true)) { + throw new InvalidArgumentException(sprintf('Path "%s" is not a file or a symlink to a file.', $path)); } if (!isset($file['content'])) { From 35c10798ba06695dfbd8b43b725dc4bb28f819b1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 16 Oct 2018 20:27:03 +0200 Subject: [PATCH 668/951] Test against upcoming php version 7.3 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 07916214473..6a9b3776ba5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ php: - 7.0 - 7.1 - 7.2 + - 7.3 matrix: include: From 15ba6c6f3e4a9fe7c42d7c10582382f03763d58f Mon Sep 17 00:00:00 2001 From: Dan Feder Date: Sun, 21 Oct 2018 18:59:12 -0400 Subject: [PATCH 669/951] Fix documentation to get release for a tag --- doc/repo/releases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index b64468a8171..1b433a5f6ab 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -21,7 +21,7 @@ Note: Draft releases are only visible to authenticated users who have push acces ### List releases for a tag ```php -$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec'); +$release = $client->api('repo')->releases()->tag('twbs', 'bootstrap', 'd890eec'); ``` ### List all releases From e10875fb7020e35c09748e23ee243329b8c042c8 Mon Sep 17 00:00:00 2001 From: Alexey Shokov Date: Fri, 2 Nov 2018 15:53:04 +0100 Subject: [PATCH 670/951] Proper type hinting for magic methods --- lib/Github/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c6a904a14cc..ecb8e694448 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -54,8 +54,8 @@ * @method Api\Repo repository() * @method Api\Repo repositories() * @method Api\Search search() - * @method Api\Organization team() - * @method Api\Organization teams() + * @method Api\Organization\Teams team() + * @method Api\Organization\Teams teams() * @method Api\User user() * @method Api\User users() * @method Api\Authorizations authorization() From cf547901ceb2a80eed37094e22e8d8e5fc39216c Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 18 Dec 2018 18:12:52 +0100 Subject: [PATCH 671/951] Declare all used properties in RateLimitResource class --- lib/Github/Api/RateLimit/RateLimitResource.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Github/Api/RateLimit/RateLimitResource.php b/lib/Github/Api/RateLimit/RateLimitResource.php index 5c7cd692c9c..661a4e5287c 100644 --- a/lib/Github/Api/RateLimit/RateLimitResource.php +++ b/lib/Github/Api/RateLimit/RateLimitResource.php @@ -7,6 +7,18 @@ */ class RateLimitResource { + /** @var string */ + private $name; + + /** @var int */ + private $limit; + + /** @var int */ + private $reset; + + /** @var int */ + private $remaining; + /** * @param string $name * @param array $data From 0efd4f50ce46c64e8abf31a265879fb18298968e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 18 Dec 2018 18:18:44 +0100 Subject: [PATCH 672/951] Add missing parameter types --- lib/Github/Api/Authorizations.php | 22 +++++++------- lib/Github/Api/Issue/Events.php | 6 ++-- lib/Github/Api/Organization.php | 6 ++-- lib/Github/Api/PullRequest/Comments.php | 2 +- lib/Github/Api/Repository/Collaborators.php | 32 ++++++++++----------- lib/Github/Api/Repository/Releases.php | 10 +++---- lib/Github/Client.php | 2 +- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index fd8e9b23f50..f53b9eb4d22 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -24,7 +24,7 @@ public function all() /** * Show a single authorization. * - * @param $clientId + * @param string $clientId * * @return array */ @@ -51,8 +51,8 @@ public function create(array $params, $OTPCode = null) /** * Update an authorization. * - * @param $clientId - * @param array $params + * @param string $clientId + * @param array $params * * @return array */ @@ -64,7 +64,7 @@ public function update($clientId, array $params) /** * Remove an authorization. * - * @param $clientId + * @param string $clientId * * @return array */ @@ -76,8 +76,8 @@ public function remove($clientId) /** * Check an authorization. * - * @param $clientId - * @param $token + * @param string $clientId + * @param string $token * * @return array */ @@ -89,8 +89,8 @@ public function check($clientId, $token) /** * Reset an authorization. * - * @param $clientId - * @param $token + * @param string $clientId + * @param string $token * * @return array */ @@ -102,8 +102,8 @@ public function reset($clientId, $token) /** * Remove an authorization. * - * @param $clientId - * @param $token + * @param string $clientId + * @param string $token */ public function revoke($clientId, $token) { @@ -113,7 +113,7 @@ public function revoke($clientId, $token) /** * Revoke all authorizations. * - * @param $clientId + * @param string $clientId */ public function revokeAll($clientId) { diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 8b70ec79e09..c846147e5f8 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -41,9 +41,9 @@ public function all($username, $repository, $issue = null, $page = 1) * * @link https://developer.github.com/v3/issues/events/#get-a-single-event * - * @param $username - * @param $repository - * @param $event + * @param string $username + * @param string $repository + * @param string $event * * @return array */ diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 49ca5c91f03..29b71d1480e 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -91,9 +91,9 @@ public function teams() /** * @link http://developer.github.com/v3/issues/#list-issues * - * @param $organization - * @param array $params - * @param int $page + * @param string $organization + * @param array $params + * @param int $page * * @return array */ diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 183bfbe06ef..c1e29032d96 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -21,7 +21,7 @@ class Comments extends AbstractApi * @link https://developer.github.com/v3/pulls/comments/#custom-media-types * * @param string|null $bodyType - * @param string|null @apiVersion + * @param string|null $apiVersion * * @return self */ diff --git a/lib/Github/Api/Repository/Collaborators.php b/lib/Github/Api/Repository/Collaborators.php index 34411884624..5c61b9bfee3 100644 --- a/lib/Github/Api/Repository/Collaborators.php +++ b/lib/Github/Api/Repository/Collaborators.php @@ -14,9 +14,9 @@ class Collaborators extends AbstractApi /** * @link https://developer.github.com/v3/repos/collaborators/#list-collaborators * - * @param $username - * @param $repository - * @param array $params + * @param string $username + * @param string $repository + * @param array $params * * @return array|string */ @@ -28,9 +28,9 @@ public function all($username, $repository, array $params = []) /** * @link https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator * - * @param $username - * @param $repository - * @param $collaborator + * @param string $username + * @param string $repository + * @param string $collaborator * * @return array|string */ @@ -42,10 +42,10 @@ public function check($username, $repository, $collaborator) /** * @link https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator * - * @param $username - * @param $repository - * @param $collaborator - * @param array $params + * @param string $username + * @param string $repository + * @param string $collaborator + * @param array $params * * @return array|string */ @@ -57,9 +57,9 @@ public function add($username, $repository, $collaborator, array $params = []) /** * @link https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator * - * @param $username - * @param $repository - * @param $collaborator + * @param string $username + * @param string $repository + * @param string $collaborator * * @return array|string */ @@ -71,9 +71,9 @@ public function remove($username, $repository, $collaborator) /** * @link https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level * - * @param $username - * @param $repository - * @param $collaborator + * @param string $username + * @param string $repository + * @param string $collaborator * * @return array|string */ diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 73fd080b42f..4657bfa71f4 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -16,8 +16,8 @@ class Releases extends AbstractApi /** * Get the latest release. * - * @param $username - * @param $repository + * @param string $username + * @param string $repository * * @return array */ @@ -29,9 +29,9 @@ public function latest($username, $repository) /** * List releases for a tag. * - * @param $username - * @param $repository - * @param $tag + * @param string $username + * @param string $repository + * @param string $tag * * @return array */ diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c6a904a14cc..7889cea0aac 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -361,7 +361,7 @@ public function getApiVersion() /** * Add a cache plugin to cache responses locally. * - * @param CacheItemPoolInterface $cache + * @param CacheItemPoolInterface $cachePool * @param array $config */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) From a7d1295edbda7e759e283b2496eb237a81eeb199 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 18 Dec 2018 18:32:54 +0100 Subject: [PATCH 673/951] Set correct property and return types --- lib/Github/Api/Issue/Labels.php | 4 ++-- lib/Github/Api/Issue/Milestones.php | 2 +- lib/Github/Api/Organization/Hooks.php | 4 ++-- lib/Github/HttpClient/Builder.php | 5 ++--- lib/Github/HttpClient/Message/ResponseMediator.php | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 1159e153ff0..047e188dd47 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -167,7 +167,7 @@ public function replace($username, $repository, $issue, array $params) * @param string $issue * @param string $label * - * @return null + * @return array|string */ public function remove($username, $repository, $issue, $label) { @@ -183,7 +183,7 @@ public function remove($username, $repository, $issue, $label) * @param string $repository * @param string $issue * - * @return null + * @return array|string */ public function clear($username, $repository, $issue) { diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 11f0e94c6b1..0e0e067c5e4 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -114,7 +114,7 @@ public function update($username, $repository, $id, array $params) * @param string $repository * @param int $id * - * @return null + * @return array|string */ public function remove($username, $repository, $id) { diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index b68a43bc3a6..fc9318a3c45 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -87,7 +87,7 @@ public function update($organization, $id, array $params) * @param string $organization * @param int $id * - * @return null + * @return array|string */ public function ping($organization, $id) { @@ -102,7 +102,7 @@ public function ping($organization, $id) * @param string $organization * @param int $id * - * @return null + * @return array|string */ public function remove($organization, $id) { diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 6a635b2df41..3b05b8fecc5 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -10,7 +10,6 @@ use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Http\Discovery\StreamFactoryDiscovery; -use Http\Message\MessageFactory; use Http\Message\RequestFactory; use Http\Message\StreamFactory; use Psr\Cache\CacheItemPoolInterface; @@ -38,7 +37,7 @@ class Builder private $pluginClient; /** - * @var MessageFactory + * @var RequestFactory */ private $requestFactory; @@ -62,7 +61,7 @@ class Builder /** * This plugin is special treated because it has to be the very last plugin. * - * @var Plugin\CachePlugin + * @var Plugin\CachePlugin|null */ private $cachePlugin; diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 6b944165f9f..dcab5b4a979 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -28,7 +28,7 @@ public static function getContent(ResponseInterface $response) /** * @param ResponseInterface $response * - * @return array|null + * @return array|void */ public static function getPagination(ResponseInterface $response) { From 4b831453e6232fd86ec8cc1bf5ba3f9e5f23c634 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 18 Dec 2018 20:04:33 +0100 Subject: [PATCH 674/951] Code improvements found with code analysis --- lib/Github/Api/AbstractApi.php | 4 ++-- lib/Github/Api/AcceptHeaderTrait.php | 2 +- lib/Github/Api/CurrentUser/Emails.php | 4 ++-- lib/Github/Api/Gists.php | 2 +- lib/Github/Api/Issue/Labels.php | 10 +++++----- lib/Github/Api/PullRequest.php | 2 +- lib/Github/Api/PullRequest/Comments.php | 2 +- lib/Github/Api/Repository/Contents.php | 2 +- lib/Github/Client.php | 2 +- .../HttpClient/Plugin/GithubExceptionThrower.php | 16 ++++++++-------- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 135ac2b22be..492e44ca4d8 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -98,7 +98,7 @@ protected function get($path, array $parameters = [], array $requestHeaders = [] if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; } - if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { + if (array_key_exists('ref', $parameters) && null === $parameters['ref']) { unset($parameters['ref']); } @@ -122,7 +122,7 @@ protected function get($path, array $parameters = [], array $requestHeaders = [] */ protected function head($path, array $parameters = [], array $requestHeaders = []) { - if (array_key_exists('ref', $parameters) && is_null($parameters['ref'])) { + if (array_key_exists('ref', $parameters) && null === $parameters['ref']) { unset($parameters['ref']); } diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php index 4a7e7a4668d..e788fd1ca5e 100644 --- a/lib/Github/Api/AcceptHeaderTrait.php +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -9,7 +9,7 @@ */ trait AcceptHeaderTrait { - protected $acceptHeaderValue = null; + protected $acceptHeaderValue; protected function get($path, array $parameters = [], array $requestHeaders = []) { diff --git a/lib/Github/Api/CurrentUser/Emails.php b/lib/Github/Api/CurrentUser/Emails.php index 15d4fad023e..23f2ab2402d 100644 --- a/lib/Github/Api/CurrentUser/Emails.php +++ b/lib/Github/Api/CurrentUser/Emails.php @@ -52,7 +52,7 @@ public function add($emails) if (is_string($emails)) { $emails = [$emails]; } elseif (0 === count($emails)) { - throw new InvalidArgumentException(); + throw new InvalidArgumentException('The user emails parameter should be a single email or an array of emails'); } return $this->post('/user/emails', $emails); @@ -74,7 +74,7 @@ public function remove($emails) if (is_string($emails)) { $emails = [$emails]; } elseif (0 === count($emails)) { - throw new InvalidArgumentException(); + throw new InvalidArgumentException('The user emails parameter should be a single email or an array of emails'); } return $this->delete('/user/emails', $emails); diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index e6bdc430640..a6f4ffa67c7 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -28,7 +28,7 @@ class Gists extends AbstractApi */ public function configure($bodyType = null) { - if (!in_array($bodyType, ['base64'])) { + if ('base64' !== $bodyType) { $bodyType = 'raw'; } diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 047e188dd47..f1f68b76295 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -120,10 +120,10 @@ public function update($username, $repository, $label, $newName, $color) * * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue * - * @param string $username - * @param string $repository - * @param int $issue - * @param string $labels + * @param string $username + * @param string $repository + * @param int $issue + * @param string|array $labels * * @return array * @@ -134,7 +134,7 @@ public function add($username, $repository, $issue, $labels) if (is_string($labels)) { $labels = [$labels]; } elseif (0 === count($labels)) { - throw new InvalidArgumentException(); + throw new InvalidArgumentException('The labels parameter should be a single label or an array of labels'); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels); diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 933dd7b1a97..1f22137afbd 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -31,7 +31,7 @@ class PullRequest extends AbstractApi */ public function configure($bodyType = null, $apiVersion = null) { - if (!in_array($apiVersion, [])) { + if (null === $apiVersion) { $apiVersion = $this->client->getApiVersion(); } diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index c1e29032d96..992fcd93bf5 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -27,7 +27,7 @@ class Comments extends AbstractApi */ public function configure($bodyType = null, $apiVersion = null) { - if (!in_array($apiVersion, ['squirrel-girl-preview'])) { + if ($apiVersion !== 'squirrel-girl-preview') { $apiVersion = $this->client->getApiVersion(); } diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index ae1b0693772..631fff2c7ba 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -143,7 +143,7 @@ public function exists($username, $repository, $path, $reference = null) 'ref' => $reference, ]); - if ($response->getStatusCode() != 200) { + if ($response->getStatusCode() !== 200) { return false; } } catch (TwoFactorAuthenticationRequiredException $ex) { diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 6e065b80fe1..e20df96a039 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -322,7 +322,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null throw new InvalidArgumentException('You need to specify authentication method!'); } - if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT])) { + if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT], true)) { $authMethod = $password; $password = null; } diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 7d46fe9c2e5..a216b365d3b 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -30,26 +30,26 @@ public function handleRequest(RequestInterface $request, callable $next, callabl // If error: $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); - if (null != $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { + if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); $reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); throw new ApiLimitExceedException($limit, $reset); } - if (401 === $response->getStatusCode()) { - if ($response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 'required;')) { - $type = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 9); + if ((401 === $response->getStatusCode()) && $response->hasHeader('X-GitHub-OTP') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 'required;')) { + $type = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-OTP'), 9); - throw new TwoFactorAuthenticationRequiredException($type); - } + throw new TwoFactorAuthenticationRequiredException($type); } $content = ResponseMediator::getContent($response); if (is_array($content) && isset($content['message'])) { - if (400 == $response->getStatusCode()) { + if (400 === $response->getStatusCode()) { throw new ErrorException($content['message'], 400); - } elseif (422 == $response->getStatusCode() && isset($content['errors'])) { + } + + if (422 === $response->getStatusCode() && isset($content['errors'])) { $errors = []; foreach ($content['errors'] as $error) { switch ($error['code']) { From 49486a8ff5e72ecda762c0ca613a60db6960c61a Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sun, 23 Dec 2018 21:30:13 +0000 Subject: [PATCH 675/951] Corrected error handling in case of 502 GitHub response (#759) * KnpLabs/php-github-api#759: Corrected error handling in case of 502 GitHub response * Covered GithubExceptionThrower with a unit test * Fixed code style * Adjusted test for PHP 5.6 - PHPUnit 6.5 --- .../Plugin/GithubExceptionThrower.php | 11 ++ .../Plugin/GithubExceptionThrowerTest.php | 149 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 7d46fe9c2e5..94bd24e3387 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -84,6 +84,17 @@ public function handleRequest(RequestInterface $request, callable $next, callabl } } + if (502 == $response->getStatusCode() && isset($content['errors']) && is_array($content['errors'])) { + $errors = []; + foreach ($content['errors'] as $error) { + if (isset($error['message'])) { + $errors[] = $error['message']; + } + } + + throw new RuntimeException(implode(', ', $errors), 502); + } + throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); }); } diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php new file mode 100644 index 00000000000..fd83e88c2f4 --- /dev/null +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -0,0 +1,149 @@ + + */ +class GithubExceptionThrowerTest extends TestCase +{ + /** + * @param ResponseInterface $response + * @param ExceptionInterface|\Exception|null $exception + * @dataProvider responseProvider + */ + public function testHandleRequest(ResponseInterface $response, ExceptionInterface $exception = null) + { + /** @var RequestInterface $request */ + $request = $this->getMockForAbstractClass(RequestInterface::class); + + $promise = $this->getMockBuilder(FulfilledPromise::class)->disableOriginalConstructor()->getMock(); + $promise->expects($this->once()) + ->method('then') + ->willReturnCallback(function ($callback) use ($response) { + return $callback($response); + }); + + $plugin = new GithubExceptionThrower(); + + if ($exception) { + $this->expectException(get_class($exception)); + $this->expectExceptionCode($exception->getCode()); + $this->expectExceptionMessage($exception->getMessage()); + } + + $plugin->handleRequest( + $request, + function (RequestInterface $request) use ($promise) { + return $promise; + }, + function (RequestInterface $request) use ($promise) { + return $promise; + } + ); + } + + /** + * @return array + */ + public static function responseProvider() + { + return [ + '200 Response' => [ + 'response' => new Response(), + 'exception' => null, + ], + 'Rate Limit Exceeded' => [ + 'response' => new Response( + 429, + [ + 'Content-Type' => 'application/json', + 'X-RateLimit-Remaining' => 0, + 'X-RateLimit-Limit' => 5000, + ], + '' + ), + 'exception' => new \Github\Exception\ApiLimitExceedException(5000), + ], + 'Two Factor Authentication Required' => [ + 'response' => new Response( + 401, + [ + 'Content-Type' => 'application/json', + 'X-GitHub-OTP' => 'required; :2fa-type', + ], + '' + ), + 'exception' => new \Github\Exception\TwoFactorAuthenticationRequiredException('2fa-type'), + ], + '400 Bad Request' => [ + 'response' => new Response( + 400, + [ + 'Content-Type' => 'application/json', + ], + json_encode( + [ + 'message' => 'Bad Request', + ] + ) + ), + 'exception' => new \Github\Exception\ErrorException('Bad Request', 400), + ], + '422 Unprocessable Entity' => [ + 'response' => new Response( + 422, + [ + 'Content-Type' => 'application/json', + ], + json_encode( + [ + 'message' => 'Bad Request', + 'errors' => [ + [ + 'code' => 'missing', + 'field' => 'field', + 'value' => 'value', + 'resource' => 'resource', + ], + ], + ] + ) + ), + 'exception' => new \Github\Exception\ErrorException('Validation Failed: The field value does not exist, for resource "resource"', 422), + ], + '502 Response' => [ + 'response' => new Response( + 502, + [ + 'Content-Type' => 'application/json', + ], + json_encode( + [ + 'errors' => [ + ['message' => 'Something went wrong with executing your query'], + ], + ] + ) + ), + 'exception' => new \Github\Exception\RuntimeException('Something went wrong with executing your query', 502), + ], + 'Default handling' => [ + 'response' => new Response( + 555, + [], + 'Error message' + ), + 'exception' => new \Github\Exception\RuntimeException('Error message', 555), + ], + ]; + } +} From ec3af21405c11926e66440f0ec599d38f7f721cf Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 1 Jan 2019 18:39:13 +0100 Subject: [PATCH 676/951] Fixed install docs broken after 2.0 release of httplug lib --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 481609ca25a..aa6bdc9b912 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] Via Composer: ```bash -$ composer require knplabs/github-api php-http/guzzle6-adapter +$ composer require knplabs/github-api php-http/guzzle6-adapter "^1.1" ``` Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md). From f75145e7a36dabeffc425be2ce87c58140519304 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 28 Jan 2019 20:14:18 +0100 Subject: [PATCH 677/951] Prepare 2.11.0 release --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d370a032502..0424c953045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.11.0 + +### Added + +- Support for Miscellaneous Licenses (#744) +- Structured Limit objects for rate limiting API (#733) +- Support for getting star creation timestamps in activity/starring endpoint (#729) + +### Fixed + +- Added missing has_projects parameter to repo create (#752) +- Proper type hinting for magic methods (#758) +- Allow symlink to files to be downloaded (#751) + +### Changed + +- Fix of PHP version in readme (#747) +- Fix documentation to get release for a tag (#755) +- Declare all used properties in RateLimitResource class (#762) +- Set correct property and return types (#764) +- Fixed install docs broken after 2.0 release of httplug lib (#767) + ## 2.10.1 ### Fixed From 16ff893203974c00655ebe49194db3189387c9c8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 16 Mar 2019 21:31:53 +0100 Subject: [PATCH 678/951] Drop hhvm support --- .travis.yml | 2 -- composer.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a9b3776ba5..e0f45b1e0df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,6 @@ php: matrix: include: - - php: hhvm - dist: trusty - php: 7.2 name: Backward compatibillity check env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./vendor/bin/roave-backward-compatibility-check" diff --git a/composer.json b/composer.json index 4c1fcea4e9d..1e701df8b7c 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.11.x-dev" + "dev-master": "2.12.x-dev" } } } From 4fd58767662f2882d75cd10590ff6d4cfd71b91b Mon Sep 17 00:00:00 2001 From: Owen Conti Date: Sun, 17 Mar 2019 12:29:18 -0600 Subject: [PATCH 679/951] Allow tags to be created without the tagger object. (#780) * Allow tags to be created without the tagger object. * Drop hhvm support * Allow tags to be created without the tagger object. * Allow tags to be created without the tagger object. --- lib/Github/Api/GitData/Tags.php | 6 +----- test/Github/Tests/Api/GitData/TagsTest.php | 5 ++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/GitData/Tags.php b/lib/Github/Api/GitData/Tags.php index 09f48bc0a80..11bf200a31f 100644 --- a/lib/Github/Api/GitData/Tags.php +++ b/lib/Github/Api/GitData/Tags.php @@ -56,11 +56,7 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(['tag', 'message', 'object', 'type']); } - if (!isset($params['tagger'])) { - throw new MissingArgumentException('tagger'); - } - - if (!isset($params['tagger']['name'], $params['tagger']['email'], $params['tagger']['date'])) { + if (isset($params['tagger']) && !isset($params['tagger']['name'], $params['tagger']['email'], $params['tagger']['date'])) { throw new MissingArgumentException(['tagger.name', 'tagger.email', 'tagger.date']); } diff --git a/test/Github/Tests/Api/GitData/TagsTest.php b/test/Github/Tests/Api/GitData/TagsTest.php index 06543edeace..acc8dab6550 100644 --- a/test/Github/Tests/Api/GitData/TagsTest.php +++ b/test/Github/Tests/Api/GitData/TagsTest.php @@ -89,9 +89,8 @@ public function shouldNotCreateTagWithoutMessageParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ - public function shouldNotCreateTagWithoutTaggerParam() + public function shouldCreateTagWithoutTaggerParam() { $data = [ 'message' => 'some message', @@ -101,7 +100,7 @@ public function shouldNotCreateTagWithoutTaggerParam() ]; $api = $this->getApiMock(); - $api->expects($this->never()) + $api->expects($this->once()) ->method('post'); $api->create('KnpLabs', 'php-github-api', $data); From 497292c19cb3659bd755fd3d8c84b53a78c0b14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Benoist?= Date: Mon, 18 Mar 2019 09:26:59 +0100 Subject: [PATCH 680/951] Fix typo (#779) Missing closing comment --- doc/rate_limits.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/rate_limits.md b/doc/rate_limits.md index 4ae826999f9..7ca39b842bc 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -6,7 +6,7 @@ Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com #### Get All Rate Limits ```php -/** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits +/** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits */ $rateLimits = $client->api('rate_limit')->getLimits(); ``` From f253ab01e0558a2b835df6cac5a6fe837174228f Mon Sep 17 00:00:00 2001 From: Zack Galbreath Date: Fri, 19 Apr 2019 11:36:58 -0400 Subject: [PATCH 681/951] Add support for creating and updating GitHub checks https://developer.github.com/v3/checks/ --- doc/README.md | 1 + doc/repo/checks.md | 31 +++++++ lib/Github/Api/Repository/Checks.php | 58 ++++++++++++++ .../Tests/Api/Repository/ChecksTest.php | 80 +++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 doc/repo/checks.md create mode 100644 lib/Github/Api/Repository/Checks.php create mode 100644 test/Github/Tests/Api/Repository/ChecksTest.php diff --git a/doc/README.md b/doc/README.md index c4c3562df9b..3d3d3570b8b 100644 --- a/doc/README.md +++ b/doc/README.md @@ -46,6 +46,7 @@ v3 APIs: * [Comments](pull_request/comments.md) * [Rate Limits](rate_limits.md) * [Repositories](repos.md) + * [Checks](repo/checks.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) * [Protection](repo/protection.md) diff --git a/doc/repo/checks.md b/doc/repo/checks.md new file mode 100644 index 00000000000..04cd6144bf7 --- /dev/null +++ b/doc/repo/checks.md @@ -0,0 +1,31 @@ +## Repo / Checks API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### Create a check for a commit + +[Visit GitHub for a full of list of parameters and their descriptions.](https://developer.github.com/v3/checks/runs/#create-a-check-run) + +```php +$params = [ + 'name' => 'my check', # required + 'head_sha' => $commitSha, # required + 'status' => 'pending', + 'details_url' => 'https://nimbleci.com/...', + 'output' => {...} +]; +$checks = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $params); +``` + +### Update an existing check on a commit + +https://developer.github.com/v3/checks/runs/#update-a-check-run + +```php +$params = [ + 'name' => 'my check', + 'status' => 'pending', + 'details_url' => 'https://nimbleci.com/...', + 'output' => {...} +]; +$checks = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $checkRunId, $params); +``` diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php new file mode 100644 index 00000000000..fcc7059d2d5 --- /dev/null +++ b/lib/Github/Api/Repository/Checks.php @@ -0,0 +1,58 @@ + + */ +class Checks extends AbstractApi +{ + 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 = []) + { + if (!isset($params['name'], $params['head_sha'])) { + throw new MissingArgumentException(['name', 'head_sha']); + } + + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + 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 = []) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId), $params); + } +} diff --git a/test/Github/Tests/Api/Repository/ChecksTest.php b/test/Github/Tests/Api/Repository/ChecksTest.php new file mode 100644 index 00000000000..23eb545141a --- /dev/null +++ b/test/Github/Tests/Api/Repository/ChecksTest.php @@ -0,0 +1,80 @@ + 'my check']; + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', $data); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateWithoutName() + { + $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)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Repository\Checks::class; + } +} From 275ce096aaadf274905e085f103e9c1ea476de82 Mon Sep 17 00:00:00 2001 From: Patrick Barsallo Date: Sun, 28 Apr 2019 12:50:35 -0500 Subject: [PATCH 682/951] Add Ability to Update a Pull Request Review (#792) * Add Ability to Update Pull Request Review * test case * stycle ci fixes * docs --- doc/pull_request/reviews.md | 5 ++ lib/Github/Api/PullRequest/Review.php | 28 ++++++++++ .../Tests/Api/PullRequest/ReviewTest.php | 53 +++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/doc/pull_request/reviews.md b/doc/pull_request/reviews.md index db61a03dde4..fdc5f09442e 100644 --- a/doc/pull_request/reviews.md +++ b/doc/pull_request/reviews.md @@ -44,3 +44,8 @@ $client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $review ```php $client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $reviewId); ``` + +### Update a review +```php +$client->api('pull_request')->reviews()->update('twbs', 'bootstrap', 12, $reviewId, 'Review body (mandatory)') +``` diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index f9795de0531..e53f7179a19 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -174,4 +174,32 @@ public function dismiss($username, $repository, $pullRequest, $id, $message) 'message' => $message, ]); } + + /** + * Update a pull request review by the username, repository, pull request number and the review id. + * + * @link https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review + * + * @param string $username the username + * @param string $repository the repository + * @param int $pullRequest the pull request number + * @param int $id the review id + * @param string $body a mandatory dismissal message + * + * @return array|string + */ + public function update($username, $repository, $pullRequest, $id, $body) + { + if (!is_string($body)) { + throw new InvalidArgumentException(sprintf('"body" must be a valid string ("%s" given).', gettype($body))); + } + + if (empty($body)) { + throw new InvalidArgumentException('"body" is mandatory and cannot be empty'); + } + + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id, [ + 'body' => $body, + ]); + } } diff --git a/test/Github/Tests/Api/PullRequest/ReviewTest.php b/test/Github/Tests/Api/PullRequest/ReviewTest.php index 56c875a09a7..829f0c8dcaf 100644 --- a/test/Github/Tests/Api/PullRequest/ReviewTest.php +++ b/test/Github/Tests/Api/PullRequest/ReviewTest.php @@ -394,6 +394,59 @@ public function shouldDismissReview() $this->assertSame($expectedValue, $api->dismiss('octocat', 'Hello-World', 12, 80, 'Dismiss reason')); } + /** + * @test + */ + public function shouldUpdateReviewComment() + { + $expectedValue = [ + 'id' => 80, + 'node_id' => 'MDE3OlB1bGxSZXF1ZXN0UmV2aWV3ODA=', + 'user' => [ + 'login' => 'octocat', + 'id' => 1, + 'avatar_url' => 'https://github.com/images/error/octocat_happy.gif', + 'gravatar_id' => '', + 'url' => 'https://api.github.com/users/octocat', + 'html_url' => 'https://github.com/octocat', + 'followers_url' => 'https://api.github.com/users/octocat/followers', + 'following_url' => 'https://api.github.com/users/octocat/following{/other_user}', + 'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}', + 'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}', + 'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions', + 'organizations_url' => 'https://api.github.com/users/octocat/orgs', + 'repos_url' => 'https://api.github.com/users/octocat/repos', + 'events_url' => 'https://api.github.com/users/octocat/events{/privacy}', + 'received_events_url' => 'https://api.github.com/users/octocat/received_events', + 'type' => 'User', + 'site_admin' => false, + ], + 'body' => 'Great stuff', + 'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091', + 'state' => 'CHANGES_REQUESTED', + 'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', + 'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', + '_links' => [ + 'html' => [ + 'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80', + ], + 'pull_request' => [ + 'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12', + ], + ], + ]; + $body = 'Nice change'; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/octocat/Hello-World/pulls/12/reviews/80') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->update('octocat', 'Hello-World', 12, 80, $body)); + } + protected function getApiClass() { return Review::class; From e6a499758c994804a2cd019eb5976e2bbabca8ec Mon Sep 17 00:00:00 2001 From: Mitchell Davis Date: Mon, 10 Jun 2019 21:08:47 +1000 Subject: [PATCH 683/951] Change DeployKeys::update method to match GitHub API (#797) * Change DeployKeys::update method to first remove the existing key and then create a new one, in accordance with the supported GitHub APIs * Change DeployKeys::update method to first remove the existing key and then create a new one, in accordance with the supported GitHub APIs * Convert tabs to spaces --- lib/Github/Api/Repository/DeployKeys.php | 4 +++- .../Tests/Api/Repository/DeployKeysTest.php | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Repository/DeployKeys.php b/lib/Github/Api/Repository/DeployKeys.php index c6c8a2ce3b1..0e45ccb626a 100644 --- a/lib/Github/Api/Repository/DeployKeys.php +++ b/lib/Github/Api/Repository/DeployKeys.php @@ -37,7 +37,9 @@ public function update($username, $repository, $id, array $params) throw new MissingArgumentException(['title', 'key']); } - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/keys/'.rawurlencode($id), $params); + $this->remove($username, $repository, $id); + + return $this->create($username, $repository, $params); } public function remove($username, $repository, $id) diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index f26c83c08e4..1e1a9ca39c6 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -111,7 +111,9 @@ public function shouldNotUpdateDeployKeyWithoutTitle() $api = $this->getApiMock(); $api->expects($this->never()) - ->method('patch'); + ->method('delete'); + $api->expects($this->never()) + ->method('post'); $api->update('KnpLabs', 'php-github-api', 123, $data); } @@ -126,7 +128,9 @@ public function shouldNotUpdateDeployKeyWithoutKey() $api = $this->getApiMock(); $api->expects($this->never()) - ->method('patch'); + ->method('delete'); + $api->expects($this->never()) + ->method('post'); $api->update('KnpLabs', 'php-github-api', 123, $data); } @@ -141,8 +145,12 @@ public function shouldUpdateDeployKey() $api = $this->getApiMock(); $api->expects($this->once()) - ->method('patch') - ->with('/repos/KnpLabs/php-github-api/keys/123', $data) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/keys/123') + ->will($this->returnValue($expectedValue)); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/keys', $data) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); From 225a85512b2801a30ca8e8fb64cf0b72ef520022 Mon Sep 17 00:00:00 2001 From: alexpozzi Date: Mon, 22 Jul 2019 09:55:19 +0200 Subject: [PATCH 684/951] Explicitly add maintainers in the README --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aa6bdc9b912..f488dcc8ff6 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,15 @@ See the [`doc` directory](doc/) for more detailed documentation. `php-github-api` is licensed under the MIT License - see the LICENSE file for details -## Credits +## Maintainers -### Sponsored by +Please read [this post](https://knplabs.com/en/blog/news-for-our-foss-projects-maintenance) first. -[![KnpLabs Team](http://knplabs.com/front/images/knp-labs-logo.png)](http://knplabs.com) +This library is maintained by the following people (alphabetically sorted) : +- @acrobat +- @Nyholm -### Contributors +## Contributors - Thanks to [Thibault Duplessis aka. ornicar](http://github.com/ornicar) for his first version of this library. - Thanks to [Joseph Bielawski aka. stloyd](http://github.com/stloyd) for his contributions and support. From f800ad327673ac22a61289f1ccbc740f09ff1dab Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 12 Aug 2019 18:53:40 +0200 Subject: [PATCH 685/951] Missing gist revision api endpoint --- doc/gists.md | 6 ++++++ lib/Github/Api/Gists.php | 15 +++++++++++++++ test/Github/Tests/Api/GistsTest.php | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/doc/gists.md b/doc/gists.md index c106005927b..7db9f2c6cd5 100644 --- a/doc/gists.md +++ b/doc/gists.md @@ -37,6 +37,12 @@ $gists = $github->api('gists')->all(); $gist = $github->api('gists')->show(1); ``` +#### Get a specific revision of a gist + +```php +$gist = $github->api('gists')->show(1, 'd189dbd4c5d96442db74ebcb62bb38e661a0c8ce'); +``` + #### Get commits for a single gist ```php diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index a6f4ffa67c7..ee88c1292d1 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -51,6 +51,21 @@ public function show($number) return $this->get('/gists/'.rawurlencode($number)); } + /** + * Get a specific revision of a gist. + * + * @param int $number + * @param string $sha + * + * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist + * + * @return array + */ + public function revision($number, $sha) + { + return $this->get('/gists/'.rawurlencode($number).'/'.rawurlencode($sha)); + } + public function create(array $params) { if (!isset($params['files']) || (!is_array($params['files']) || 0 === count($params['files']))) { diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 8e179693656..e0fba63a6c9 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -52,6 +52,22 @@ public function shouldShowGist() $this->assertEquals($expectedArray, $api->show(123)); } + /** + * @test + */ + public function shouldShowGistWithSpecificReference() + { + $expectedArray = ['id' => '123', 'sha' => 'd189dbd4c5d96442db74ebcb62bb38e661a0c8ce']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/gists/123/d189dbd4c5d96442db74ebcb62bb38e661a0c8ce') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->revision(123, 'd189dbd4c5d96442db74ebcb62bb38e661a0c8ce')); + } + /** * @test */ From 46ffb7022632f8549d2319d167bc77bc5c01ae64 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 16 Mar 2019 22:14:53 +0100 Subject: [PATCH 686/951] Drop support for unsupported php versions --- .travis.yml | 2 -- README.md | 2 +- composer.json | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e0f45b1e0df..4630e91bffd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ env: - TEST_COMMAND="vendor/bin/phpunit --verbose --coverage-text" php: - - 5.6 - - 7.0 - 7.1 - 7.2 - 7.3 diff --git a/README.md b/README.md index f488dcc8ff6..47ff1282522 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements -* PHP >= 5.6 +* PHP >= 7.1 * A [HTTP client](https://packagist.org/providers/php-http/client-implementation) * A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation) * (optional) PHPUnit to run tests. diff --git a/composer.json b/composer.json index 1e701df8b7c..238b6aba771 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^5.6 || ^7.0", + "php": "^7.1", "psr/http-message": "^1.0", "psr/cache": "^1.0", "php-http/httplug": "^1.1", @@ -27,7 +27,7 @@ "php-http/cache-plugin": "^1.4" }, "require-dev": { - "phpunit/phpunit": "^5.5 || ^6.0", + "phpunit/phpunit": "^6.0", "php-http/guzzle6-adapter": "^1.0", "php-http/mock-client": "^1.0", "guzzlehttp/psr7": "^1.2", From 0077a9fd34a99e499da355e3da2f19a7fd57650c Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 13 Aug 2019 16:28:56 +0200 Subject: [PATCH 687/951] Bump phpunit to supported version --- .gitignore | 1 + composer.json | 2 +- phpunit.xml.dist | 1 - test/Github/Tests/Api/AbstractApiTest.php | 4 ++-- .../Tests/Api/CurrentUser/DeployKeysTest.php | 9 ++++++--- .../Tests/Api/CurrentUser/EmailsTest.php | 9 ++++++--- .../Tests/Api/CurrentUser/FollowersTest.php | 4 +++- .../Tests/Api/CurrentUser/MembershipsTest.php | 4 +++- .../Tests/Api/CurrentUser/StarringTest.php | 4 +++- .../Tests/Api/CurrentUser/WatchersTest.php | 4 +++- test/Github/Tests/Api/DeploymentTest.php | 4 +++- test/Github/Tests/Api/GistsTest.php | 4 +++- test/Github/Tests/Api/GitData/BlobsTest.php | 9 ++++++--- test/Github/Tests/Api/GitData/CommitsTest.php | 11 +++++++---- .../Tests/Api/GitData/ReferencesTest.php | 11 +++++++---- test/Github/Tests/Api/GitData/TagsTest.php | 19 +++++++++++-------- test/Github/Tests/Api/GitData/TreesTest.php | 17 ++++++++++------- test/Github/Tests/Api/Issue/AssigneesTest.php | 5 +++-- test/Github/Tests/Api/Issue/CommentsTest.php | 5 +++-- test/Github/Tests/Api/Issue/LabelsTest.php | 3 ++- .../Github/Tests/Api/Issue/MilestonesTest.php | 3 ++- test/Github/Tests/Api/IssueTest.php | 4 +++- .../Tests/Api/Organization/HooksTest.php | 7 ++++--- .../Tests/Api/Organization/ProjectsTest.php | 3 ++- .../Tests/Api/Organization/TeamsTest.php | 5 +++-- test/Github/Tests/Api/Project/CardsTest.php | 3 ++- test/Github/Tests/Api/Project/ColumnsTest.php | 7 ++++--- .../Tests/Api/PullRequest/CommentsTest.php | 11 ++++++----- .../Tests/Api/PullRequest/ReviewTest.php | 9 +++++---- test/Github/Tests/Api/PullRequestTest.php | 10 ++++++---- test/Github/Tests/Api/RateLimitTest.php | 4 +--- .../Tests/Api/Repository/AssetsTest.php | 3 ++- .../Tests/Api/Repository/ChecksTest.php | 5 +++-- .../Tests/Api/Repository/CommentsTest.php | 5 +++-- .../Tests/Api/Repository/ContentsTest.php | 15 ++++++++------- .../Tests/Api/Repository/DeployKeysTest.php | 9 +++++---- .../Github/Tests/Api/Repository/HooksTest.php | 7 ++++--- .../Tests/Api/Repository/LabelsTest.php | 9 +++++---- .../Tests/Api/Repository/ProjectsTest.php | 3 ++- .../Tests/Api/Repository/ReleasesTest.php | 3 ++- .../Tests/Api/Repository/StatusesTest.php | 3 ++- .../Tests/Api/Repository/TrafficTest.php | 2 ++ test/Github/Tests/Api/TestCase.php | 2 +- test/Github/Tests/ClientTest.php | 7 ++++--- .../{ => Plugin}/PathPrependTest.php | 0 test/Github/Tests/Integration/GistTest.php | 4 +++- .../Tests/Integration/RateLimitTest.php | 5 +++-- test/Github/Tests/Integration/RepoTest.php | 6 +++--- test/Github/Tests/Integration/TestCase.php | 2 +- test/Github/Tests/Integration/UserTest.php | 8 +++++--- 50 files changed, 179 insertions(+), 115 deletions(-) rename test/Github/Tests/HttpClient/{ => Plugin}/PathPrependTest.php (100%) diff --git a/.gitignore b/.gitignore index 2c9d04ccd11..ebe7b7ea7a3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .php_cs.cache phpunit.xml +.phpunit.result.cache composer.lock composer.phar vendor/* diff --git a/composer.json b/composer.json index 238b6aba771..af0e7df5ad9 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php-http/cache-plugin": "^1.4" }, "require-dev": { - "phpunit/phpunit": "^6.0", + "phpunit/phpunit": "^7.0 || ^8.0", "php-http/guzzle6-adapter": "^1.0", "php-http/mock-client": "^1.0", "guzzlehttp/psr7": "^1.2", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c390af0e017..3b6dc204b03 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="vendor/autoload.php" > diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index e4ce3ae9171..ec8dd1e0be0 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -171,13 +171,13 @@ public function shouldNotPassEmptyRefToClient() $api = $this->getAbstractApiObject($client); $actual = $this->getMethod($api, 'get')->invokeArgs($api, ['/path', ['ref' => null]]); - $this->assertInternalType('array', $actual); + $this->assertIsArray($actual); } /** * @param $client * - * @return \PHPUnit_Framework_MockObject_MockObject + * @return \PHPUnit\Framework\MockObject\MockObject */ protected function getAbstractApiObject($client) { diff --git a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php index 7b1abd37923..4f147e25e02 100644 --- a/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php +++ b/test/Github/Tests/Api/CurrentUser/DeployKeysTest.php @@ -1,6 +1,9 @@ expectException(MissingArgumentException::class); $data = ['key' => 'ssh-rsa ...']; $api = $this->getApiMock(); @@ -70,10 +73,10 @@ public function shouldNotCreateKeyWithoutTitleParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateKeyWithoutKeyParam() { + $this->expectException(MissingArgumentException::class); $data = ['title' => 'my key']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/CurrentUser/EmailsTest.php b/test/Github/Tests/Api/CurrentUser/EmailsTest.php index 2cc4c746712..1fed2a0d780 100644 --- a/test/Github/Tests/Api/CurrentUser/EmailsTest.php +++ b/test/Github/Tests/Api/CurrentUser/EmailsTest.php @@ -1,6 +1,9 @@ expectException(InvalidArgumentException::class); $api = $this->getApiMock(); $api->expects($this->any()) ->method('delete'); @@ -99,10 +102,10 @@ public function shouldAddEmails() /** * @test - * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotAddEmailsWhenAreNotPass() { + $this->expectException(InvalidArgumentException::class); $api = $this->getApiMock(); $api->expects($this->any()) ->method('post'); diff --git a/test/Github/Tests/Api/CurrentUser/FollowersTest.php b/test/Github/Tests/Api/CurrentUser/FollowersTest.php index 0ad32693008..19b4b0faab6 100644 --- a/test/Github/Tests/Api/CurrentUser/FollowersTest.php +++ b/test/Github/Tests/Api/CurrentUser/FollowersTest.php @@ -1,6 +1,8 @@ expectException(MissingArgumentException::class); $api = $this->getApiMock(); $statusData = ['description' => 'waiting to start']; diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index e0fba63a6c9..093af712911 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Api; +use Github\Exception\MissingArgumentException; + class GistsTest extends TestCase { /** @@ -128,10 +130,10 @@ public function shouldListGistForks() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateGistWithoutFile() { + $this->expectException(MissingArgumentException::class); $input = [ 'description' => '', 'public' => false, diff --git a/test/Github/Tests/Api/GitData/BlobsTest.php b/test/Github/Tests/Api/GitData/BlobsTest.php index a871414f96b..368d47c3cc2 100644 --- a/test/Github/Tests/Api/GitData/BlobsTest.php +++ b/test/Github/Tests/Api/GitData/BlobsTest.php @@ -1,6 +1,9 @@ expectException(MissingArgumentException::class); $data = ['content' => 'some cotent']; $api = $this->getApiMock(); @@ -82,10 +85,10 @@ public function shouldNotCreateBlobWithoutEncoding() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateBlobWithoutContent() { + $this->expectException(MissingArgumentException::class); $data = ['encoding' => 'utf8']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/GitData/CommitsTest.php b/test/Github/Tests/Api/GitData/CommitsTest.php index 3d973c6ab59..20903f3e1f2 100644 --- a/test/Github/Tests/Api/GitData/CommitsTest.php +++ b/test/Github/Tests/Api/GitData/CommitsTest.php @@ -1,6 +1,9 @@ expectException(MissingArgumentException::class); $data = ['tree' => 1234, 'parents' => []]; $api = $this->getApiMock(); @@ -54,10 +57,10 @@ public function shouldNotCreateCommitWithoutMessageParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateCommitWithoutTreeParam() { + $this->expectException(MissingArgumentException::class); $data = ['message' => 'some message', 'parents' => []]; $api = $this->getApiMock(); @@ -69,10 +72,10 @@ public function shouldNotCreateCommitWithoutTreeParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateCommitWithoutParentsParam() { + $this->expectException(MissingArgumentException::class); $data = ['message' => 'some message', 'tree' => '12334']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 55a3fa0edd6..768085f69bf 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -1,6 +1,9 @@ expectException(MissingArgumentException::class); $data = ['ref' => '123']; $api = $this->getApiMock(); @@ -134,10 +137,10 @@ public function shouldNotCreateReferenceWithoutShaParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReferenceWithoutRefsParam() { + $this->expectException(MissingArgumentException::class); $data = ['sha' => '1234']; $api = $this->getApiMock(); @@ -166,10 +169,10 @@ public function shouldUpdateReference() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNoUpdateReferenceWithoutSha() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/GitData/TagsTest.php b/test/Github/Tests/Api/GitData/TagsTest.php index acc8dab6550..83230175554 100644 --- a/test/Github/Tests/Api/GitData/TagsTest.php +++ b/test/Github/Tests/Api/GitData/TagsTest.php @@ -1,6 +1,9 @@ expectException(MissingArgumentException::class); $data = [ 'tag' => 'v2.2', 'object' => 'test', @@ -108,10 +111,10 @@ public function shouldCreateTagWithoutTaggerParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerNameParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'message' => 'some message', 'tag' => 'v2.2', @@ -132,10 +135,10 @@ public function shouldNotCreateTagWithoutTaggerNameParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerEmailParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'message' => 'some message', 'tag' => 'v2.2', @@ -156,10 +159,10 @@ public function shouldNotCreateTagWithoutTaggerEmailParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTaggerDateParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'message' => 'some message', 'tag' => 'v2.2', @@ -180,10 +183,10 @@ public function shouldNotCreateTagWithoutTaggerDateParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTagParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'message' => 'some message', 'object' => 'test', @@ -204,10 +207,10 @@ public function shouldNotCreateTagWithoutTagParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutObjectParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'message' => 'some message', 'tag' => 'v2.2', @@ -228,10 +231,10 @@ public function shouldNotCreateTagWithoutObjectParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTagWithoutTypeParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'message' => 'some message', 'tag' => 'v2.2', diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index 58ef5cef2a0..901af559e24 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -1,6 +1,9 @@ expectException(MissingArgumentException::class); $data = [ 'tree' => [ 'path' => 'path', @@ -107,10 +110,10 @@ public function shouldNotCreateTreeWithoutShaAndContentParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutPathParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'tree' => [ 'mode' => 'mode', @@ -128,10 +131,10 @@ public function shouldNotCreateTreeWithoutPathParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutModeParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'tree' => [ 'path' => 'path', @@ -149,10 +152,10 @@ public function shouldNotCreateTreeWithoutModeParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutTypeParam() { + $this->expectException(MissingArgumentException::class); $data = [ 'tree' => [ 'path' => 'path', @@ -170,10 +173,10 @@ public function shouldNotCreateTreeWithoutTypeParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWithoutTreeParam() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); @@ -185,10 +188,10 @@ public function shouldNotCreateTreeWithoutTreeParam() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTreeWhenTreeParamIsNotArray() { + $this->expectException(MissingArgumentException::class); $data = [ 'tree' => '', ]; diff --git a/test/Github/Tests/Api/Issue/AssigneesTest.php b/test/Github/Tests/Api/Issue/AssigneesTest.php index 8777f0923b2..b6939a1b59e 100644 --- a/test/Github/Tests/Api/Issue/AssigneesTest.php +++ b/test/Github/Tests/Api/Issue/AssigneesTest.php @@ -3,6 +3,7 @@ namespace Github\Tests\Api\Issue; use Github\Api\Issue\Assignees; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class AssigneesTest extends TestCase @@ -35,10 +36,10 @@ public function shouldCheckAssignee() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotAddAssigneeMissingParameter() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); @@ -67,10 +68,10 @@ public function shouldAddAssignee() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotRemoveAssigneeMissingParameter() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 51c67fe8f85..df8e5130937 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Issue; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class CommentsTest extends TestCase @@ -40,10 +41,10 @@ public function shouldShowIssueComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutBody() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); @@ -72,10 +73,10 @@ public function shouldCreateIssueComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateWithoutBody() { + $this->expectException(MissingArgumentException::class); $data = ['somedata']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index af8f14c67cb..ec55ccc54cb 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Issue; +use Github\Exception\InvalidArgumentException; use Github\Tests\Api\TestCase; class LabelsTest extends TestCase @@ -191,10 +192,10 @@ public function shouldReplaceLabels() /** * @test - * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotAddWhenDoNotHaveLabelsToAdd() { + $this->expectException(InvalidArgumentException::class); $api = $this->getApiMock(); $api->expects($this->any()) ->method('post'); diff --git a/test/Github/Tests/Api/Issue/MilestonesTest.php b/test/Github/Tests/Api/Issue/MilestonesTest.php index 18963580b8a..6a1996e0bbc 100644 --- a/test/Github/Tests/Api/Issue/MilestonesTest.php +++ b/test/Github/Tests/Api/Issue/MilestonesTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Issue; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class MilestonesTest extends TestCase @@ -41,10 +42,10 @@ public function shouldCreateMilestone() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateMilestoneWithoutTitle() { + $this->expectException(MissingArgumentException::class); $expectedValue = [['title' => 'milestone']]; $data = []; diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 2fed3618853..b976f402451 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Api; +use Github\Exception\MissingArgumentException; + class IssueTest extends TestCase { /** @@ -88,10 +90,10 @@ public function shouldCreateIssue() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateIssueWithoutTitle() { + $this->expectException(MissingArgumentException::class); $data = [ 'body' => 'some body', ]; diff --git a/test/Github/Tests/Api/Organization/HooksTest.php b/test/Github/Tests/Api/Organization/HooksTest.php index 5c905ece70f..82d586a087e 100644 --- a/test/Github/Tests/Api/Organization/HooksTest.php +++ b/test/Github/Tests/Api/Organization/HooksTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Organization; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class HooksTest extends TestCase @@ -56,10 +57,10 @@ public function shouldRemoveHook() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateHookWithoutName() { + $this->expectException(MissingArgumentException::class); $data = ['config' => 'conf']; $api = $this->getApiMock(); @@ -71,10 +72,10 @@ public function shouldNotCreateHookWithoutName() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateHookWithoutConfig() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'test']; $api = $this->getApiMock(); @@ -103,10 +104,10 @@ public function shouldCreateHook() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateHookWithoutConfig() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Organization/ProjectsTest.php b/test/Github/Tests/Api/Organization/ProjectsTest.php index 8ac5bf52229..05d607e34d8 100644 --- a/test/Github/Tests/Api/Organization/ProjectsTest.php +++ b/test/Github/Tests/Api/Organization/ProjectsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Organization; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class ProjectsTest extends TestCase @@ -24,10 +25,10 @@ public function shouldGetAllRepositoryProjects() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutName() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 4cff3609764..3c5474181e7 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Organization; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class TeamsTest extends TestCase @@ -184,10 +185,10 @@ public function shouldRemoveTeamRepository() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateTeamWithoutName() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); @@ -250,10 +251,10 @@ public function shouldCreateWithPullPermissionWhenPermissionParamNotRecognized() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateTeamWithoutName() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Project/CardsTest.php b/test/Github/Tests/Api/Project/CardsTest.php index 6195f1b3514..8b3b37090db 100644 --- a/test/Github/Tests/Api/Project/CardsTest.php +++ b/test/Github/Tests/Api/Project/CardsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Project; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class CardsTest extends TestCase @@ -90,10 +91,10 @@ public function shouldRemoveCard() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotMoveWithoutPosition() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Project/ColumnsTest.php b/test/Github/Tests/Api/Project/ColumnsTest.php index 7ce3a1693f2..7df1225190b 100644 --- a/test/Github/Tests/Api/Project/ColumnsTest.php +++ b/test/Github/Tests/Api/Project/ColumnsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Project; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class ColumnsTest extends TestCase @@ -40,10 +41,10 @@ public function shouldShowColumn() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutName() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); @@ -72,10 +73,10 @@ public function shouldCreateColumn() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateWithoutName() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); @@ -120,10 +121,10 @@ public function shouldRemoveCard() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotMoveWithoutPosition() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/PullRequest/CommentsTest.php b/test/Github/Tests/Api/PullRequest/CommentsTest.php index 872934260d1..b9a7ec59514 100644 --- a/test/Github/Tests/Api/PullRequest/CommentsTest.php +++ b/test/Github/Tests/Api/PullRequest/CommentsTest.php @@ -3,6 +3,7 @@ namespace Github\Tests\Api\PullRequest; use Github\Api\PullRequest\Comments; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class CommentsTest extends TestCase @@ -266,10 +267,10 @@ public function shouldCreateReviewComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReviewCommentWithoutCommitId() { + $this->expectException(MissingArgumentException::class); $data = [ 'path' => 'file1.txt', 'position' => 4, @@ -287,10 +288,10 @@ public function shouldNotCreateReviewCommentWithoutCommitId() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReviewCommentWithoutPath() { + $this->expectException(MissingArgumentException::class); $data = [ 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'position' => 4, @@ -308,10 +309,10 @@ public function shouldNotCreateReviewCommentWithoutPath() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReviewCommentWithoutPosition() { + $this->expectException(MissingArgumentException::class); $data = [ 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'path' => 'file1.txt', @@ -329,10 +330,10 @@ public function shouldNotCreateReviewCommentWithoutPosition() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateReviewCommentWithoutBody() { + $this->expectException(MissingArgumentException::class); $data = [ 'commit_id' => '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'path' => 'file1.txt', @@ -414,10 +415,10 @@ public function shouldUpdateReviewComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateReviewCommentWithoutBody() { + $this->expectException(MissingArgumentException::class); $expectedValue = [ 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', 'id' => 1, diff --git a/test/Github/Tests/Api/PullRequest/ReviewTest.php b/test/Github/Tests/Api/PullRequest/ReviewTest.php index 829f0c8dcaf..eb94203bc68 100644 --- a/test/Github/Tests/Api/PullRequest/ReviewTest.php +++ b/test/Github/Tests/Api/PullRequest/ReviewTest.php @@ -2,8 +2,9 @@ namespace Github\Tests\Api\PullRequest; -use Github\Api\PullRequest\Comments; use Github\Api\PullRequest\Review; +use Github\Exception\InvalidArgumentException; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class ReviewTest extends TestCase @@ -231,10 +232,10 @@ public function shouldCreatePendingReviewWithoutEvent() /** * @test - * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotCreateReviewWithInvalidEvent() { + $this->expectException(InvalidArgumentException::class); $data = [ 'event' => 'DISMISSED', 'body' => 'Nice change', @@ -306,10 +307,10 @@ public function shouldSubmitReviewComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotSubmitReviewWithoutEvent() { + $this->expectException(MissingArgumentException::class); $data = [ 'body' => 'Nice change', ]; @@ -325,10 +326,10 @@ public function shouldNotSubmitReviewWithoutEvent() /** * @test - * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotSubmitReviewWithInvalidEvent() { + $this->expectException(InvalidArgumentException::class); $data = [ 'event' => 'DISMISSED', 'body' => 'Nice change', diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index a3486d1f301..3f2acceb913 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Api; +use Github\Exception\MissingArgumentException; + class PullRequestTest extends TestCase { /** @@ -244,10 +246,10 @@ public function shouldCreatePullRequestUsingIssueId() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestWithoutBase() { + $this->expectException(MissingArgumentException::class); $data = [ 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', @@ -263,10 +265,10 @@ public function shouldNotCreatePullRequestWithoutBase() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestWithoutHead() { + $this->expectException(MissingArgumentException::class); $data = [ 'base' => 'master', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', @@ -282,10 +284,10 @@ public function shouldNotCreatePullRequestWithoutHead() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { + $this->expectException(MissingArgumentException::class); $data = [ 'base' => 'master', 'head' => 'virtualtestbranch', @@ -301,10 +303,10 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreatePullRequestWithoutIssueIdOrTitle() { + $this->expectException(MissingArgumentException::class); $data = [ 'base' => 'master', 'head' => 'virtualtestbranch', diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index 1c3a1f3c3dd..547b5dc2797 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -41,10 +41,8 @@ class RateLimitTest extends TestCase * * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { - parent::setUp(); - $this->api = $this->getApiMock(); $this->api->expects($this->once()) ->method('get') diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 9341cb5ac99..029c10a380f 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class AssetsTest extends TestCase @@ -86,10 +87,10 @@ public function shouldEditReleaseAsset() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotEditReleaseAssetWithoutName() { + $this->expectException(MissingArgumentException::class); $assetId = 5; $data = ['not_a_name' => 'just a value']; diff --git a/test/Github/Tests/Api/Repository/ChecksTest.php b/test/Github/Tests/Api/Repository/ChecksTest.php index 23eb545141a..dcc0883d8d7 100644 --- a/test/Github/Tests/Api/Repository/ChecksTest.php +++ b/test/Github/Tests/Api/Repository/ChecksTest.php @@ -2,16 +2,17 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class ChecksTest extends TestCase { /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutHeadSha() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'my check']; $api = $this->getApiMock(); @@ -23,10 +24,10 @@ public function shouldNotCreateWithoutHeadSha() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutName() { + $this->expectException(MissingArgumentException::class); $data = ['head_sha' => 'commitSHA123456']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/CommentsTest.php b/test/Github/Tests/Api/Repository/CommentsTest.php index b573d3735c3..949bf4e231d 100644 --- a/test/Github/Tests/Api/Repository/CommentsTest.php +++ b/test/Github/Tests/Api/Repository/CommentsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class CommentsTest extends TestCase @@ -56,10 +57,10 @@ public function shouldShowComment() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutBody() { + $this->expectException(MissingArgumentException::class); $data = ['line' => 53, 'path' => 'test.php', 'position' => 2]; $api = $this->getApiMock(); @@ -105,10 +106,10 @@ public function shouldCreateRepositoryCommitCommentWithoutLine() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateWithoutBody() { + $this->expectException(MissingArgumentException::class); $api = $this->getApiMock(); $api->expects($this->never()) ->method('patch'); diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 12fa01d44ef..122fbf5cdf9 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Exception\TwoFactorAuthenticationRequiredException; use Github\Tests\Api\TestCase; use GuzzleHttp\Psr7\Response; @@ -85,10 +86,10 @@ public function shouldReturnFalseWhenFileIsNotFound($failureStub) /** * @test - * @expectedException \Github\Exception\TwoFactorAuthenticationRequiredException */ public function shouldBubbleTwoFactorAuthenticationRequiredExceptionsWhenCheckingFileRequiringAuth() { + $this->expectException(TwoFactorAuthenticationRequiredException::class); $api = $this->getApiMock(); $api->expects($this->once()) ->method('head') @@ -126,11 +127,11 @@ public function shouldCreateNewFile() /** * @test - * @expectedException \Github\Exception\MissingArgumentException - * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! */ public function shouldThrowExceptionWhenCreateNewFileWithInvalidCommitter() { + $this->expectException(MissingArgumentException::class); + $this->expectExceptionMessage('One or more of required ("name", "email") parameters is missing!'); $committer = ['invalid_key' => 'some data']; $api = $this->getApiMock(); $api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, $committer); @@ -166,11 +167,11 @@ public function shouldUpdateFile() /** * @test - * @expectedException \Github\Exception\MissingArgumentException - * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! */ public function shouldThrowExceptionWhenUpdateFileWithInvalidCommitter() { + $this->expectException(MissingArgumentException::class); + $this->expectExceptionMessage('One or more of required ("name", "email") parameters is missing!'); $committer = ['invalid_key' => 'some data']; $api = $this->getApiMock(); $api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, null, $committer); @@ -204,11 +205,11 @@ public function shouldDeleteFile() /** * @test - * @expectedException \Github\Exception\MissingArgumentException - * @expectedExceptionMessage One or more of required ("name", "email") parameters is missing! */ public function shouldThrowExceptionWhenDeleteFileWithInvalidCommitter() { + $this->expectException(MissingArgumentException::class); + $this->expectExceptionMessage('One or more of required ("name", "email") parameters is missing!'); $committer = ['invalid_key' => 'some data']; $api = $this->getApiMock(); $api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'a commit message', null, null, $committer); diff --git a/test/Github/Tests/Api/Repository/DeployKeysTest.php b/test/Github/Tests/Api/Repository/DeployKeysTest.php index 1e1a9ca39c6..2962390bc83 100644 --- a/test/Github/Tests/Api/Repository/DeployKeysTest.php +++ b/test/Github/Tests/Api/Repository/DeployKeysTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class DeployKeysTest extends TestCase @@ -56,10 +57,10 @@ public function shouldRemoveDeployKey() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateDeployKeyWithoutName() { + $this->expectException(MissingArgumentException::class); $data = ['config' => 'conf']; $api = $this->getApiMock(); @@ -71,10 +72,10 @@ public function shouldNotCreateDeployKeyWithoutName() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateDeployKeyWithoutColor() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'test']; $api = $this->getApiMock(); @@ -103,10 +104,10 @@ public function shouldCreateDeployKey() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateDeployKeyWithoutTitle() { + $this->expectException(MissingArgumentException::class); $data = ['key' => 'ssh-rsa 12323213']; $api = $this->getApiMock(); @@ -120,10 +121,10 @@ public function shouldNotUpdateDeployKeyWithoutTitle() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateDeployKeyWithoutKey() { + $this->expectException(MissingArgumentException::class); $data = ['title' => 'test']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index 6571d04496d..6d1a1b7f328 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class HooksTest extends TestCase @@ -56,10 +57,10 @@ public function shouldRemoveHook() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateHookWithoutName() { + $this->expectException(MissingArgumentException::class); $data = ['config' => 'conf']; $api = $this->getApiMock(); @@ -71,10 +72,10 @@ public function shouldNotCreateHookWithoutName() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateHookWithoutColor() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'test']; $api = $this->getApiMock(); @@ -103,10 +104,10 @@ public function shouldCreateHook() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateHookWithoutConfig() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'test']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index df9f03844ec..6373d459e08 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class LabelsTest extends TestCase @@ -56,10 +57,10 @@ public function shouldRemoveLabel() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateLabelWithoutName() { + $this->expectException(MissingArgumentException::class); $data = ['color' => 'red']; $api = $this->getApiMock(); @@ -71,10 +72,10 @@ public function shouldNotCreateLabelWithoutName() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateLabelWithoutColor() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'test']; $api = $this->getApiMock(); @@ -103,10 +104,10 @@ public function shouldCreateLabel() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateLabelWithoutName() { + $this->expectException(MissingArgumentException::class); $data = ['color' => 'red']; $api = $this->getApiMock(); @@ -118,10 +119,10 @@ public function shouldNotUpdateLabelWithoutName() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotUpdateLabelWithoutColor() { + $this->expectException(MissingArgumentException::class); $data = ['name' => 'test']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/ProjectsTest.php b/test/Github/Tests/Api/Repository/ProjectsTest.php index 1c0b0f2ce4c..225bda4baf6 100644 --- a/test/Github/Tests/Api/Repository/ProjectsTest.php +++ b/test/Github/Tests/Api/Repository/ProjectsTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class ProjectsTest extends TestCase @@ -24,10 +25,10 @@ public function shouldGetAllRepositoryProjects() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutName() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index 297ee283a08..8668195c1e6 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class ReleasesTest extends TestCase @@ -94,10 +95,10 @@ public function shouldCreateRepositoryRelease() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateRepositoryReleaseWithoutTagName() { + $this->expectException(MissingArgumentException::class); $data = ['not_a_tag_name' => '1.1']; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/StatusesTest.php b/test/Github/Tests/Api/Repository/StatusesTest.php index f286d79aa51..e253955f25a 100644 --- a/test/Github/Tests/Api/Repository/StatusesTest.php +++ b/test/Github/Tests/Api/Repository/StatusesTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Api\Repository; +use Github\Exception\MissingArgumentException; use Github\Tests\Api\TestCase; class StatusesTest extends TestCase @@ -57,10 +58,10 @@ public function shouldShowCombinedCommitStatuses() /** * @test - * @expectedException \Github\Exception\MissingArgumentException */ public function shouldNotCreateWithoutStatus() { + $this->expectException(MissingArgumentException::class); $data = []; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/TrafficTest.php b/test/Github/Tests/Api/Repository/TrafficTest.php index f13a71ace1b..b6136cebe86 100644 --- a/test/Github/Tests/Api/Repository/TrafficTest.php +++ b/test/Github/Tests/Api/Repository/TrafficTest.php @@ -1,5 +1,7 @@ expectException(InvalidArgumentException::class); $client = new Client(); $client->authenticate('login', null, null); @@ -145,20 +146,20 @@ public function shouldGetMagicApiInstance($apiName, $class) /** * @test - * @expectedException \Github\Exception\InvalidArgumentException */ public function shouldNotGetApiInstance() { + $this->expectException(InvalidArgumentException::class); $client = new Client(); $client->api('do_not_exist'); } /** * @test - * @expectedException BadMethodCallException */ public function shouldNotGetMagicApiInstance() { + $this->expectException(BadMethodCallException::class); $client = new Client(); $client->doNotExist(); } diff --git a/test/Github/Tests/HttpClient/PathPrependTest.php b/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php similarity index 100% rename from test/Github/Tests/HttpClient/PathPrependTest.php rename to test/Github/Tests/HttpClient/Plugin/PathPrependTest.php diff --git a/test/Github/Tests/Integration/GistTest.php b/test/Github/Tests/Integration/GistTest.php index e8ce7bc2543..deb079f57e6 100644 --- a/test/Github/Tests/Integration/GistTest.php +++ b/test/Github/Tests/Integration/GistTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Integration; +use Github\Exception\RuntimeException; + /** * @group integration */ @@ -25,10 +27,10 @@ public function shouldRetrievePublicGistsListWhenCalledAnonymously() /** * @test - * @expectedException \Github\Exception\RuntimeException */ public function shouldNotGetStarredListWithoutAuthorization() { + $this->expectException(RuntimeException::class); $this->client->api('gists')->all('starred'); } diff --git a/test/Github/Tests/Integration/RateLimitTest.php b/test/Github/Tests/Integration/RateLimitTest.php index c4b5a521645..b003e5b0604 100644 --- a/test/Github/Tests/Integration/RateLimitTest.php +++ b/test/Github/Tests/Integration/RateLimitTest.php @@ -17,7 +17,8 @@ public function shouldRetrievedRateLimits() $response = $this->client->api('rate_limit')->getRateLimits(); $this->assertArrayHasKey('resources', $response); - $this->assertArraySubset(['resources' => ['core' => ['limit' => 60]]], $response); + $this->assertArrayHasKey('resources', $response); + $this->assertSame(['core' => ['limit' => 60]], $response['resources']); } /** @@ -27,7 +28,7 @@ public function shouldRetrieveRateLimitsAndReturnLimitInstances() { $response = $this->client->api('rate_limit')->getLimits(); - $this->assertInternalType('array', $response); + $this->assertIsArray($response); $this->assertContainsOnlyInstancesOf(RateLimitResource::class, $response); $this->assertEquals(60, $response->getLimit('core')->getLimit()); } diff --git a/test/Github/Tests/Integration/RepoTest.php b/test/Github/Tests/Integration/RepoTest.php index 076175f2523..2d958e35713 100644 --- a/test/Github/Tests/Integration/RepoTest.php +++ b/test/Github/Tests/Integration/RepoTest.php @@ -21,7 +21,7 @@ public function shouldShowPRDiffIfHeaderIsPresent() $diff = $this->client->api('pull_request')->show('KnpLabs', 'php-github-api', '92'); - $this->assertInternalType('string', $diff); + $this->assertIsString($diff); } /** @@ -38,7 +38,7 @@ public function shouldRetrieveRawBlob() 'e50d5e946385cff052636e2f09f36b03d1c368f4' ); - $this->assertInternalType('string', $contents); + $this->assertIsString($contents); $this->assertStringStartsWith('assertInternalType('string', $contents); + $this->assertIsString($contents); $this->assertStringStartsWith('{', $contents); } diff --git a/test/Github/Tests/Integration/TestCase.php b/test/Github/Tests/Integration/TestCase.php index 6f8e5815719..319070d5014 100644 --- a/test/Github/Tests/Integration/TestCase.php +++ b/test/Github/Tests/Integration/TestCase.php @@ -16,7 +16,7 @@ class TestCase extends \PHPUnit\Framework\TestCase */ protected $client; - public function setUp() + public function setUp(): void { // You have to specify authentication here to run full suite $client = new Client(); diff --git a/test/Github/Tests/Integration/UserTest.php b/test/Github/Tests/Integration/UserTest.php index d08f1d643a2..57dbeceeefc 100644 --- a/test/Github/Tests/Integration/UserTest.php +++ b/test/Github/Tests/Integration/UserTest.php @@ -2,6 +2,8 @@ namespace Github\Tests\Integration; +use Github\Exception\RuntimeException; + /** * @group integration */ @@ -32,10 +34,10 @@ public function shouldShowUserData() /** * @test - * @expectedException \Github\Exception\RuntimeException */ public function shouldNotUpdateUserWithoutAuthorization() { + $this->expectException(RuntimeException::class); $this->client->api('current_user')->update(['email' => 'leszek.prabucki@gmail.com']); } @@ -69,19 +71,19 @@ public function shouldGetFollowersUsers() /** * @test - * @expectedException \Github\Exception\RuntimeException */ public function shouldNotFollowUserWithoutAuthorization() { + $this->expectException(RuntimeException::class); $this->client->api('current_user')->follow()->follow('KnpLabs'); } /** * @test - * @expectedException \Github\Exception\RuntimeException */ public function shouldNotUnfollowUserWithoutAuthorization() { + $this->expectException(RuntimeException::class); $this->client->api('current_user')->follow()->unfollow('KnpLabs'); } From 391f8ebed5b466675d271abc4c4b4ec05bee6af8 Mon Sep 17 00:00:00 2001 From: Andrii Bodnar <29282228+andrii-bodnar@users.noreply.github.com> Date: Tue, 24 Sep 2019 14:35:43 +0300 Subject: [PATCH 688/951] Fix links in 'Organization / Webhooks API' doc --- doc/organization/webhooks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/organization/webhooks.md b/doc/organization/webhooks.md index 83898603c16..669e3446125 100644 --- a/doc/organization/webhooks.md +++ b/doc/organization/webhooks.md @@ -1,11 +1,11 @@ ## Organization / Webhooks API -[Back to the navigation](README.md) +[Back to the navigation](../README.md) Listing, showing, creating, updating, testing and removing organizations webhooks. Wraps [GitHub Organization Webhooks API](https://developer.github.com/v3/orgs/hooks/). Additional APIs: -* [Organization](issue/organization.md) +* [Organization](../doc/organization) ### List webhooks for an organization From 8e3060617f25bb0b31d23a524ca02b0deff8b2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 3 Oct 2019 17:17:59 +0200 Subject: [PATCH 689/951] Add $params to files from pull request --- lib/Github/Api/PullRequest.php | 9 +++-- test/Github/Tests/Api/PullRequestTest.php | 40 ++++++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 1f22137afbd..ca11c8882a1 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -90,9 +90,14 @@ public function commits($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); } - public function files($username, $repository, $id) + public function files($username, $repository, $id, array $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files'); + $parameters = array_merge([ + 'page' => 1, + 'per_page' => 30, + ], $params); + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters); } /** diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 3f2acceb913..31f1625e258 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -97,12 +97,28 @@ public function shouldShowFilesFromPullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls/15/files') + ->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 1, 'per_page' => 30]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15')); } + /** + * @test + */ + public function shouldShowFilesFromPullRequestForPage() + { + $expectedArray = [['id' => 'id', 'sha' => '123123']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 2, 'per_page' => 30]) + ->willReturn($expectedArray); + + $this->assertSame($expectedArray, $api->files('ezsystems', 'ezpublish', '15', ['page' => 2, 'per_page' => 30])); + } + /** * @test */ @@ -211,10 +227,10 @@ public function shouldMergePullRequestWithMergeMethod() public function shouldCreatePullRequestUsingTitle() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -231,8 +247,8 @@ public function shouldCreatePullRequestUsingTitle() public function shouldCreatePullRequestUsingIssueId() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'issue' => 25, ]; @@ -251,9 +267,9 @@ public function shouldNotCreatePullRequestWithoutBase() { $this->expectException(MissingArgumentException::class); $data = [ - 'head' => 'virtualtestbranch', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -270,9 +286,9 @@ public function shouldNotCreatePullRequestWithoutHead() { $this->expectException(MissingArgumentException::class); $data = [ - 'base' => 'master', + 'base' => 'master', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -289,8 +305,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { $this->expectException(MissingArgumentException::class); $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', ]; From fad45b075eec20f0c06051461384864e2f271fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 10 Oct 2019 18:31:56 +0200 Subject: [PATCH 690/951] Do not set the default values for requests --- lib/Github/Api/PullRequest.php | 16 +++------------- test/Github/Tests/Api/PullRequestTest.php | 6 +++--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index ca11c8882a1..fbb763dc5bf 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -55,17 +55,12 @@ public function configure($bodyType = null, $apiVersion = null) * * @param string $username the username * @param string $repository the repository - * @param array $params a list of extra parameters. + * @param array $parameters a list of extra parameters. * * @return array array of pull requests for the project */ - public function all($username, $repository, array $params = []) + public function all($username, $repository, array $parameters = []) { - $parameters = array_merge([ - 'page' => 1, - 'per_page' => 30, - ], $params); - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $parameters); } @@ -90,13 +85,8 @@ public function commits($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); } - public function files($username, $repository, $id, array $params = []) + public function files($username, $repository, $id, array $parameters = []) { - $parameters = array_merge([ - 'page' => 1, - 'per_page' => 30, - ], $params); - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/files', $parameters); } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 31f1625e258..49be44fbf2f 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -32,7 +32,7 @@ public function shouldGetOpenPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open', 'per_page' => 30, 'page' => 1]) + ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'open']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'open'])); @@ -48,7 +48,7 @@ public function shouldGetClosedPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed', 'per_page' => 30, 'page' => 1]) + ->with('/repos/ezsystems/ezpublish/pulls', ['state' => 'closed']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', ['state' => 'closed'])); @@ -97,7 +97,7 @@ public function shouldShowFilesFromPullRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls/15/files', ['page' => 1, 'per_page' => 30]) + ->with('/repos/ezsystems/ezpublish/pulls/15/files') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->files('ezsystems', 'ezpublish', '15')); From b718781d931b5b6db7af9493504408fc434e89e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 10 Oct 2019 19:52:09 +0200 Subject: [PATCH 691/951] Trigger Travis From e4920bb90b3af863cb97ef8b6d2fca06dd74db44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 17 Oct 2019 19:05:09 +0200 Subject: [PATCH 692/951] Update .gitattributes --- .gitattributes | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index 043395a4003..c459022a96c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,8 +2,5 @@ /doc export-ignore /test export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/.travis.yml export-ignore +/.* export-ignore /phpunit.xml.dist export-ignore -/README.markdown export-ignore From 1919769ef430f70a747b65a6641939415832e279 Mon Sep 17 00:00:00 2001 From: Leon Husmann Date: Sat, 19 Oct 2019 12:15:41 +0200 Subject: [PATCH 693/951] add existing checks to repo as described in the docs --- lib/Github/Api/Repo.php | 13 +++++++++++++ test/Github/Tests/Api/RepoTest.php | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index c8e6a24d631..37cb8aac794 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Repository\Checks; use Github\Api\Repository\Collaborators; use Github\Api\Repository\Comments; use Github\Api\Repository\Commits; @@ -682,4 +683,16 @@ public function transfer($username, $repository, $newOwner, $teamId = []) return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]); } + + /** + * Manage the checks of a repository. + * + * @link https://developer.github.com/v3/checks + * + * @return Checks + */ + public function checks() + { + return new Checks($this->client); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 3ddf7cf8054..e6dfaa619a9 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -607,6 +607,16 @@ 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 */ From 8c17007866cedb56266286c6ecdfd66e2d1106a3 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 28 Oct 2019 10:55:38 +0000 Subject: [PATCH 694/951] Delete .php_cs --- .php_cs | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .php_cs diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 83782b0f551..00000000000 --- a/.php_cs +++ /dev/null @@ -1,14 +0,0 @@ -in(__DIR__); - -$config = PhpCsFixer\Config::create() - ->setRiskyAllowed(true) - ->setRules([ - - ]) - ->setFinder($finder) -; - -return $config; From 6f8fff215c55249f18a13040e0915c4ab410b701 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 28 Oct 2019 10:56:51 +0000 Subject: [PATCH 695/951] Enabled return_assignment on StyleCI --- .styleci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.styleci.yml b/.styleci.yml index 504456e7afa..4187da89396 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,5 +1,8 @@ preset: recommended +enabled: + - return_assignment + disabled: - align_double_arrow - no_multiline_whitespace_before_semicolons From 1b66f2c5740504931c78f499a378ba70f18b962c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=97=A0=E5=BF=83?= <448901948@qq.com> Date: Tue, 29 Oct 2019 15:45:29 +0800 Subject: [PATCH 696/951] Update Trees.php If the sha is null then the file will be deleted. --- lib/Github/Api/GitData/Trees.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/GitData/Trees.php b/lib/Github/Api/GitData/Trees.php index d514d9f8205..939e8619b73 100644 --- a/lib/Github/Api/GitData/Trees.php +++ b/lib/Github/Api/GitData/Trees.php @@ -54,7 +54,7 @@ public function create($username, $repository, array $params) } // If `sha` is not set, `content` is required - if (!isset($tree['sha']) && !isset($tree['content'])) { + if (!array_key_exists('sha', $tree) && !isset($tree['content'])) { throw new MissingArgumentException("tree.$key.content"); } } From a21dbd715ddd32e99086833bf96127ab26604f0e Mon Sep 17 00:00:00 2001 From: BroderFluff <42545290+BroderFluff@users.noreply.github.com> Date: Fri, 1 Nov 2019 14:54:52 +0100 Subject: [PATCH 697/951] Added checks() in Repo. (#809) * added checks() in Repo * tidy * removed space at end of line * removed another space at end of line * moved use-statement --- lib/Github/Api/Repo.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 37cb8aac794..3a3636365d0 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -311,6 +311,18 @@ public function commits() return new Commits($this->client); } + /** + * Manage checks on a repository. + * + * @link https://developer.github.com/v3/checks/ + * + * @return Checks + */ + public function checks() + { + return new Checks($this->client); + } + /** * Manage the content of a repository. * From de9322c9c4ec8c40781e23d0eff075a758bd8b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=97=A0=E5=BF=83?= Date: Fri, 1 Nov 2019 23:11:52 +0800 Subject: [PATCH 698/951] Add support for Pages API (#824) * Add support for Pages API * Apply fixes from StyleCI * fixed * Apply fixes from StyleCI --- lib/Github/Api/Repo.php | 6 + lib/Github/Api/Repository/Pages.php | 60 +++++++ .../Github/Tests/Api/Repository/PagesTest.php | 150 ++++++++++++++++++ 3 files changed, 216 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 3a3636365d0..abbf73b5665 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; @@ -607,6 +608,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..b641cb957c0 --- /dev/null +++ b/lib/Github/Api/Repository/Pages.php @@ -0,0 +1,60 @@ + + */ +class Pages extends AbstractApi +{ + use AcceptHeaderTrait; + + public function show($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); + } + + 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'); + } + + 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..c6b34cbc8b3 --- /dev/null +++ b/test/Github/Tests/Api/Repository/PagesTest.php @@ -0,0 +1,150 @@ + '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 157bd55c6698045747de6edc5eb5977460925156 Mon Sep 17 00:00:00 2001 From: t-kuni Date: Sat, 2 Nov 2019 00:23:12 +0900 Subject: [PATCH 699/951] Improve to can specify parameters on issue comments api. (#815) * Improve to can specify properties on issue comments api. (cherry picked from commit 9900b21a5670b7c6dbecb5b46d93302ca0d2ef89) * fix typo. * Add message which tell deprecated. --- lib/Github/Api/Issue/Comments.php | 21 +++++++++++++------- test/Github/Tests/Api/Issue/CommentsTest.php | 18 +++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index a664d533274..7dd2c96e9d2 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -41,18 +41,25 @@ public function configure($bodyType = null) * * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue * - * @param string $username - * @param string $repository - * @param int $issue - * @param int $page + * @param string $username + * @param string $repository + * @param int $issue + * @param int|array $page Passing integer is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead. * * @return array */ public function all($username, $repository, $issue, $page = 1) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', [ - 'page' => $page, - ]); + if (is_array($page)) { + $parameters = $page; + } else { + @trigger_error(sprintf('Passing integer to the "page" argument in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead.', __METHOD__), E_USER_DEPRECATED); + $parameters = [ + 'page' => $page, + ]; + } + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $parameters); } /** diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index df8e5130937..08f4ff0ff16 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -23,6 +23,24 @@ public function shouldGetAllIssueComments() $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); } + /** + * @test + */ + public function shouldGetAllIssueCommentsBySpecifyParameters() + { + $expectedValue = [['comment1data'], ['comment2data']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/issues/123/comments', ['since' => '1990-08-03T00:00:00Z']) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123, [ + 'since' => '1990-08-03T00:00:00Z', + ])); + } + /** * @test */ From 7e2d2f3bd3cf17b47e6fee8bf78a0c5557dc1762 Mon Sep 17 00:00:00 2001 From: Daniel Fahlke Date: Fri, 1 Nov 2019 16:32:20 +0100 Subject: [PATCH 700/951] Update rate_limits.md to reflect actual implementation (#808) * Update rate_limits.md * Update rate_limits.md --- doc/rate_limits.md | 61 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/doc/rate_limits.md b/doc/rate_limits.md index 7ca39b842bc..3239a44b612 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -5,9 +5,68 @@ Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com #### Get All Rate Limits +##### new way ```php /** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits */ -$rateLimits = $client->api('rate_limit')->getLimits(); +$rateLimits = $client->api('rate_limit')->getResources(); +``` + +var_dump() output: +``` +array(4) { + ["core"]=> + object(Github\Api\RateLimit\RateLimitResource)#30 (4) { + ["name":"Github\Api\RateLimit\RateLimitResource":private]=> + string(4) "core" + ["limit":"Github\Api\RateLimit\RateLimitResource":private]=> + int(5000) + ["reset":"Github\Api\RateLimit\RateLimitResource":private]=> + int(1566137712) + ["remaining":"Github\Api\RateLimit\RateLimitResource":private]=> + int(5000) + } + ["search"]=> + object(Github\Api\RateLimit\RateLimitResource)#32 (4) { + ["name":"Github\Api\RateLimit\RateLimitResource":private]=> + string(6) "search" + ["limit":"Github\Api\RateLimit\RateLimitResource":private]=> + int(30) + ["reset":"Github\Api\RateLimit\RateLimitResource":private]=> + int(1566134172) + ["remaining":"Github\Api\RateLimit\RateLimitResource":private]=> + int(30) + } + ["graphql"]=> + object(Github\Api\RateLimit\RateLimitResource)#43 (4) { + ["name":"Github\Api\RateLimit\RateLimitResource":private]=> + string(7) "graphql" + ["limit":"Github\Api\RateLimit\RateLimitResource":private]=> + int(5000) + ["reset":"Github\Api\RateLimit\RateLimitResource":private]=> + int(1566137712) + ["remaining":"Github\Api\RateLimit\RateLimitResource":private]=> + int(5000) + } + ["integration_manifest"]=> + object(Github\Api\RateLimit\RateLimitResource)#44 (4) { + ["name":"Github\Api\RateLimit\RateLimitResource":private]=> + string(20) "integration_manifest" + ["limit":"Github\Api\RateLimit\RateLimitResource":private]=> + int(5000) + ["reset":"Github\Api\RateLimit\RateLimitResource":private]=> + int(1566137712) + ["remaining":"Github\Api\RateLimit\RateLimitResource":private]=> + int(5000) + } +} +``` + + +##### deprecated way + +```php +/** @var array $rateLimits */ +$rateLimits = $client->api('rate_limit')->getRateLimits(); ``` #### Get Core Rate Limit From 50968591b9aba0d6204056b5bcdb78c7435a9fb5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 1 Nov 2019 22:47:17 +0100 Subject: [PATCH 701/951] Remove duplicate checks method --- lib/Github/Api/Repo.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index abbf73b5665..e9eaf44c781 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -701,16 +701,4 @@ public function transfer($username, $repository, $newOwner, $teamId = []) return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]); } - - /** - * Manage the checks of a repository. - * - * @link https://developer.github.com/v3/checks - * - * @return Checks - */ - public function checks() - { - return new Checks($this->client); - } } From 5071f3eeae507a2bac026666a20c77ac8cca9fa2 Mon Sep 17 00:00:00 2001 From: Adam Allport Date: Fri, 1 Nov 2019 22:04:21 +0000 Subject: [PATCH 702/951] Added header for apps (#823) * Added header for apps * Removed blank line * Made config calls private * :expressionless: StyleCI * Made configure public to pass tests * Style * Function rename and made final * Update lib/Github/Api/Apps.php --- lib/Github/Api/Apps.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 1467d2aaf43..feaddb9d9cc 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -9,6 +9,13 @@ */ class Apps extends AbstractApi { + use AcceptHeaderTrait; + + private function configurePreviewHeader() + { + $this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json'; + } + /** * Create an access token for an installation. * @@ -27,6 +34,8 @@ public function createInstallationToken($installationId, $userId = null) $parameters['user_id'] = $userId; } + $this->configurePreviewHeader(); + return $this->post('/app/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); } @@ -39,6 +48,8 @@ public function createInstallationToken($installationId, $userId = null) */ public function findInstallations() { + $this->configurePreviewHeader(); + return $this->get('/app/installations'); } @@ -58,6 +69,8 @@ public function listRepositories($userId = null) $parameters['user_id'] = $userId; } + $this->configurePreviewHeader(); + return $this->get('/installation/repositories', $parameters); } @@ -73,6 +86,8 @@ public function listRepositories($userId = null) */ public function addRepository($installationId, $repositoryId) { + $this->configurePreviewHeader(); + return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } @@ -88,6 +103,8 @@ public function addRepository($installationId, $repositoryId) */ public function removeRepository($installationId, $repositoryId) { + $this->configurePreviewHeader(); + return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); } } From 18c6083a22501e36b205a0a229413a80e42e3b65 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 3 Nov 2019 12:48:04 +0100 Subject: [PATCH 703/951] Allow httplug 2.0 (#802) * Allow httplug 2.0 * suppress invalid BC warnings --- .github/bc-test.sh | 49 +++++++++++++++++++ .travis.yml | 3 +- composer.json | 8 +-- .../HttpClient/Plugin/Authentication.php | 4 +- .../Plugin/GithubExceptionThrower.php | 4 +- lib/Github/HttpClient/Plugin/History.php | 7 +-- lib/Github/HttpClient/Plugin/HistoryTrait.php | 32 ++++++++++++ lib/Github/HttpClient/Plugin/PathPrepend.php | 4 +- test/Github/Tests/Api/AbstractApiTest.php | 30 ++++-------- .../Plugin/GithubExceptionThrowerTest.php | 2 +- .../HttpClient/Plugin/PathPrependTest.php | 2 +- 11 files changed, 109 insertions(+), 36 deletions(-) create mode 100755 .github/bc-test.sh create mode 100644 lib/Github/HttpClient/Plugin/HistoryTrait.php diff --git a/.github/bc-test.sh b/.github/bc-test.sh new file mode 100755 index 00000000000..1f66ee13ab0 --- /dev/null +++ b/.github/bc-test.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# +# This file is a hack to suppress warnings from Roave BC check +# + +echo "Running..." + +# Capture output to variable +OUTPUT=$(./vendor/bin/roave-backward-compatibility-check 2>&1) +echo "$OUTPUT" + +# Remove rows we want to suppress +OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\Authentication#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` +OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\Authentication#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` +OUTPUT=`echo "$OUTPUT" | sed '/The parameter $exception of Github\\\HttpClient\\\Plugin\\\History#addFailure() changed from Http\\\Client\\\Exception to a non-contravariant Psr\\\Http\\\Client\\\ClientExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/The parameter $exception of Github\\\HttpClient\\\Plugin\\\History#addFailure() changed from Http\\\Client\\\Exception to Psr\\\Http\\\Client\\\ClientExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\PathPrepend#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` +OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\GithubExceptionThrower#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getMessage() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getCode() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getFile() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getLine() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getTrace() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getPrevious() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method getTraceAsString() was added to interface Github\\\Exception\\\ExceptionInterface/'d` +OUTPUT=`echo "$OUTPUT" | sed '/Method __toString() was added to interface Github\\\Exception\\\ExceptionInterface/'d` + +# Number of rows we found with "[BC]" in them +BC_BREAKS=`echo "$OUTPUT" | grep -o '\[BC\]' | wc -l | awk '{ print $1 }'` + +# The last row of the output is "X backwards-incompatible changes detected". Find X. +STATED_BREAKS=`echo "$OUTPUT" | tail -n 1 | awk -F' ' '{ print $1 }'` + +# If +# We found "[BC]" in the command output after we removed suppressed lines +# OR +# We have suppressed X number of BC breaks. If $STATED_BREAKS is larger than X +# THEN +# exit 1 + +if [ $BC_BREAKS -gt 0 ] || [ $STATED_BREAKS -gt 13 ]; then + echo "EXIT 1" + exit 1 +fi + +# No BC breaks found +echo "EXIT 0" +exit 0 diff --git a/.travis.yml b/.travis.yml index 4630e91bffd..6912ddfbfbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ sudo: false cache: directories: - - vendor - $HOME/.composer/cache env: @@ -19,7 +18,7 @@ matrix: include: - php: 7.2 name: Backward compatibillity check - env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./vendor/bin/roave-backward-compatibility-check" + env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./.github/bc-test.sh" before_install: - if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; diff --git a/composer.json b/composer.json index af0e7df5ad9..10eacd31e0a 100644 --- a/composer.json +++ b/composer.json @@ -20,16 +20,16 @@ "php": "^7.1", "psr/http-message": "^1.0", "psr/cache": "^1.0", - "php-http/httplug": "^1.1", + "php-http/httplug": "^1.1 || ^2.0", "php-http/discovery": "^1.0", "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.6", + "php-http/client-common": "^1.6 || ^2.0", "php-http/cache-plugin": "^1.4" }, "require-dev": { "phpunit/phpunit": "^7.0 || ^8.0", - "php-http/guzzle6-adapter": "^1.0", - "php-http/mock-client": "^1.0", + "php-http/guzzle6-adapter": "^1.0 || ^2.0", + "php-http/mock-client": "^1.2", "guzzlehttp/psr7": "^1.2", "cache/array-adapter": "^0.4" }, diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 920d65722c6..0ab09ab20ba 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -14,6 +14,8 @@ */ class Authentication implements Plugin { + use Plugin\VersionBridgePlugin; + private $tokenOrLogin; private $password; private $method; @@ -28,7 +30,7 @@ public function __construct($tokenOrLogin, $password, $method) /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index a0593924b7a..933c06a5817 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -18,10 +18,12 @@ */ class GithubExceptionThrower implements Plugin { + use Plugin\VersionBridgePlugin; + /** * {@inheritdoc} */ - public function handleRequest(RequestInterface $request, callable $next, callable $first) + public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { return $next($request)->then(function (ResponseInterface $response) use ($request) { if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) { diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 303d81404dc..0f59bbb65f9 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -3,7 +3,6 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin\Journal; -use Http\Client\Exception; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -14,6 +13,8 @@ */ class History implements Journal { + use HistoryTrait; + /** * @var ResponseInterface */ @@ -31,8 +32,4 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons { $this->lastResponse = $response; } - - public function addFailure(RequestInterface $request, Exception $exception) - { - } } diff --git a/lib/Github/HttpClient/Plugin/HistoryTrait.php b/lib/Github/HttpClient/Plugin/HistoryTrait.php new file mode 100644 index 00000000000..fbc5335d318 --- /dev/null +++ b/lib/Github/HttpClient/Plugin/HistoryTrait.php @@ -0,0 +1,32 @@ +getUri()->getPath(); if (strpos($currentPath, $this->path) !== 0) { diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index ec8dd1e0be0..ae2fa7cd3b6 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -4,6 +4,7 @@ use Github\Api\AbstractApi; use GuzzleHttp\Psr7\Response; +use Http\Client\Common\HttpMethodsClientInterface; class AbstractApiTest extends TestCase { @@ -212,26 +213,15 @@ protected function getClientMock() */ protected function getHttpMethodsMock(array $methods = []) { - $methods = array_merge(['sendRequest'], $methods); - $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) - ->disableOriginalConstructor() - ->setMethods($methods) - ->getMock(); - $mock - ->expects($this->any()) - ->method('sendRequest'); - - return $mock; - } - - /** - * @return \Http\Client\HttpClient - */ - protected function getHttpClientMock() - { - $mock = $this->getMockBuilder(\Http\Client\HttpClient::class) - ->setMethods(['sendRequest']) - ->getMock(); + if (interface_exists(HttpMethodsClientInterface::class)) { + $mock = $this->createMock(HttpMethodsClientInterface::class); + } else { + $methods = array_merge(['sendRequest'], $methods); + $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) + ->disableOriginalConstructor() + ->setMethods($methods) + ->getMock(); + } $mock ->expects($this->any()) ->method('sendRequest'); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index fd83e88c2f4..84027aa4339 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -40,7 +40,7 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac $this->expectExceptionMessage($exception->getMessage()); } - $plugin->handleRequest( + $plugin->doHandleRequest( $request, function (RequestInterface $request) use ($promise) { return $promise; diff --git a/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php b/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php index fdfe180980a..e5feda2cf3d 100644 --- a/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php +++ b/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php @@ -20,7 +20,7 @@ public function testPathIsPrepended($uri, $expectedPath) $plugin = new PathPrepend('/api/v3'); $newRequest = null; - $plugin->handleRequest($request, function ($request) use (&$newRequest) { + $plugin->doHandleRequest($request, function ($request) use (&$newRequest) { $newRequest = $request; }, function () { throw new \RuntimeException('Did not expect plugin to call first'); From f991fe4150da0a9fed3209e183b4dee12e1ae17d Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 3 Nov 2019 13:05:11 +0100 Subject: [PATCH 704/951] Changelog for 2.12.0 --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0424c953045..e13952e0555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,36 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.12.0 + +### Added + +- Support for HTTPlug 2.0 and PSR-18 +- Add support for GitHub Checks +- Add support for GitHub Pages +- Add support to update a Pull Request Review +- Add support to get specific revision of a gist +- Added a 4th argument `$parameters` to `PullRequest::files()` +- Added `Accept` headers to Github Apps + +### Removed + +- Active support for HHVM +- Support for PHP <7.1 + +### Changed + +- Allow tags to be created without the `Tagger` object +- When updating DeployKeys we will first remove existing then add a new DeployKey + +### Fixed + +- In `Trees` we should check if `array_key_exists('sha', $tree)` instead of `isset` to avoid issues with `null`. (#822) + +### Deprecated + +- Passing an integer (`$page`) as 4th arugment in `Comments::all()` is deprecated. It should be an array. + ## 2.11.0 ### Added From d180ab25284567fd05a4a664df11d9cd089fea42 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 4 Nov 2019 08:53:59 +0100 Subject: [PATCH 705/951] Using a string is deprecated --- doc/issue/assignees.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/issue/assignees.md b/doc/issue/assignees.md index d03524ae24d..58071d74f97 100644 --- a/doc/issue/assignees.md +++ b/doc/issue/assignees.md @@ -18,11 +18,11 @@ $info = $client->api('issue')->assignees()->check('KnpLabs', 'php-github-api', ' ### Add assignee ```php -$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user']); +$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => ['test-user']]); ``` ### Remove assignee ```php -$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user']); +$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => ['test-user']]); ``` From 1a4225096a9209099cc70735e89f73ed347de6b6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 5 Nov 2019 18:21:52 +0000 Subject: [PATCH 706/951] Fixed handling of validation errors --- lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 933c06a5817..04f137f06cf 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -76,13 +76,18 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla break; default: - $errors[] = $error['message']; + if (isset($error['message'])) { + $errors[] = $error['message']; + } break; } } - throw new ValidationFailedException('Validation Failed: '.implode(', ', $errors), 422); + throw new ValidationFailedException( + $errors ? 'Validation Failed: '.implode(', ', $errors) : 'Validation Failed', + 422 + ); } } From 51b1bef76b99c41f414fd2fdfdd034c8c14382ca Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 7 Nov 2019 17:08:24 +0100 Subject: [PATCH 707/951] Prepare 2.12.1 release --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e13952e0555..2e86df46931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.12.1 + +### Fixed + +- Fixed bug in handling of validation errors +- Updated docs to not use deprected string parameter in issue assignee call + ## 2.12.0 ### Added From 4018a9359792d2cd5ae10a45818884fd261b9527 Mon Sep 17 00:00:00 2001 From: Jamie Huson Date: Thu, 14 Nov 2019 01:45:44 -0800 Subject: [PATCH 708/951] Added missing Apps endpoints (#814) * add Apps endpoint /apps/installations/:installation_id: * add Apps endpoint delete /apps/installations/:installation_id: * add Apps endpoint get /org/:org:/installation * add Apps endpoint get /repos/:owner/:repo/installation * add Apps endpoint get /users/:username/installation * fix styling of comments * use the configurePreviewHeader() function in newly added endpoints * switch to camel casing for some arg names --- lib/Github/Api/Apps.php | 79 ++++++++++++++++++++++++++++++ test/Github/Tests/Api/AppTest.php | 80 ++++++++++++++++++++++++++++++- 2 files changed, 158 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index feaddb9d9cc..4985928a8f5 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -53,6 +53,85 @@ public function findInstallations() return $this->get('/app/installations'); } + /** + * Get an installation of the application. + * + * @link https://developer.github.com/v3/apps/#get-an-installation + * + * @param $installationId An integration installation id + * + * @return array + */ + public function getInstallation($installationId) + { + $this->configurePreviewHeader(); + + return $this->get('/app/installations/'.rawurldecode($installationId)); + } + + /** + * Get an installation of the application for an organization. + * + * @link https://developer.github.com/v3/apps/#get-an-organization-installation + * + * @param $org An organization + * + * @return array + */ + public function getInstallationForOrganization($org) + { + $this->configurePreviewHeader(); + + return $this->get('/org/'.rawurldecode($org).'/installation'); + } + + /** + * Get an installation of the application for a repository. + * + * @link https://developer.github.com/v3/apps/#get-a-repository-installation + * + * @param $owner the owner of a repository + * @param $repo the name of the repository + * + * @return array + */ + public function getInstallationForRepo($owner, $repo) + { + $this->configurePreviewHeader(); + + return $this->get('/repos/'.rawurldecode($owner).'/'.rawurldecode($repo).'/installation'); + } + + /** + * Get an installation of the application for a user. + * + * @link https://developer.github.com/v3/apps/#get-a-user-installation + * + * @param $username + * + * @return array + */ + public function getInstallationForUser($username) + { + $this->configurePreviewHeader(); + + return $this->get('/users/'.rawurldecode($username).'/installation'); + } + + /** + * Delete an installation of the application. + * + * @link https://developer.github.com/v3/apps/#delete-an-installation + * + * @param $installationId An integration installation id + */ + public function removeInstallation($installationId) + { + $this->configurePreviewHeader(); + + $this->delete('/app/installations/'.rawurldecode($installationId)); + } + /** * List repositories that are accessible to the authenticated installation. * diff --git a/test/Github/Tests/Api/AppTest.php b/test/Github/Tests/Api/AppTest.php index 446ebf5d72f..e5d5fcf57b4 100644 --- a/test/Github/Tests/Api/AppTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -27,7 +27,7 @@ public function shouldCreateInstallationTokenForInstallation() /** * @test */ - public function shouldFindRepositoriesForApplication() + public function shouldFindInstallationsForApplication() { $result = ['installation1', 'installation2']; @@ -40,6 +40,84 @@ public function shouldFindRepositoriesForApplication() $this->assertEquals($result, $api->findInstallations()); } + /** + * @test + */ + public function shouldGetInstallationForApplication() + { + $result = ['installation1']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/app/installations/1234') + ->willReturn($result); + + $this->assertEquals($result, $api->getInstallation('1234')); + } + + /** + * @test + */ + public function shouldGetInstallationForOrganization() + { + $result = ['installation1']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/org/1234/installation') + ->willReturn($result); + + $this->assertEquals($result, $api->getInstallationForOrganization('1234')); + } + + /** + * @test + */ + public function shouldGetInstallationForRepo() + { + $result = ['installation1']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/MyOrg/MyRepo/installation') + ->willReturn($result); + + $this->assertEquals($result, $api->getInstallationForRepo('MyOrg', 'MyRepo')); + } + + /** + * @test + */ + public function shouldGetInstallationForUser() + { + $result = ['installation1']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/users/octocat/installation') + ->willReturn($result); + + $this->assertEquals($result, $api->getInstallationForUser('octocat')); + } + + /** + * @test + */ + public function shouldDeleteInstallationForApplication() + { + $id = 123; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/app/installations/'.$id); + + $api->removeInstallation($id); + } + /** * @test */ From f6462d2813b74c66ca1f3f9f73d4155f6d3c8024 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 14 Nov 2019 10:54:03 +0100 Subject: [PATCH 709/951] Bump branch-alias for next minor release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 10eacd31e0a..7767e041259 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.12.x-dev" + "dev-master": "2.13.x-dev" } } } From 923dfd1cd987b5ef3080a95bba53fd1c9ae6e334 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 14 Nov 2019 11:10:51 +0100 Subject: [PATCH 710/951] Enable testing against php 7.4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6912ddfbfbc..79fc2ebde35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4snapshot matrix: include: From 005189cd65bf9323543ed074078cb027d919d8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20T=C3=B3th?= Date: Fri, 15 Nov 2019 18:51:11 +0100 Subject: [PATCH 711/951] Add support for draft PRs (#820) * Add support for draft PRs #807 * Use acceptHeadervalue from the AcceptHeaderTrait * Fix test for PullRequest * Use strict equivalence in PullRequest * Remove unused headers var in PullRequest --- doc/pull_requests.md | 1 + lib/Github/Api/PullRequest.php | 5 +++++ test/Github/Tests/Api/PullRequestTest.php | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index ee15fb642c5..c6d5a8e6b39 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -54,6 +54,7 @@ The ``$pullRequest`` array contains the same elements as every entry in the resu A pull request can either be created by supplying both the Title & Body, OR an Issue ID. Details regarding the content of parameters 3 and 4 of the ``create``. +You can create a draft pull request by adding a parameter with key `draft` and value `true`. #### Populated with Title and Body diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index fbb763dc5bf..a92e71b186c 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -156,6 +156,11 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(['issue', 'body']); } + if (isset($params['draft']) && $params['draft'] === true) { + //This feature is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.shadow-cat-preview+json'; + } + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params); } diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 49be44fbf2f..660368fd4f5 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -260,6 +260,27 @@ public function shouldCreatePullRequestUsingIssueId() $api->create('ezsystems', 'ezpublish', $data); } + /** + * @test + */ + public function shouldCreateDraftPullRequest() + { + $data = [ + 'base' => 'master', + 'head' => 'virtualtestbranch', + 'title' => 'TITLE: Testing draft pull-request creation from PHP Github API', + 'body' => 'BODY: Testing draft pull-request creation from PHP Github API', + 'draft' => 'true', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/ezsystems/ezpublish/pulls', $data); + + $api->create('ezsystems', 'ezpublish', $data); + } + /** * @test */ From 364e76577c5616ce4539dc0f5038dac1337e10f3 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 23 Nov 2019 17:06:23 +0100 Subject: [PATCH 712/951] Create FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000000..823ad09b27d --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [acrobat] From 7990fb7729c0d068749726555e54cf01c9f75c2f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 20 Dec 2019 09:51:37 +0000 Subject: [PATCH 713/951] Update .travis.yml --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79fc2ebde35..8f4e1727eb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: php -sudo: false + +dist: bionic cache: directories: @@ -13,7 +14,7 @@ php: - 7.1 - 7.2 - 7.3 - - 7.4snapshot + - 7.4 matrix: include: @@ -25,7 +26,7 @@ before_install: - if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; install: - - travis_retry composer install --no-interaction + - travis_retry composer install script: - $TEST_COMMAND From 06405d00673992ac80f6add2e06bf1867675ffb1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 11 Jan 2020 19:32:35 +0000 Subject: [PATCH 714/951] Apply fixes from StyleCI --- lib/Github/Api/AbstractApi.php | 4 +--- lib/Github/Api/GitData/Blobs.php | 4 +--- lib/Github/Api/PullRequest/Review.php | 2 +- lib/Github/Api/Repository/Assets.php | 4 +--- lib/Github/Api/Repository/Contents.php | 14 +++++++------- test/Github/Tests/Api/IssueTest.php | 4 ++-- test/Github/Tests/Api/PullRequest/CommentsTest.php | 2 +- test/Github/Tests/Functional/CacheTest.php | 2 +- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 492e44ca4d8..a9204787659 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -126,9 +126,7 @@ protected function head($path, array $parameters = [], array $requestHeaders = [ unset($parameters['ref']); } - $response = $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders); - - return $response; + return $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders); } /** diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index be68771d9bd..c6269e86663 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -43,9 +43,7 @@ public function configure($bodyType = null) */ public function show($username, $repository, $sha) { - $response = $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha)); - - return $response; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs/'.rawurlencode($sha)); } /** diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index e53f7179a19..f984deab1e5 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -171,7 +171,7 @@ public function dismiss($username, $repository, $pullRequest, $id, $message) } return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals', [ - 'message' => $message, + 'message' => $message, ]); } diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index dbe6da2251a..899b2db34c0 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -74,9 +74,7 @@ public function create($username, $repository, $id, $name, $contentType, $conten // Asset creation requires a separate endpoint, uploads.github.com. // Change the base url for the HTTP client temporarily while we execute // this request. - $response = $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, ['Content-Type' => $contentType]); - - return $response; + return $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, ['Content-Type' => $contentType]); } /** diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 631fff2c7ba..2cd11ddbc6f 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -102,8 +102,8 @@ public function create($username, $repository, $path, $content, $message, $branc $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); $parameters = [ - 'content' => base64_encode($content), - 'message' => $message, + 'content' => base64_encode($content), + 'message' => $message, ]; if (null !== $branch) { @@ -178,9 +178,9 @@ public function update($username, $repository, $path, $content, $message, $sha, $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); $parameters = [ - 'content' => base64_encode($content), - 'message' => $message, - 'sha' => $sha, + 'content' => base64_encode($content), + 'message' => $message, + 'sha' => $sha, ]; if (null !== $branch) { @@ -219,8 +219,8 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); $parameters = [ - 'message' => $message, - 'sha' => $sha, + 'message' => $message, + 'sha' => $sha, ]; if (null !== $branch) { diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index b976f402451..6ad07439edd 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -16,7 +16,7 @@ public function shouldGetIssues() ]; $sentData = $data + [ 'page' => 1, - ]; + ]; $api = $this->getApiMock(); $api->expects($this->once()) @@ -43,7 +43,7 @@ public function shouldGetIssuesUsingAdditionalParameters() ]; $sentData = $data + [ 'page' => 1, - ]; + ]; $api = $this->getApiMock(); $api->expects($this->once()) diff --git a/test/Github/Tests/Api/PullRequest/CommentsTest.php b/test/Github/Tests/Api/PullRequest/CommentsTest.php index b9a7ec59514..c180607e837 100644 --- a/test/Github/Tests/Api/PullRequest/CommentsTest.php +++ b/test/Github/Tests/Api/PullRequest/CommentsTest.php @@ -14,7 +14,7 @@ class CommentsTest extends TestCase public function shouldGetAllReviewCommentsForAPullRequest() { $expectedValue = [ - [ + [ 'url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/comments/1', 'id' => 1, 'pull_request_review_id' => 42, diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index 6fd190dbca8..a220d355684 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -61,7 +61,7 @@ private function getCurrentUserResponse($username) ]; $body = \GuzzleHttp\Psr7\stream_for(json_encode([ - 'login' => $username, + 'login' => $username, ])); return new Response(200, $headers, $body); From 1fd92a7bf22974f046f42fedbc24a4d14c3406ff Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 12 Jan 2020 12:55:06 +0100 Subject: [PATCH 715/951] Fix error in bc-check script --- .github/bc-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/bc-test.sh b/.github/bc-test.sh index 1f66ee13ab0..8f2e3877854 100755 --- a/.github/bc-test.sh +++ b/.github/bc-test.sh @@ -30,7 +30,7 @@ OUTPUT=`echo "$OUTPUT" | sed '/Method __toString() was added to interface Github BC_BREAKS=`echo "$OUTPUT" | grep -o '\[BC\]' | wc -l | awk '{ print $1 }'` # The last row of the output is "X backwards-incompatible changes detected". Find X. -STATED_BREAKS=`echo "$OUTPUT" | tail -n 1 | awk -F' ' '{ print $1 }'` +STATED_BREAKS=`echo "$OUTPUT" | tail -n 1 | awk -F' ' '{ print $1 }' | sed s/No/0/` # If # We found "[BC]" in the command output after we removed suppressed lines From 05cdb4d17ef76e8500633f137ed94b08b8b90136 Mon Sep 17 00:00:00 2001 From: YJ Tso Date: Mon, 13 Jan 2020 13:58:47 -0800 Subject: [PATCH 716/951] further detail on ResultPager parameters Previously it was non-obvious how parameters were passed to called methods. --- doc/result_pager.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/result_pager.md b/doc/result_pager.md index 1147674edcc..3eb0a115f5f 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -21,6 +21,12 @@ Parameters of the `fetchAll` method: * The method of the API object you're using * The parameters of the method +Parameters are passed to the API method via [call_user_func_array](https://www.php.net/manual/en/function.call-user-func-array.php). + +```php +$parameters = array('github', 'all', 1); // $organization, $type, $page +``` + #### Get the first page ```php From f2ce0d9da679c171df6500d38a9b07036f5a90cc Mon Sep 17 00:00:00 2001 From: Scott Deeter Date: Mon, 20 Jan 2020 13:06:09 -0800 Subject: [PATCH 717/951] Allow create & remove to set and remove requests for teams --- lib/Github/Api/PullRequest/ReviewRequest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php index 8321fd27cac..540307559e2 100644 --- a/lib/Github/Api/PullRequest/ReviewRequest.php +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -39,12 +39,13 @@ public function all($username, $repository, $pullRequest, array $params = []) * @param string $repository * @param int $pullRequest * @param array $reviewers + * @param array $teamReviewers * * @return string */ - public function create($username, $repository, $pullRequest, array $reviewers) + public function create($username, $repository, $pullRequest, array $reviewers = [], array $teamReviewers = []) { - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers, 'team_reviewers' => $teamReviewers]); } /** @@ -54,11 +55,12 @@ public function create($username, $repository, $pullRequest, array $reviewers) * @param string $repository * @param int $pullRequest * @param array $reviewers + * @param array $teamReviewers * * @return string */ - public function remove($username, $repository, $pullRequest, array $reviewers) + public function remove($username, $repository, $pullRequest, array $reviewers = [], array $teamReviewers = []) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers, 'team_reviewers' => $teamReviewers]); } } From 0a19add18d7bf10a7e304127ecd6f84210d66252 Mon Sep 17 00:00:00 2001 From: Scott Deeter Date: Mon, 20 Jan 2020 14:49:44 -0800 Subject: [PATCH 718/951] Updated ReviewRequestTest create & remove tests --- test/Github/Tests/Api/PullRequest/ReviewRequestTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php b/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php index f6d98cb3a77..3335b4a3494 100644 --- a/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php +++ b/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php @@ -35,10 +35,10 @@ public function shouldCreateReviewRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser']]) + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser'], 'team_reviewers' => ['testteam']]) ; - $api->create('octocat', 'Hello-World', 12, ['testuser']); + $api->create('octocat', 'Hello-World', 12, ['testuser'], ['testteam']); } /** @@ -49,10 +49,10 @@ public function shouldDeleteReviewRequest() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser']]) + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser'], 'team_reviewers' => ['testteam']]) ; - $api->remove('octocat', 'Hello-World', 12, ['testuser']); + $api->remove('octocat', 'Hello-World', 12, ['testuser'], ['testteam']); } /** From 3bce87ce3c6f348a46fd704c3d10fb2c4205efa4 Mon Sep 17 00:00:00 2001 From: Sara Bine Date: Wed, 29 Jan 2020 17:16:48 -0800 Subject: [PATCH 719/951] Add repo community profile API endpoint --- doc/repos.md | 6 ++++++ lib/Github/Api/Repo.php | 18 ++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index d6abe19a0fe..c5dbfe89b7a 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -312,6 +312,12 @@ $milestones = $client->api('repo')->milestones('ornicar', 'php-github-api'); Returns a list of milestones. +### Get the community profile metrics for a repository + +```php +$communityProfile = $client->api('repo')->communityProfile('ornicar', 'php-github-api'); +``` + ### Get the contents of a repository's code of conduct ```php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index e9eaf44c781..682fcfb856e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -627,6 +627,24 @@ public function events($username, $repository, $page = 1) return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]); } + /** + * Get the community profile metrics for a repository. + * + * @link https://developer.github.com/v3/repos/community/#retrieve-community-profile-metrics + * + * @param string $username + * @param string $repository + * + * @return array + */ + public function communityProfile($username, $repository) + { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.black-panther-preview+json'; + + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/profile'); + } + /** * Get the contents of a repository's code of conduct. * diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index e6dfaa619a9..ff1fe4f7e6e 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -538,6 +538,22 @@ public function shouldGetRepositoryEvents() $this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3)); } + /** + * @test + */ + public function shouldGetRepositoryCommunityProfile() + { + $expectedArray = ['health_percentage' => 100, 'description' => 'A simple PHP GitHub API client...']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/community/profile') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->communityProfile('KnpLabs', 'php-github-api')); + } + /** * @test */ From eae2774ff24b931ba55c445d5fccf8e4dfa55a70 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 15 Feb 2020 16:08:51 +0000 Subject: [PATCH 720/951] Remove ended nightshade-preview --- lib/Github/Api/Repo.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index e9eaf44c781..a626594ade3 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -696,9 +696,6 @@ public function replaceTopics($username, $repository, array $topics) */ public function transfer($username, $repository, $newOwner, $teamId = []) { - //This api is in preview mode, so set the correct accept-header - $this->acceptHeaderValue = 'application/vnd.github.nightshade-preview+json'; - return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]); } } From 2fe12b82a7fe5896ae4f067d4c62326c4041602f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 15 Feb 2020 17:32:34 +0000 Subject: [PATCH 721/951] Support the new authorizations API and deprecate old one --- lib/Github/Api/Authorizations.php | 89 +++++++++++++++++++- test/Github/Tests/Api/AuthorizationsTest.php | 68 +++++++++++++++ 2 files changed, 155 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index f53b9eb4d22..f0122a3fc17 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -11,10 +11,19 @@ */ class Authorizations extends AbstractApi { + use AcceptHeaderTrait; + + private function configurePreviewHeader() + { + $this->acceptHeaderValue = 'application/vnd.github.doctor-strange-preview+json'; + } + /** * List all authorizations. * * @return array + * + * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. */ public function all() { @@ -27,6 +36,8 @@ public function all() * @param string $clientId * * @return array + * + * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. */ public function show($clientId) { @@ -36,10 +47,12 @@ public function show($clientId) /** * Create an authorization. * - * @param array $params - * @param null $OTPCode + * @param array $params + * @param string|null $OTPCode * * @return array + * + * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. */ public function create(array $params, $OTPCode = null) { @@ -55,6 +68,8 @@ public function create(array $params, $OTPCode = null) * @param array $params * * @return array + * + * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. */ public function update($clientId, array $params) { @@ -67,6 +82,8 @@ public function update($clientId, array $params) * @param string $clientId * * @return array + * + * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. */ public function remove($clientId) { @@ -80,12 +97,29 @@ public function remove($clientId) * @param string $token * * @return array + * + * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::checkToken() instead. */ public function check($clientId, $token) { return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } + /** + * Check an application token. + * + * @param string $clientId + * @param string|null $token + * + * @return array + */ + public function checkToken($clientId, $token = null) + { + $this->configurePreviewHeader(); + + return $this->post('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); + } + /** * Reset an authorization. * @@ -93,17 +127,36 @@ public function check($clientId, $token) * @param string $token * * @return array + * + * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::resetToken() instead. */ public function reset($clientId, $token) { return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); } + /** + * Reset an application token. + * + * @param string $clientId + * @param string|null $token + * + * @return array + */ + public function resetToken($clientId, $token = null) + { + $this->configurePreviewHeader(); + + return $this->patch('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); + } + /** * Remove an authorization. * * @param string $clientId * @param string $token + * + * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteToken() instead. */ public function revoke($clientId, $token) { @@ -114,9 +167,41 @@ public function revoke($clientId, $token) * Revoke all authorizations. * * @param string $clientId + * + * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteGrant() instead. */ public function revokeAll($clientId) { $this->delete('/applications/'.rawurlencode($clientId).'/tokens'); } + + /** + * Revoke an application token. + * + * @param string $clientId + * @param string|null $token + * + * @return void + */ + public function deleteToken($clientId, $token = null) + { + $this->configurePreviewHeader(); + + $this->delete('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); + } + + /** + * Revoke an application authorization. + * + * @param string $clientId + * @param string|null $token + * + * @return void + */ + public function deleteGrant($clientId, $token = null) + { + $this->configurePreviewHeader(); + + $this->delete('/applications/'.rawurlencode($clientId).'/grant', $token ? ['access_token' => $token] : []); + } } diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php index a8170827484..87ace7c51f1 100644 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ b/test/Github/Tests/Api/AuthorizationsTest.php @@ -86,6 +86,24 @@ public function shouldDeleteAuthorization() $api->remove($id); } + /** + * @test + */ + public function shouldCheckApplicationToken() + { + $id = 123; + $token = 'abc'; + $expectedArray = ['id' => $id]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/applications/'.$id.'/token', ['access_token' => $token]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->checkToken($id, $token)); + } + /** * @test */ @@ -120,6 +138,24 @@ public function shouldResetAuthorization() $api->reset($id, $token); } + /** + * @test + */ + public function shouldResetApplicationToken() + { + $id = 123; + $token = 'abcde'; + $expectedArray = ['id' => $id]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/applications/'.$id.'/token', ['access_token' => $token]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->resetToken($id, $token)); + } + /** * @test */ @@ -151,6 +187,38 @@ public function shouldRevokeAllAuthorizations() $api->revokeAll($id); } + /** + * @test + */ + public function shouldDeleteApplicationToken() + { + $id = 123; + $token = 'abcde'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/applications/'.$id.'/token', ['access_token' => $token]); + + $api->deleteToken($id, $token); + } + + /** + * @test + */ + public function shouldDeleteApplicationAuthorization() + { + $id = 123; + $token = 'abcde'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/applications/'.$id.'/grant', ['access_token' => $token]); + + $api->deleteGrant($id, $token); + } + /** * @return string */ From d40e5b1274bace1858b7e133aa4bd13e1f3b204d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 16 Mar 2020 20:45:46 +0100 Subject: [PATCH 722/951] Prepare 2.13.0 release --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e86df46931..1e447f19e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.13.0 + +### Added + +- Support the new authorizations API +- Repo community profile API endpoint +- Support for draft PRs +- Missing Apps endpoints +- Test against php 7.4 + +### Changed + +- Allow create & remove to set and remove requests for teams + ## 2.12.1 ### Fixed From c7b418616084e53c780007b926d436fef551fb52 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 27 Mar 2020 13:58:55 +0100 Subject: [PATCH 723/951] fix api link in Issue\Labels::add() --- lib/Github/Api/Issue/Labels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index f1f68b76295..a287d6ccfa6 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -118,7 +118,7 @@ public function update($username, $repository, $label, $newName, $color) /** * Add a label to an issue. * - * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue + * @link https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue * * @param string $username * @param string $repository From 051a3b74b5a0504546d5da304461c9cbe03a430c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 27 Mar 2020 14:33:58 +0100 Subject: [PATCH 724/951] fix phpdoc --- lib/Github/Api/Issue/Labels.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index f1f68b76295..05c89f5f0c3 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -164,7 +164,7 @@ public function replace($username, $repository, $issue, array $params) * * @param string $username * @param string $repository - * @param string $issue + * @param int $issue * @param string $label * * @return array|string @@ -181,7 +181,7 @@ public function remove($username, $repository, $issue, $label) * * @param string $username * @param string $repository - * @param string $issue + * @param int $issue * * @return array|string */ From c4dc58b7718bca17687fa7248a2e8d0e6e7a7a2b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 27 Mar 2020 15:12:27 +0100 Subject: [PATCH 725/951] fix CS --- lib/Github/Api/Issue/Labels.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 05c89f5f0c3..de6fe76df02 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -164,7 +164,7 @@ public function replace($username, $repository, $issue, array $params) * * @param string $username * @param string $repository - * @param int $issue + * @param int $issue * @param string $label * * @return array|string @@ -181,7 +181,7 @@ public function remove($username, $repository, $issue, $label) * * @param string $username * @param string $repository - * @param int $issue + * @param int $issue * * @return array|string */ From e9c65f68cb5cb4e299f73a60e38b0bfc10d4d1e5 Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 2 Apr 2020 02:18:21 +0200 Subject: [PATCH 726/951] Fix up milestones() for params --- lib/Github/Api/Repo.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 151a61b6790..dcfe4d39f4a 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -590,12 +590,13 @@ public function merge($username, $repository, $base, $head, $message = null) /** * @param string $username * @param string $repository + * @param array $parameters * * @return array */ - public function milestones($username, $repository) + public function milestones($username, $repository, array $parameters = []) { - return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones'); + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones', $parameters); } public function projects() From 19838653981171aa3bf16a64ccfc1fb5a8e05f58 Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Thu, 2 Apr 2020 02:19:54 +0200 Subject: [PATCH 727/951] Change CS --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index dcfe4d39f4a..63fd0358df7 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -590,7 +590,7 @@ public function merge($username, $repository, $base, $head, $message = null) /** * @param string $username * @param string $repository - * @param array $parameters + * @param array $parameters * * @return array */ From 624da985f19883e5a64f554f1fc06f2a2e5c43c2 Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Mon, 13 Apr 2020 18:48:14 +0300 Subject: [PATCH 728/951] Ignore PHPStorm's .idea directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ebe7b7ea7a3..d244324f4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ phpunit.xml composer.lock composer.phar vendor/* +.idea/* From 3f332edcd4014cccdd9c5b8500c84564dc5dda53 Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Mon, 13 Apr 2020 19:52:07 +0300 Subject: [PATCH 729/951] Fix various Teams' URIs - \Github\Api\Organization\Teams::show - \Github\Api\Organization\Teams::update - \Github\Api\Organization\Teams::remove - \Github\Api\Organization\Teams::members - \Github\Api\Organization\Teams::check - \Github\Api\Organization\Teams::addMember - \Github\Api\Organization\Teams::removeMember --- lib/Github/Api/Organization/Teams.php | 49 +++++++++++++------ .../Tests/Api/Organization/TeamsTest.php | 34 ++++++------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 401dbe4f116..00b57758b05 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -32,12 +32,18 @@ public function create($organization, array $params) return $this->post('/orgs/'.rawurlencode($organization).'/teams', $params); } - public function show($team) + /** + * @link https://developer.github.com/v3/teams/#list-teams + */ + public function show($team, $organization) { - return $this->get('/teams/'.rawurlencode($team)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } - public function update($team, array $params) + /** + * @link https://developer.github.com/v3/teams/#edit-team + */ + public function update($team, array $params, $organization) { if (!isset($params['name'])) { throw new MissingArgumentException('name'); @@ -46,32 +52,47 @@ public function update($team, array $params) $params['permission'] = 'pull'; } - return $this->patch('/teams/'.rawurlencode($team), $params); + return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); } - public function remove($team) + /** + * @link https://developer.github.com/v3/teams/#delete-team + */ + public function remove($team, $organization) { - return $this->delete('/teams/'.rawurlencode($team)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } - public function members($team) + /** + * @link https://developer.github.com/v3/teams/members/#list-team-members + */ + public function members($team, $organization) { - return $this->get('/teams/'.rawurlencode($team).'/members'); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); } - public function check($team, $username) + /** + * @link https://developer.github.com/v3/teams/members/#get-team-membership + */ + public function check($team, $username, $organization) { - return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - public function addMember($team, $username) + /** + * @link https://developer.github.com/v3/teams/members/#add-or-update-team-membership + */ + public function addMember($team, $username, $organization) { - return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - public function removeMember($team, $username) + /** + * @link https://developer.github.com/v3/teams/members/#remove-team-membership + */ + public function removeMember($team, $username, $organization) { - return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function repositories($team) diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 3c5474181e7..3538113ad61 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -33,10 +33,10 @@ public function shouldCheckIfMemberIsInOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/teams/KnpWorld/memberships/l3l0') + ->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0')); + $this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0', 'KnpLabs')); } /** @@ -49,10 +49,10 @@ public function shouldRemoveOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/teams/KnpWorld') + ->with('/orgs/KnpLabs/teams/KnpWorld') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->remove('KnpWorld')); + $this->assertEquals($expectedValue, $api->remove('KnpWorld', 'KnpLabs')); } /** @@ -65,10 +65,10 @@ public function shouldShowOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/teams/KnpWorld') + ->with('/orgs/KnpLabs/teams/KnpWorld') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->show('KnpWorld')); + $this->assertEquals($expectedValue, $api->show('KnpWorld', 'KnpLabs')); } /** @@ -81,10 +81,10 @@ public function shouldGetTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/teams/KnpWorld/members') + ->with('/orgs/KnpLabs/teams/KnpWorld/members') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->members('KnpWorld')); + $this->assertEquals($expectedValue, $api->members('KnpWorld', 'KnpLabs')); } /** @@ -97,10 +97,10 @@ public function shouldAddTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/teams/KnpWorld/memberships/l3l0') + ->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0')); + $this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0', 'KnpLabs')); } /** @@ -113,10 +113,10 @@ public function shouldRemoveTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/teams/KnpWorld/memberships/l3l0') + ->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0')); + $this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0', 'KnpLabs')); } /** @@ -261,7 +261,7 @@ public function shouldNotUpdateTeamWithoutName() $api->expects($this->never()) ->method('patch'); - $api->update('KnpWorld', $data); + $api->update('KnpWorld', $data, 'KnpLabs'); } /** @@ -275,10 +275,10 @@ public function shouldUpdateOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/teams/KnpWorld', $data) + ->with('/orgs/KnpLabs/teams/KnpWorld', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); + $this->assertEquals($expectedValue, $api->update('KnpWorld', $data, 'KnpLabs')); } /** @@ -292,10 +292,10 @@ public function shouldUpdateWithPullPermissionWhenPermissionParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull']) + ->with('/orgs/KnpLabs/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); + $this->assertEquals($expectedValue, $api->update('KnpWorld', $data, 'KnpLabs')); } /** From 8c5616c2886d27f58956e8ad2014036db34c993f Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 13 Apr 2020 10:18:26 -0700 Subject: [PATCH 730/951] remove incorrect MissingArgumentException, add docs, update tests --- doc/README.md | 1 + doc/repo/labels.md | 48 +++++++++++++++++++ lib/Github/Api/Repository/Labels.php | 4 -- .../Tests/Api/Repository/LabelsTest.php | 34 +------------ 4 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 doc/repo/labels.md diff --git a/doc/README.md b/doc/README.md index 3d3d3570b8b..c97c33ddc17 100644 --- a/doc/README.md +++ b/doc/README.md @@ -49,6 +49,7 @@ v3 APIs: * [Checks](repo/checks.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) + * [Labels](repo/labels.md) * [Protection](repo/protection.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) diff --git a/doc/repo/labels.md b/doc/repo/labels.md new file mode 100644 index 00000000000..5e924058f77 --- /dev/null +++ b/doc/repo/labels.md @@ -0,0 +1,48 @@ +## Repo / Labels API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List all labels for this repository + +```php +$labels = $client->api('repo')->labels()->all('twbs', 'bootstrap'); +``` + +### Get a single label + +```php +$label = $client->api('repo')->labels()->show('twbs', 'bootstrap', 'feature'); +``` + +### Create a label + +> Requires [authentication](../security.md). + +```php +$params = [ + 'name' => 'bug', + 'color' => 'f29513', + 'description' => 'Something isn\'t working', +]; +$label = $client->api('repo')->labels()->create('twbs', 'bootstrap', $params); +``` + +### Update a label + +> Requires [authentication](../security.md). + +```php +$params = [ + 'new_name' => 'bug :bug:', + 'color' => 'b01f26', + 'description' => 'Small bug fix required', +]; +$label = $client->api('repo')->labels()->update('twbs', 'bootstrap', 'bug', $params); +``` + +### Delete a label + +> Requires [authentication](../security.md). + +```php +$label = $client->api('repo')->labels()->remove('twbs', 'bootstrap', 'bug'); +``` diff --git a/lib/Github/Api/Repository/Labels.php b/lib/Github/Api/Repository/Labels.php index 7829e551e25..28ca4d53c0f 100644 --- a/lib/Github/Api/Repository/Labels.php +++ b/lib/Github/Api/Repository/Labels.php @@ -33,10 +33,6 @@ public function create($username, $repository, array $params) public function update($username, $repository, $label, array $params) { - if (!isset($params['name'], $params['color'])) { - throw new MissingArgumentException(['name', 'color']); - } - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); } diff --git a/test/Github/Tests/Api/Repository/LabelsTest.php b/test/Github/Tests/Api/Repository/LabelsTest.php index 6373d459e08..4fe2fd81493 100644 --- a/test/Github/Tests/Api/Repository/LabelsTest.php +++ b/test/Github/Tests/Api/Repository/LabelsTest.php @@ -102,43 +102,13 @@ public function shouldCreateLabel() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** - * @test - */ - public function shouldNotUpdateLabelWithoutName() - { - $this->expectException(MissingArgumentException::class); - $data = ['color' => 'red']; - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('patch'); - - $api->update('KnpLabs', 'php-github-api', 'labelName', $data); - } - - /** - * @test - */ - public function shouldNotUpdateLabelWithoutColor() - { - $this->expectException(MissingArgumentException::class); - $data = ['name' => 'test']; - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('patch'); - - $api->update('KnpLabs', 'php-github-api', 'labelName', $data); - } - /** * @test */ public function shouldUpdateLabel() { - $expectedValue = ['label' => 'somename']; - $data = ['name' => 'test', 'color' => 'red']; + $expectedValue = ['name' => 'test']; + $data = ['new_name' => 'test', 'color' => 'red']; $api = $this->getApiMock(); $api->expects($this->once()) From 7742bd1d322b4129ac56ece532ae2c45cd9d6738 Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Tue, 14 Apr 2020 16:30:58 +0300 Subject: [PATCH 731/951] Revert "Ignore PHPStorm's .idea directory" This reverts commit 624da985f19883e5a64f554f1fc06f2a2e5c43c2. --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index d244324f4d7..ebe7b7ea7a3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ phpunit.xml composer.lock composer.phar vendor/* -.idea/* From ca63e29962c4a11d9e3573e2d8b826127e234aec Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Tue, 14 Apr 2020 16:38:40 +0300 Subject: [PATCH 732/951] fixes backward compatibility check --- lib/Github/Api/Organization/Teams.php | 56 ++++++++++++++++++++------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 00b57758b05..563c5907427 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -35,15 +35,19 @@ public function create($organization, array $params) /** * @link https://developer.github.com/v3/teams/#list-teams */ - public function show($team, $organization) + public function show($team, $organization = null) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); + if ($organization) { + return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team)); + } + + return $this->get('/teams/'.rawurlencode($team)); } /** * @link https://developer.github.com/v3/teams/#edit-team */ - public function update($team, array $params, $organization) + public function update($team, array $params, $organization = null) { if (!isset($params['name'])) { throw new MissingArgumentException('name'); @@ -52,47 +56,71 @@ public function update($team, array $params, $organization) $params['permission'] = 'pull'; } - return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); + if ($organization) { + return $this->patch('/teams/' . rawurlencode($team), $params); + } + + return $this->patch('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team), $params); } /** * @link https://developer.github.com/v3/teams/#delete-team */ - public function remove($team, $organization) + public function remove($team, $organization = null) { - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); + if ($organization) { + return $this->delete('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team)); + } + + return $this->delete('/teams/' . rawurlencode($team)); } /** * @link https://developer.github.com/v3/teams/members/#list-team-members */ - public function members($team, $organization) + public function members($team, $organization = null) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); + if ($organization) { + return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/members'); + } + + return $this->get('/teams/' . rawurlencode($team) . '/members'); } /** * @link https://developer.github.com/v3/teams/members/#get-team-membership */ - public function check($team, $username, $organization) + public function check($team, $username, $organization = null) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if ($organization) { + return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + } + + return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** * @link https://developer.github.com/v3/teams/members/#add-or-update-team-membership */ - public function addMember($team, $username, $organization) + public function addMember($team, $username, $organization = null) { - return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if ($organization) { + return $this->put('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + } + + return $this->put('/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); } /** * @link https://developer.github.com/v3/teams/members/#remove-team-membership */ - public function removeMember($team, $username, $organization) + public function removeMember($team, $username, $organization = null) { - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if ($organization) { + return $this->delete('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + } + + return $this->delete('/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); } public function repositories($team) From 9f5071cbf7832adcd652d23fc1a69d57d0fbf51a Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Tue, 14 Apr 2020 16:40:48 +0300 Subject: [PATCH 733/951] fix update() --- lib/Github/Api/Organization/Teams.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 563c5907427..846cc402db2 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -38,7 +38,7 @@ public function create($organization, array $params) public function show($team, $organization = null) { if ($organization) { - return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } return $this->get('/teams/'.rawurlencode($team)); @@ -57,10 +57,10 @@ public function update($team, array $params, $organization = null) } if ($organization) { - return $this->patch('/teams/' . rawurlencode($team), $params); + return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); } - return $this->patch('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team), $params); + return $this->patch('/teams/'.rawurlencode($team), $params); } /** @@ -69,10 +69,10 @@ public function update($team, array $params, $organization = null) public function remove($team, $organization = null) { if ($organization) { - return $this->delete('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } - return $this->delete('/teams/' . rawurlencode($team)); + return $this->delete('/teams/'.rawurlencode($team)); } /** @@ -81,10 +81,10 @@ public function remove($team, $organization = null) public function members($team, $organization = null) { if ($organization) { - return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/members'); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/members'); } - return $this->get('/teams/' . rawurlencode($team) . '/members'); + return $this->get('/teams/'.rawurlencode($team).'/members'); } /** @@ -93,7 +93,7 @@ public function members($team, $organization = null) public function check($team, $username, $organization = null) { if ($organization) { - return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/memberships/' . rawurlencode($username)); } return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); @@ -105,10 +105,10 @@ public function check($team, $username, $organization = null) public function addMember($team, $username, $organization = null) { if ($organization) { - return $this->put('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/memberships/' . rawurlencode($username)); } - return $this->put('/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** @@ -117,10 +117,10 @@ public function addMember($team, $username, $organization = null) public function removeMember($team, $username, $organization = null) { if ($organization) { - return $this->delete('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/memberships/' . rawurlencode($username)); } - return $this->delete('/teams/' . rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function repositories($team) From 6ecdb0a78f48e4b4b7065b8c7a6a03eec8747261 Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Tue, 14 Apr 2020 16:47:13 +0300 Subject: [PATCH 734/951] style fix --- lib/Github/Api/Organization/Teams.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 846cc402db2..05eb9ac7989 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -81,7 +81,7 @@ public function remove($team, $organization = null) public function members($team, $organization = null) { if ($organization) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/members'); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); } return $this->get('/teams/'.rawurlencode($team).'/members'); @@ -93,7 +93,7 @@ public function members($team, $organization = null) public function check($team, $username, $organization = null) { if ($organization) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); @@ -105,7 +105,7 @@ public function check($team, $username, $organization = null) public function addMember($team, $username, $organization = null) { if ($organization) { - return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); @@ -117,7 +117,7 @@ public function addMember($team, $username, $organization = null) public function removeMember($team, $username, $organization = null) { if ($organization) { - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team) . '/memberships/' . rawurlencode($username)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); From d8603c2f1f451672274563f0d9620d19c6c699b3 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Fri, 17 Apr 2020 21:34:02 +0200 Subject: [PATCH 735/951] Fix typos --- test/Github/Tests/Api/RepoTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index ff1fe4f7e6e..4bdfb419edd 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -378,10 +378,10 @@ public function shouldNotDelete() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/repos/l3l0Repo/uknown-repo') + ->with('/repos/l3l0Repo/unknown-repo') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->remove('l3l0Repo', 'uknown-repo')); + $this->assertEquals($expectedArray, $api->remove('l3l0Repo', 'unknown-repo')); } /** From 6ceeb55dddafb90367db36b9a875c3b86ce36c4c Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Mon, 20 Apr 2020 17:54:58 +0300 Subject: [PATCH 736/951] changes based on @acrobat's suggestions --- lib/Github/Api/Organization/Teams.php | 57 ++++++++++++++++----------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 05eb9ac7989..00361734acc 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -7,7 +7,6 @@ /** * @link http://developer.github.com/v3/orgs/teams/ - * * @author Joseph Bielawski */ class Teams extends AbstractApi @@ -37,11 +36,13 @@ public function create($organization, array $params) */ public function show($team, $organization = null) { - if ($organization) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->get('/teams/'.rawurlencode($team)); } - return $this->get('/teams/'.rawurlencode($team)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } /** @@ -56,11 +57,13 @@ public function update($team, array $params, $organization = null) $params['permission'] = 'pull'; } - if ($organization) { - return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->patch('/teams/'.rawurlencode($team), $params); } - return $this->patch('/teams/'.rawurlencode($team), $params); + return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); } /** @@ -68,11 +71,13 @@ public function update($team, array $params, $organization = null) */ public function remove($team, $organization = null) { - if ($organization) { - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->delete('/teams/'.rawurlencode($team)); } - return $this->delete('/teams/'.rawurlencode($team)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } /** @@ -80,11 +85,13 @@ public function remove($team, $organization = null) */ public function members($team, $organization = null) { - if ($organization) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->get('/teams/'.rawurlencode($team).'/members'); } - return $this->get('/teams/'.rawurlencode($team).'/members'); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); } /** @@ -92,11 +99,13 @@ public function members($team, $organization = null) */ public function check($team, $username, $organization = null) { - if ($organization) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** @@ -104,11 +113,13 @@ public function check($team, $username, $organization = null) */ public function addMember($team, $username, $organization = null) { - if ($organization) { - return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** @@ -116,11 +127,13 @@ public function addMember($team, $username, $organization = null) */ public function removeMember($team, $username, $organization = null) { - if ($organization) { - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function repositories($team) From 25504440b6b2fa6b6800c7c08741e55e13848a41 Mon Sep 17 00:00:00 2001 From: Vasilis Lolos Date: Mon, 20 Apr 2020 17:56:41 +0300 Subject: [PATCH 737/951] styling fix --- lib/Github/Api/Organization/Teams.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 00361734acc..8b84028db24 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -7,6 +7,7 @@ /** * @link http://developer.github.com/v3/orgs/teams/ + * * @author Joseph Bielawski */ class Teams extends AbstractApi From 1cb5115cbd0d64beab434f5c15c8f3c3b88b64fd Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 20 Apr 2020 20:00:55 +0200 Subject: [PATCH 738/951] Updat branch alias to 2.14.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7767e041259..2f46ebc4129 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.13.x-dev" + "dev-master": "2.14.x-dev" } } } From 5eb55ce410e499b505f590aa20492e14fcf252f6 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 20 Apr 2020 21:48:06 +0200 Subject: [PATCH 739/951] feature #863 Add sort and direction for fetching organizations repos (pgrimaud) This PR was squashed before being merged into the 2.13.x-dev branch. Discussion ---------- Hi, It's possible to sort repositories of organizations here : https://developer.github.com/v3/repos/#list-organization-repositories. I added `$sort` and `$direction` parameters after actual parameters to avoid BC. Associated tests are updated too. Commits ------- 5c3aee1f68509c91e9ae0d233f9dab37e315678a Add sort and direction for fetching organizations repos 6aa74fbe88cb4e1fe73330622a33ba142c1f285d Fix styleci 041af9203b50d43509b474c010c88f85c846dd60 Set new parameters as null instead of default values 304bd1904214aa220ea94ee90f804ed527d8bb7d Fix styleci --- lib/Github/Api/Notification.php | 1 + lib/Github/Api/Organization.php | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 0d73d6076c7..e8c9b246a11 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -23,6 +23,7 @@ class Notification extends AbstractApi * @param bool $includingRead * @param bool $participating * @param DateTime|null $since + * @param DateTime|null $before * * @return array array of notifications */ diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 29b71d1480e..32eba7d2d87 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -53,15 +53,27 @@ public function update($organization, array $params) * @param string $organization the user name * @param string $type the type of repositories * @param int $page the page + * @param string $sort sort by + * @param string $direction direction of sort, asc or desc * * @return array the repositories */ - public function repositories($organization, $type = 'all', $page = 1) + public function repositories($organization, $type = 'all', $page = 1, $sort = null, $direction = null) { - return $this->get('/orgs/'.rawurlencode($organization).'/repos', [ + $parameters = [ 'type' => $type, 'page' => $page, - ]); + ]; + + if ($sort !== null) { + $parameters['sort'] = $sort; + } + + if ($direction !== null) { + $parameters['direction'] = $direction; + } + + return $this->get('/orgs/'.rawurlencode($organization).'/repos', $parameters); } /** From 83acc0796345015b4770a5ec02a48154d6edef66 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 25 Apr 2020 22:31:02 +0200 Subject: [PATCH 740/951] Prepare 2.14.0 release --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e447f19e5b..a7cbd25ed8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +## 2.14.0 + +### Added +- Replace deprecated Organization\Teams api calls ([lolos](https://github.com/lolos)) [#860](https://github.com/KnpLabs/php-github-api/issues/860) +- Add sort and direction for fetching organizations repos ([pgrimaud](https://github.com/pgrimaud)) [#863](https://github.com/KnpLabs/php-github-api/issues/863) +- Added parameters to Repo/milestones() method ([dereuromark](https://github.com/dereuromark)) [#856](https://github.com/KnpLabs/php-github-api/issues/856) + +### Fixed + +- Remove incorrect MissingArgumentException in Labels api ([bobeagan](https://github.com/bobeagan)) [#861](https://github.com/KnpLabs/php-github-api/issues/861) + +### Changed +- Fix typos in test/Github/Tests/Api/RepoTest.php ([pgrimaud](https://github.com/pgrimaud)) [#862](https://github.com/KnpLabs/php-github-api/issues/862) +- further detail on ResultPager parameters ([sepiariver](https://github.com/sepiariver)) [#843](https://github.com/KnpLabs/php-github-api/issues/843) +- fix phpdoc in labels api ([staabm](https://github.com/staabm)) [#854](https://github.com/KnpLabs/php-github-api/issues/854) +- fix api link in Issue\Labels::add() phpdoc ([staabm](https://github.com/staabm)) [#853](https://github.com/KnpLabs/php-github-api/issues/853) + ## 2.13.0 ### Added From f7b14da9b6bcbc6c7cf3566b3b9498e83a4b64cf Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 2 May 2020 20:52:42 +0200 Subject: [PATCH 741/951] Prepare deprecation of authentication methods --- doc/security.md | 15 ++++-- lib/Github/Client.php | 20 +++++++- .../HttpClient/Plugin/Authentication.php | 10 +++- test/Github/Tests/ClientTest.php | 3 ++ .../HttpClient/Plugin/AuthenticationTest.php | 50 +++++++++++++++++++ 5 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php diff --git a/doc/security.md b/doc/security.md index afc1adeef52..174300bb573 100644 --- a/doc/security.md +++ b/doc/security.md @@ -15,11 +15,16 @@ $client->authenticate($usernameOrToken, $password, $method); `$usernameOrToken` is, of course, the username (or in some cases token/client ID, more details you can find below), and guess what should contain `$password`. The `$method` can contain one of the five allowed values: -* `Github\Client::AUTH_URL_TOKEN` -* `Github\Client::AUTH_URL_CLIENT_ID` -* `Github\Client::AUTH_HTTP_TOKEN` -* `Github\Client::AUTH_HTTP_PASSWORD` -* `Github\Client::AUTH_JWT` +#### Deprecated 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. + +#### Supported methods +* `Github\Client::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret +* `Github\Client::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header +* `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`, `Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in diff --git a/lib/Github/Client.php b/lib/Github/Client.php index e20df96a039..2052461335d 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -72,30 +72,48 @@ class Client /** * Constant for authentication method. Indicates the default, but deprecated * login with username and token in URL. + * + * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters */ const AUTH_URL_TOKEN = 'url_token'; /** * Constant for authentication method. Not indicates the new login, but allows * usage of unauthenticated rate limited requests for given client_id + client_secret. + * + * @deprecated Use `Client::AUTH_CLIENT_ID` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters */ const AUTH_URL_CLIENT_ID = 'url_client_id'; /** * Constant for authentication method. Indicates the new favored login method * with username and password via HTTP Authentication. + * + * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters */ const AUTH_HTTP_PASSWORD = 'http_password'; /** * Constant for authentication method. Indicates the new login method with * with username and token via HTTP Authentication. + * + * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. */ const AUTH_HTTP_TOKEN = 'http_token'; + /** + * Authenticate using a client_id/client_secret combination. + */ + const AUTH_CLIENT_ID = 'client_id_header'; + + /** + * Authenticate using a GitHub access token. + */ + const AUTH_ACCESS_TOKEN = 'access_token_header'; + /** * Constant for authentication method. Indicates JSON Web Token - * authentication required for integration access to the API. + * authentication required for GitHub apps access to the API. */ const AUTH_JWT = 'jwt'; diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 0ab09ab20ba..06c593bb99f 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -34,6 +34,8 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla { switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: + @trigger_error('Using the "Client::AUTH_HTTP_PASSWORD" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); + case Client::AUTH_CLIENT_ID: $request = $request->withHeader( 'Authorization', sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)) @@ -41,10 +43,14 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla break; case Client::AUTH_HTTP_TOKEN: + @trigger_error('Using the "Client::AUTH_HTTP_TOKEN" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); + case Client::AUTH_ACCESS_TOKEN: $request = $request->withHeader('Authorization', sprintf('token %s', $this->tokenOrLogin)); break; case Client::AUTH_URL_CLIENT_ID: + @trigger_error('Using the "Client::AUTH_URL_CLIENT_ID" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_CLIENT_ID" instead.', E_USER_DEPRECATED); + $uri = $request->getUri(); $query = $uri->getQuery(); @@ -61,6 +67,8 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla break; case Client::AUTH_URL_TOKEN: + @trigger_error('Using the "Client::AUTH_URL_TOKEN" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); + $uri = $request->getUri(); $query = $uri->getQuery(); @@ -72,11 +80,9 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla $uri = $uri->withQuery($query); $request = $request->withUri($uri); break; - case Client::AUTH_JWT: $request = $request->withHeader('Authorization', sprintf('Bearer %s', $this->tokenOrLogin)); break; - default: throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); break; diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index cae5e8f29d1..550bc8169f6 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -71,7 +71,10 @@ public function getAuthenticationFullData() ['login', 'password', Client::AUTH_HTTP_PASSWORD], ['token', null, Client::AUTH_HTTP_TOKEN], ['token', null, Client::AUTH_URL_TOKEN], + ['token', null, Client::AUTH_ACCESS_TOKEN], ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID], + ['client_id', 'client_secret', Client::AUTH_CLIENT_ID], + ['token', null, Client::AUTH_JWT], ]; } diff --git a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php new file mode 100644 index 00000000000..bf9f64e1af9 --- /dev/null +++ b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php @@ -0,0 +1,50 @@ +doHandleRequest($request, static function ($request) use (&$newRequest) { + /** @var Request $newRequest */ + $newRequest = $request; + }, static function () { + throw new \RuntimeException('Did not expect plugin to call first'); + }); + + $this->assertNotNull($newRequest); + + if ($expectedHeader) { + $this->assertContains($expectedHeader, $newRequest->getHeader('Authorization')); + } else { + $this->assertEquals($expectedUrl, $newRequest->getUri()->__toString()); + } + } + + public function getAuthenticationData() + { + return [ + ['login', 'password', Client::AUTH_HTTP_PASSWORD, sprintf('Basic %s', base64_encode('login'.':'.'password'))], + ['access_token', null, Client::AUTH_HTTP_TOKEN, 'token access_token'], + ['token', null, Client::AUTH_URL_TOKEN, null, '/?access_token=token'], + ['access_token', null, Client::AUTH_ACCESS_TOKEN, 'token access_token'], + ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID, null, '/?client_id=client_id&client_secret=client_secret'], + ['client_id', 'client_secret', Client::AUTH_CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))], + ['jwt_token', null, Client::AUTH_JWT, 'Bearer jwt_token'], + ]; + } +} From f2abf32492bff676ca6ddd2ddcc48ab211092294 Mon Sep 17 00:00:00 2001 From: Marcel Kuhmann Date: Thu, 7 May 2020 19:45:12 +0200 Subject: [PATCH 742/951] minor #871 Added phpstan (clxkoders) This PR was squashed before being merged into the 2.14.x-dev branch. Discussion ---------- closes #857 Commits ------- 452ef7218e85e649f0ad268d65b146a85b03a7c3 Update .travis.yml a59e75e780d751579038da1ebbb2e5eaac55e6c9 added phpstan a77c8850a5d1dbbd9a0921b31df3df13f30894d8 added phpstan-baseline e395c86ceecc9d8d16c647ca7d281c062ac39a9c reset phpstan level to 0 2f9e50792a4543cc58e7334a16e43d947c11220d Update .travis.yml 53d52c72ba67de7a97e161143c19cf1160199803 remove phpstan baseline f90467ebd49590d2c8b0b7a7ac02c72a39f0b230 remove phpstan baseline --- .travis.yml | 4 ++++ composer.json | 3 ++- phpstan.neon.dist | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon.dist diff --git a/.travis.yml b/.travis.yml index 8f4e1727eb8..7bb93d8fcbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,10 @@ matrix: - php: 7.2 name: Backward compatibillity check env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./.github/bc-test.sh" + - php: 7.1 + name: phpstan + script: + - vendor/bin/phpstan analyse --no-progress before_install: - if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; diff --git a/composer.json b/composer.json index 2f46ebc4129..c42123f94c0 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "php-http/guzzle6-adapter": "^1.0 || ^2.0", "php-http/mock-client": "^1.2", "guzzlehttp/psr7": "^1.2", - "cache/array-adapter": "^0.4" + "cache/array-adapter": "^0.4", + "phpstan/phpstan": "^0.12.23" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000000..31545070d13 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + level: 0 + paths: + - lib From 877386be3a0bd374e347a50abfbad3bdeb30ba6d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 10 May 2020 21:28:56 +0200 Subject: [PATCH 743/951] Phpstan level 2 fixes --- lib/Github/Api/Apps.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 4985928a8f5..7a98e731ee8 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -58,7 +58,7 @@ public function findInstallations() * * @link https://developer.github.com/v3/apps/#get-an-installation * - * @param $installationId An integration installation id + * @param int $installationId An integration installation id * * @return array */ @@ -74,7 +74,7 @@ public function getInstallation($installationId) * * @link https://developer.github.com/v3/apps/#get-an-organization-installation * - * @param $org An organization + * @param string $org An organization * * @return array */ @@ -90,8 +90,8 @@ public function getInstallationForOrganization($org) * * @link https://developer.github.com/v3/apps/#get-a-repository-installation * - * @param $owner the owner of a repository - * @param $repo the name of the repository + * @param string $owner the owner of a repository + * @param string $repo the name of the repository * * @return array */ @@ -107,7 +107,7 @@ public function getInstallationForRepo($owner, $repo) * * @link https://developer.github.com/v3/apps/#get-a-user-installation * - * @param $username + * @param string $username * * @return array */ @@ -123,7 +123,7 @@ public function getInstallationForUser($username) * * @link https://developer.github.com/v3/apps/#delete-an-installation * - * @param $installationId An integration installation id + * @param int $installationId An integration installation id */ public function removeInstallation($installationId) { From 92cad4dc69cb2177690d8d7a286989bd3e32184b Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 10 May 2020 21:29:56 +0200 Subject: [PATCH 744/951] Phpstan level 4 fixes --- lib/Github/Api/Repository/Assets.php | 4 ++-- lib/Github/HttpClient/Plugin/Authentication.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 899b2db34c0..56db6843de5 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -67,8 +67,8 @@ public function show($username, $repository, $id) */ public function create($username, $repository, $id, $name, $contentType, $content) { - if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || !OPENSSL_TLSEXT_SERVER_NAME) { - throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported by your PHP version. See http://php.net/manual/en/openssl.constsni.php.'); + if (!defined('OPENSSL_TLSEXT_SERVER_NAME') || OPENSSL_TLSEXT_SERVER_NAME == 0) { + throw new ErrorException('Asset upload support requires Server Name Indication. This is not supported by your PHP version. See https://www.php.net/manual/en/openssl.constsni.php.'); } // Asset creation requires a separate endpoint, uploads.github.com. diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 0ab09ab20ba..6c0f98f1f73 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -79,7 +79,6 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla default: throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); - break; } return $next($request); From cc3972b4d005b81ab4f10021afe480b0d48b64e8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 10 May 2020 21:28:56 +0200 Subject: [PATCH 745/951] Use phpstan level 4 as default --- phpstan.neon.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 31545070d13..1c57e1fef7e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,4 +1,4 @@ parameters: - level: 0 - paths: - - lib + level: 4 + paths: + - lib From 695ef02af423619ecd686d62c9f9586649b71561 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 14 May 2020 20:17:29 +0200 Subject: [PATCH 746/951] Bump branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c42123f94c0..b49d5cdb0ec 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.14.x-dev" + "dev-master": "2.15.x-dev" } } } From 11b683ce24eebeab9276fb54307e0b2069a1032d Mon Sep 17 00:00:00 2001 From: Nick Poulos Date: Mon, 18 May 2020 14:34:47 -0400 Subject: [PATCH 747/951] feature #875 Add Support For GitData Reference Matching Methods (nickpoulos) This PR was squashed before being merged into the 2.14.x-dev branch. Discussion ---------- This PR adds two methods - `matchingBranch()` and `matchingTag()` to `GitHub/Api/GitData/References.php`. These methods return the references for a given branch or tag, respectively. There are two more tests to `GitHub/Tests/Api/GitData/ReferencesTest.php`, `shouldGetAllMatchingBranchRepoReferences` and `shouldGetAllMatchingTagRepoReferences`. Documentation here: https://developer.github.com/v3/git/refs/#list-matching-references Commits ------- fe50ad19e00625dc55abea9db729950efbdf4d67 Add matchingBranch() and matchingTags() Methods To References.php 791f5631a087356309e720c3911a49ce372cc380 Add New Tests In ReferencesTest For Our Two New Methods f9f39afd69987ddc06936ef6853508f0c3e986b0 Apply Requested Fixes 8107e1366fe4cb197515ee0200dfaa8d1fb1b7e8 Add Documentation For method matching() in gitdata/references.md 7e5dfc9e305184c79bdeb6153bbd3654343f3a60 Refactor Dual Methods To Single, and Fix Test 61fe18b28a85d6ed72ecf6e22a3f08b51d41bad9 Remove link from DocBlock 2856710dd6de5aa07e990752324179cee3e8485e Add $this->encodeReference() call Inside matching() 1fc94710eed57e143c9f2416505bc1e253fbdae9 Update ReferencesTest.php To Use A More Realistic Parameter d63d9a16f2e67ad867633d849b672bd7e9579f6e StyleCI Add Period --- doc/gitdata/references.md | 7 ++++++- lib/Github/Api/GitData/References.php | 16 ++++++++++++++++ test/Github/Tests/Api/GitData/ReferencesTest.php | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/gitdata/references.md b/doc/gitdata/references.md index cc4ee25eb7c..8cc2b971e7e 100644 --- a/doc/gitdata/references.md +++ b/doc/gitdata/references.md @@ -7,6 +7,11 @@ $references = $client->api('gitData')->references()->all('KnpLabs', 'php-github-api'); ``` +### List Matching references +```php +$references = $client->api('gitData')->references()->matching('KnpLabs', 'php-github-api', 'heads/branchName'); // use 'tags/tagName' for third argument if ref is tag +``` + ### Show a reference ```php @@ -41,4 +46,4 @@ $references = $client->api('gitData')->references()->branches('KnpLabs', 'php-gi ### List all tags ```php $references = $client->api('gitData')->references()->tags('KnpLabs', 'php-github-api'); -``` \ No newline at end of file +``` diff --git a/lib/Github/Api/GitData/References.php b/lib/Github/Api/GitData/References.php index c54c0c8aad0..d67cbe512b9 100644 --- a/lib/Github/Api/GitData/References.php +++ b/lib/Github/Api/GitData/References.php @@ -25,6 +25,22 @@ public function all($username, $repository) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs'); } + /** + * Get all matching references for the supplied reference name. + * + * @param string $username + * @param string $repository + * @param string $reference + * + * @return array + */ + public function matching(string $username, string $repository, string $reference): array + { + $reference = $this->encodeReference($reference); + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/'.$reference); + } + /** * Get all branches of a repository. * diff --git a/test/Github/Tests/Api/GitData/ReferencesTest.php b/test/Github/Tests/Api/GitData/ReferencesTest.php index 768085f69bf..70f17cde1d8 100644 --- a/test/Github/Tests/Api/GitData/ReferencesTest.php +++ b/test/Github/Tests/Api/GitData/ReferencesTest.php @@ -71,6 +71,22 @@ public function shouldGetAllRepoReferences() $this->assertEquals($expectedValue, $api->all('l3l0', 'l3l0repo')); } + /** + * @test + */ + public function shouldGetAllMatchingReferences() + { + $expectedValue = [['reference' => 'some data']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/l3l0/l3l0repo/git/matching-refs/heads/refName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->matching('l3l0', 'l3l0repo', 'heads/refName')); + } + /** * @test */ From 5c68ecc7495e3d0ab604eaf363352f8c08e96aab Mon Sep 17 00:00:00 2001 From: Jim Lind Date: Wed, 3 Jun 2020 09:04:16 -0400 Subject: [PATCH 748/951] Include links to all children --- doc/pull_requests.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/pull_requests.md b/doc/pull_requests.md index c6d5a8e6b39..d87e6180043 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -3,6 +3,8 @@ Additional APIs: * [Review Comments](pull_request/comments.md) +* [Review Request](pull_request/review_request.md) +* [Reviews](pull_request/reviews.md) Lets you list pull requests for a given repository, list one pull request in particular along with its discussion, and create a pull-request. From 57c79394f745335e66e0e0ceff53ab1d2147ce49 Mon Sep 17 00:00:00 2001 From: Jim Lind Date: Wed, 3 Jun 2020 09:06:31 -0400 Subject: [PATCH 749/951] Update README.md --- doc/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/README.md b/doc/README.md index c97c33ddc17..26ddcd6fbd0 100644 --- a/doc/README.md +++ b/doc/README.md @@ -44,6 +44,8 @@ v3 APIs: * [Cards](project/cards.md) * [Pull Requests](pull_requests.md) * [Comments](pull_request/comments.md) + * [Review Request](pull_request/review_request.md) + * [Reviews](pull_request/reviews.md) * [Rate Limits](rate_limits.md) * [Repositories](repos.md) * [Checks](repo/checks.md) From f84efb4527657a67b88c7f624b738a5c6e8c2e5d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 9 Jun 2020 22:52:15 +0200 Subject: [PATCH 750/951] Make invalid request error more clear --- lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 2 +- .../Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 04f137f06cf..dde0b45ccff 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -48,7 +48,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla $content = ResponseMediator::getContent($response); if (is_array($content) && isset($content['message'])) { if (400 === $response->getStatusCode()) { - throw new ErrorException($content['message'], 400); + throw new ErrorException(sprintf('%s (%s)', $content['message'], $response->getReasonPhrase()), 400); } if (422 === $response->getStatusCode() && isset($content['errors'])) { diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 84027aa4339..32be44ce1d5 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -92,11 +92,11 @@ public static function responseProvider() ], json_encode( [ - 'message' => 'Bad Request', + 'message' => 'Problems parsing JSON', ] ) ), - 'exception' => new \Github\Exception\ErrorException('Bad Request', 400), + 'exception' => new \Github\Exception\ErrorException('Problems parsing JSON (Bad Request)', 400), ], '422 Unprocessable Entity' => [ 'response' => new Response( From d557dc4b43b44aeeef14c8f531809cd6ebcbbbc1 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Thu, 11 Jun 2020 17:16:42 -0400 Subject: [PATCH 751/951] bug #881 fix: use new media type for branch protections (iBotPeaches) This PR was squashed before being merged into the 2.15.x-dev branch. Discussion ---------- Not sure when this changed, but `loki` is not the preview anymore. It is `luke-cage`. Without this fix you won't get back branch protection values. (like required amount of reviewers). https://developer.github.com/v3/repos/branches/#get-branch-protection If you need to support commit signature crud, that has a different media type under Protections, but I don't see that supported at this time. Commits ------- 1b767b3786b76f4ca2b44e24b31f4449e2880ff3 fix: use new media type for branch protections 3e821c405cd9641b8db6582890e3ec0a1ce09f19 fix: set preview header for endpoints that require it only ab9241ef9b57d3ba7ebaae9bbefbe6c85390dac2 Revert "fix: use new media type for branch protections" --- lib/Github/Api/Repository/Protection.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 73d1e6b5897..05dc39819b8 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -34,6 +34,9 @@ public function configure() */ public function show($username, $repository, $branch) { + // Preview endpoint + $this->acceptHeaderValue = 'application/vnd.github.luke-cage-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection'); } @@ -51,6 +54,9 @@ public function show($username, $repository, $branch) */ public function update($username, $repository, $branch, array $params = []) { + // Preview endpoint + $this->acceptHeaderValue = 'application/vnd.github.luke-cage-preview+json'; + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection', $params); } From 63ab967255084ee23226582ab22400622e80449f Mon Sep 17 00:00:00 2001 From: Vova Yatsyuk Date: Tue, 23 Jun 2020 23:47:06 +0300 Subject: [PATCH 752/951] Added missing 'machine-man-preview' accept headers --- lib/Github/Api/CurrentUser.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 0c858b078b4..ea6619226b5 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -18,6 +18,8 @@ */ class CurrentUser extends AbstractApi { + use AcceptHeaderTrait; + public function show() { return $this->get('/user'); @@ -185,23 +187,27 @@ public function subscriptions() } /** - * @link https://developer.github.com/v3/integrations/#list-installations-for-user + * @link https://developer.github.com/v3/apps/installations/#list-app-installations-accessible-to-the-user-access-token * * @param array $params */ public function installations(array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json'; + return $this->get('/user/installations', array_merge(['page' => 1], $params)); } /** - * @link https://developer.github.com/v3/integrations/installations/#list-repositories-accessible-to-the-user-for-an-installation + * @link https://developer.github.com/v3/apps/installations/#list-repositories-accessible-to-the-user-access-token * * @param string $installationId the ID of the Installation * @param array $params */ public function repositoriesByInstallation($installationId, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.machine-man-preview+json'; + return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(['page' => 1], $params)); } } From 4daa6d5725111b113ee6b985ff98939e2da066d3 Mon Sep 17 00:00:00 2001 From: YoonPer Date: Sun, 28 Jun 2020 15:38:10 +0800 Subject: [PATCH 753/951] Fix typo in /lib/Github/Api/RateLimit.php --- lib/Github/Api/RateLimit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index e05508998e9..13e84ba16ce 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -95,7 +95,7 @@ public function getCoreLimit() /** * Get search rate limit. * - * @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead + * @deprecated since 2.11.0 Use `->getResource('search')->getLimit()` instead * * @return int */ From ec31be1ca9e4b994175ca7e43481e7d4908478e5 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 28 Jun 2020 15:59:55 +0100 Subject: [PATCH 754/951] Switch to PSR18 client impl --- .travis.yml | 2 +- README.md | 22 +++++++++---- composer.json | 14 ++++---- lib/Github/Api/AbstractApi.php | 2 +- lib/Github/Api/Repo.php | 2 +- lib/Github/Api/Repository/Contents.php | 20 ++++++------ lib/Github/Client.php | 12 +++---- lib/Github/HttpClient/Builder.php | 16 +++++----- .../HttpClient/Message/ResponseMediator.php | 2 +- .../HttpClient/Plugin/Authentication.php | 21 ++++++++++-- .../Plugin/GithubExceptionThrower.php | 5 ++- lib/Github/HttpClient/Plugin/History.php | 9 ++++-- lib/Github/HttpClient/Plugin/HistoryTrait.php | 32 ------------------- lib/Github/HttpClient/Plugin/PathPrepend.php | 8 +++-- test/Github/Tests/Api/TestCase.php | 6 ++-- test/Github/Tests/ClientTest.php | 14 ++++---- .../HttpClient/Plugin/AuthenticationTest.php | 5 ++- .../Plugin/GithubExceptionThrowerTest.php | 32 +++++++++++-------- .../HttpClient/Plugin/PathPrependTest.php | 5 ++- test/Github/Tests/ResultPagerTest.php | 10 +++--- 20 files changed, 125 insertions(+), 114 deletions(-) delete mode 100644 lib/Github/HttpClient/Plugin/HistoryTrait.php diff --git a/.travis.yml b/.travis.yml index 7bb93d8fcbb..4274b4dee75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ matrix: - php: 7.2 name: Backward compatibillity check env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./.github/bc-test.sh" - - php: 7.1 + - php: 7.4 name: phpstan script: - vendor/bin/phpstan analyse --no-progress diff --git a/README.md b/README.md index 47ff1282522..1bf8be42c06 100644 --- a/README.md +++ b/README.md @@ -20,24 +20,34 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements * PHP >= 7.1 -* A [HTTP client](https://packagist.org/providers/php-http/client-implementation) +* A [HTTP client](https://packagist.org/providers/psr/http-client-implementation) * A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation) * (optional) PHPUnit to run tests. ## Install -Via Composer: +Via [Composer](https://getcomposer.org). + +### PHP 7.2+: ```bash -$ composer require knplabs/github-api php-http/guzzle6-adapter "^1.1" +composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1 ``` -Why `php-http/guzzle6-adapter`? We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io/). Read about clients in our [docs](doc/customize.md). +### PHP 7.1+: + +```bash +composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1 +``` +### Laravel 5.5+: + +```bash +composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1 +``` -## Using Laravel? +We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell). -[Laravel GitHub](https://github.com/GrahamCampbell/Laravel-GitHub) by [Graham Campbell](https://github.com/GrahamCampbell) might interest you. ## Basic usage of `php-github-api` client diff --git a/composer.json b/composer.json index b49d5cdb0ec..3417cad716a 100644 --- a/composer.json +++ b/composer.json @@ -18,17 +18,17 @@ ], "require": { "php": "^7.1", - "psr/http-message": "^1.0", + "php-http/client-common": "^2.1", + "php-http/cache-plugin": "^1.7", + "php-http/discovery": "^1.7", + "php-http/httplug": "^2.1", "psr/cache": "^1.0", - "php-http/httplug": "^1.1 || ^2.0", - "php-http/discovery": "^1.0", - "php-http/client-implementation": "^1.0", - "php-http/client-common": "^1.6 || ^2.0", - "php-http/cache-plugin": "^1.4" + "psr/http-client-implementation": "^1.0", + "psr/http-message": "^1.0" }, "require-dev": { "phpunit/phpunit": "^7.0 || ^8.0", - "php-http/guzzle6-adapter": "^1.0 || ^2.0", + "php-http/guzzle6-adapter": "^2.0", "php-http/mock-client": "^1.2", "guzzlehttp/psr7": "^1.2", "cache/array-adapter": "^0.4", diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index a9204787659..9435d8cd530 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -232,7 +232,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders = * * @param array $parameters Request parameters * - * @return null|string + * @return string|null */ protected function createJsonBody(array $parameters) { diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 63fd0358df7..02cb02d1454 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -183,7 +183,7 @@ public function showById($id) * @param string $description repository description * @param string $homepage homepage url * @param bool $public `true` for public, `false` for private - * @param null|string $organization username of organization if applicable + * @param string|null $organization username of organization if applicable * @param bool $hasIssues `true` to enable issues for this repository, `false` to disable them * @param bool $hasWiki `true` to enable the wiki for this repository, `false` to disable it * @param bool $hasDownloads `true` to enable downloads for this repository, `false` to disable them diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 2cd11ddbc6f..98c85723c2f 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -45,7 +45,7 @@ public function configure($bodyType = null) * * @param string $username the user who owns the repository * @param string $repository the name of the repository - * @param null|string $reference reference to a branch or commit + * @param string|null $reference reference to a branch or commit * * @return array information for README file */ @@ -63,8 +63,8 @@ public function readme($username, $repository, $reference = null) * * @param string $username the user who owns the repository * @param string $repository the name of the repository - * @param null|string $path path to file or directory - * @param null|string $reference reference to a branch or commit + * @param string|null $path path to file or directory + * @param string|null $reference reference to a branch or commit * * @return array|string information for file | information for each item in directory */ @@ -90,7 +90,7 @@ public function show($username, $repository, $path = null, $reference = null) * @param string $path path to file * @param string $content contents of the new file * @param string $message the commit message - * @param null|string $branch name of a branch + * @param string|null $branch name of a branch * @param null|array $committer information about the committer * * @throws MissingArgumentException @@ -126,7 +126,7 @@ public function create($username, $repository, $path, $content, $message, $branc * @param string $username the user who owns the repository * @param string $repository the name of the repository * @param string $path path of file to check - * @param null|string $reference reference to a branch or commit + * @param string|null $reference reference to a branch or commit * * @return bool */ @@ -166,7 +166,7 @@ public function exists($username, $repository, $path, $reference = null) * @param string $content contents of the new file * @param string $message the commit message * @param string $sha blob SHA of the file being replaced - * @param null|string $branch name of a branch + * @param string|null $branch name of a branch * @param null|array $committer information about the committer * * @throws MissingArgumentException @@ -207,7 +207,7 @@ public function update($username, $repository, $path, $content, $message, $sha, * @param string $path path to file * @param string $message the commit message * @param string $sha blob SHA of the file being deleted - * @param null|string $branch name of a branch + * @param string|null $branch name of a branch * @param null|array $committer information about the committer * * @throws MissingArgumentException @@ -245,7 +245,7 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null * @param string $username the user who owns the repository * @param string $repository the name of the repository * @param string $format format of archive: tarball or zipball - * @param null|string $reference reference to a branch or commit + * @param string|null $reference reference to a branch or commit * * @return string repository archive binary data */ @@ -265,12 +265,12 @@ public function archive($username, $repository, $format, $reference = null) * @param string $username the user who owns the repository * @param string $repository the name of the repository * @param string $path path to file - * @param null|string $reference reference to a branch or commit + * @param string|null $reference reference to a branch or commit * * @throws InvalidArgumentException If $path is not a file or if its encoding is different from base64 * @throws ErrorException If $path doesn't include a 'content' index * - * @return null|string content of file, or null in case of base64_decode failure + * @return string|null content of file, or null in case of base64_decode failure */ public function download($username, $repository, $path, $reference = null) { diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 2052461335d..09f62c422d8 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -12,9 +12,9 @@ use Github\HttpClient\Plugin\PathPrepend; use Http\Client\Common\HttpMethodsClient; use Http\Client\Common\Plugin; -use Http\Client\HttpClient; use Http\Discovery\UriFactoryDiscovery; use Psr\Cache\CacheItemPoolInterface; +use Psr\Http\Client\ClientInterface; /** * Simple yet very cool PHP GitHub client. @@ -161,13 +161,13 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul } /** - * Create a Github\Client using a HttpClient. + * Create a Github\Client using a HTTP client. * - * @param HttpClient $httpClient + * @param ClientInterface $httpClient * * @return Client */ - public static function createWithHttpClient(HttpClient $httpClient) + public static function createWithHttpClient(ClientInterface $httpClient) { $builder = new Builder($httpClient); @@ -329,8 +329,8 @@ public function api($name) * Authenticate a user for all next requests. * * @param string $tokenOrLogin GitHub private token/username/client ID - * @param null|string $password GitHub password/secret (optionally can contain $authMethod) - * @param null|string $authMethod One of the AUTH_* class constants + * @param string|null $password GitHub password/secret (optionally can contain $authMethod) + * @param string|null $authMethod One of the AUTH_* class constants * * @throws InvalidArgumentException If no authentication method was given */ diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 3b05b8fecc5..e68edc738d4 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -6,13 +6,13 @@ use Http\Client\Common\Plugin; use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; use Http\Client\Common\PluginClientFactory; -use Http\Client\HttpClient; -use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Http\Discovery\StreamFactoryDiscovery; use Http\Message\RequestFactory; use Http\Message\StreamFactory; use Psr\Cache\CacheItemPoolInterface; +use Psr\Http\Client\ClientInterface; /** * A builder that builds the API client. @@ -25,7 +25,7 @@ class Builder /** * The object that sends HTTP messages. * - * @var HttpClient + * @var ClientInterface */ private $httpClient; @@ -73,16 +73,16 @@ class Builder private $headers = []; /** - * @param HttpClient $httpClient - * @param RequestFactory $requestFactory - * @param StreamFactory $streamFactory + * @param ClientInterface $httpClient + * @param RequestFactory $requestFactory + * @param StreamFactory $streamFactory */ public function __construct( - HttpClient $httpClient = null, + ClientInterface $httpClient = null, RequestFactory $requestFactory = null, StreamFactory $streamFactory = null ) { - $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); + $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find(); $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); } diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index dcab5b4a979..2082fb288fa 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -52,7 +52,7 @@ public static function getPagination(ResponseInterface $response) /** * @param ResponseInterface $response * - * @return null|string + * @return string|null */ public static function getApiLimit(ResponseInterface $response) { diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index de6237bef8b..5336a0140c2 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -5,6 +5,7 @@ use Github\Client; use Github\Exception\RuntimeException; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -14,12 +15,26 @@ */ class Authentication implements Plugin { - use Plugin\VersionBridgePlugin; - + /** + * @var string + */ private $tokenOrLogin; + + /** + * @var string|null + */ private $password; + + /** + * @var string|null + */ private $method; + /** + * @param string $tokenOrLogin GitHub private token/username/client ID + * @param string|null $password GitHub password/secret (optionally can contain $method) + * @param string|null $method One of the AUTH_* class constants + */ public function __construct($tokenOrLogin, $password, $method) { $this->tokenOrLogin = $tokenOrLogin; @@ -30,7 +45,7 @@ public function __construct($tokenOrLogin, $password, $method) /** * {@inheritdoc} */ - public function doHandleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { switch ($this->method) { case Client::AUTH_HTTP_PASSWORD: diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index dde0b45ccff..1e470301c77 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -9,6 +9,7 @@ use Github\Exception\ValidationFailedException; use Github\HttpClient\Message\ResponseMediator; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -18,12 +19,10 @@ */ class GithubExceptionThrower implements Plugin { - use Plugin\VersionBridgePlugin; - /** * {@inheritdoc} */ - public function doHandleRequest(RequestInterface $request, callable $next, callable $first) + public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise { return $next($request)->then(function (ResponseInterface $response) use ($request) { if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) { diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 0f59bbb65f9..4967bfe595d 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -3,6 +3,7 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin\Journal; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -13,10 +14,8 @@ */ class History implements Journal { - use HistoryTrait; - /** - * @var ResponseInterface + * @var ResponseInterface|null */ private $lastResponse; @@ -32,4 +31,8 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons { $this->lastResponse = $response; } + + public function addFailure(RequestInterface $request, ClientExceptionInterface $exception) + { + } } diff --git a/lib/Github/HttpClient/Plugin/HistoryTrait.php b/lib/Github/HttpClient/Plugin/HistoryTrait.php deleted file mode 100644 index fbc5335d318..00000000000 --- a/lib/Github/HttpClient/Plugin/HistoryTrait.php +++ /dev/null @@ -1,32 +0,0 @@ -getUri()->getPath(); if (strpos($currentPath, $this->path) !== 0) { diff --git a/test/Github/Tests/Api/TestCase.php b/test/Github/Tests/Api/TestCase.php index d240f246d48..4fd6a49234c 100644 --- a/test/Github/Tests/Api/TestCase.php +++ b/test/Github/Tests/Api/TestCase.php @@ -2,6 +2,8 @@ namespace Github\Tests\Api; +use Github\Client; +use Psr\Http\Client\ClientInterface; use ReflectionMethod; abstract class TestCase extends \PHPUnit\Framework\TestCase @@ -16,14 +18,14 @@ abstract protected function getApiClass(); */ protected function getApiMock() { - $httpClient = $this->getMockBuilder(\Http\Client\HttpClient::class) + $httpClient = $this->getMockBuilder(ClientInterface::class) ->setMethods(['sendRequest']) ->getMock(); $httpClient ->expects($this->any()) ->method('sendRequest'); - $client = \Github\Client::createWithHttpClient($httpClient); + $client = Client::createWithHttpClient($httpClient); return $this->getMockBuilder($this->getApiClass()) ->setMethods(['get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head']) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 550bc8169f6..15a6bf401ac 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -9,7 +9,7 @@ use Github\HttpClient\Builder; use Github\HttpClient\Plugin\Authentication; use GuzzleHttp\Psr7\Response; -use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; class ClientTest extends \PHPUnit\Framework\TestCase @@ -21,7 +21,7 @@ public function shouldNotHaveToPassHttpClientToConstructor() { $client = new Client(); - $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); + $this->assertInstanceOf(ClientInterface::class, $client->getHttpClient()); } /** @@ -29,12 +29,12 @@ public function shouldNotHaveToPassHttpClientToConstructor() */ public function shouldPassHttpClientInterfaceToConstructor() { - $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) + $httpClientMock = $this->getMockBuilder(ClientInterface::class) ->getMock(); $client = Client::createWithHttpClient($httpClientMock); - $this->assertInstanceOf(\Http\Client\HttpClient::class, $client->getHttpClient()); + $this->assertInstanceOf(ClientInterface::class, $client->getHttpClient()); } /** @@ -43,7 +43,7 @@ public function shouldPassHttpClientInterfaceToConstructor() */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) { - $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) + $builder = $this->getMockBuilder(Builder::class) ->setMethods(['addPlugin', 'removePlugin']) ->disableOriginalConstructor() ->getMock(); @@ -84,7 +84,7 @@ public function getAuthenticationFullData() */ public function shouldAuthenticateUsingGivenParameters($token, $method) { - $builder = $this->getMockBuilder(\Github\HttpClient\Builder::class) + $builder = $this->getMockBuilder(Builder::class) ->setMethods(['addPlugin', 'removePlugin']) ->getMock(); $builder->expects($this->once()) @@ -217,7 +217,7 @@ public function getApiClassesProvider() */ public function testEnterpriseUrl() { - $httpClientMock = $this->getMockBuilder(HttpClient::class) + $httpClientMock = $this->getMockBuilder(ClientInterface::class) ->setMethods(['sendRequest']) ->getMock(); diff --git a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php index bf9f64e1af9..bcff0d8df88 100644 --- a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php +++ b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php @@ -5,6 +5,7 @@ use Github\Client; use Github\HttpClient\Plugin\Authentication; use GuzzleHttp\Psr7\Request; +use Http\Promise\FulfilledPromise; use PHPUnit\Framework\TestCase; class AuthenticationTest extends TestCase @@ -19,9 +20,11 @@ public function testAuthenticationMethods($tokenOrLogin, $password, $method, $ex /** @var Request $newRequest */ $newRequest = null; - $plugin->doHandleRequest($request, static function ($request) use (&$newRequest) { + $plugin->handleRequest($request, static function ($request) use (&$newRequest) { /** @var Request $newRequest */ $newRequest = $request; + + return new FulfilledPromise('FOO'); }, static function () { throw new \RuntimeException('Did not expect plugin to call first'); }); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 32be44ce1d5..8a3f788b664 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -4,8 +4,9 @@ use Github\Exception\ExceptionInterface; use Github\HttpClient\Plugin\GithubExceptionThrower; -use GuzzleHttp\Promise\FulfilledPromise; use GuzzleHttp\Psr7\Response; +use Http\Client\Promise\HttpFulfilledPromise; +use Http\Client\Promise\HttpRejectedPromise; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -25,22 +26,11 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac /** @var RequestInterface $request */ $request = $this->getMockForAbstractClass(RequestInterface::class); - $promise = $this->getMockBuilder(FulfilledPromise::class)->disableOriginalConstructor()->getMock(); - $promise->expects($this->once()) - ->method('then') - ->willReturnCallback(function ($callback) use ($response) { - return $callback($response); - }); + $promise = new HttpFulfilledPromise($response); $plugin = new GithubExceptionThrower(); - if ($exception) { - $this->expectException(get_class($exception)); - $this->expectExceptionCode($exception->getCode()); - $this->expectExceptionMessage($exception->getMessage()); - } - - $plugin->doHandleRequest( + $result = $plugin->handleRequest( $request, function (RequestInterface $request) use ($promise) { return $promise; @@ -49,6 +39,20 @@ function (RequestInterface $request) use ($promise) { return $promise; } ); + + if ($exception) { + $this->assertInstanceOf(HttpRejectedPromise::class, $result); + } else { + $this->assertInstanceOf(HttpFulfilledPromise::class, $result); + } + + if ($exception) { + $this->expectException(get_class($exception)); + $this->expectExceptionCode($exception->getCode()); + $this->expectExceptionMessage($exception->getMessage()); + } + + $result->wait(); } /** diff --git a/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php b/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php index e5feda2cf3d..f5d4052d94d 100644 --- a/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php +++ b/test/Github/Tests/HttpClient/Plugin/PathPrependTest.php @@ -4,6 +4,7 @@ use Github\HttpClient\Plugin\PathPrepend; use GuzzleHttp\Psr7\Request; +use Http\Promise\FulfilledPromise; use PHPUnit\Framework\TestCase; /** @@ -20,8 +21,10 @@ public function testPathIsPrepended($uri, $expectedPath) $plugin = new PathPrepend('/api/v3'); $newRequest = null; - $plugin->doHandleRequest($request, function ($request) use (&$newRequest) { + $plugin->handleRequest($request, function ($request) use (&$newRequest) { $newRequest = $request; + + return new FulfilledPromise('FOO'); }, function () { throw new \RuntimeException('Did not expect plugin to call first'); }); diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index a105a84f054..e8892501d44 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -2,11 +2,13 @@ namespace Github\Tests; +use Github\Api\ApiInterface; use Github\Api\Organization\Members; use Github\Api\Search; use Github\ResultPager; use Github\Tests\Mock\PaginatedResponse; use Http\Client\HttpClient; +use Psr\Http\Client\ClientInterface; /** * ResultPagerTest. @@ -29,7 +31,7 @@ public function shouldGetAllResults() $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) + $httpClientMock = $this->getMockBuilder(ClientInterface::class) ->setMethods(['sendRequest']) ->getMock(); $httpClientMock @@ -76,7 +78,7 @@ public function shouldGetAllSearchResults() $response = new PaginatedResponse($amountLoops, $content); // httpClient mock - $httpClientMock = $this->getMockBuilder(\Http\Client\HttpClient::class) + $httpClientMock = $this->getMockBuilder(ClientInterface::class) ->setMethods(['sendRequest']) ->getMock(); $httpClientMock @@ -99,10 +101,10 @@ public function testFetch() $result = 'foo'; $method = 'bar'; $parameters = ['baz']; - $api = $this->getMockBuilder(\Github\Api\ApiInterface::class) + $api = $this->getMockBuilder(ApiInterface::class) ->getMock(); - $paginator = $this->getMockBuilder(\Github\ResultPager::class) + $paginator = $this->getMockBuilder(ResultPager::class) ->disableOriginalConstructor() ->setMethods(['callApi', 'postFetch']) ->getMock(); From 7684011ae6c977da0c3a1276d388debd9cf5a9be Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Jun 2020 22:33:55 +0200 Subject: [PATCH 755/951] Bump branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3417cad716a..c7e42f8f372 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.15.x-dev" + "dev-master": "3.0.x-dev" } } } From 1884306e96c5887eb1c5d1361e69cf0bfea172e5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Jun 2020 22:35:52 +0200 Subject: [PATCH 756/951] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b49d5cdb0ec..04d539b440a 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-master": "2.15.x-dev" + "dev-2.x": "2.15.x-dev" } } } From 88e7a2346f1048c60fd543efbefbad69454323a3 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Jun 2020 23:25:08 +0200 Subject: [PATCH 757/951] Fix broken roave/bc-check test --- .github/bc-test.sh | 49 ---------------------------------------------- .travis.yml | 4 ++-- 2 files changed, 2 insertions(+), 51 deletions(-) delete mode 100755 .github/bc-test.sh diff --git a/.github/bc-test.sh b/.github/bc-test.sh deleted file mode 100755 index 8f2e3877854..00000000000 --- a/.github/bc-test.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -# -# This file is a hack to suppress warnings from Roave BC check -# - -echo "Running..." - -# Capture output to variable -OUTPUT=$(./vendor/bin/roave-backward-compatibility-check 2>&1) -echo "$OUTPUT" - -# Remove rows we want to suppress -OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\Authentication#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` -OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\Authentication#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` -OUTPUT=`echo "$OUTPUT" | sed '/The parameter $exception of Github\\\HttpClient\\\Plugin\\\History#addFailure() changed from Http\\\Client\\\Exception to a non-contravariant Psr\\\Http\\\Client\\\ClientExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/The parameter $exception of Github\\\HttpClient\\\Plugin\\\History#addFailure() changed from Http\\\Client\\\Exception to Psr\\\Http\\\Client\\\ClientExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\PathPrepend#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` -OUTPUT=`echo "$OUTPUT" | sed '/The return type of Github\\\HttpClient\\\Plugin\\\GithubExceptionThrower#handleRequest() changed from no type to Http\\\Promise\\\Promise/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getMessage() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getCode() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getFile() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getLine() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getTrace() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getPrevious() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method getTraceAsString() was added to interface Github\\\Exception\\\ExceptionInterface/'d` -OUTPUT=`echo "$OUTPUT" | sed '/Method __toString() was added to interface Github\\\Exception\\\ExceptionInterface/'d` - -# Number of rows we found with "[BC]" in them -BC_BREAKS=`echo "$OUTPUT" | grep -o '\[BC\]' | wc -l | awk '{ print $1 }'` - -# The last row of the output is "X backwards-incompatible changes detected". Find X. -STATED_BREAKS=`echo "$OUTPUT" | tail -n 1 | awk -F' ' '{ print $1 }' | sed s/No/0/` - -# If -# We found "[BC]" in the command output after we removed suppressed lines -# OR -# We have suppressed X number of BC breaks. If $STATED_BREAKS is larger than X -# THEN -# exit 1 - -if [ $BC_BREAKS -gt 0 ] || [ $STATED_BREAKS -gt 13 ]; then - echo "EXIT 1" - exit 1 -fi - -# No BC breaks found -echo "EXIT 0" -exit 0 diff --git a/.travis.yml b/.travis.yml index 7bb93d8fcbb..137da8275d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,9 @@ php: matrix: include: - - php: 7.2 + - php: 7.4.7 name: Backward compatibillity check - env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="./.github/bc-test.sh" + env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="vendor/bin/roave-backward-compatibility-check" - php: 7.1 name: phpstan script: From bacb73d70f719938b4899e784a747bca6dd44405 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 28 Jun 2020 22:41:00 +0100 Subject: [PATCH 758/951] minor #892 Don't use deprecated auth in examples (GrahamCampbell) This PR was squashed before being merged into the 2.x branch. Discussion ---------- `AUTH_HTTP_TOKEN` is deprecated, and all examples should instead use `AUTH_ACCESS_TOKEN`. Commits ------- e851bd071d2eca0d252e6f38ecb033c8c77ddb74 Don't use deprecated auth in example 5f1e6f7775c57dc0569a5966c07e8141422874a9 Update security.md --- doc/currentuser/repositories.md | 2 +- doc/security.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/currentuser/repositories.md b/doc/currentuser/repositories.md index fe1ec702e63..a3e2922b20f 100644 --- a/doc/currentuser/repositories.md +++ b/doc/currentuser/repositories.md @@ -25,6 +25,6 @@ There are three values that can be passed into the `repositories` method: `type` ```php $client = new \Github\Client(); -$client->authenticate($github_token, null, \Github\Client::AUTH_HTTP_TOKEN); +$client->authenticate($github_token, null, \Github\Client::AUTH_ACCESS_TOKEN); $client->currentUser()->repositories(); ``` diff --git a/doc/security.md b/doc/security.md index 174300bb573..1ced88b97c2 100644 --- a/doc/security.md +++ b/doc/security.md @@ -51,11 +51,11 @@ Note however that GitHub describes this method as deprecated. In most case you s ### Authenticating as an Integration To authenticate as an integration you need to supply a JSON Web Token with `Github\Client::AUTH_JWT` to request -and installation access token which is then usable with `Github\Client::AUTH_HTTP_TOKEN`. [Github´s integration +and installation access token which is then usable with `Github\Client::AUTH_ACCESS_TOKEN`. [Github´s integration authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail. It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. -The following sample code authenticates as an installation using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.2.0) +The following sample code authenticates as an installation using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.3.2) to generate a JSON Web Token (JWT). ```php @@ -78,7 +78,7 @@ $jwt = (new Builder) $github->authenticate($jwt, null, Github\Client::AUTH_JWT); $token = $github->api('apps')->createInstallationToken($installationId); -$github->authenticate($token['token'], null, Github\Client::AUTH_HTTP_TOKEN); +$github->authenticate($token['token'], null, Github\Client::AUTH_ACCESS_TOKEN); ``` The `$integrationId` you can find in the about section of your github app. From f12554a3dced7695e1ee516f94c7eb94a2df771e Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 2 Jul 2020 00:04:26 +0100 Subject: [PATCH 759/951] Removed shadow-cat --- lib/Github/Api/PullRequest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index a92e71b186c..fbb763dc5bf 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -156,11 +156,6 @@ public function create($username, $repository, array $params) throw new MissingArgumentException(['issue', 'body']); } - if (isset($params['draft']) && $params['draft'] === true) { - //This feature is in preview mode, so set the correct accept-header - $this->acceptHeaderValue = 'application/vnd.github.shadow-cat-preview+json'; - } - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params); } From e31de4ea7c8fb1e3bba7a21d72e205713f856e0e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 3 Jul 2020 21:53:24 +0200 Subject: [PATCH 760/951] Fixed incorrect MissingArgumentException parent constructor values --- lib/Github/Exception/MissingArgumentException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index 96e217acde7..f5e46ef68aa 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -15,6 +15,6 @@ public function __construct($required, $code = 0, $previous = null) $required = [$required]; } - parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code, $previous); + parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code, 1, __FILE__, __LINE__, $previous); } } From 2cfb13dbd53ebf65b19dadd80ca0dce452096f6e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 3 Jul 2020 21:47:47 +0200 Subject: [PATCH 761/951] Don't urlencode integer values --- lib/Github/Api/Apps.php | 10 ++-- lib/Github/Api/CurrentUser/Notifications.php | 10 ++-- lib/Github/Api/CurrentUser/PublicKeys.php | 4 +- lib/Github/Api/Deployment.php | 6 +-- lib/Github/Api/Gist/Comments.php | 6 +-- lib/Github/Api/Gists.php | 53 +++++++++++++++++++- lib/Github/Api/Issue.php | 8 +-- lib/Github/Api/Issue/Comments.php | 10 ++-- lib/Github/Api/Issue/Events.php | 2 +- lib/Github/Api/Issue/Labels.php | 10 ++-- lib/Github/Api/Issue/Milestones.php | 8 +-- lib/Github/Api/Issue/Timeline.php | 2 +- lib/Github/Api/Organization/Hooks.php | 8 +-- lib/Github/Api/PullRequest.php | 2 +- lib/Github/Api/PullRequest/Comments.php | 10 ++-- lib/Github/Api/PullRequest/Review.php | 2 +- lib/Github/Api/Repo.php | 4 +- lib/Github/Api/Repository/Assets.php | 10 ++-- lib/Github/Api/Repository/Downloads.php | 4 +- lib/Github/Api/Repository/Releases.php | 6 +-- lib/Github/Api/User.php | 2 +- test/Github/Tests/Api/RepoTest.php | 2 +- 22 files changed, 115 insertions(+), 64 deletions(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 7a98e731ee8..bb2a2c463f9 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -36,7 +36,7 @@ public function createInstallationToken($installationId, $userId = null) $this->configurePreviewHeader(); - return $this->post('/app/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); + return $this->post('/app/installations/'.$installationId.'/access_tokens', $parameters); } /** @@ -66,7 +66,7 @@ public function getInstallation($installationId) { $this->configurePreviewHeader(); - return $this->get('/app/installations/'.rawurldecode($installationId)); + return $this->get('/app/installations/'.$installationId); } /** @@ -129,7 +129,7 @@ public function removeInstallation($installationId) { $this->configurePreviewHeader(); - $this->delete('/app/installations/'.rawurldecode($installationId)); + $this->delete('/app/installations/'.$installationId); } /** @@ -167,7 +167,7 @@ public function addRepository($installationId, $repositoryId) { $this->configurePreviewHeader(); - return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->put('/installations/'.$installationId.'/repositories/'.$repositoryId); } /** @@ -184,6 +184,6 @@ public function removeRepository($installationId, $repositoryId) { $this->configurePreviewHeader(); - return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); + return $this->delete('/installations/'.$installationId.'/repositories/'.$repositoryId); } } diff --git a/lib/Github/Api/CurrentUser/Notifications.php b/lib/Github/Api/CurrentUser/Notifications.php index 36dfb57ef8f..9f3f2ce7bac 100644 --- a/lib/Github/Api/CurrentUser/Notifications.php +++ b/lib/Github/Api/CurrentUser/Notifications.php @@ -83,7 +83,7 @@ public function markAsReadInRepository($username, $repository, array $params = [ */ public function markAsRead($id, array $params) { - return $this->patch('/notifications/threads/'.rawurlencode($id), $params); + return $this->patch('/notifications/threads/'.$id, $params); } /** @@ -97,7 +97,7 @@ public function markAsRead($id, array $params) */ public function show($id) { - return $this->get('/notifications/threads/'.rawurlencode($id)); + return $this->get('/notifications/threads/'.$id); } /** @@ -111,7 +111,7 @@ public function show($id) */ public function showSubscription($id) { - return $this->get('/notifications/threads/'.rawurlencode($id).'/subscription'); + return $this->get('/notifications/threads/'.$id.'/subscription'); } /** @@ -126,7 +126,7 @@ public function showSubscription($id) */ public function createSubscription($id, array $params) { - return $this->put('/notifications/threads/'.rawurlencode($id).'/subscription', $params); + return $this->put('/notifications/threads/'.$id.'/subscription', $params); } /** @@ -140,6 +140,6 @@ public function createSubscription($id, array $params) */ public function removeSubscription($id) { - return $this->delete('/notifications/threads/'.rawurlencode($id).'/subscription'); + return $this->delete('/notifications/threads/'.$id.'/subscription'); } } diff --git a/lib/Github/Api/CurrentUser/PublicKeys.php b/lib/Github/Api/CurrentUser/PublicKeys.php index 706e14051ba..cb24dec9ace 100644 --- a/lib/Github/Api/CurrentUser/PublicKeys.php +++ b/lib/Github/Api/CurrentUser/PublicKeys.php @@ -35,7 +35,7 @@ public function all() */ public function show($id) { - return $this->get('/user/keys/'.rawurlencode($id)); + return $this->get('/user/keys/'.$id); } /** @@ -69,6 +69,6 @@ public function create(array $params) */ public function remove($id) { - return $this->delete('/user/keys/'.rawurlencode($id)); + return $this->delete('/user/keys/'.$id); } } diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index a6e9bacd755..6fa8700a6da 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -38,7 +38,7 @@ public function all($username, $repository, array $params = []) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id); } /** @@ -88,7 +88,7 @@ public function updateStatus($username, $repository, $id, array $params) throw new MissingArgumentException(['state']); } - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses', $params); } /** @@ -102,6 +102,6 @@ public function updateStatus($username, $repository, $id, array $params) */ public function getStatuses($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.rawurlencode($id).'/statuses'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses'); } } diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 0e022622ed8..251ec7305ab 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -56,7 +56,7 @@ public function all($gist) */ public function show($gist, $comment) { - return $this->get('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + return $this->get('/gists/'.rawurlencode($gist).'/comments/'.$comment); } /** @@ -83,7 +83,7 @@ public function create($gist, $body) */ public function update($gist, $comment_id, $body) { - return $this->patch('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment_id), ['body' => $body]); + return $this->patch('/gists/'.rawurlencode($gist).'/comments/'.$comment_id, ['body' => $body]); } /** @@ -96,6 +96,6 @@ public function update($gist, $comment_id, $body) */ public function remove($gist, $comment) { - return $this->delete('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment)); + return $this->delete('/gists/'.rawurlencode($gist).'/comments/'.$comment); } } diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index ee88c1292d1..69adef426fe 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -37,6 +37,11 @@ public function configure($bodyType = null) return $this; } + /** + * @param string|null $type + * + * @return array|string + */ public function all($type = null) { if (!in_array($type, ['public', 'starred'])) { @@ -46,6 +51,11 @@ public function all($type = null) return $this->get('/gists/'.rawurlencode($type)); } + /** + * @param string $number + * + * @return array + */ public function show($number) { return $this->get('/gists/'.rawurlencode($number)); @@ -54,7 +64,7 @@ public function show($number) /** * Get a specific revision of a gist. * - * @param int $number + * @param string $number * @param string $sha * * @link https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist @@ -77,41 +87,82 @@ public function create(array $params) return $this->post('/gists', $params); } + /** + * @param string $id + * @param array $params + * + * @return array + */ public function update($id, array $params) { return $this->patch('/gists/'.rawurlencode($id), $params); } + /** + * @param string $id + * + * @return array + */ public function commits($id) { return $this->get('/gists/'.rawurlencode($id).'/commits'); } + /** + * @param string $id + * + * @return array + */ public function fork($id) { return $this->post('/gists/'.rawurlencode($id).'/fork'); } + /** + * @param string $id + * + * @return array + */ public function forks($id) { return $this->get('/gists/'.rawurlencode($id).'/forks'); } + /** + * @param string $id + * + * @return array + */ public function remove($id) { return $this->delete('/gists/'.rawurlencode($id)); } + /** + * @param string $id + * + * @return array + */ public function check($id) { return $this->get('/gists/'.rawurlencode($id).'/star'); } + /** + * @param string $id + * + * @return array + */ public function star($id) { return $this->put('/gists/'.rawurlencode($id).'/star'); } + /** + * @param string $id + * + * @return array + */ public function unstar($id) { return $this->delete('/gists/'.rawurlencode($id).'/star'); diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 9b7d1d043ed..73598267a6b 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -113,7 +113,7 @@ public function org($organization, $state, array $params = []) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$id); } /** @@ -154,7 +154,7 @@ public function create($username, $repository, array $params) */ public function update($username, $repository, $id, array $params) { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$id, $params); } /** @@ -170,7 +170,7 @@ public function update($username, $repository, $id, array $params) */ public function lock($username, $repository, $id) { - return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock'); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$id.'/lock'); } /** @@ -186,7 +186,7 @@ public function lock($username, $repository, $id) */ public function unlock($username, $repository, $id) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock'); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$id.'/lock'); } /** diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 7dd2c96e9d2..997271c2f0b 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -59,7 +59,7 @@ public function all($username, $repository, $issue, $page = 1) ]; } - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $parameters); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/comments', $parameters); } /** @@ -75,7 +75,7 @@ public function all($username, $repository, $issue, $page = 1) */ public function show($username, $repository, $comment) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.$comment); } /** @@ -98,7 +98,7 @@ public function create($username, $repository, $issue, array $params) throw new MissingArgumentException('body'); } - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/comments', $params); } /** @@ -121,7 +121,7 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.$comment, $params); } /** @@ -137,6 +137,6 @@ public function update($username, $repository, $comment, array $params) */ public function remove($username, $repository, $comment) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.$comment); } } diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index c846147e5f8..a628b2c60bf 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -26,7 +26,7 @@ class Events extends AbstractApi public function all($username, $repository, $issue = null, $page = 1) { if (null !== $issue) { - $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events'; + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/events'; } else { $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events'; } diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 248c4a7b583..d719578d943 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -29,7 +29,7 @@ public function all($username, $repository, $issue = null) if ($issue === null) { $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels'; } else { - $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'; + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels'; } return $this->get($path); @@ -137,7 +137,7 @@ public function add($username, $repository, $issue, $labels) throw new InvalidArgumentException('The labels parameter should be a single label or an array of labels'); } - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels', $labels); } /** @@ -154,7 +154,7 @@ public function add($username, $repository, $issue, $labels) */ public function replace($username, $repository, $issue, array $params) { - return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels', $params); } /** @@ -171,7 +171,7 @@ public function replace($username, $repository, $issue, array $params) */ public function remove($username, $repository, $issue, $label) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels/'.rawurlencode($label)); } /** @@ -187,6 +187,6 @@ public function remove($username, $repository, $issue, $label) */ public function clear($username, $repository, $issue) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels'); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/labels'); } } diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 0e0e067c5e4..4cf2a3d5518 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -56,7 +56,7 @@ public function all($username, $repository, array $params = []) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.$id); } /** @@ -102,7 +102,7 @@ public function update($username, $repository, $id, array $params) $params['state'] = 'open'; } - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.$id, $params); } /** @@ -118,7 +118,7 @@ public function update($username, $repository, $id, array $params) */ public function remove($username, $repository, $id) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.$id); } /** @@ -134,6 +134,6 @@ public function remove($username, $repository, $id) */ public function labels($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.$id.'/labels'); } } diff --git a/lib/Github/Api/Issue/Timeline.php b/lib/Github/Api/Issue/Timeline.php index c0f76f2f761..16ec4b069b2 100644 --- a/lib/Github/Api/Issue/Timeline.php +++ b/lib/Github/Api/Issue/Timeline.php @@ -29,6 +29,6 @@ public function configure() */ public function all($username, $repository, $issue) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/timeline'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/timeline'); } } diff --git a/lib/Github/Api/Organization/Hooks.php b/lib/Github/Api/Organization/Hooks.php index fc9318a3c45..945cabc8667 100644 --- a/lib/Github/Api/Organization/Hooks.php +++ b/lib/Github/Api/Organization/Hooks.php @@ -33,7 +33,7 @@ public function all($organization) */ public function show($organization, $id) { - return $this->get('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); + return $this->get('/orgs/'.rawurlencode($organization).'/hooks/'.$id); } /** @@ -76,7 +76,7 @@ public function update($organization, $id, array $params) throw new MissingArgumentException(['config']); } - return $this->patch('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id), $params); + return $this->patch('/orgs/'.rawurlencode($organization).'/hooks/'.$id, $params); } /** @@ -91,7 +91,7 @@ public function update($organization, $id, array $params) */ public function ping($organization, $id) { - return $this->post('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id).'/pings'); + return $this->post('/orgs/'.rawurlencode($organization).'/hooks/'.$id.'/pings'); } /** @@ -106,6 +106,6 @@ public function ping($organization, $id) */ public function remove($organization, $id) { - return $this->delete('/orgs/'.rawurlencode($organization).'/hooks/'.rawurlencode($id)); + return $this->delete('/orgs/'.rawurlencode($organization).'/hooks/'.$id); } } diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index fbb763dc5bf..ffc713ba4a3 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -77,7 +77,7 @@ public function all($username, $repository, array $parameters = []) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$id); } public function commits($username, $repository, $id) diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 992fcd93bf5..3b71d490771 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -57,7 +57,7 @@ public function configure($bodyType = null, $apiVersion = null) public function all($username, $repository, $pullRequest = null, array $params = []) { if (null !== $pullRequest) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/comments'); } $parameters = array_merge([ @@ -81,7 +81,7 @@ public function all($username, $repository, $pullRequest = null, array $params = */ public function show($username, $repository, $comment) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.$comment); } /** @@ -109,7 +109,7 @@ public function create($username, $repository, $pullRequest, array $params) throw new MissingArgumentException(['commit_id', 'path', 'position']); } - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/comments', $params); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/comments', $params); } /** @@ -132,7 +132,7 @@ public function update($username, $repository, $comment, array $params) throw new MissingArgumentException('body'); } - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.$comment, $params); } /** @@ -148,6 +148,6 @@ public function update($username, $repository, $comment, array $params) */ public function remove($username, $repository, $comment) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.rawurlencode($comment)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/comments/'.$comment); } } diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index f984deab1e5..249477f0478 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -93,7 +93,7 @@ public function remove($username, $repository, $pullRequest, $id) */ public function comments($username, $repository, $pullRequest, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/reviews/'.rawurlencode($id).'/comments'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/comments'); } /** diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 63fd0358df7..867cb7efd08 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -64,7 +64,7 @@ public function all($id = null) return $this->get('/repositories'); } - return $this->get('/repositories?since='.rawurldecode($id)); + return $this->get('/repositories', ['since' => $id]); } /** @@ -171,7 +171,7 @@ public function show($username, $repository) */ public function showById($id) { - return $this->get('/repositories/'.rawurlencode($id)); + return $this->get('/repositories/'.$id); } /** diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 56db6843de5..39cdc5da913 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -25,7 +25,7 @@ class Assets extends AbstractApi */ public function all($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.$id.'/assets'); } /** @@ -40,7 +40,7 @@ public function all($username, $repository, $id) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.$id); } /** @@ -74,7 +74,7 @@ public function create($username, $repository, $id, $name, $contentType, $conten // Asset creation requires a separate endpoint, uploads.github.com. // Change the base url for the HTTP client temporarily while we execute // this request. - return $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets?name='.$name, $content, ['Content-Type' => $contentType]); + return $this->postRaw('https://uploads.github.com/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.$id.'/assets?name='.$name, $content, ['Content-Type' => $contentType]); } /** @@ -96,7 +96,7 @@ public function edit($username, $repository, $id, array $params) throw new MissingArgumentException('name'); } - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.$id, $params); } /** @@ -111,6 +111,6 @@ public function edit($username, $repository, $id, array $params) */ public function remove($username, $repository, $id) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.$id); } } diff --git a/lib/Github/Api/Repository/Downloads.php b/lib/Github/Api/Repository/Downloads.php index ed4c42f27d4..c959c61545e 100644 --- a/lib/Github/Api/Repository/Downloads.php +++ b/lib/Github/Api/Repository/Downloads.php @@ -39,7 +39,7 @@ public function all($username, $repository) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.$id); } /** @@ -55,6 +55,6 @@ public function show($username, $repository, $id) */ public function remove($username, $repository, $id) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/downloads/'.$id); } } diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 4657bfa71f4..9d869b72d4a 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -65,7 +65,7 @@ public function all($username, $repository, array $params = []) */ public function show($username, $repository, $id) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.$id); } /** @@ -100,7 +100,7 @@ public function create($username, $repository, array $params) */ public function edit($username, $repository, $id, array $params) { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.$id, $params); } /** @@ -114,7 +114,7 @@ public function edit($username, $repository, $id, array $params) */ public function remove($username, $repository, $id) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.$id); } /** diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index c4414c56c75..e23418ad73d 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -42,7 +42,7 @@ public function all($id = null) return $this->get('/users'); } - return $this->get('/users', ['since' => rawurldecode($id)]); + return $this->get('/users', ['since' => $id]); } /** diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 4bdfb419edd..88434750883 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -110,7 +110,7 @@ public function shouldGetAllRepositoriesStartingIndex() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repositories?since=2') + ->with('/repositories', ['since' => 2]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all(2)); From 1c16592519612b5911cc4e1b4a17758eb86e566e Mon Sep 17 00:00:00 2001 From: Thomas Genin Date: Sat, 4 Jul 2020 00:50:17 -0700 Subject: [PATCH 762/951] feature #894 Show user by ID (genintho) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Revamp of https://github.com/KnpLabs/php-github-api/pull/372 which was abandonned, and following the example of https://github.com/KnpLabs/php-github-api/pull/579 As of 2020, gettting data by ID is still undocumented. I contacted Github support to make sure it could be relied on. > Screen Shot 2020-07-02 at 10 12 15 PM ------ I have been working with an old application and I have to deal with actions made by user that have changed their login since. The old login are now used by totally different people, which can be problematic. Commits ------- 5ed46ccfc2e9a09f50358f383e6671b6f569f072 Update User.php 57034925e3d5da8e59db3f7a8cc14d74704a92dc Add unit test 62b43ab53ec6b684f2c715d64e018d30f743b460 Documentation cdaad05d68adfab5c62a160d54ca5b169e92a7ea Remove usage of rawurlencode --- doc/users.md | 7 +++++++ lib/Github/Api/User.php | 15 +++++++++++++++ test/Github/Tests/Api/UserTest.php | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/doc/users.md b/doc/users.md index b6c36309d70..3bc20c39bc3 100644 --- a/doc/users.md +++ b/doc/users.md @@ -36,6 +36,13 @@ $user = $client->api('user')->show('KnpLabs'); Returns an array of information about the user. + +You can also use the User ID, but it will use an undocumented Github API + +```php +$user = $client->api('user')->showById(202732); +``` + ### Update user information > Requires [authentication](security.md). diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index e23418ad73d..e80cb4c67c5 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -59,6 +59,21 @@ public function show($username) return $this->get('/users/'.rawurlencode($username)); } + /** + * Get extended information about a user by its id. + * Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on. + * + * @link http://developer.github.com/v3/users/ + * + * @param int $id the id of the user to show + * + * @return array information about the user + */ + public function showById($id) + { + return $this->get('/user/'.$id); + } + /** * Get extended information about a user by its username. * diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 0c9eea62b9d..795c48fa992 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -20,6 +20,22 @@ public function shouldShowUser() $this->assertEquals($expectedArray, $api->show('l3l0')); } + /** + * @test + */ + public function shouldShowByIdUser() + { + $expectedArray = ['id' => 1, 'username' => 'l3l0']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->showById(1)); + } + /** * @test */ From af2139e309b9ae5d7d04424ba63968e6dbb233ac Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 4 Jul 2020 11:15:49 +0100 Subject: [PATCH 763/951] Added AUTH_ACCESS_TOKEN to allowed methods --- lib/Github/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 2052461335d..fb29f14be84 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -340,7 +340,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null throw new InvalidArgumentException('You need to specify authentication method!'); } - if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_JWT], true)) { + if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_ACCESS_TOKEN, self::AUTH_JWT], true)) { $authMethod = $password; $password = null; } From 7d676d01bb26e3da4547bf74f82dbfa22a39c913 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 4 Jul 2020 12:55:56 +0200 Subject: [PATCH 764/951] minor #897 phpstan level 6 fixes (acrobat, GrahamCampbell) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Added missing docblocks to prepare code for typehints/return types + fixed some incorrect types in parameters Commits ------- d2d0fa6eddf35e1ab7463936fb42cad411dc5845 phpstan level 6 fixes d6ab64a30ddcd481da69e331b016dd00d11a9206 Fix getApiLimit in a way that variables only have one type ca3a6631ef9edaeb61a419b823089f804ba01396 Merge pull request #1 from GrahamCampbell/patch-1 843f04fd42f0104b882d951a73562e14743afffb Don't report missing iterable value type warnings ac70da0ec189607c14390252484e0819623703ac Improve apilimit method --- lib/Github/Api/AcceptHeaderTrait.php | 1 + lib/Github/Client.php | 11 +++++++++-- lib/Github/Exception/ApiLimitExceedException.php | 14 ++++++++++++++ lib/Github/Exception/MissingArgumentException.php | 5 +++++ .../TwoFactorAuthenticationRequiredException.php | 9 +++++++++ lib/Github/HttpClient/Builder.php | 14 ++++++++++++++ lib/Github/HttpClient/Message/ResponseMediator.php | 12 +++++++++--- lib/Github/HttpClient/Plugin/Authentication.php | 11 ++++++++++- .../HttpClient/Plugin/GithubExceptionThrower.php | 7 ++++--- lib/Github/HttpClient/Plugin/History.php | 3 +++ lib/Github/HttpClient/Plugin/HistoryTrait.php | 6 ++++++ lib/Github/HttpClient/Plugin/PathPrepend.php | 8 +++++++- lib/Github/ResultPager.php | 6 ++++++ lib/Github/ResultPagerInterface.php | 2 ++ phpstan.neon.dist | 13 ++++++++++++- 15 files changed, 111 insertions(+), 11 deletions(-) diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php index e788fd1ca5e..3d22824fdba 100644 --- a/lib/Github/Api/AcceptHeaderTrait.php +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -9,6 +9,7 @@ */ trait AcceptHeaderTrait { + /** @var string */ protected $acceptHeaderValue; protected function get($path, array $parameters = [], array $requestHeaders = []) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 2052461335d..9b27c346677 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -333,6 +333,8 @@ public function api($name) * @param null|string $authMethod One of the AUTH_* class constants * * @throws InvalidArgumentException If no authentication method was given + * + * @return void */ public function authenticate($tokenOrLogin, $password = null, $authMethod = null) { @@ -357,6 +359,8 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null * Sets the URL of your GitHub Enterprise instance. * * @param string $enterpriseUrl URL of the API in the form of http(s)://hostname + * + * @return void */ private function setEnterpriseUrl($enterpriseUrl) { @@ -381,6 +385,8 @@ public function getApiVersion() * * @param CacheItemPoolInterface $cachePool * @param array $config + * + * @return void */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { @@ -389,6 +395,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) /** * Remove the cache plugin. + * + * @return void */ public function removeCache() { @@ -397,8 +405,7 @@ public function removeCache() /** * @param string $name - * - * @throws BadMethodCallException + * @param array $args * * @return ApiInterface */ diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index 0283175f19b..f2dd9b874d6 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -9,9 +9,17 @@ */ class ApiLimitExceedException extends RuntimeException { + /** @var int */ private $limit; + /** @var int */ private $reset; + /** + * @param int $limit + * @param int $reset + * @param int $code + * @param \Throwable|null $previous + */ public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = null) { $this->limit = (int) $limit; @@ -20,11 +28,17 @@ public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = parent::__construct(sprintf('You have reached GitHub hourly limit! Actual limit is: %d', $limit), $code, $previous); } + /** + * @return int + */ public function getLimit() { return $this->limit; } + /** + * @return int + */ public function getResetTime() { return $this->reset; diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index f5e46ef68aa..7a14bb51ae7 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -9,6 +9,11 @@ */ class MissingArgumentException extends ErrorException { + /** + * @param string|array $required + * @param int $code + * @param \Throwable|null $previous + */ public function __construct($required, $code = 0, $previous = null) { if (is_string($required)) { diff --git a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php index 6f93fe40b14..0e63b277ce6 100644 --- a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php +++ b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php @@ -4,14 +4,23 @@ class TwoFactorAuthenticationRequiredException extends RuntimeException { + /** @var string */ private $type; + /** + * @param string $type + * @param int $code + * @param \Throwable|null $previous + */ public function __construct($type, $code = 0, $previous = null) { $this->type = $type; parent::__construct('Two factor authentication is enabled on this account', $code, $previous); } + /** + * @return string + */ public function getType() { return $this->type; diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 3b05b8fecc5..90263cb6632 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -113,6 +113,8 @@ public function getHttpClient() * Add a new plugin to the end of the plugin chain. * * @param Plugin $plugin + * + * @return void */ public function addPlugin(Plugin $plugin) { @@ -124,6 +126,8 @@ public function addPlugin(Plugin $plugin) * Remove a plugin by its fully qualified class name (FQCN). * * @param string $fqcn + * + * @return void */ public function removePlugin($fqcn) { @@ -137,6 +141,8 @@ public function removePlugin($fqcn) /** * Clears used headers. + * + * @return void */ public function clearHeaders() { @@ -148,6 +154,8 @@ public function clearHeaders() /** * @param array $headers + * + * @return void */ public function addHeaders(array $headers) { @@ -160,6 +168,8 @@ public function addHeaders(array $headers) /** * @param string $header * @param string $headerValue + * + * @return void */ public function addHeaderValue($header, $headerValue) { @@ -178,6 +188,8 @@ public function addHeaderValue($header, $headerValue) * * @param CacheItemPoolInterface $cachePool * @param array $config + * + * @return void */ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) { @@ -190,6 +202,8 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) /** * Remove the cache plugin. + * + * @return void */ public function removeCache() { diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index dcab5b4a979..67cc7016c54 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -56,13 +56,19 @@ public static function getPagination(ResponseInterface $response) */ public static function getApiLimit(ResponseInterface $response) { - $remainingCalls = self::getHeader($response, 'X-RateLimit-Remaining'); + $remainingCallsHeader = self::getHeader($response, 'X-RateLimit-Remaining'); - if (null !== $remainingCalls && 1 > $remainingCalls) { + if (null === $remainingCallsHeader) { + return null; + } + + $remainingCalls = (int) $remainingCallsHeader; + + if (1 > $remainingCalls) { throw new ApiLimitExceedException($remainingCalls); } - return $remainingCalls; + return $remainingCallsHeader; } /** diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index de6237bef8b..a70593b8791 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -5,6 +5,7 @@ use Github\Client; use Github\Exception\RuntimeException; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -16,10 +17,18 @@ class Authentication implements Plugin { use Plugin\VersionBridgePlugin; + /** @var string */ private $tokenOrLogin; + /** @var string|null */ private $password; + /** @var string|null */ private $method; + /** + * @param string $tokenOrLogin + * @param string|null $password + * @param string|null $method + */ public function __construct($tokenOrLogin, $password, $method) { $this->tokenOrLogin = $tokenOrLogin; @@ -28,7 +37,7 @@ public function __construct($tokenOrLogin, $password, $method) } /** - * {@inheritdoc} + * @return Promise */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index dde0b45ccff..60382074a40 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -9,6 +9,7 @@ use Github\Exception\ValidationFailedException; use Github\HttpClient\Message\ResponseMediator; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -21,7 +22,7 @@ class GithubExceptionThrower implements Plugin use Plugin\VersionBridgePlugin; /** - * {@inheritdoc} + * @return Promise */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { @@ -33,8 +34,8 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla // If error: $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { - $limit = ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); - $reset = ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); + $limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); + $reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); throw new ApiLimitExceedException($limit, $reset); } diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 0f59bbb65f9..c23621b87ed 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -28,6 +28,9 @@ public function getLastResponse() return $this->lastResponse; } + /** + * @return void + */ public function addSuccess(RequestInterface $request, ResponseInterface $response) { $this->lastResponse = $response; diff --git a/lib/Github/HttpClient/Plugin/HistoryTrait.php b/lib/Github/HttpClient/Plugin/HistoryTrait.php index fbc5335d318..611db512917 100644 --- a/lib/Github/HttpClient/Plugin/HistoryTrait.php +++ b/lib/Github/HttpClient/Plugin/HistoryTrait.php @@ -15,6 +15,9 @@ */ trait HistoryTrait { + /** + * @return void + */ public function addFailure(RequestInterface $request, ClientExceptionInterface $exception) { } @@ -25,6 +28,9 @@ public function addFailure(RequestInterface $request, ClientExceptionInterface $ */ trait HistoryTrait { + /** + * @return void + */ public function addFailure(RequestInterface $request, Exception $exception) { } diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 1245c6923a2..3c55f72f13c 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -3,6 +3,7 @@ namespace Github\HttpClient\Plugin; use Http\Client\Common\Plugin; +use Http\Promise\Promise; use Psr\Http\Message\RequestInterface; /** @@ -14,6 +15,7 @@ class PathPrepend implements Plugin { use Plugin\VersionBridgePlugin; + /** @var string */ private $path; /** @@ -25,7 +27,11 @@ public function __construct($path) } /** - * {@inheritdoc} + * @param RequestInterface $request + * @param callable $next + * @param callable $first + * + * @return Promise */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 24f2a32f135..defcde23e6a 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -161,6 +161,8 @@ public function fetchLast() /** * @param string $key + * + * @return bool */ protected function has($key) { @@ -169,6 +171,8 @@ protected function has($key) /** * @param string $key + * + * @return array */ protected function get($key) { @@ -178,6 +182,8 @@ protected function get($key) return ResponseMediator::getContent($result); } + + return []; } /** diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index c5add903648..80660247900 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -43,6 +43,8 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = []); /** * Method that performs the actual work to refresh the pagination property. + * + * @return void */ public function postFetch(); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1c57e1fef7e..9e84171f2c5 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,4 +1,15 @@ parameters: - level: 4 + checkMissingIterableValueType: false + + level: 6 paths: - lib + + ignoreErrors: + # Ignore typehint errors on api classes + - + message: '#Method (.*) with no typehint specified\.#' + path: lib/Github/Api + - + message: '#Method (.*) has no return typehint specified\.#' + path: lib/Github/Api From afbe6c4695bce0d5a077981427b4062573f6da28 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 4 Jul 2020 16:07:09 +0200 Subject: [PATCH 765/951] Use correct branch name for branch-alias on master --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8f93d08e463..c7e42f8f372 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "3.0.x-dev" + "dev-master": "3.0.x-dev" } } } From 409622242d12bee81cbf0c75bbfbde50c237e0f2 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 4 Jul 2020 15:08:56 +0100 Subject: [PATCH 766/951] minor #900 Remove BC check on 3.x (GrahamCampbell) This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- Can be added back once 3.0.0 is tagged. Commits ------- b78cc5b12361f89094ecf195ab5dbe58fa99f93f Remove BC check on 3.x 4027cb9601e6cd32420f53b6e84fd067f709017b Restore with comment --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 133bbd8e710..6c58f8f6881 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,10 @@ php: matrix: include: - - php: 7.4.7 - name: Backward compatibillity check - env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="vendor/bin/roave-backward-compatibility-check" +# BC check disabled until 3.0.0 is tagged +# - php: 7.4.7 +# name: Backward compatibillity check +# env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="vendor/bin/roave-backward-compatibility-check" - php: 7.4 name: phpstan script: From e2393e7863a7a8cbc73df51965a1e840d7016587 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 4 Jul 2020 15:16:18 +0100 Subject: [PATCH 767/951] Fixed 2.x -> master merge --- lib/Github/HttpClient/Plugin/History.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index 21bdb6cbbb3..eaf3f19cc5b 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -35,6 +35,9 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons $this->lastResponse = $response; } + /** + * @return void + */ public function addFailure(RequestInterface $request, ClientExceptionInterface $exception) { } From f14ec90e8ce585418f2bd580539c49eb5172a6a1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 4 Jul 2020 17:19:57 +0200 Subject: [PATCH 768/951] Also set the master branch alias in 2.x branch --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 04d539b440a..989f686495f 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "2.15.x-dev" + "dev-2.x": "2.15.x-dev", + "dev-master": "3.0.x-dev" } } } From 4619ebd1f2d79ac1c02e2644b1d6939c4874e85f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 6 Jul 2020 20:18:14 +0100 Subject: [PATCH 769/951] feature #888 Switch to PSR-17 and remove deprecated code (GrahamCampbell) This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- This PR removes all the deprecated code from the codebase, and switches to PSR-17 which replaces the old PHP HTTP interfaces, just like PSR-18 replaced some of the others (implemented in an earlier PR). Commits ------- ee1bf7f41d25775edabf9861468f0aa075432e05 Removed deprecated code 692ca2a1f9808b05559e7e1b57fa1e642e0bc7ff Finished removing old code 1e30efd7ffde7a926988447d927c6f7b7d00a9de Update doc/security.md 2054e2094b677069ef04a4c1f52a7d2e606800c2 PSR-17 and HttpMethodsClientInterface 0fdecefd66773c0378e069866e601a9b749102c0 Returns --- README.md | 17 +- composer.json | 23 +- doc/rate_limits.md | 9 - doc/security.md | 34 +-- lib/Github/Api/Authorizations.php | 142 ----------- lib/Github/Api/CurrentUser.php | 20 -- lib/Github/Api/Integrations.php | 26 -- lib/Github/Api/Issue.php | 22 -- lib/Github/Api/Issue/Assignees.php | 6 +- lib/Github/Api/Issue/Comments.php | 21 +- lib/Github/Api/Organization/Teams.php | 56 +---- lib/Github/Api/RateLimit.php | 36 --- lib/Github/Api/Repo.php | 32 --- lib/Github/Api/Repository/Protection.php | 7 - lib/Github/Api/Search.php | 4 +- lib/Github/Api/User.php | 29 --- lib/Github/Client.php | 71 ++---- lib/Github/HttpClient/Builder.php | 32 +-- .../HttpClient/Plugin/Authentication.php | 62 +---- test/Github/Tests/Api/AbstractApiTest.php | 13 +- test/Github/Tests/Api/AuthorizationsTest.php | 229 ------------------ test/Github/Tests/Api/CurrentUserTest.php | 16 -- test/Github/Tests/Api/Issue/CommentsTest.php | 2 +- test/Github/Tests/Api/IssueTest.php | 48 ---- test/Github/Tests/Api/RateLimitTest.php | 14 +- test/Github/Tests/Api/RepoTest.php | 38 --- test/Github/Tests/Api/UserTest.php | 19 -- test/Github/Tests/ClientTest.php | 19 +- test/Github/Tests/Functional/CacheTest.php | 6 +- .../HttpClient/Plugin/AuthenticationTest.php | 4 - test/Github/Tests/Integration/TestCase.php | 5 +- 31 files changed, 110 insertions(+), 952 deletions(-) delete mode 100644 lib/Github/Api/Integrations.php delete mode 100644 test/Github/Tests/Api/AuthorizationsTest.php diff --git a/README.md b/README.md index 1bf8be42c06..9d6637d85f2 100644 --- a/README.md +++ b/README.md @@ -20,30 +20,29 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements * PHP >= 7.1 -* A [HTTP client](https://packagist.org/providers/psr/http-client-implementation) -* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation) -* (optional) PHPUnit to run tests. +* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) +* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation) ## Install Via [Composer](https://getcomposer.org). -### PHP 7.2+: +### PHP 7.1+: ```bash -composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1 +composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0 ``` -### PHP 7.1+: +### PHP 7.2+: ```bash -composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1 +composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 ``` -### Laravel 5.5+: +### Laravel 6+: ```bash -composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1 +composer require graham-campbell/github^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 ``` We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell). diff --git a/composer.json b/composer.json index 084a96137fb..0d253946dcb 100644 --- a/composer.json +++ b/composer.json @@ -18,21 +18,26 @@ ], "require": { "php": "^7.1", - "php-http/client-common": "^2.1", + "php-http/client-common": "^2.2", "php-http/cache-plugin": "^1.7", - "php-http/discovery": "^1.7", + "php-http/discovery": "^1.9", "php-http/httplug": "^2.1", + "php-http/multipart-stream-builder": "^1.1", "psr/cache": "^1.0", "psr/http-client-implementation": "^1.0", + "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^8.0", - "php-http/guzzle6-adapter": "^2.0", - "php-http/mock-client": "^1.2", - "guzzlehttp/psr7": "^1.2", - "cache/array-adapter": "^0.4", - "phpstan/phpstan": "^0.12.23" + "cache/array-adapter": "^1.0.1", + "guzzlehttp/psr7": "^1.5.2", + "http-interop/http-factory-guzzle": "^1.0", + "php-http/guzzle6-adapter": "^2.0.1", + "php-http/mock-client": "^1.4", + "phpstan/phpstan": "^0.12.32", + "phpstan/extension-installer": "^1.0.4", + "phpstan/phpstan-deprecation-rules": "^0.12.4", + "phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } @@ -40,8 +45,6 @@ "autoload-dev": { "psr-4": { "Github\\Tests\\": "test/Github/Tests/"} }, - "minimum-stability": "dev", - "prefer-stable": true, "extra": { "branch-alias": { "dev-2.x": "2.15.x-dev", diff --git a/doc/rate_limits.md b/doc/rate_limits.md index 3239a44b612..454981d0b4f 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -5,7 +5,6 @@ Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com #### Get All Rate Limits -##### new way ```php /** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits */ $rateLimits = $client->api('rate_limit')->getResources(); @@ -61,14 +60,6 @@ array(4) { } ``` - -##### deprecated way - -```php -/** @var array $rateLimits */ -$rateLimits = $client->api('rate_limit')->getRateLimits(); -``` - #### Get Core Rate Limit ```php diff --git a/doc/security.md b/doc/security.md index 1ced88b97c2..1af022a90d5 100644 --- a/doc/security.md +++ b/doc/security.md @@ -6,47 +6,29 @@ properties on Repositories and some others. Therefore this step is facultative. ### Authenticate -GitHub provides some different ways of authentication. This API implementation implements three of them which are handled by one function: +GitHub provides some different ways of authentication. This API implementation implements three of them which are +handled by one function: ```php $client->authenticate($usernameOrToken, $password, $method); ``` `$usernameOrToken` is, of course, the username (or in some cases token/client ID, more details you can find below), -and guess what should contain `$password`. The `$method` can contain one of the five allowed values: - -#### Deprecated 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. +and guess what should contain `$password`. The `$method` can contain one of the three allowed values: #### Supported methods * `Github\Client::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret * `Github\Client::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header * `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app -The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`, -`Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in -`$usernameOrToken` variable (`$password` is omitted in this particular case). For the -`Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID` -`$usernameOrToken` should contain your client ID, and `$password` should contain client secret. - -After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, -all further requests are done as the given user. +The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_ACCESS_TOKEN` and +`Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in +this particular case). -### About authentication methods - -The `Github\Client::AUTH_URL_TOKEN` authentication method sends the API token in URL parameters. -The `Github\Client::AUTH_URL_CLIENT_ID` authentication method sends the client ID and secret in URL parameters. -The `Github\Client::AUTH_HTTP_*` authentication methods send their values to GitHub using HTTP Basic Authentication. The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header. -`Github\Client::AUTH_URL_TOKEN` used to be the only available authentication method. To prevent existing applications -from changing their behavior in case of an API upgrade, this method is chosen as the default for this API implementation. - -Note however that GitHub describes this method as deprecated. In most case you should use the -`Github\Client::AUTH_HTTP_TOKEN` instead. +After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, all +further requests are done as the given user. ### Authenticating as an Integration diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index f0122a3fc17..6032c7fadb2 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -11,100 +11,6 @@ */ class Authorizations extends AbstractApi { - use AcceptHeaderTrait; - - private function configurePreviewHeader() - { - $this->acceptHeaderValue = 'application/vnd.github.doctor-strange-preview+json'; - } - - /** - * List all authorizations. - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function all() - { - return $this->get('/authorizations'); - } - - /** - * Show a single authorization. - * - * @param string $clientId - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function show($clientId) - { - return $this->get('/authorizations/'.rawurlencode($clientId)); - } - - /** - * Create an authorization. - * - * @param array $params - * @param string|null $OTPCode - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function create(array $params, $OTPCode = null) - { - $headers = null === $OTPCode ? [] : ['X-GitHub-OTP' => $OTPCode]; - - return $this->post('/authorizations', $params, $headers); - } - - /** - * Update an authorization. - * - * @param string $clientId - * @param array $params - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function update($clientId, array $params) - { - return $this->patch('/authorizations/'.rawurlencode($clientId), $params); - } - - /** - * Remove an authorization. - * - * @param string $clientId - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function remove($clientId) - { - return $this->delete('/authorizations/'.rawurlencode($clientId)); - } - - /** - * Check an authorization. - * - * @param string $clientId - * @param string $token - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::checkToken() instead. - */ - public function check($clientId, $token) - { - return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); - } - /** * Check an application token. * @@ -115,26 +21,9 @@ public function check($clientId, $token) */ public function checkToken($clientId, $token = null) { - $this->configurePreviewHeader(); - return $this->post('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); } - /** - * Reset an authorization. - * - * @param string $clientId - * @param string $token - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::resetToken() instead. - */ - public function reset($clientId, $token) - { - return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); - } - /** * Reset an application token. * @@ -145,36 +34,9 @@ public function reset($clientId, $token) */ public function resetToken($clientId, $token = null) { - $this->configurePreviewHeader(); - return $this->patch('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); } - /** - * Remove an authorization. - * - * @param string $clientId - * @param string $token - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteToken() instead. - */ - public function revoke($clientId, $token) - { - $this->delete('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); - } - - /** - * Revoke all authorizations. - * - * @param string $clientId - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteGrant() instead. - */ - public function revokeAll($clientId) - { - $this->delete('/applications/'.rawurlencode($clientId).'/tokens'); - } - /** * Revoke an application token. * @@ -185,8 +47,6 @@ public function revokeAll($clientId) */ public function deleteToken($clientId, $token = null) { - $this->configurePreviewHeader(); - $this->delete('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); } @@ -200,8 +60,6 @@ public function deleteToken($clientId, $token = null) */ public function deleteGrant($clientId, $token = null) { - $this->configurePreviewHeader(); - $this->delete('/applications/'.rawurlencode($clientId).'/grant', $token ? ['access_token' => $token] : []); } } diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index ea6619226b5..18e197f8c77 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -150,16 +150,6 @@ public function watchers() return new Watchers($this->client); } - /** - * @deprecated Use watchers() instead - */ - public function watched($page = 1) - { - return $this->get('/user/watched', [ - 'page' => $page, - ]); - } - /** * @return Starring */ @@ -168,16 +158,6 @@ public function starring() return new Starring($this->client); } - /** - * @deprecated Use starring() instead - */ - public function starred($page = 1) - { - return $this->get('/user/starred', [ - 'page' => $page, - ]); - } - /** * @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched */ diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php deleted file mode 100644 index bd4f78a4f07..00000000000 --- a/lib/Github/Api/Integrations.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -class Integrations extends Apps -{ - /** - * @deprecated - * Configure the accept header for Early Access to the integrations api (DEPRECATED) - * @see https://developer.github.com/v3/apps/ - * - * @return self - */ - public function configure() - { - return $this; - } -} diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 73598267a6b..875f305f127 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -58,28 +58,6 @@ public function all($username, $repository, array $params = []) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(['page' => 1], $params)); } - /** - * Search issues by username, repo, state and keyword. - * - * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * @link http://developer.github.com/v3/search/#search-issues - * - * @param string $username the username - * @param string $repository the repository - * @param string $state the issue state, can be open or closed - * @param string $keyword the keyword to filter issues by - * - * @return array list of issues found - */ - public function find($username, $repository, $state, $keyword) - { - if (!in_array($state, ['open', 'closed'])) { - $state = 'open'; - } - - return $this->get('/legacy/issues/search/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($state).'/'.rawurlencode($keyword)); - } - /** * List issues by organization. * diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php index 1e5e0b727a1..8ae86d1cd99 100644 --- a/lib/Github/Api/Issue/Assignees.php +++ b/lib/Github/Api/Issue/Assignees.php @@ -3,6 +3,7 @@ namespace Github\Api\Issue; use Github\Api\AbstractApi; +use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; class Assignees extends AbstractApi @@ -47,6 +48,7 @@ public function check($username, $repository, $assignee) * @param string $issue * @param array $parameters * + * @throws InvalidArgumentException * @throws MissingArgumentException * * @return string @@ -58,9 +60,7 @@ public function add($username, $repository, $issue, array $parameters) } if (!is_array($parameters['assignees'])) { - @trigger_error(sprintf('Passing the "assignees" parameter as a string in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array of strings instead', __METHOD__), E_USER_DEPRECATED); - - $parameters['assignees'] = [$parameters['assignees']]; + throw new InvalidArgumentException('The assignees parameter should be an array of assignees'); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters); diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 997271c2f0b..396f5060893 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -41,25 +41,16 @@ public function configure($bodyType = null) * * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue * - * @param string $username - * @param string $repository - * @param int $issue - * @param int|array $page Passing integer is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead. + * @param string $username + * @param string $repository + * @param int $issue + * @param array $params * * @return array */ - public function all($username, $repository, $issue, $page = 1) + public function all($username, $repository, $issue, array $params = []) { - if (is_array($page)) { - $parameters = $page; - } else { - @trigger_error(sprintf('Passing integer to the "page" argument in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead.', __METHOD__), E_USER_DEPRECATED); - $parameters = [ - 'page' => $page, - ]; - } - - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/comments', $parameters); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/comments', $params); } /** diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 8b84028db24..00b57758b05 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -35,21 +35,15 @@ public function create($organization, array $params) /** * @link https://developer.github.com/v3/teams/#list-teams */ - public function show($team, $organization = null) + public function show($team, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->get('/teams/'.rawurlencode($team)); - } - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } /** * @link https://developer.github.com/v3/teams/#edit-team */ - public function update($team, array $params, $organization = null) + public function update($team, array $params, $organization) { if (!isset($params['name'])) { throw new MissingArgumentException('name'); @@ -58,82 +52,46 @@ public function update($team, array $params, $organization = null) $params['permission'] = 'pull'; } - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->patch('/teams/'.rawurlencode($team), $params); - } - return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); } /** * @link https://developer.github.com/v3/teams/#delete-team */ - public function remove($team, $organization = null) + public function remove($team, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->delete('/teams/'.rawurlencode($team)); - } - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } /** * @link https://developer.github.com/v3/teams/members/#list-team-members */ - public function members($team, $organization = null) + public function members($team, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->get('/teams/'.rawurlencode($team).'/members'); - } - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); } /** * @link https://developer.github.com/v3/teams/members/#get-team-membership */ - public function check($team, $username, $organization = null) + public function check($team, $username, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); - } - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** * @link https://developer.github.com/v3/teams/members/#add-or-update-team-membership */ - public function addMember($team, $username, $organization = null) + public function addMember($team, $username, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); - } - return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** * @link https://developer.github.com/v3/teams/members/#remove-team-membership */ - public function removeMember($team, $username, $organization = null) + public function removeMember($team, $username, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); - } - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index 13e84ba16ce..10b8b5b3288 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -18,18 +18,6 @@ class RateLimit extends AbstractApi */ protected $resources = []; - /** - * Get rate limits data in an array. - * - * @deprecated since 2.11.0 Use `->getResources()` instead - * - * @return array - */ - public function getRateLimits() - { - return $this->fetchLimits(); - } - /** * Gets the rate limit resource objects. * @@ -79,28 +67,4 @@ protected function fetchLimits() return $result; } - - /** - * Get core rate limit. - * - * @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead - * - * @return int - */ - public function getCoreLimit() - { - return $this->getResource('core')->getLimit(); - } - - /** - * Get search rate limit. - * - * @deprecated since 2.11.0 Use `->getResource('search')->getLimit()` instead - * - * @return int - */ - public function getSearchLimit() - { - return $this->getResource('search')->getLimit(); - } } diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index ca5cbc90dc0..c7c3555c45e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -33,22 +33,6 @@ class Repo extends AbstractApi { use AcceptHeaderTrait; - /** - * Search repositories by keyword. - * - * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * @link http://developer.github.com/v3/search/#search-repositories - * - * @param string $keyword the search query - * @param array $params - * - * @return array list of found repositories - */ - public function find($keyword, array $params = []) - { - return $this->get('/legacy/repos/search/'.rawurlencode($keyword), array_merge(['start_page' => 1], $params)); - } - /** * List all public repositories. * @@ -530,22 +514,6 @@ public function teams($username, $repository) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams'); } - /** - * @deprecated see subscribers method - * - * @param string $username - * @param string $repository - * @param int $page - * - * @return array - */ - public function watchers($username, $repository, $page = 1) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', [ - 'page' => $page, - ]); - } - /** * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 05dc39819b8..b559557a944 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -14,13 +14,6 @@ class Protection extends AbstractApi { use AcceptHeaderTrait; - public function configure() - { - $this->acceptHeaderValue = 'application/vnd.github.loki-preview+json'; - - return $this; - } - /** * Retrieves configured protection for the provided branch. * diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 84626ae32db..5a585e77149 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -90,7 +90,7 @@ public function users($q, $sort = 'updated', $order = 'desc') */ public function commits($q, $sort = null, $order = 'desc') { - //This api is in preview mode, so set the correct accept-header + // This api is in preview mode, so set the correct accept-header $this->acceptHeaderValue = 'application/vnd.github.cloak-preview'; return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]); @@ -107,7 +107,7 @@ public function commits($q, $sort = null, $order = 'desc') */ public function topics($q) { - //This api is in preview mode, so set the correct accept-header + // This api is in preview mode, so set the correct accept-header $this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json'; return $this->get('/search/topics', ['q' => $q]); diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index e80cb4c67c5..b36ae47123b 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -12,21 +12,6 @@ */ class User extends AbstractApi { - /** - * Search users by username. - * - * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * @link http://developer.github.com/v3/search/#search-users - * - * @param string $keyword the keyword to search - * - * @return array list of users found - */ - public function find($keyword) - { - return $this->get('/legacy/user/search/'.rawurlencode($keyword)); - } - /** * Request all users. * @@ -132,20 +117,6 @@ public function followers($username, array $parameters = [], array $requestHeade return $this->get('/users/'.rawurlencode($username).'/followers', $parameters, $requestHeaders); } - /** - * Request the repository that a specific user is watching. - * - * @deprecated see subscriptions method - * - * @param string $username the username - * - * @return array list of watched repositories - */ - public function watched($username) - { - return $this->get('/users/'.rawurlencode($username).'/watched'); - } - /** * Request starred repositories that a specific user has starred. * diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ad4470c216c..c9adb7c2919 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -10,9 +10,9 @@ use Github\HttpClient\Plugin\GithubExceptionThrower; use Github\HttpClient\Plugin\History; use Github\HttpClient\Plugin\PathPrepend; -use Http\Client\Common\HttpMethodsClient; +use Http\Client\Common\HttpMethodsClientInterface; use Http\Client\Common\Plugin; -use Http\Discovery\UriFactoryDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; @@ -31,8 +31,6 @@ * @method Api\Gists gist() * @method Api\Gists gists() * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Integrations integration() (deprecated) - * @method Api\Integrations integrations() (deprecated) * @method Api\Apps apps() * @method Api\Issue issue() * @method Api\Issue issues() @@ -69,51 +67,27 @@ */ class Client { - /** - * Constant for authentication method. Indicates the default, but deprecated - * login with username and token in URL. - * - * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters - */ - const AUTH_URL_TOKEN = 'url_token'; - - /** - * Constant for authentication method. Not indicates the new login, but allows - * usage of unauthenticated rate limited requests for given client_id + client_secret. - * - * @deprecated Use `Client::AUTH_CLIENT_ID` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters - */ - const AUTH_URL_CLIENT_ID = 'url_client_id'; - - /** - * Constant for authentication method. Indicates the new favored login method - * with username and password via HTTP Authentication. - * - * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters - */ - const AUTH_HTTP_PASSWORD = 'http_password'; - - /** - * Constant for authentication method. Indicates the new login method with - * with username and token via HTTP Authentication. - * - * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. - */ - const AUTH_HTTP_TOKEN = 'http_token'; - /** * Authenticate using a client_id/client_secret combination. + * + * @var string */ const AUTH_CLIENT_ID = 'client_id_header'; /** * Authenticate using a GitHub access token. + * + * @var string */ const AUTH_ACCESS_TOKEN = 'access_token_header'; /** - * Constant for authentication method. Indicates JSON Web Token - * authentication required for GitHub apps access to the API. + * Constant for authentication method. + * + * Indicates JSON Web Token authentication required for GitHub apps access + * to the API. + * + * @var string */ const AUTH_JWT = 'jwt'; @@ -142,12 +116,12 @@ class Client public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); - $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder(); + $this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder(); $builder->addPlugin(new GithubExceptionThrower()); $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); $builder->addPlugin(new Plugin\RedirectPlugin()); - $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); + $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri('https://api.github.com'))); $builder->addPlugin(new Plugin\HeaderDefaultsPlugin([ 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ])); @@ -222,11 +196,6 @@ public function api($name) $api = new Api\Miscellaneous\Gitignore($this); break; - case 'integration': - case 'integrations': - $api = new Api\Integrations($this); - break; - case 'apps': $api = new Api\Apps($this); break; @@ -338,17 +307,13 @@ public function api($name) */ public function authenticate($tokenOrLogin, $password = null, $authMethod = null) { - if (null === $password && null === $authMethod) { - throw new InvalidArgumentException('You need to specify authentication method!'); - } - - if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_ACCESS_TOKEN, self::AUTH_JWT], true)) { + if (null === $authMethod && (self::AUTH_JWT === $password || self::AUTH_ACCESS_TOKEN === $password)) { $authMethod = $password; $password = null; } if (null === $authMethod) { - $authMethod = self::AUTH_HTTP_PASSWORD; + throw new InvalidArgumentException('You need to specify authentication method!'); } $this->getHttpClientBuilder()->removePlugin(Authentication::class); @@ -368,7 +333,7 @@ private function setEnterpriseUrl($enterpriseUrl) $builder->removePlugin(Plugin\AddHostPlugin::class); $builder->removePlugin(PathPrepend::class); - $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); + $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri($enterpriseUrl))); $builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion()))); } @@ -427,7 +392,7 @@ public function getLastResponse() } /** - * @return HttpMethodsClient + * @return HttpMethodsClientInterface */ public function getHttpClient() { diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index d18bbcff332..47d46527928 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -3,16 +3,16 @@ namespace Github\HttpClient; use Http\Client\Common\HttpMethodsClient; +use Http\Client\Common\HttpMethodsClientInterface; use Http\Client\Common\Plugin; use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; use Http\Client\Common\PluginClientFactory; -use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; -use Http\Discovery\StreamFactoryDiscovery; -use Http\Message\RequestFactory; -use Http\Message\StreamFactory; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; /** * A builder that builds the API client. @@ -32,17 +32,17 @@ class Builder /** * A HTTP client with all our plugins. * - * @var HttpMethodsClient + * @var HttpMethodsClientInterface */ private $pluginClient; /** - * @var RequestFactory + * @var RequestFactoryInterface */ private $requestFactory; /** - * @var StreamFactory + * @var StreamFactoryInterface */ private $streamFactory; @@ -73,22 +73,22 @@ class Builder private $headers = []; /** - * @param ClientInterface $httpClient - * @param RequestFactory $requestFactory - * @param StreamFactory $streamFactory + * @param ClientInterface|null $httpClient + * @param RequestFactoryInterface|null $requestFactory + * @param StreamFactoryInterface|null $streamFactory */ public function __construct( ClientInterface $httpClient = null, - RequestFactory $requestFactory = null, - StreamFactory $streamFactory = null + RequestFactoryInterface $requestFactory = null, + StreamFactoryInterface $streamFactory = null ) { - $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find(); - $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); - $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); + $this->httpClient = $httpClient ?? Psr18ClientDiscovery::find(); + $this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory(); + $this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory(); } /** - * @return HttpMethodsClient + * @return HttpMethodsClientInterface */ public function getHttpClient() { diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 48145dba6d8..48131099672 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -46,62 +46,26 @@ public function __construct($tokenOrLogin, $password, $method) * @return Promise */ public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise + { + $request = $request->withHeader( + 'Authorization', + $this->getAuthorizationHeader() + ); + + return $next($request); + } + + private function getAuthorizationHeader(): string { switch ($this->method) { - case Client::AUTH_HTTP_PASSWORD: - @trigger_error('Using the "Client::AUTH_HTTP_PASSWORD" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); case Client::AUTH_CLIENT_ID: - $request = $request->withHeader( - 'Authorization', - sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)) - ); - break; - - case Client::AUTH_HTTP_TOKEN: - @trigger_error('Using the "Client::AUTH_HTTP_TOKEN" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); + return sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)); case Client::AUTH_ACCESS_TOKEN: - $request = $request->withHeader('Authorization', sprintf('token %s', $this->tokenOrLogin)); - break; - - case Client::AUTH_URL_CLIENT_ID: - @trigger_error('Using the "Client::AUTH_URL_CLIENT_ID" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_CLIENT_ID" instead.', E_USER_DEPRECATED); - - $uri = $request->getUri(); - $query = $uri->getQuery(); - - $parameters = [ - 'client_id' => $this->tokenOrLogin, - 'client_secret' => $this->password, - ]; - - $query .= empty($query) ? '' : '&'; - $query .= utf8_encode(http_build_query($parameters, '', '&')); - - $uri = $uri->withQuery($query); - $request = $request->withUri($uri); - break; - - case Client::AUTH_URL_TOKEN: - @trigger_error('Using the "Client::AUTH_URL_TOKEN" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); - - $uri = $request->getUri(); - $query = $uri->getQuery(); - - $parameters = ['access_token' => $this->tokenOrLogin]; - - $query .= empty($query) ? '' : '&'; - $query .= utf8_encode(http_build_query($parameters, '', '&')); - - $uri = $uri->withQuery($query); - $request = $request->withUri($uri); - break; + return sprintf('token %s', $this->tokenOrLogin); case Client::AUTH_JWT: - $request = $request->withHeader('Authorization', sprintf('Bearer %s', $this->tokenOrLogin)); - break; + return sprintf('Bearer %s', $this->tokenOrLogin); default: throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); } - - return $next($request); } } diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index ae2fa7cd3b6..428ece12cf3 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -209,19 +209,12 @@ protected function getClientMock() * * @param array $methods * - * @return \Http\Client\Common\HttpMethodsClient + * @return \Http\Client\Common\HttpMethodsClientInterface */ protected function getHttpMethodsMock(array $methods = []) { - if (interface_exists(HttpMethodsClientInterface::class)) { - $mock = $this->createMock(HttpMethodsClientInterface::class); - } else { - $methods = array_merge(['sendRequest'], $methods); - $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) - ->disableOriginalConstructor() - ->setMethods($methods) - ->getMock(); - } + $mock = $this->createMock(HttpMethodsClientInterface::class); + $mock ->expects($this->any()) ->method('sendRequest'); diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php deleted file mode 100644 index 87ace7c51f1..00000000000 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ /dev/null @@ -1,229 +0,0 @@ - '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->all()); - } - - /** - * @test - */ - public function shouldShowAuthorization() - { - $id = 123; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/authorizations/'.$id) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->show($id)); - } - - /** - * @test - */ - public function shouldAuthorization() - { - $input = [ - 'note' => '', - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/authorizations', $input); - - $api->create($input); - } - - /** - * @test - */ - public function shouldUpdateAuthorization() - { - $id = 123; - $input = [ - 'note' => '', - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/authorizations/'.$id, $input); - - $api->update($id, $input); - } - - /** - * @test - */ - public function shouldDeleteAuthorization() - { - $id = 123; - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/authorizations/'.$id); - - $api->remove($id); - } - - /** - * @test - */ - public function shouldCheckApplicationToken() - { - $id = 123; - $token = 'abc'; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/applications/'.$id.'/token', ['access_token' => $token]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->checkToken($id, $token)); - } - - /** - * @test - */ - public function shouldCheckAuthorization() - { - $id = 123; - $token = 'abc'; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/applications/'.$id.'/tokens/'.$token) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->check($id, $token)); - } - - /** - * @test - */ - public function shouldResetAuthorization() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/applications/'.$id.'/tokens/'.$token); - - $api->reset($id, $token); - } - - /** - * @test - */ - public function shouldResetApplicationToken() - { - $id = 123; - $token = 'abcde'; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/applications/'.$id.'/token', ['access_token' => $token]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->resetToken($id, $token)); - } - - /** - * @test - */ - public function shouldRevokeAuthorization() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/tokens/'.$token); - - $api->revoke($id, $token); - } - - /** - * @test - */ - public function shouldRevokeAllAuthorizations() - { - $id = 123; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/tokens'); - - $api->revokeAll($id); - } - - /** - * @test - */ - public function shouldDeleteApplicationToken() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/token', ['access_token' => $token]); - - $api->deleteToken($id, $token); - } - - /** - * @test - */ - public function shouldDeleteApplicationAuthorization() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/grant', ['access_token' => $token]); - - $api->deleteGrant($id, $token); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \Github\Api\Authorizations::class; - } -} diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index ace2301b650..5de99f5c911 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -68,22 +68,6 @@ public function shouldGetIssuesAssignedToUser() $this->assertEquals($expectedArray, $api->issues(['some' => 'param'])); } - /** - * @test - */ - public function shouldGetWatchedRepositories() - { - $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/user/watched', ['page' => 1]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->watched(1)); - } - /** * @test */ diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 08f4ff0ff16..3a8db85a922 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -17,7 +17,7 @@ public function shouldGetAllIssueComments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/issues/123/comments', ['page' => 1]) + ->with('/repos/KnpLabs/php-github-api/issues/123/comments', []) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 6ad07439edd..bc8b80fdf5e 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -156,54 +156,6 @@ public function shouldReOpenIssue() $api->update('ornicar', 'php-github-api', 14, $data); } - /** - * @test - */ - public function shouldSearchOpenIssues() - { - $expectedArray = [['id' => '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'open', 'Invalid Commits')); - } - - /** - * @test - */ - public function shouldSearchClosedIssues() - { - $expectedArray = [['id' => '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/KnpLabs/php-github-api/closed/Invalid%20Commits') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'closed', 'Invalid Commits')); - } - - /** - * @test - */ - public function shouldSearchOpenIssuesWhenStateNotRecognized() - { - $expectedArray = [['id' => '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'abc', 'Invalid Commits')); - } - /** * @test */ diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index 547b5dc2797..d13d001d890 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -37,11 +37,9 @@ class RateLimitTest extends TestCase protected $api; /** - * Used to construct common expectations for the API input data in each unit test. - * - * {@inheritdoc} + * @before */ - protected function setUp(): void + public function initMocks() { $this->api = $this->getApiMock(); $this->api->expects($this->once()) @@ -50,14 +48,6 @@ protected function setUp(): void ->will($this->returnValue($this->expectedArray)); } - /** - * @test - */ - public function shouldReturnRateLimitArray() - { - $this->assertSame($this->expectedArray, $this->api->getRateLimits()); - } - /** * @test */ diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 88434750883..9bc5363333b 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -36,44 +36,6 @@ public function shouldShowRepositoryById() $this->assertEquals($expectedArray, $api->showById(123456)); } - /** - * @test - */ - public function shouldSearchRepositories() - { - $expectedArray = [ - ['id' => 1, 'name' => 'php'], - ['id' => 2, 'name' => 'php-cs'], - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/php', ['myparam' => 2, 'start_page' => 1]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('php', ['myparam' => 2])); - } - - /** - * @test - */ - public function shouldPaginateFoundRepositories() - { - $expectedArray = [ - ['id' => 3, 'name' => 'fork of php'], - ['id' => 4, 'name' => 'fork of php-cs'], - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/php', ['start_page' => 2]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('php', ['start_page' => 2])); - } - /** * @test */ diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 795c48fa992..491a58f8602 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -117,25 +117,6 @@ public function shouldGetAllUsersSince() $this->assertEquals($expectedArray, $api->all(2)); } - /** - * @test - */ - public function shouldSearchUsers() - { - $expectedArray = [ - ['id' => 1, 'username' => 'l3l0'], - ['id' => 2, 'username' => 'l3l0test'], - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/user/search/l3l0') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('l3l0')); - } - /** * @test */ diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 15a6bf401ac..e92493cffad 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -68,11 +68,7 @@ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $me public function getAuthenticationFullData() { return [ - ['login', 'password', Client::AUTH_HTTP_PASSWORD], - ['token', null, Client::AUTH_HTTP_TOKEN], - ['token', null, Client::AUTH_URL_TOKEN], ['token', null, Client::AUTH_ACCESS_TOKEN], - ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID], ['client_id', 'client_secret', Client::AUTH_CLIENT_ID], ['token', null, Client::AUTH_JWT], ]; @@ -80,16 +76,15 @@ public function getAuthenticationFullData() /** * @test - * @dataProvider getAuthenticationPartialData */ - public function shouldAuthenticateUsingGivenParameters($token, $method) + public function shouldAuthenticateUsingGivenParameters() { $builder = $this->getMockBuilder(Builder::class) ->setMethods(['addPlugin', 'removePlugin']) ->getMock(); $builder->expects($this->once()) ->method('addPlugin') - ->with($this->equalTo(new Authentication($token, null, $method))); + ->with($this->equalTo(new Authentication('token', null, Client::AUTH_ACCESS_TOKEN))); $builder->expects($this->once()) ->method('removePlugin') @@ -103,15 +98,7 @@ public function shouldAuthenticateUsingGivenParameters($token, $method) ->method('getHttpClientBuilder') ->willReturn($builder); - $client->authenticate($token, $method); - } - - public function getAuthenticationPartialData() - { - return [ - ['token', Client::AUTH_HTTP_TOKEN], - ['token', Client::AUTH_URL_TOKEN], - ]; + $client->authenticate('token', Client::AUTH_ACCESS_TOKEN); } /** diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index a220d355684..625807700ba 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -25,7 +25,7 @@ public function shouldServeCachedResponse() $github = Client::createWithHttpClient($mockClient); $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); - $github->authenticate('fake_token_aaa', Client::AUTH_HTTP_TOKEN); + $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); $userA = $github->currentUser()->show(); $this->assertEquals('nyholm', $userA['login']); @@ -45,11 +45,11 @@ public function shouldVaryOnAuthorization() $github = Client::createWithHttpClient($mockClient); $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); - $github->authenticate('fake_token_aaa', Client::AUTH_HTTP_TOKEN); + $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); $userA = $github->currentUser()->show(); $this->assertEquals('nyholm', $userA['login']); - $github->authenticate('fake_token_bbb', Client::AUTH_HTTP_TOKEN); + $github->authenticate('fake_token_bbb', Client::AUTH_ACCESS_TOKEN); $userB = $github->currentUser()->show(); $this->assertEquals('octocat', $userB['login'], 'We must vary on the Authorization header.'); } diff --git a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php index bcff0d8df88..e8c3d24a6a6 100644 --- a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php +++ b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php @@ -41,11 +41,7 @@ public function testAuthenticationMethods($tokenOrLogin, $password, $method, $ex public function getAuthenticationData() { return [ - ['login', 'password', Client::AUTH_HTTP_PASSWORD, sprintf('Basic %s', base64_encode('login'.':'.'password'))], - ['access_token', null, Client::AUTH_HTTP_TOKEN, 'token access_token'], - ['token', null, Client::AUTH_URL_TOKEN, null, '/?access_token=token'], ['access_token', null, Client::AUTH_ACCESS_TOKEN, 'token access_token'], - ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID, null, '/?client_id=client_id&client_secret=client_secret'], ['client_id', 'client_secret', Client::AUTH_CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))], ['jwt_token', null, Client::AUTH_JWT, 'Bearer jwt_token'], ]; diff --git a/test/Github/Tests/Integration/TestCase.php b/test/Github/Tests/Integration/TestCase.php index 319070d5014..d101b1b1efe 100644 --- a/test/Github/Tests/Integration/TestCase.php +++ b/test/Github/Tests/Integration/TestCase.php @@ -16,7 +16,10 @@ class TestCase extends \PHPUnit\Framework\TestCase */ protected $client; - public function setUp(): void + /** + * @before + */ + public function initClient() { // You have to specify authentication here to run full suite $client = new Client(); From 0e74e30dc8159bde0ea467f9227fdf1d02b0af22 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Sat, 11 Jul 2020 09:01:34 -0700 Subject: [PATCH 770/951] feature #865 add additional check run methods (bobeagan, acrobat) This PR was squashed before being merged into the 2.x branch. Discussion ---------- fixes #864 Commits ------- 3d50b433dbb825bd1dab3261d40c99f09b6686cb add additional check run methods 6b50566f5da7b2ec2a5b9690cf5636d6912369ba fix patch to get fb030b4598f68703175337d4b8cae4bf14c31ce7 Add tests --- doc/repo/checks.md | 33 +++++++++++- lib/Github/Api/Repository/Checks.php | 52 +++++++++++++++++++ .../Tests/Api/Repository/ChecksTest.php | 39 ++++++++++++++ 3 files changed, 122 insertions(+), 2 deletions(-) diff --git a/doc/repo/checks.md b/doc/repo/checks.md index 04cd6144bf7..3e24d9b4868 100644 --- a/doc/repo/checks.md +++ b/doc/repo/checks.md @@ -13,7 +13,7 @@ $params = [ 'details_url' => 'https://nimbleci.com/...', 'output' => {...} ]; -$checks = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $params); +$check = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $params); ``` ### Update an existing check on a commit @@ -27,5 +27,34 @@ $params = [ 'details_url' => 'https://nimbleci.com/...', 'output' => {...} ]; -$checks = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $checkRunId, $params); +$check = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $checkRunId, $params); +``` + +### List check runs for a Git reference + +https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-git-reference + +```php +$params = [ + 'check_name' => 'my check', + 'status' => 'completed', + 'filter' => 'latest', +]; +$checks = $client->api('repo')->checks()->all('NimbleCI', 'docker-web-tester-behat', $ref, $params); +``` + +### Get a check run + +https://developer.github.com/v3/checks/runs/#get-a-check-run + +```php +$check = $client->api('repo')->checks()->show('NimbleCI', 'docker-web-tester-behat', $checkRunId); +``` + +### List check run annotations + +https://developer.github.com/v3/checks/runs/#list-check-run-annotations + +```php +$annotations = $client->api('repo')->checks()->annotations('NimbleCI', 'docker-web-tester-behat', $checkRunId); ``` diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php index fcc7059d2d5..35724a7d112 100644 --- a/lib/Github/Api/Repository/Checks.php +++ b/lib/Github/Api/Repository/Checks.php @@ -55,4 +55,56 @@ public function update($username, $repository, $checkRunId, array $params = []) 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 = []) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + 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) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + 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) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); + } } diff --git a/test/Github/Tests/Api/Repository/ChecksTest.php b/test/Github/Tests/Api/Repository/ChecksTest.php index dcc0883d8d7..6db5695842c 100644 --- a/test/Github/Tests/Api/Repository/ChecksTest.php +++ b/test/Github/Tests/Api/Repository/ChecksTest.php @@ -71,6 +71,45 @@ public function shouldUpdateCheck() $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 */ From 39dff7133d1a0c52761abe65094a78ce1d716d3a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 11 Jul 2020 18:36:28 +0200 Subject: [PATCH 771/951] Remove description line from changelog to allow automatic update --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7cbd25ed8d..ca587cc2228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,4 @@ -# Change Log - -The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +# Changelog ## 2.14.0 From 03445f26843ec44319fe1f3c2a8ef6fcd545a154 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 11 Jul 2020 18:45:45 +0200 Subject: [PATCH 772/951] Update changelog for 2.15.0 release --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca587cc2228..794ce1f1838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 2.15.0 + +### Added +- Prepare deprecation of authentication methods ([acrobat](https://github.com/acrobat)) [#870](https://github.com/KnpLabs/php-github-api/issues/870) +- Add Support For GitData Reference Matching Methods ([nickpoulos](https://github.com/nickpoulos)) [#875](https://github.com/KnpLabs/php-github-api/issues/875) +- Make invalid request error more clear ([acrobat](https://github.com/acrobat)) [#880](https://github.com/KnpLabs/php-github-api/issues/880) +- Show user by ID ([genintho](https://github.com/genintho)) [#894](https://github.com/KnpLabs/php-github-api/issues/894) +- add additional check run methods ([bobeagan](https://github.com/bobeagan), [acrobat](https://github.com/acrobat)) [#865](https://github.com/KnpLabs/php-github-api/issues/865) + +### Changed +- Added phpstan ([clxkoders](https://github.com/clxkoders)) [#871](https://github.com/KnpLabs/php-github-api/issues/871) +- Increase phpstan to level 4 ([acrobat](https://github.com/acrobat)) [#874](https://github.com/KnpLabs/php-github-api/issues/874) +- [Documentation] Add Missing Children to Pull Request Index ([jimlind](https://github.com/jimlind)) [#877](https://github.com/KnpLabs/php-github-api/issues/877) +- [Documentation] Include links to Pull Request Children on Pull Request Doc. ([jimlind](https://github.com/jimlind)) [#878](https://github.com/KnpLabs/php-github-api/issues/878) +- Fix typo in /lib/Github/Api/RateLimit.php ([yoonper](https://github.com/yoonper)) [#886](https://github.com/KnpLabs/php-github-api/issues/886) +- Don't use deprecated auth in examples ([GrahamCampbell](https://github.com/GrahamCampbell)) [#892](https://github.com/KnpLabs/php-github-api/issues/892) +- Removed shadow-cat ([GrahamCampbell](https://github.com/GrahamCampbell)) [#893](https://github.com/KnpLabs/php-github-api/issues/893) +- Don't urlencode integer values ([acrobat](https://github.com/acrobat)) [#895](https://github.com/KnpLabs/php-github-api/issues/895) +- phpstan level 6 fixes ([acrobat](https://github.com/acrobat), [GrahamCampbell](https://github.com/GrahamCampbell)) [#897](https://github.com/KnpLabs/php-github-api/issues/897) + +### Fixed +- fix: use new media type for branch protections ([iBotPeaches](https://github.com/iBotPeaches)) [#881](https://github.com/KnpLabs/php-github-api/issues/881) +- Added missing 'machine-man-preview' accept headers ([vovayatsyuk](https://github.com/vovayatsyuk)) [#883](https://github.com/KnpLabs/php-github-api/issues/883) +- Fix broken roave/bc-check test ([acrobat](https://github.com/acrobat)) [#890](https://github.com/KnpLabs/php-github-api/issues/890) +- Fixed incorrect MissingArgumentException parent constructor values ([acrobat](https://github.com/acrobat)) [#896](https://github.com/KnpLabs/php-github-api/issues/896) +- Added AUTH_ACCESS_TOKEN to allowed methods ([GrahamCampbell](https://github.com/GrahamCampbell)) [#899](https://github.com/KnpLabs/php-github-api/issues/899) + ## 2.14.0 ### Added From c76af658784d3cc947732696b0c6d88a57897947 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 14 Jul 2020 23:02:10 +0100 Subject: [PATCH 773/951] Use RFC3986 for building URI query strings --- lib/Github/Api/AbstractApi.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 9435d8cd530..666ccf1e4d5 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -103,7 +103,7 @@ protected function get($path, array $parameters = [], array $requestHeaders = [] } if (count($parameters) > 0) { - $path .= '?'.http_build_query($parameters); + $path .= '?'.http_build_query($parameters, '', '&', PHP_QUERY_RFC3986); } $response = $this->client->getHttpClient()->get($path, $requestHeaders); @@ -126,7 +126,7 @@ protected function head($path, array $parameters = [], array $requestHeaders = [ unset($parameters['ref']); } - return $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders); + return $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters, '', '&', PHP_QUERY_RFC3986), $requestHeaders); } /** From d934db040114662c67dc120c142cc5fba30beef6 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 18 Jul 2020 20:48:18 +0100 Subject: [PATCH 774/951] Fix the HTTP methods client --- composer.json | 2 +- lib/Github/HttpClient/Builder.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0d253946dcb..047d4646238 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^7.1", - "php-http/client-common": "^2.2", + "php-http/client-common": "^2.3", "php-http/cache-plugin": "^1.7", "php-http/discovery": "^1.9", "php-http/httplug": "^2.1", diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index 47d46527928..bbf35d1b4bf 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -102,7 +102,8 @@ public function getHttpClient() $this->pluginClient = new HttpMethodsClient( (new PluginClientFactory())->createClient($this->httpClient, $plugins), - $this->requestFactory + $this->requestFactory, + $this->streamFactory ); } From 307d74ef15bcf7a4762527f25249b6f3c81a043a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 11 Aug 2020 19:57:38 +0100 Subject: [PATCH 775/951] bug #908 [2.x] Use RFC3986 for building URI query strings (GrahamCampbell) This PR was squashed before being merged into the 2.x branch. Discussion ---------- https://github.com/KnpLabs/php-github-api/pull/906, but for 2.x. Commits ------- 1530c3f298604fd7942d920abc134ac8aa6a5258 Update Authentication.php 6df6b9ef12cf589b5ed57a2c49dcc527afc03b79 Update AbstractApi.php --- lib/Github/Api/AbstractApi.php | 4 ++-- lib/Github/HttpClient/Plugin/Authentication.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index a9204787659..d4d501ed3ec 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -103,7 +103,7 @@ protected function get($path, array $parameters = [], array $requestHeaders = [] } if (count($parameters) > 0) { - $path .= '?'.http_build_query($parameters); + $path .= '?'.http_build_query($parameters, '', '&', PHP_QUERY_RFC3986); } $response = $this->client->getHttpClient()->get($path, $requestHeaders); @@ -126,7 +126,7 @@ protected function head($path, array $parameters = [], array $requestHeaders = [ unset($parameters['ref']); } - return $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters), $requestHeaders); + return $this->client->getHttpClient()->head($path.'?'.http_build_query($parameters, '', '&', PHP_QUERY_RFC3986), $requestHeaders); } /** diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index a70593b8791..669fb1d8965 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -69,7 +69,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla ]; $query .= empty($query) ? '' : '&'; - $query .= utf8_encode(http_build_query($parameters, '', '&')); + $query .= utf8_encode(http_build_query($parameters, '', '&', PHP_QUERY_RFC3986)); $uri = $uri->withQuery($query); $request = $request->withUri($uri); From 9b01208e1e5500201b45699c911ad53d08f59105 Mon Sep 17 00:00:00 2001 From: Eirik Stanghelle Morland Date: Sat, 15 Aug 2020 16:07:38 +0200 Subject: [PATCH 776/951] feature #913 Add support for SSO errors coming from the API (eiriksm) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Hello, thanks for this! I just had a case where a token I used were throwing a runtimeexception because the org in question for the resource, had enforced SAML authentication. This was not something I could explicitly catch and do something with, so here is a PR fixing that. Thanks again, keep up the good work! Commits ------- eec78a70949bcaeb3eeb3808369f21dda06038a3 Add support for SSO errors coming from the API 282fd585d53a3129e2cc382b5c96253c037de4de Code style 9a9bec73a0e374b036204d77e342521c532d0b10 phpstan fixes 51b49cba2d42494dbb82bb874d3f3ec2efe3f3ff Code style e566606dc2ceb81f5f21c5accf6dcce9f108a0ce Add a test for sso required exception 4588ad53175b3c79b4ff050a5a3503ceb892c11a Code style 54cf8f179b192ba3e6c5739cf3525eedefb32bee Code style --- lib/Github/Exception/SsoRequiredException.php | 32 +++++++++++++++++++ .../Plugin/GithubExceptionThrower.php | 11 +++++++ .../Plugin/GithubExceptionThrowerTest.php | 10 ++++++ 3 files changed, 53 insertions(+) create mode 100644 lib/Github/Exception/SsoRequiredException.php diff --git a/lib/Github/Exception/SsoRequiredException.php b/lib/Github/Exception/SsoRequiredException.php new file mode 100644 index 00000000000..6a47eea7738 --- /dev/null +++ b/lib/Github/Exception/SsoRequiredException.php @@ -0,0 +1,32 @@ +url = $url; + + parent::__construct('Resource protected by organization SAML enforcement. You must grant your personal token access to this organization.', $code, $previous); + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } +} diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 60382074a40..b16ec620308 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -5,6 +5,7 @@ use Github\Exception\ApiLimitExceedException; use Github\Exception\ErrorException; use Github\Exception\RuntimeException; +use Github\Exception\SsoRequiredException; use Github\Exception\TwoFactorAuthenticationRequiredException; use Github\Exception\ValidationFailedException; use Github\HttpClient\Message\ResponseMediator; @@ -103,6 +104,16 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla throw new RuntimeException(implode(', ', $errors), 502); } + if ((403 === $response->getStatusCode()) && $response->hasHeader('X-GitHub-SSO') && 0 === strpos((string) ResponseMediator::getHeader($response, 'X-GitHub-SSO'), 'required;')) { + // The header will look something like this: + // required; url=https://github.com/orgs/octodocs-test/sso?authorization_request=AZSCKtL4U8yX1H3sCQIVnVgmjmon5fWxks5YrqhJgah0b2tlbl9pZM4EuMz4 + // So we strip out the first 14 characters, leaving only the URL. + // @see https://developer.github.com/v3/auth/#authenticating-for-saml-sso + $url = substr((string) ResponseMediator::getHeader($response, 'X-GitHub-SSO'), 14); + + throw new SsoRequiredException($url); + } + throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); }); } diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 32be44ce1d5..7011e1fe6bb 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -136,6 +136,16 @@ public static function responseProvider() ), 'exception' => new \Github\Exception\RuntimeException('Something went wrong with executing your query', 502), ], + 'Sso required Response' => [ + 'response' => new Response( + 403, + [ + 'Content-Type' => 'application/json', + 'X-GitHub-SSO' => 'required; url=https://github.com/orgs/octodocs-test/sso?authorization_request=AZSCKtL4U8yX1H3sCQIVnVgmjmon5fWxks5YrqhJgah0b2tlbl9pZM4EuMz4', + ] + ), + 'exception' => new \Github\Exception\SsoRequiredException('https://github.com/orgs/octodocs-test/sso?authorization_request=AZSCKtL4U8yX1H3sCQIVnVgmjmon5fWxks5YrqhJgah0b2tlbl9pZM4EuMz4'), + ], 'Default handling' => [ 'response' => new Response( 555, From d6f66f90383ac5594e32a10887e7fe9c38a955ff Mon Sep 17 00:00:00 2001 From: Michiel Kempen Date: Fri, 11 Sep 2020 13:44:35 +0200 Subject: [PATCH 777/951] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d6637d85f2..f01fd8db17b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/h ### Laravel 6+: ```bash -composer require graham-campbell/github^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 +composer require graham-campbell/github:^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 ``` We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell). From 0440829c882cdc786f04cd7264e5ba80905b24f6 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 28 Sep 2020 10:03:31 +0200 Subject: [PATCH 778/951] Fix: Wrong PHPDoc description --- lib/Github/Api/Search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 84626ae32db..05786ebdb78 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -97,7 +97,7 @@ public function commits($q, $sort = null, $order = 'desc') } /** - * Search commits by filter (q). + * Search topics by filter (q). * * @link https://developer.github.com/v3/search/#search-topics * From 1bc51c4e58da8b41d09858eb4df694fe31d59b89 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 2 Oct 2020 08:23:08 +0200 Subject: [PATCH 779/951] Remove antiope preview header as checks api is now stable --- lib/Github/Api/Repository/Checks.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php index 35724a7d112..8f63c843430 100644 --- a/lib/Github/Api/Repository/Checks.php +++ b/lib/Github/Api/Repository/Checks.php @@ -3,7 +3,6 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; -use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** @@ -13,8 +12,6 @@ */ class Checks extends AbstractApi { - use AcceptHeaderTrait; - /** * @link https://developer.github.com/v3/checks/runs/#create-a-check-run * @@ -32,9 +29,6 @@ public function create($username, $repository, array $params = []) throw new MissingArgumentException(['name', 'head_sha']); } - // This api is in preview mode, so set the correct accept-header. - $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs', $params); } @@ -50,9 +44,6 @@ public function create($username, $repository, array $params = []) */ public function update($username, $repository, $checkRunId, array $params = []) { - // This api is in preview mode, so set the correct accept-header. - $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId), $params); } @@ -68,9 +59,6 @@ public function update($username, $repository, $checkRunId, array $params = []) */ public function all($username, $repository, $ref, $params = []) { - // This api is in preview mode, so set the correct accept-header. - $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); } @@ -85,9 +73,6 @@ public function all($username, $repository, $ref, $params = []) */ public function show($username, $repository, $checkRunId) { - // This api is in preview mode, so set the correct accept-header. - $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId)); } @@ -102,9 +87,6 @@ public function show($username, $repository, $checkRunId) */ public function annotations($username, $repository, $checkRunId) { - // This api is in preview mode, so set the correct accept-header. - $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); } } From da5124c2b94e10f7a1fcdccc7d2419642525e1e2 Mon Sep 17 00:00:00 2001 From: Matthieu Calie Date: Mon, 5 Oct 2020 15:52:12 +0200 Subject: [PATCH 780/951] Add OutsideCollaborators api https://developer.github.com/v3/orgs/outside_collaborators/ --- lib/Github/Api/Organization.php | 9 ++ .../Api/Organization/OutsideCollaborators.php | 52 +++++++++++ lib/Github/Client.php | 92 ++++++++++--------- .../Organization/OutsideCollaboratorsTest.php | 66 +++++++++++++ test/Github/Tests/ClientTest.php | 3 + 5 files changed, 179 insertions(+), 43 deletions(-) create mode 100644 lib/Github/Api/Organization/OutsideCollaborators.php create mode 100644 test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 32eba7d2d87..46dd975ca0a 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -4,6 +4,7 @@ use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; +use Github\Api\Organization\OutsideCollaborators; use Github\Api\Organization\Teams; /** @@ -100,6 +101,14 @@ public function teams() return new Teams($this->client); } + /** + * @return OutsideCollaborators + */ + public function outsideCollaborators() + { + return new OutsideCollaborators($this->client); + } + /** * @link http://developer.github.com/v3/issues/#list-issues * diff --git a/lib/Github/Api/Organization/OutsideCollaborators.php b/lib/Github/Api/Organization/OutsideCollaborators.php new file mode 100644 index 00000000000..958100a56ee --- /dev/null +++ b/lib/Github/Api/Organization/OutsideCollaborators.php @@ -0,0 +1,52 @@ + + */ +class OutsideCollaborators extends AbstractApi +{ + /** + * @link https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators-for-an-organization + * + * @param string $organization the organization + * @param array $params + * + * @return array the organizations + */ + public function all($organization, array $params = []) + { + return $this->get('/orgs/'.rawurlencode($organization).'/outside_collaborators', $params); + } + + /** + * @link https://developer.github.com/v3/orgs/outside_collaborators/#convert-an-organization-member-to-outside-collaborator + * + * @param string $organization the organization + * @param string $username the github username + * + * @return array + */ + public function convert($organization, $username) + { + return $this->put('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username)); + } + + /** + * @link https://developer.github.com/v3/orgs/outside_collaborators/#remove-outside-collaborator-from-an-organization + * + * @param string $organization the organization + * @param string $username the username + * + * @return array + */ + public function remove($organization, $username) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username)); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 86ed95c19d8..a6170570032 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -19,49 +19,50 @@ /** * Simple yet very cool PHP GitHub client. * - * @method Api\CurrentUser currentUser() - * @method Api\CurrentUser me() - * @method Api\Enterprise ent() - * @method Api\Enterprise enterprise() - * @method Api\Miscellaneous\CodeOfConduct codeOfConduct() - * @method Api\Miscellaneous\Emojis emojis() - * @method Api\Miscellaneous\Licenses licenses() - * @method Api\GitData git() - * @method Api\GitData gitData() - * @method Api\Gists gist() - * @method Api\Gists gists() - * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Integrations integration() (deprecated) - * @method Api\Integrations integrations() (deprecated) - * @method Api\Apps apps() - * @method Api\Issue issue() - * @method Api\Issue issues() - * @method Api\Markdown markdown() - * @method Api\Notification notification() - * @method Api\Notification notifications() - * @method Api\Organization organization() - * @method Api\Organization organizations() - * @method Api\Organization\Projects orgProject() - * @method Api\Organization\Projects orgProjects() - * @method Api\Organization\Projects organizationProject() - * @method Api\Organization\Projects organizationProjects() - * @method Api\PullRequest pr() - * @method Api\PullRequest pullRequest() - * @method Api\PullRequest pullRequests() - * @method Api\RateLimit rateLimit() - * @method Api\Repo repo() - * @method Api\Repo repos() - * @method Api\Repo repository() - * @method Api\Repo repositories() - * @method Api\Search search() - * @method Api\Organization\Teams team() - * @method Api\Organization\Teams teams() - * @method Api\User user() - * @method Api\User users() - * @method Api\Authorizations authorization() - * @method Api\Authorizations authorizations() - * @method Api\Meta meta() - * @method Api\GraphQL graphql() + * @method Api\CurrentUser currentUser() + * @method Api\CurrentUser me() + * @method Api\Enterprise ent() + * @method Api\Enterprise enterprise() + * @method Api\Miscellaneous\CodeOfConduct codeOfConduct() + * @method Api\Miscellaneous\Emojis emojis() + * @method Api\Miscellaneous\Licenses licenses() + * @method Api\GitData git() + * @method Api\GitData gitData() + * @method Api\Gists gist() + * @method Api\Gists gists() + * @method Api\Miscellaneous\Gitignore gitignore() + * @method Api\Integrations integration() (deprecated) + * @method Api\Integrations integrations() (deprecated) + * @method Api\Apps apps() + * @method Api\Issue issue() + * @method Api\Issue issues() + * @method Api\Markdown markdown() + * @method Api\Notification notification() + * @method Api\Notification notifications() + * @method Api\Organization organization() + * @method Api\Organization organizations() + * @method Api\Organization\Projects orgProject() + * @method Api\Organization\Projects orgProjects() + * @method Api\Organization\Projects organizationProject() + * @method Api\Organization\Projects organizationProjects() + * @method Api\Organization\OutsideCollaborators outsideCollaborators() + * @method Api\PullRequest pr() + * @method Api\PullRequest pullRequest() + * @method Api\PullRequest pullRequests() + * @method Api\RateLimit rateLimit() + * @method Api\Repo repo() + * @method Api\Repo repos() + * @method Api\Repo repository() + * @method Api\Repo repositories() + * @method Api\Search search() + * @method Api\Organization\Teams team() + * @method Api\Organization\Teams teams() + * @method Api\User user() + * @method Api\User users() + * @method Api\Authorizations authorization() + * @method Api\Authorizations authorizations() + * @method Api\Meta meta() + * @method Api\GraphQL graphql() * * @author Joseph Bielawski * @@ -318,6 +319,11 @@ public function api($name) $api = new Api\GraphQL($this); break; + case 'outsideCollaborators': + case 'outside_collaborators': + $api = new Api\Organization\OutsideCollaborators($this); + break; + default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); } diff --git a/test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php b/test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php new file mode 100644 index 00000000000..eb74b266c09 --- /dev/null +++ b/test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php @@ -0,0 +1,66 @@ + 'KnpLabs']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/outside_collaborators') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldConvertAnOrganizationMemberToOutsideCollaborator() + { + $expectedValue = 'expectedResponse'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/outside_collaborators/username') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->convert('KnpLabs', 'username')); + } + + /** + * @test + */ + public function shouldRemoveAnOutsideCollaboratorFromAnOrganization() + { + $expectedValue = 'expectedResponse'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/outside_collaborators/username') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'username')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Organization\OutsideCollaborators::class; + } +} diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 550bc8169f6..25b559329da 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -209,6 +209,9 @@ public function getApiClassesProvider() ['authorizations', Api\Authorizations::class], ['meta', Api\Meta::class], + + ['outsideCollaborators', Api\Organization\OutsideCollaborators::class], + ['outside_collaborators', Api\Organization\OutsideCollaborators::class], ]; } From 25f92065b293788e6deea56bbe98fcad56190b23 Mon Sep 17 00:00:00 2001 From: Craig Morris Date: Sat, 24 Oct 2020 10:06:05 +0100 Subject: [PATCH 781/951] bug #915 Fix call to test a webhook method (morrislaptop) This PR was squashed before being merged into the 2.x branch. Discussion ---------- See renamed URL in the note at https://docs.github.com/en/rest/reference/repos#test-the-push-repository-webhook Using old URL gives an error "Resource not accessible by integration" Commits ------- 76510c3312ca39e21c827f8745b240cb66c4a549 Fix webhook test function 7c0c814bed644d60955ce36a5e55f47ce4e8fc2d Update HooksTest.php --- lib/Github/Api/Repository/Hooks.php | 2 +- test/Github/Tests/Api/Repository/HooksTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Hooks.php b/lib/Github/Api/Repository/Hooks.php index db67f40270e..be87e0146b6 100644 --- a/lib/Github/Api/Repository/Hooks.php +++ b/lib/Github/Api/Repository/Hooks.php @@ -47,7 +47,7 @@ public function ping($username, $repository, $id) public function test($username, $repository, $id) { - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/test'); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/hooks/'.rawurlencode($id).'/tests'); } public function remove($username, $repository, $id) diff --git a/test/Github/Tests/Api/Repository/HooksTest.php b/test/Github/Tests/Api/Repository/HooksTest.php index 6d1a1b7f328..00cdc69df2c 100644 --- a/test/Github/Tests/Api/Repository/HooksTest.php +++ b/test/Github/Tests/Api/Repository/HooksTest.php @@ -144,7 +144,7 @@ public function shouldTestHook() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/hooks/123/test') + ->with('/repos/KnpLabs/php-github-api/hooks/123/tests') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->test('KnpLabs', 'php-github-api', 123)); From 21feb10975cfb82879402fb6452c6c792dae55df Mon Sep 17 00:00:00 2001 From: Niels Theen Date: Fri, 6 Nov 2020 00:32:30 +0100 Subject: [PATCH 782/951] Adding GitHub authentication to GraphQL documentation --- doc/graphql.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/graphql.md b/doc/graphql.md index 89080b24227..4151012342c 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -9,6 +9,16 @@ Wraps [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/). $rateLimits = $client->api('graphql')->execute($query); ``` +#### Authentication + +To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticated]((../security.md)). + +```php +$client->authenticate($token, null, Github\Client::AUTH_ACCESS_TOKEN); + +$result = $client->api('graphql')->execute($query); +``` + #### Use variables [Variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) allow specifying of requested data without dynamical change of a query on a client side. @@ -28,5 +38,7 @@ $variables = [ 'organizationLogin' => 'KnpLabs' ]; +$client->authenticate('', null, Github\Client::AUTH_ACCESS_TOKEN); + $orgInfo = $client->api('graphql')->execute($query, $variables); -``` \ No newline at end of file +``` From 5cd52a6ea3f95211cabddc7f4f69b91ae27598c9 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 7 Nov 2020 15:13:49 +0100 Subject: [PATCH 783/951] Switch CI setup from travisci to github actions --- .github/workflows/ci.yml | 53 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 36 --------------------------- 2 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000000..c57a68bb60b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,53 @@ +name: CI + +on: + [push, pull_request] + +jobs: + test: + name: Test on ${{ matrix.php-versions }} PHP + runs-on: ubuntu-latest + + strategy: + matrix: + php-versions: ['7.1', '7.2', '7.3', '7.4'] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: xdebug + + - name: Install Composer Dependencies + uses: ramsey/composer-install@v1 + + - name: Run phpunit + run: vendor/bin/phpunit --verbose --coverage-text + + roave_bc_check: + name: Roave BC Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga + + phpstan: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.1 + + - name: Install Composer Dependencies + uses: ramsey/composer-install@v1 + + - name: Run phpstan + run: vendor/bin/phpstan analyse --no-progress diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 137da8275d4..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -language: php - -dist: bionic - -cache: - directories: - - $HOME/.composer/cache - -env: - global: - - TEST_COMMAND="vendor/bin/phpunit --verbose --coverage-text" - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -matrix: - include: - - php: 7.4.7 - name: Backward compatibillity check - env: DEPENDENCIES="roave/backward-compatibility-check" TEST_COMMAND="vendor/bin/roave-backward-compatibility-check" - - php: 7.1 - name: phpstan - script: - - vendor/bin/phpstan analyse --no-progress - -before_install: - - if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi; - -install: - - travis_retry composer install - -script: - - $TEST_COMMAND From 915457749301c9e75dabaac7434e1b4934219bbe Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 7 Nov 2020 18:02:39 +0100 Subject: [PATCH 784/951] Fix bc break in check api class --- lib/Github/Api/Repository/Checks.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php index 8f63c843430..90ca66e7b18 100644 --- a/lib/Github/Api/Repository/Checks.php +++ b/lib/Github/Api/Repository/Checks.php @@ -3,6 +3,7 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** @@ -12,6 +13,9 @@ */ class Checks extends AbstractApi { + // NEXT_MAJOR: remove trait use. + use AcceptHeaderTrait; + /** * @link https://developer.github.com/v3/checks/runs/#create-a-check-run * From 5eaca391e8683160fb441d702270488ff14a078a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 7 Nov 2020 20:00:40 +0100 Subject: [PATCH 785/951] Replace deprecated method call on Psr17FactoryDiscovery --- composer.json | 2 +- lib/Github/Client.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 047d4646238..b7c3b9a7301 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^7.1", "php-http/client-common": "^2.3", "php-http/cache-plugin": "^1.7", - "php-http/discovery": "^1.9", + "php-http/discovery": "^1.11", "php-http/httplug": "^2.1", "php-http/multipart-stream-builder": "^1.1", "psr/cache": "^1.0", diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ca82a6355c5..b2fca10e568 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -122,7 +122,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul $builder->addPlugin(new GithubExceptionThrower()); $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); $builder->addPlugin(new Plugin\RedirectPlugin()); - $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri('https://api.github.com'))); + $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('https://api.github.com'))); $builder->addPlugin(new Plugin\HeaderDefaultsPlugin([ 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ])); @@ -339,7 +339,7 @@ private function setEnterpriseUrl($enterpriseUrl) $builder->removePlugin(Plugin\AddHostPlugin::class); $builder->removePlugin(PathPrepend::class); - $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri($enterpriseUrl))); + $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri($enterpriseUrl))); $builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion()))); } From b9c287326fe26181f08ae161a64ecdf91395c989 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 7 Nov 2020 20:07:01 +0100 Subject: [PATCH 786/951] Apply styleci fixes on master --- lib/Github/Client.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index b2fca10e568..a77a9b8f010 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -31,18 +31,18 @@ * @method Api\Gists gist() * @method Api\Gists gists() * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Apps apps() - * @method Api\Issue issue() - * @method Api\Issue issues() - * @method Api\Markdown markdown() - * @method Api\Notification notification() - * @method Api\Notification notifications() - * @method Api\Organization organization() - * @method Api\Organization organizations() - * @method Api\Organization\Projects orgProject() - * @method Api\Organization\Projects orgProjects() - * @method Api\Organization\Projects organizationProject() - * @method Api\Organization\Projects organizationProjects() + * @method Api\Apps apps() + * @method Api\Issue issue() + * @method Api\Issue issues() + * @method Api\Markdown markdown() + * @method Api\Notification notification() + * @method Api\Notification notifications() + * @method Api\Organization organization() + * @method Api\Organization organizations() + * @method Api\Organization\Projects orgProject() + * @method Api\Organization\Projects orgProjects() + * @method Api\Organization\Projects organizationProject() + * @method Api\Organization\Projects organizationProjects() * @method Api\Organization\OutsideCollaborators outsideCollaborators() * @method Api\PullRequest pr() * @method Api\PullRequest pullRequest() From 119d58b2c08ac5d768a384d3775818bc3f897d96 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 7 Nov 2020 20:09:37 +0100 Subject: [PATCH 787/951] Disable roave bc check until 3.0.0 is released --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c57a68bb60b..8fdae35ce2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,11 +30,13 @@ jobs: roave_bc_check: name: Roave BC Check runs-on: ubuntu-latest + # BC check disabled until 3.0.0 is tagged steps: - - uses: actions/checkout@v2 - - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga + - run: echo true +# - uses: actions/checkout@v2 +# +# - name: Roave BC Check +# uses: docker://nyholm/roave-bc-check-ga phpstan: runs-on: ubuntu-latest From f82214aa1652cbc21f3d3fd6df8cf6a0324f650f Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 8 Nov 2020 14:39:40 +0100 Subject: [PATCH 788/951] feature #931 Add support for creating a repo dispatch event (Nyholm) This PR was squashed before being merged into the 2.x branch. Discussion ---------- If you want to trigger a custom action, you need this API call. Commits ------- 6557c72e57ed6525ca92391df75bfae07a18a1f0 Add support for creating a repo dispatch evnet a068d5cb51f6533dc5d6b92f8ed7aeda26699da1 cs a1527d58fe3416aafbd313b302a4bcc8121eb79a Update URL 8a6a553d44867c4fd52bd148f0c9b805931c17df Style fix --- doc/repos.md | 8 ++++++++ lib/Github/Api/Repo.php | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index c5dbfe89b7a..0c7068987d5 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -346,3 +346,11 @@ You can optionally assign some teams by passing an array with their ID's if you' ```php $repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1234]); ``` + +### Create a repository dispatch event + +Example when you want to configure custom github action workflows. + +```php +$client->api('repo')->dispatch('KnpLabs', 'php-github-api', 'acme-event', ['foo'=>'bar']); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 867cb7efd08..45c36099d53 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -276,6 +276,25 @@ public function readme($username, $repository, $format = 'raw') ]); } + /** + * Create a repository dispatch event. + * + * @link https://developer.github.com/v3/repos/#create-a-repository-dispatch-event + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $eventType A custom webhook event name + * + * @return mixed null on success, array on error with 'message' + */ + public function dispatch($username, $repository, $eventType, array $clientPayload) + { + return $this->post(\sprintf('/repos/%s/%s/dispatches', rawurlencode($username), rawurlencode($repository)), [ + 'event_type' => $eventType, + 'client_payload' => $clientPayload, + ]); + } + /** * Manage the collaborators of a repository. * From e1c5dca1b7d2abeb218a041c29e522d62f7c6a7f Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 8 Nov 2020 14:42:56 +0100 Subject: [PATCH 789/951] Update changelog for 2.16.0 release --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 794ce1f1838..539fe67bea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 2.16.0 + +### Added +- Add support for SSO errors coming from the API ([eiriksm](https://github.com/eiriksm)) [#913](https://github.com/KnpLabs/php-github-api/issues/913) +- Add OutsideCollaborators api ([Matth--](https://github.com/Matth--)) [#925](https://github.com/KnpLabs/php-github-api/issues/925) +- Add support for creating a repo dispatch event ([Nyholm](https://github.com/Nyholm)) [#931](https://github.com/KnpLabs/php-github-api/issues/931) + +### Changed +- Fix: Wrong PHPDoc description ([OskarStark](https://github.com/OskarStark)) [#922](https://github.com/KnpLabs/php-github-api/issues/922) +- Adding GitHub authentication to GraphQL documentation ([legionth](https://github.com/legionth)) [#927](https://github.com/KnpLabs/php-github-api/issues/927) + +### Fixed +- Use RFC3986 for building URI query strings ([GrahamCampbell](https://github.com/GrahamCampbell)) [#908](https://github.com/KnpLabs/php-github-api/issues/908) +- Fix call to test a webhook method ([morrislaptop](https://github.com/morrislaptop)) [#915](https://github.com/KnpLabs/php-github-api/issues/915) + ## 2.15.0 ### Added From 8dac42918fa0bf57da1077724b6780e580b43c86 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 8 Nov 2020 14:49:43 +0100 Subject: [PATCH 790/951] Update branch-alias after 2.16.0 release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 989f686495f..42703e30569 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "2.15.x-dev", + "dev-2.x": "2.16.x-dev", "dev-master": "3.0.x-dev" } } From 9fbd6d1a1fac8affb93cd3a6ae2f13b7151bc40f Mon Sep 17 00:00:00 2001 From: Tobias Schlitt Date: Thu, 12 Nov 2020 10:08:20 +0100 Subject: [PATCH 791/951] Fix: Missing auth method in list of omitted passwords. --- doc/security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/security.md b/doc/security.md index 1ced88b97c2..10608a7eb51 100644 --- a/doc/security.md +++ b/doc/security.md @@ -27,7 +27,7 @@ and guess what should contain `$password`. The `$method` can contain one of the * `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`, -`Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in +`Github\Client::AUTH_HTTP_TOKEN`, `Github\Client::AUTH_ACCESS_TOKEN` and `Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in this particular case). For the `Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID` `$usernameOrToken` should contain your client ID, and `$password` should contain client secret. From 49e774a40d12e160c69d3b572e7a02b397d91e66 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 9 Nov 2020 21:19:21 +0100 Subject: [PATCH 792/951] Improve checks api implementation --- doc/README.md | 3 +- doc/repo/check_runs.md | 67 +++++++++++ doc/repo/check_suites.md | 48 ++++++++ doc/repo/checks.md | 2 + lib/Github/Api/Repo.php | 21 ++++ lib/Github/Api/Repository/Checks.php | 13 ++- .../Api/Repository/Checks/CheckRuns.php | 71 ++++++++++++ .../Api/Repository/Checks/CheckSuites.php | 61 ++++++++++ .../Api/Repository/Checks/CheckRunsTest.php | 109 ++++++++++++++++++ .../Api/Repository/Checks/CheckSuitsTest.php | 93 +++++++++++++++ 10 files changed, 486 insertions(+), 2 deletions(-) create mode 100644 doc/repo/check_runs.md create mode 100644 doc/repo/check_suites.md create mode 100644 lib/Github/Api/Repository/Checks/CheckRuns.php create mode 100644 lib/Github/Api/Repository/Checks/CheckSuites.php create mode 100644 test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php create mode 100644 test/Github/Tests/Api/Repository/Checks/CheckSuitsTest.php diff --git a/doc/README.md b/doc/README.md index 26ddcd6fbd0..361cdaaba8b 100644 --- a/doc/README.md +++ b/doc/README.md @@ -48,7 +48,8 @@ v3 APIs: * [Reviews](pull_request/reviews.md) * [Rate Limits](rate_limits.md) * [Repositories](repos.md) - * [Checks](repo/checks.md) + * [Check Runs](repo/check_runs.md) + * [Check Suites](repo/check_suites.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) * [Labels](repo/labels.md) diff --git a/doc/repo/check_runs.md b/doc/repo/check_runs.md new file mode 100644 index 00000000000..87109e07e69 --- /dev/null +++ b/doc/repo/check_runs.md @@ -0,0 +1,67 @@ +## Repo / Checks runs API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### Create a check run + +[Visit GitHub for a full of list of parameters and their descriptions.](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run) + +```php +$params = [ + 'name' => 'my check', # required + 'head_sha' => $commitSha, # required + 'status' => 'queued', + 'output' => [/*...*/] +]; +$check = $client->api('repo')->checkRuns()->create('KnpLabs', 'php-github-api', $params); +``` + +### Get a check run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-run + +```php +$check = $client->api('repo')->checkRuns()->show('KnpLabs', 'php-github-api', $checkRunId); +``` + +### Update an existing check run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-a-check-run + +```php +$params = [ + 'name' => 'my check', + 'status' => 'in_progress', + 'output' => [/*...*/] +]; +$check = $client->api('repo')->checkRuns()->update('KnpLabs', 'php-github-api', $checkRunId, $params); +``` + +### List check run annotations + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations + +```php +$annotations = $client->api('repo')->checkRuns()->annotations('KnpLabs', 'php-github-api', $checkRunId); +``` + +### List check runs for a check suite + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-in-a-check-suite + +```php +$params = [/*...*/]; +$checks = $client->api('repo')->checkRuns()->allForCheckSuite('KnpLabs', 'php-github-api', $checkSuiteId, $params); +``` + +### List check runs for a Git reference + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-for-a-git-reference + +```php +$params = [/*...*/]; +$checks = $client->api('repo')->checkRuns()->allForReference('KnpLabs', 'php-github-api', $reference, $params); +``` + + + + diff --git a/doc/repo/check_suites.md b/doc/repo/check_suites.md new file mode 100644 index 00000000000..7131674b510 --- /dev/null +++ b/doc/repo/check_suites.md @@ -0,0 +1,48 @@ +## Repo / Check suites API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### Create a check suite + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-suite + +```php +$params = [ + 'head_sha' => $commitSha, # required +]; +$check = $client->api('repo')->checkSuites()->create('KnpLabs', 'php-github-api', $params); +``` + +### Update check suite preferences + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-repository-preferences-for-check-suites + +```php +$params = [/*...*/]; +$check = $client->api('repo')->checkSuites()->updatePreferences('KnpLabs', 'php-github-api', $params); +``` + +### Get a check suite + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-suite + +```php +$check = $client->api('repo')->checkSuites()->getCheckSuite('KnpLabs', 'php-github-api', $checkSuiteId); +``` + +### Rerequest a check suite + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#rerequest-a-check-suite + +```php +$annotations = $client->api('repo')->checkSuites()->rerequest('KnpLabs', 'php-github-api', $checkSuiteId); +``` + + +### List check suites for a Git reference + +https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-suites-for-a-git-reference + +```php +$params = [/*...*/]; +$checks = $client->api('repo')->checkSuites()->allForReference('KnpLabs', 'php-github-api', $reference, $params); +``` diff --git a/doc/repo/checks.md b/doc/repo/checks.md index 3e24d9b4868..f81f1f6f8f3 100644 --- a/doc/repo/checks.md +++ b/doc/repo/checks.md @@ -1,6 +1,8 @@ ## Repo / Checks API [Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +**This API class is deprecated use the [Check runs](check_runs.md) and the [Check suites](check_suites.md) api classes.** + ### Create a check for a commit [Visit GitHub for a full of list of parameters and their descriptions.](https://developer.github.com/v3/checks/runs/#create-a-check-run) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 45c36099d53..76bb1baa1c1 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -3,6 +3,8 @@ namespace Github\Api; use Github\Api\Repository\Checks; +use Github\Api\Repository\Checks\CheckRuns; +use Github\Api\Repository\Checks\CheckSuites; use Github\Api\Repository\Collaborators; use Github\Api\Repository\Comments; use Github\Api\Repository\Commits; @@ -335,14 +337,33 @@ public function commits() * 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->client); } + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-runs + */ + public function checkRuns(): CheckRuns + { + return new CheckRuns($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-suites + */ + public function checkSuites(): CheckSuites + { + return new CheckSuites($this->client); + } + /** * Manage the content of a repository. * diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php index 90ca66e7b18..b4be88668cb 100644 --- a/lib/Github/Api/Repository/Checks.php +++ b/lib/Github/Api/Repository/Checks.php @@ -7,7 +7,8 @@ use Github\Exception\MissingArgumentException; /** - * @link https://developer.github.com/v3/checks/ + * @link https://developer.github.com/v3/checks/ + * @deprecated since 2.17 and will be removed in 3.0. Use the "Github\Api\Repository\Checks\CheckRuns" or "Github\Api\Repository\Checks\CheckSuits" api classes instead. * * @author Zack Galbreath */ @@ -29,6 +30,8 @@ class Checks extends AbstractApi */ 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']); } @@ -48,6 +51,8 @@ public function create($username, $repository, array $params = []) */ 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); } @@ -63,6 +68,8 @@ public function update($username, $repository, $checkRunId, array $params = []) */ 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); } @@ -77,6 +84,8 @@ public function all($username, $repository, $ref, $params = []) */ 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)); } @@ -91,6 +100,8 @@ public function show($username, $repository, $checkRunId) */ 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/Api/Repository/Checks/CheckRuns.php b/lib/Github/Api/Repository/Checks/CheckRuns.php new file mode 100644 index 00000000000..6f91997e8b4 --- /dev/null +++ b/lib/Github/Api/Repository/Checks/CheckRuns.php @@ -0,0 +1,71 @@ +post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs', $params); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-run + * + * @return array + */ + public function show(string $username, string $repository, int $checkRunId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-a-check-run + * + * @return array + */ + public function update(string $username, string $repository, int $checkRunId, array $params = []) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId, $params); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations + * + * @return array + */ + public function annotations(string $username, string $repository, int $checkRunId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId.'/annotations'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-in-a-check-suite + * + * @return array + */ + public function allForCheckSuite(string $username, string $repository, int $checkSuiteId, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId.'/check-runs', $params); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-for-a-git-reference + * + * @return array + */ + public function allForReference(string $username, string $repository, string $ref, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); + } +} diff --git a/lib/Github/Api/Repository/Checks/CheckSuites.php b/lib/Github/Api/Repository/Checks/CheckSuites.php new file mode 100644 index 00000000000..d597fed54e7 --- /dev/null +++ b/lib/Github/Api/Repository/Checks/CheckSuites.php @@ -0,0 +1,61 @@ +post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites', $params); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-repository-preferences-for-check-suites + * + * @return array + */ + public function updatePreferences(string $username, string $repository, array $params = []) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/preferences', $params); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-suite + * + * @return array + */ + public function getCheckSuite(string $username, string $repository, int $checkSuiteId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#rerequest-a-check-suite + * + * @return array + */ + public function rerequest(string $username, string $repository, int $checkSuiteId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId.'/rerequest'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-suites-for-a-git-reference + * + * @return array + */ + public function allForReference(string $username, string $repository, string $ref, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-suites', $params); + } +} diff --git a/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php b/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php new file mode 100644 index 00000000000..4b7ff086ec5 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php @@ -0,0 +1,109 @@ + 'success']; + $data = ['head_sha' => 'commitSHA123456', 'name' => 'my check']; + + /** @var CheckRuns|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/check-runs', $data) + ->willReturn($expectedValue); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + */ + public function shouldShowSingleCheckRun() + { + /** @var CheckRuns|MockObject $api */ + $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 shouldUpdateCheck() + { + $expectedValue = ['state' => 'success']; + $data = ['head_sha' => 'commitSHA123456', 'name' => 'my check']; + + /** @var CheckRuns|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/check-runs/123', $data) + ->willReturn($expectedValue); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + } + + /** + * @test + */ + public function shouldListCheckRunAnnotations() + { + /** @var CheckRuns|MockObject $api */ + $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); + } + + /** + * @test + */ + public function shouldGetAllChecksForCheckSuite() + { + $params = ['test' => true]; + /** @var CheckRuns|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/check-suites/123/check-runs', $params); + + $api->allForCheckSuite('KnpLabs', 'php-github-api', 123, $params); + } + + /** + * @test + */ + public function shouldGetAllChecksForReference() + { + $params = ['test' => true]; + /** @var CheckRuns|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/commits/cb4abc15424c0015b4468d73df55efb8b60a4a3d/check-runs', $params); + + $api->allForReference('KnpLabs', 'php-github-api', 'cb4abc15424c0015b4468d73df55efb8b60a4a3d', $params); + } + + protected function getApiClass(): string + { + return CheckRuns::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Checks/CheckSuitsTest.php b/test/Github/Tests/Api/Repository/Checks/CheckSuitsTest.php new file mode 100644 index 00000000000..87d8831d0da --- /dev/null +++ b/test/Github/Tests/Api/Repository/Checks/CheckSuitsTest.php @@ -0,0 +1,93 @@ + 'success']; + $data = ['head_sha' => 'commitSHA123456', 'name' => 'my check']; + + /** @var CheckSuites|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/check-suites', $data) + ->willReturn($expectedValue); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + */ + public function shouldUpdateCheckSuitePreferences() + { + $expectedValue = ['preferences' => []]; + $data = ['preference_1' => true]; + + /** @var CheckSuites|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/check-suites/preferences', $data) + ->willReturn($expectedValue); + + $this->assertEquals($expectedValue, $api->updatePreferences('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + */ + public function shouldGetCheckSuite() + { + /** @var CheckSuites|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/check-suites/14'); + + $api->getCheckSuite('KnpLabs', 'php-github-api', 14); + } + + /** + * @test + */ + public function shouldRerequest() + { + /** @var CheckSuites|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/check-suites/14/rerequest'); + + $api->rerequest('KnpLabs', 'php-github-api', 14); + } + + /** + * @test + */ + public function shouldGetAllCheckSuitesForReference() + { + /** @var CheckSuites|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/commits/cb4abc15424c0015b4468d73df55efb8b60a4a3d/check-suites'); + + $api->allForReference('KnpLabs', 'php-github-api', 'cb4abc15424c0015b4468d73df55efb8b60a4a3d'); + } + + protected function getApiClass(): string + { + return CheckSuites::class; + } +} From ab89dcd5f845b9f7280bbcee298ff88589097fea Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 12 Nov 2020 18:13:56 +0100 Subject: [PATCH 793/951] Improve github actions setup --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c57a68bb60b..daffb5b9ac4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,10 +5,11 @@ on: jobs: test: - name: Test on ${{ matrix.php-versions }} PHP + name: Test on PHP ${{ matrix.php-versions }} runs-on: ubuntu-latest strategy: + fail-fast: false matrix: php-versions: ['7.1', '7.2', '7.3', '7.4'] @@ -19,13 +20,13 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} - coverage: xdebug + coverage: none - name: Install Composer Dependencies uses: ramsey/composer-install@v1 - name: Run phpunit - run: vendor/bin/phpunit --verbose --coverage-text + run: vendor/bin/phpunit --verbose roave_bc_check: name: Roave BC Check @@ -37,6 +38,7 @@ jobs: uses: docker://nyholm/roave-bc-check-ga phpstan: + name: PHPStan runs-on: ubuntu-latest steps: @@ -45,6 +47,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: 7.1 + coverage: none - name: Install Composer Dependencies uses: ramsey/composer-install@v1 From 26dafcddb9739c0afc16dc74ae6e0ca2f4d0fe38 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 14 Nov 2020 18:07:32 +0100 Subject: [PATCH 794/951] Update changelog for 2.17.0 release --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 539fe67bea3..6d35102f1e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 2.17.0 + +### Added + +- Improve checks api implementation ([acrobat](https://github.com/acrobat)) [#932](https://github.com/KnpLabs/php-github-api/issues/932) + +### Changed +- Missing auth method in list of omitted passwords. ([tobyS](https://github.com/tobyS)) [#933](https://github.com/KnpLabs/php-github-api/issues/933) +- Improve github actions setup ([acrobat](https://github.com/acrobat)) [#935](https://github.com/KnpLabs/php-github-api/issues/935) + ## 2.16.0 ### Added From b586af24435cbb3160b83ab5fc5b7994e9a20f98 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 14 Nov 2020 18:08:31 +0100 Subject: [PATCH 795/951] Update branch alias after 2.17 release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 42703e30569..628307f4d9b 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "2.16.x-dev", + "dev-2.x": "2.17.x-dev", "dev-master": "3.0.x-dev" } } From d4d1dad66d7d1b54baccc9d236b5610bf3cc4a94 Mon Sep 17 00:00:00 2001 From: Ashley Clarke Date: Sat, 14 Nov 2020 19:02:44 +0100 Subject: [PATCH 796/951] Update apps.md --- doc/apps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/apps.md b/doc/apps.md index 7cc9b45a17e..7133ceb117a 100644 --- a/doc/apps.md +++ b/doc/apps.md @@ -36,7 +36,7 @@ $repositories = $client->api('apps')->listRepositories(456); ### List repositories for a given installation and user -``` +```php $repositories = $client->api('current_user')->repositoriesByInstallation(456); ``` From 1831db1bd1a673ed9f2b1c51bed1ced8b74e512f Mon Sep 17 00:00:00 2001 From: Sean Taylor Date: Fri, 20 Nov 2020 13:42:05 +0000 Subject: [PATCH 797/951] feature #938 Add parameters to PullRequest commits method (seanmtaylor) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Add a `$parameters` parameter to the `PullRequest::commits()` method to allow for pagination. As per the docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#list-commits-on-a-pull-request Commits ------- 2069be213d3fc1b102a4559482a63c6260b7d550 Add parameters to PullRequest commits method 86b531f3f2e4237afeb401fc8abb8028e141f809 Add shouldShowCommitsFromPullRequestForPage --- lib/Github/Api/PullRequest.php | 4 ++-- test/Github/Tests/Api/PullRequestTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index ffc713ba4a3..fcc46c84104 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -80,9 +80,9 @@ public function show($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$id); } - public function commits($username, $repository, $id) + public function commits($username, $repository, $id, array $parameters = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits', $parameters); } public function files($username, $repository, $id, array $parameters = []) diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 660368fd4f5..90505535ff9 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -87,6 +87,22 @@ public function shouldShowCommitsFromPullRequest() $this->assertEquals($expectedArray, $api->commits('ezsystems', 'ezpublish', '15')); } + /** + * @test + */ + public function shouldShowCommitsFromPullRequestForPage() + { + $expectedArray = [['id' => 'id', 'sha' => '123123']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/ezsystems/ezpublish/pulls/15/commits', ['page' => 2, 'per_page' => 30]) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->commits('ezsystems', 'ezpublish', '15', ['page' => 2, 'per_page' => 30])); + } + /** * @test */ From 562ca30753396cf12fb1542338cfca3e12696709 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 20 Nov 2020 14:47:14 +0100 Subject: [PATCH 798/951] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 628307f4d9b..05c818c8654 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "2.17.x-dev", + "dev-2.x": "2.18.x-dev", "dev-master": "3.0.x-dev" } } From 2599aad51204d686858a41c715c98e6d0e884a90 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 7 Nov 2020 20:59:04 +0100 Subject: [PATCH 799/951] Allow PHP8 and switch psr cache dev dependency to symfony/cache to allow php8 testing Tweaked minimum versions (by GrahamCampbell) Co-authored-by: Graham Campbell --- .github/workflows/ci.yml | 4 ++-- composer.json | 26 +++++++++++----------- test/Github/Tests/Functional/CacheTest.php | 6 ++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4e55d8ca42..0b4799abe62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.1', '7.2', '7.3', '7.4'] + php-versions: ['7.2', '7.3', '7.4', '8.0'] steps: - uses: actions/checkout@v2 @@ -48,7 +48,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: 7.1 + php-version: 7.2 coverage: none - name: Install Composer Dependencies diff --git a/composer.json b/composer.json index 780369b682e..759ee567756 100644 --- a/composer.json +++ b/composer.json @@ -17,27 +17,27 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2 || ^8.0", + "php-http/cache-plugin": "^1.7.1", "php-http/client-common": "^2.3", - "php-http/cache-plugin": "^1.7", - "php-http/discovery": "^1.11", - "php-http/httplug": "^2.1", - "php-http/multipart-stream-builder": "^1.1", + "php-http/discovery": "^1.12", + "php-http/httplug": "^2.2", + "php-http/multipart-stream-builder": "^1.1.2", "psr/cache": "^1.0", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0" }, "require-dev": { - "cache/array-adapter": "^1.0.1", - "guzzlehttp/psr7": "^1.5.2", + "symfony/cache": "^5.1.8", + "guzzlehttp/psr7": "^1.7", "http-interop/http-factory-guzzle": "^1.0", - "php-http/guzzle6-adapter": "^2.0.1", - "php-http/mock-client": "^1.4", - "phpstan/phpstan": "^0.12.32", - "phpstan/extension-installer": "^1.0.4", - "phpstan/phpstan-deprecation-rules": "^0.12.4", - "phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0" + "guzzlehttp/guzzle": "^7.2", + "php-http/mock-client": "^1.4.1", + "phpstan/phpstan": "^0.12.57", + "phpstan/extension-installer": "^1.0.5", + "phpstan/phpstan-deprecation-rules": "^0.12.5", + "phpunit/phpunit": "^8.5 || ^9.4" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index 625807700ba..58afe5f61f3 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -2,9 +2,9 @@ namespace Github\Tests\Functional; -use Cache\Adapter\PHPArray\ArrayCachePool; use Github\Client; use GuzzleHttp\Psr7\Response; +use Symfony\Component\Cache\Adapter\ArrayAdapter; /** * @group functional @@ -23,7 +23,7 @@ public function shouldServeCachedResponse() $mockClient->addResponse($this->getCurrentUserResponse('octocat')); $github = Client::createWithHttpClient($mockClient); - $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); + $github->addCache(new ArrayAdapter(), ['default_ttl'=>600]); $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); $userA = $github->currentUser()->show(); @@ -43,7 +43,7 @@ public function shouldVaryOnAuthorization() $mockClient->addResponse($this->getCurrentUserResponse('octocat')); $github = Client::createWithHttpClient($mockClient); - $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); + $github->addCache(new ArrayAdapter(), ['default_ttl'=>600]); $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); $userA = $github->currentUser()->show(); From 820186f6bca4d2ca579e5a97a132862e21664a98 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 29 Nov 2020 12:03:45 +0100 Subject: [PATCH 800/951] Throw exception for graphql errors --- .../Plugin/GithubExceptionThrower.php | 36 +++++++++++++++++++ .../Plugin/GithubExceptionThrowerTest.php | 23 ++++++++++++ 2 files changed, 59 insertions(+) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index b16ec620308..4a68aa3921f 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -29,6 +29,8 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla { return $next($request)->then(function (ResponseInterface $response) use ($request) { if ($response->getStatusCode() < 400 || $response->getStatusCode() > 600) { + $this->checkGraphqlErrors($response); + return $response; } @@ -117,4 +119,38 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); }); } + + /** + * The graphql api doesn't return a 5xx http status for errors. Instead it returns a 200 with an error body. + * + * @throws RuntimeException + */ + private function checkGraphqlErrors(ResponseInterface $response): void + { + if ($response->getStatusCode() !== 200) { + return; + } + + $content = ResponseMediator::getContent($response); + if (!is_array($content)) { + return; + } + + if (!isset($content['errors']) || !is_array($content['errors'])) { + return; + } + + $errors = []; + foreach ($content['errors'] as $error) { + if (isset($error['message'])) { + $errors[] = $error['message']; + } + } + + if (empty($errors)) { + return; + } + + throw new RuntimeException(implode(', ', $errors)); + } } diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 7011e1fe6bb..9c1de98d59d 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -154,6 +154,29 @@ public static function responseProvider() ), 'exception' => new \Github\Exception\RuntimeException('Error message', 555), ], + 'Graphql error response (200)' => [ + 'response' => new Response( + 200, + [ + 'content-type' => 'application/json', + ], + json_encode( + [ + 'errors' => [ + [ + ['path' => ['query', 'repository']], + 'message' => 'Field "xxxx" doesn\'t exist on type "Issue"', + ], + [ + ['path' => ['query', 'repository']], + 'message' => 'Field "dummy" doesn\'t exist on type "PullRequest"', + ], + ], + ] + ) + ), + 'exception' => new \Github\Exception\RuntimeException('Field "xxxx" doesn\'t exist on type "Issue", Field "dummy" doesn\'t exist on type "PullRequest"'), + ], ]; } } From 8df513307092563bf45aedc9405c8ceaafb4cf57 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 29 Nov 2020 19:13:53 +0000 Subject: [PATCH 801/951] Make PHP 7.2.5 the minimum version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 759ee567756..f33d730c767 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^7.2.5 || ^8.0", "php-http/cache-plugin": "^1.7.1", "php-http/client-common": "^2.3", "php-http/discovery": "^1.12", From 703955e44615c059425c908634cada6e0bd9c49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20DE=C4=9EER?= Date: Mon, 30 Nov 2020 11:18:16 +0300 Subject: [PATCH 802/951] repo: added actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(actions): added self-hosted runners Signed-off-by: Emre DEĞER repo: added actions feat(actions): added self-hosted runners Signed-off-by: Emre DEĞER repo: added actions refactored fix(actions: reformated self-hosted runners repo: added actions refactored fix(actions: reformated self-hosted runners feat(actions): added repo's secrets Signed-off-by: Emre DEĞER feat(actions): added organization's secrets Signed-off-by: Emre DEĞER feat(actions): formated Signed-off-by: Emre DEĞER docs(actions): updated php doc blocks updated `@link` for new docs Signed-off-by: Emre DEĞER feat(actions): updated for requested changes Signed-off-by: Emre DEĞER feat(actions): added docs Signed-off-by: Emre DEĞER feat(actions): updated download example cases Signed-off-by: Emre DEĞER fix(actions): removed todos Signed-off-by: Emre DEĞER --- README.md | 1 + doc/organization/actions/secrets.md | 85 +++++++ doc/repo/actions/artifacts.md | 44 ++++ doc/repo/actions/secrets.md | 54 +++++ doc/repo/actions/self_hosted_runners.md | 35 +++ doc/repo/actions/workflow_jobs.md | 27 +++ doc/repo/actions/workflow_runs.md | 76 ++++++ doc/repo/actions/workflows.md | 26 +++ lib/Github/Api/Organization.php | 9 + .../Api/Organization/Actions/Secrets.php | 144 ++++++++++++ lib/Github/Api/Repo.php | 54 +++++ .../Api/Repository/Actions/Artifacts.php | 82 +++++++ lib/Github/Api/Repository/Actions/Secrets.php | 95 ++++++++ .../Repository/Actions/SelfHostedRunners.php | 65 ++++++ .../Api/Repository/Actions/WorkflowJobs.php | 54 +++++ .../Api/Repository/Actions/WorkflowRuns.php | 139 +++++++++++ .../Api/Repository/Actions/Workflows.php | 53 +++++ .../Api/Organization/Actions/SecretsTest.php | 219 ++++++++++++++++++ .../Api/Repository/Actions/ArtifactsTest.php | 96 ++++++++ .../Api/Repository/Actions/SecretsTest.php | 136 +++++++++++ .../Actions/SelfHostedRunnersTest.php | 115 +++++++++ .../Repository/Actions/WorkflowJobsTest.php | 57 +++++ .../Repository/Actions/WorkflowRunsTest.php | 205 ++++++++++++++++ .../Api/Repository/Actions/WorkflowsTest.php | 96 ++++++++ 24 files changed, 1967 insertions(+) create mode 100644 doc/organization/actions/secrets.md create mode 100644 doc/repo/actions/artifacts.md create mode 100644 doc/repo/actions/secrets.md create mode 100644 doc/repo/actions/self_hosted_runners.md create mode 100644 doc/repo/actions/workflow_jobs.md create mode 100644 doc/repo/actions/workflow_runs.md create mode 100644 doc/repo/actions/workflows.md create mode 100644 lib/Github/Api/Organization/Actions/Secrets.php create mode 100644 lib/Github/Api/Repository/Actions/Artifacts.php create mode 100644 lib/Github/Api/Repository/Actions/Secrets.php create mode 100644 lib/Github/Api/Repository/Actions/SelfHostedRunners.php create mode 100644 lib/Github/Api/Repository/Actions/WorkflowJobs.php create mode 100644 lib/Github/Api/Repository/Actions/WorkflowRuns.php create mode 100644 lib/Github/Api/Repository/Actions/Workflows.php create mode 100644 test/Github/Tests/Api/Organization/Actions/SecretsTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/SecretsTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php diff --git a/README.md b/README.md index 47ff1282522..c715a8dc5f2 100644 --- a/README.md +++ b/README.md @@ -109,5 +109,6 @@ This library is maintained by the following people (alphabetically sorted) : - Thanks to [Nicolas Pastorino](http://github.com/jeanvoye) for his contribution on the Pull Request API. - Thanks to [Edoardo Rivello](http://github.com/erivello) for his contribution on the Gists API. - Thanks to [Miguel Piedrafita](https://github.com/m1guelpf) for his contribution to the v4 & Apps API. +- Thanks to [Emre DEGER](https://github.com/lexor) for his contribution to the Actions API. Thanks to GitHub for the high quality API and documentation. diff --git a/doc/organization/actions/secrets.md b/doc/organization/actions/secrets.md new file mode 100644 index 00000000000..113a37997ac --- /dev/null +++ b/doc/organization/actions/secrets.md @@ -0,0 +1,85 @@ +## Organization / Secrets API +[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md) + +### List organization secrets + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-organization-secrets + +```php +$secrets = $client->organization()->secrets()->all('KnpLabs'); +``` + +### Get an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-secret + +```php +$secret = $client->organization()->secrets()->show('KnpLabs', $secretName); +``` + +### Create an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + +```php +$client->organization()->secrets()->create('KnpLabs', $secretName, [ + 'encrypted_value' => $encryptedValue, + 'visibility' => $visibility, + 'selected_repository_ids' => $selectedRepositoryIds, +]); +``` + +### Update an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + +```php +$client->organization()->secrets()->update('KnpLabs', $secretName, [ + 'key_id' => 'keyId', + 'encrypted_value' => 'encryptedValue', + 'visibility' => 'private', +]); +``` + +### Delete an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-organization-secret + +```php +$client->organization()->secrets()->remove('KnpLabs', $secretName); +``` + +### List selected repositories for organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-selected-repositories-for-an-organization-secret + +```php +$client->organization()->secrets()->selectedRepositories('KnpLabs', $secretName); +``` + +### Set selected repositories for an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#set-selected-repositories-for-an-organization-secret + +```php +$client->organization()->secrets()->setSelectedRepositories('KnpLabs', 'secretName', [ + 'selected_repository_ids' => [1, 2, 3], +]); +``` + +### Remove selected repository from an organization secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#remove-selected-repository-from-an-organization-secret + +```php +$client->organization()->secrets()->addSecret('KnpLabs', $repositoryId, $secretName); +``` + +### Get an organization public key + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-public-key + +```php +$client->organization()->secrets()->publicKey('KnpLabs'); +``` + diff --git a/doc/repo/actions/artifacts.md b/doc/repo/actions/artifacts.md new file mode 100644 index 00000000000..b457f12c806 --- /dev/null +++ b/doc/repo/actions/artifacts.md @@ -0,0 +1,44 @@ +## Repo / Artifacts API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List artifacts for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-artifacts-for-a-repository + +```php +$artifacts = $client->api('repo')->artifacts()->all('KnpLabs'); +``` + +### List workflow run artifacts + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-run-artifacts + +```php +$runArtifacts = $client->api('repo')->artifacts()->runArtifacts('KnpLabs', 'php-github-api', $runId); +``` + +### Get an artifact + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-artifact + +```php +$artifact = $client->api('repo')->artifacts()->show('KnpLabs', 'php-github-api', $artifactId); +``` + +### Delete an artifact + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-artifact + +```php +$client->api('repo')->artifacts()->delete('KnpLabs', 'php-github-api', $artifactId); +``` + + +### Download an artifact + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact + +```php +$artifactFile = $client->api('repo')->artifacts()->download('KnpLabs', 'php-github-api', $artifactId, $format = 'zip'); +file_put_contents($artifactId.'.'.$format, $artifactFile); +``` diff --git a/doc/repo/actions/secrets.md b/doc/repo/actions/secrets.md new file mode 100644 index 00000000000..037409fd53e --- /dev/null +++ b/doc/repo/actions/secrets.md @@ -0,0 +1,54 @@ +## Repo / Secrets API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List repository secrets + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-secrets + +```php +$secrets = $client->api('repo')->secrets()->all('KnpLabs', 'php-github-api'); +``` + +### Get a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-secret + +```php +$secret = $client->api('repo')->secrets()->show('KnpLabs', 'php-github-api', $secretName); +``` + +### Create a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + +```php +$client->api('repo')->secrets()->create('KnpLabs', 'php-github-api', $secretName, [ + 'encrypted_value' => $encryptedValue, +]); $client->api('repo')->secrets()->all(); +``` + +### Update a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + +```php +$client->api('repo')->secrets()->update('KnpLabs', 'php-github-api', $secretName, [ + 'key_id' => $keyId, 'encrypted_value' => $encryptedValue, +]); +``` + +### Delete a repository secret + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-repository-secret + +```php +$client->api('repo')->secrets()->remove('KnpLabs', 'php-github-api', $secretName); +``` + +### Get a repository public key + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-public-key + +```php +$publicKey = $client->api('repo')->secrets()->publicKey('KnpLabs', 'php-github-api'); +``` diff --git a/doc/repo/actions/self_hosted_runners.md b/doc/repo/actions/self_hosted_runners.md new file mode 100644 index 00000000000..1c09767d6cd --- /dev/null +++ b/doc/repo/actions/self_hosted_runners.md @@ -0,0 +1,35 @@ +## Repo / Self Hosted Runners API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +# List self-hosted runners for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-self-hosted-runners-for-a-repository + +```php +$runners = $client->api('repo')->selfHostedRunners()->all('KnpLabs', 'php-github-api'); +``` + +# Get a self-hosted runner for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-self-hosted-runner-for-a-repository + +```php +$runner = $client->api('repo')->selfHostedRunners()->show('KnpLabs', 'php-github-api', $runnerId); +``` + +# Delete a self-hosted runner from a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository + +```php +$client->api('repo')->selfHostedRunners()->remove('KnpLabs', 'php-github-api', $runnerId); +``` + +# List runner applications for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-runner-applications-for-a-repository + +```php +$applications = $client->api('repo')->selfHostedRunners()->applications('KnpLabs', 'php-github-api'); +``` + diff --git a/doc/repo/actions/workflow_jobs.md b/doc/repo/actions/workflow_jobs.md new file mode 100644 index 00000000000..151c59c5e95 --- /dev/null +++ b/doc/repo/actions/workflow_jobs.md @@ -0,0 +1,27 @@ +## Repo / Workflow Jobs API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List jobs for a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-jobs-for-a-workflow-run + +```php +$client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $runId); +``` + +### Get a job for a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-job-for-a-workflow-run + +```php +$job = $client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $jobId); +``` + +### Download job logs for a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-job-logs-for-a-workflow-run + +```php +$jobLogs = $client->api('repo')->workflowJobs()->downloadLogs('KnpLabs', 'php-github-api', $jobId); +file_put_contents('jobLogs.zip', $jobLogs); +``` diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md new file mode 100644 index 00000000000..88c6da7c621 --- /dev/null +++ b/doc/repo/actions/workflow_runs.md @@ -0,0 +1,76 @@ +## Repo / Workflow Runs API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List workflow runs for a repository + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs-for-a-repository + +```php +$workflowRuns = $client->api('repo')->workflowRuns()->all('KnpLabs', 'php-github-api'); +``` + +### List workflow runs + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs + +```php +$runs = $client->api('repo')->workflowRuns()->listRuns('KnpLabs', 'php-github-api', $workflowId); +``` + +### Get a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow-run + +```php +$workflowRun = $client->api('repo')->workflowRuns()->show('KnpLabs', 'php-github-api', $runId); +``` + +### Delete a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run + +```php +$client->api('repo')->workflowRuns()->remove('KnpLabs', 'php-github-api', $runId); +``` + +### Re-run a workflow + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#re-run-a-workflow + +```php +$client->api('repo')->workflowRuns()->rerun('KnpLabs', 'php-github-api', $runId); +``` + +### Cancel a workflow run + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#cancel-a-workflow-run + +```php +$client->api('repo')->workflowRuns()->cancel('KnpLabs', 'php-github-api', $runId); +``` + +### Get workflow run usage + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-run-usage + +```php +$workflowUsage = $client->api('repo')->workflowRuns()->usage('KnpLabs', 'php-github-api', $runId); +``` + +### Download workflow run logs + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-workflow-run-logs + +```php +$logs = $client->api('repo')->workflowRuns()->downloadLogs('KnpLabs', 'php-github-api', $runId); + +file_put_contents('logs.zip', $logs); +``` + +### Delete workflow run logs + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-workflow-run-logs + +```php +$client->api('repo')->workflowRuns()->deleteLogs('KnpLabs', 'php-github-api', $runId); +``` diff --git a/doc/repo/actions/workflows.md b/doc/repo/actions/workflows.md new file mode 100644 index 00000000000..d6689d90aa2 --- /dev/null +++ b/doc/repo/actions/workflows.md @@ -0,0 +1,26 @@ +## Repo / Workflows API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +### List repository workflows + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows + +```php +$workflows = $client->api('repo')->workflows()->all('KnpLabs', 'php-github-api'); +``` + +### Get a workflow + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow + +```php +$workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', $workflowId); +``` + +### Get workflow usage + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage + +```php +$usage = $client->api('repo')->workflows()->usage('KnpLabs', 'php-github-api', $workflowId); +``` diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 46dd975ca0a..be4df40ac25 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Organization\Actions\Secrets; use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; use Github\Api\Organization\OutsideCollaborators; @@ -101,6 +102,14 @@ public function teams() return new Teams($this->client); } + /** + * @return Secrets + */ + public function secrets(): Secrets + { + return new Secrets($this->client); + } + /** * @return OutsideCollaborators */ diff --git a/lib/Github/Api/Organization/Actions/Secrets.php b/lib/Github/Api/Organization/Actions/Secrets.php new file mode 100644 index 00000000000..7a08212907f --- /dev/null +++ b/lib/Github/Api/Organization/Actions/Secrets.php @@ -0,0 +1,144 @@ +get('/orgs/'.rawurlencode($organization).'/actions/secrets'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-secret + * + * @param string $organization + * @param string $secretName + * + * @return array|string + */ + public function show(string $organization, string $secretName) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + * + * @param string $organization + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function create(string $organization, string $secretName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + * + * @param string $organization + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function update(string $organization, string $secretName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-organization-secret + * + * @param string $organization + * @param string $secretName + * + * @return array|string + */ + public function remove(string $organization, string $secretName) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-selected-repositories-for-an-organization-secret + * + * @param string $organization + * @param string $secretName + * + * @return array|string + */ + public function selectedRepositories(string $organization, string $secretName) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#set-selected-repositories-for-an-organization-secret + * + * @param string $organization + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function setSelectedRepositories(string $organization, string $secretName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#add-selected-repository-to-an-organization-secret + * + * @param string $organization + * @param string $repositoryId + * @param string $secretName + * + * @return array|string + */ + public function addSecret(string $organization, string $repositoryId, string $secretName) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories/'.$repositoryId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#remove-selected-repository-from-an-organization-secret + * + * @param string $organization + * @param string $repositoryId + * @param string $secretName + * + * @return array|string + */ + public function removeSecret(string $organization, string $repositoryId, string $secretName) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories/'.$repositoryId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-public-key + * + * @param string $organization + * + * @return array|string + */ + public function publicKey(string $organization) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/secret-key'); + } +} diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 76bb1baa1c1..b9b02ea0b30 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -2,6 +2,12 @@ namespace Github\Api; +use Github\Api\Repository\Actions\Artifacts; +use Github\Api\Repository\Actions\Secrets; +use Github\Api\Repository\Actions\SelfHostedRunners; +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; @@ -364,6 +370,54 @@ public function checkSuites(): CheckSuites return new CheckSuites($this->client); } + /** + * @link https://developer.github.com/v3/actions/artifacts/#artifacts + */ + public function artifacts(): Artifacts + { + return new Artifacts($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflows + */ + public function workflows(): Workflows + { + return new Workflows($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-runs + */ + public function workflowRuns(): WorkflowRuns + { + return new WorkflowRuns($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-jobs + */ + public function workflowJobs(): WorkflowJobs + { + return new WorkflowJobs($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#self-hosted-runners + */ + public function selfHostedRunners(): SelfHostedRunners + { + return new SelfHostedRunners($this->client); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#secrets + */ + public function secrets(): Secrets + { + return new Secrets($this->client); + } + /** * Manage the content of a repository. * diff --git a/lib/Github/Api/Repository/Actions/Artifacts.php b/lib/Github/Api/Repository/Actions/Artifacts.php new file mode 100644 index 00000000000..b81d560b00d --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Artifacts.php @@ -0,0 +1,82 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-run-artifacts + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function runArtifacts(string $username, string $repository, int $runId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/artifacts'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-artifact + * + * @param string $username + * @param string $repository + * @param int $artifactId + * + * @return array + */ + public function show(string $username, string $repository, int $artifactId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts/'.$artifactId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-artifact + * + * @param string $username + * @param string $repository + * @param int $artifactId + * + * @return array + */ + public function remove(string $username, string $repository, int $artifactId) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts/'.$artifactId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact + * + * @param string $username + * @param string $repository + * @param int $artifactId + * @param string $format + * + * @return array + */ + public function download(string $username, string $repository, int $artifactId, string $format = 'zip') + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/artifacts/'.$artifactId.'/'.$format); + } +} diff --git a/lib/Github/Api/Repository/Actions/Secrets.php b/lib/Github/Api/Repository/Actions/Secrets.php new file mode 100644 index 00000000000..4c38de203dc --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Secrets.php @@ -0,0 +1,95 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * + * @return array|string + */ + public function show(string $username, string $repository, string $secretName) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function create(string $username, string $repository, string $secretName, array $parameters = []) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function update(string $username, string $repository, string $secretName, array $parameters = []) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-repository-secret + * + * @param string $username + * @param string $repository + * @param string $secretName + * + * @return array|string + */ + public function remove(string $username, string $repository, string $secretName) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-public-key + * + * @param string $username + * @param string $repository + * + * @return array|string + */ + public function publicKey(string $username, string $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/secret-key'); + } +} diff --git a/lib/Github/Api/Repository/Actions/SelfHostedRunners.php b/lib/Github/Api/Repository/Actions/SelfHostedRunners.php new file mode 100644 index 00000000000..4a20b1169bf --- /dev/null +++ b/lib/Github/Api/Repository/Actions/SelfHostedRunners.php @@ -0,0 +1,65 @@ +get('/repos/'.rawurlencode($username).'/'.rawurldecode($repository).'/actions/runners'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-self-hosted-runner-for-a-repository + * + * @param string $username + * @param string $repository + * @param int $runnerId + * + * @return array|string + */ + public function show(string $username, string $repository, int $runnerId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurldecode($repository).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository + * + * @param string $username + * @param string $repository + * @param int $runnerId + * + * @return array|string + */ + public function remove(string $username, string $repository, int $runnerId) + { + return $this->delete('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-runner-applications-for-a-repository + * + * @param string $username + * @param string $repository + * + * @return array|string + */ + public function applications(string $username, string $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runners/downloads'); + } +} diff --git a/lib/Github/Api/Repository/Actions/WorkflowJobs.php b/lib/Github/Api/Repository/Actions/WorkflowJobs.php new file mode 100644 index 00000000000..edcb806ee6c --- /dev/null +++ b/lib/Github/Api/Repository/Actions/WorkflowJobs.php @@ -0,0 +1,54 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/jobs', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-job-for-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $jobId + * + * @return array + */ + public function show(string $username, string $repository, int $jobId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/jobs/'.$jobId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-job-logs-for-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $jobId + * + * @return array + */ + public function downloadLogs(string $username, string $repository, int $jobId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/jobs/'.$jobId.'/logs'); + } +} diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php new file mode 100644 index 00000000000..27213826207 --- /dev/null +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -0,0 +1,139 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs + * + * @param string $username + * @param string $repository + * @param string $workflowId + * @param array $parameters + * + * @return array + */ + public function listRuns(string $username, string $repository, string $workflowId, array $parameters = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId.'/runs', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $runId + * @param array $parameters + * + * @return array + */ + public function show(string $username, string $repository, int $runId, array $parameters = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId, $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + */ + public function remove(string $username, string $repository, int $runId) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#re-run-a-workflow + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function rerun(string $username, string $repository, int $runId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/rerun'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#cancel-a-workflow-run + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function cancel(string $username, string $repository, int $runId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/cancel'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-run-usage + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array + */ + public function usage(string $username, string $repository, int $runId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/timing'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-workflow-run-logs + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + */ + public function downloadLogs(string $username, string $repository, int $runId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-workflow-run-logs + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + */ + public function deleteLogs(string $username, string $repository, int $runId) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs'); + } +} diff --git a/lib/Github/Api/Repository/Actions/Workflows.php b/lib/Github/Api/Repository/Actions/Workflows.php new file mode 100644 index 00000000000..3843c59a0ba --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Workflows.php @@ -0,0 +1,53 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows', $parameters); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow + * + * @param string $username + * @param string $repository + * @param int $workflowId + * + * @return array + */ + public function show(string $username, string $repository, int $workflowId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage + * + * @param string $username + * @param string $repository + * @param int $workflowId + * + * @return array|string + */ + public function usage(string $username, string $repository, int $workflowId) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId.'/timing'); + } +} diff --git a/test/Github/Tests/Api/Organization/Actions/SecretsTest.php b/test/Github/Tests/Api/Organization/Actions/SecretsTest.php new file mode 100644 index 00000000000..cf10c066c99 --- /dev/null +++ b/test/Github/Tests/Api/Organization/Actions/SecretsTest.php @@ -0,0 +1,219 @@ + 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'all'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'private'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'selected'], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetOrganizationSecret() + { + $expectedArray = []; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'secretName')); + } + + /** + * @test + */ + public function shouldCreateOrganizationSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'secretName', [ + 'encrypted_value' => 'foo', 'visibility' => 'all', 'selected_repository_ids' => [1, 2, 3], + ])); + } + + /** + * @test + */ + public function shouldUpdateOrganizationSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'secretName', [ + 'key_id' => 'keyId', + 'encrypted_value' => 'encryptedValue', + 'visibility' => 'private', + ])); + } + + /** + * @test + */ + public function shouldRemoveOrganizationSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'secretName')); + } + + /** + * @test + */ + public function shouldGetSelectedRepositories() + { + $expectedArray = [1, 2, 3]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->selectedRepositories('KnpLabs', 'secretName')); + } + + /** + * @test + */ + public function shouldSetSelectedRepositories() + { + $expectedArray = [ + 'selected_repository_ids' => [1, 2, 3], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->setSelectedRepositories('KnpLabs', 'secretName', [ + 'selected_repository_ids' => [1, 2, 3], + ])); + } + + /** + * @test + */ + public function shouldAddSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addSecret('KnpLabs', '1', 'secretName')); + } + + /** + * @test + */ + public function shouldRemoveSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/secrets/secretName/repositories/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeSecret('KnpLabs', '1', 'secretName')); + } + + /** + * @test + */ + public function shouldGetPublicKey() + { + $expectedArray = ['key_id' => 'key_id', 'key' => 'foo']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/secrets/secret-key') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->publicKey('KnpLabs')); + } + + protected function getApiClass() + { + return Secrets::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php b/test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php new file mode 100644 index 00000000000..90ace988bab --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/ArtifactsTest.php @@ -0,0 +1,96 @@ + 'id', + 'node_id' => 'node_id', + 'name' => 'name', + 'size_in_bytes' => 453, + 'url' => 'foo', + 'archive_download_url' => 'foo', + 'expired' => false, + 'created_at' => '2020-01-10T14:59:22Z', + 'expires_at' => '2020-01-21T14:59:22Z', + ], + ]; + + /** @var Artifacts|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/artifacts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetRunArtifacts() + { + $expectedArray = [ + [ + 'id' => 'id', + 'node_id' => 'node_id', + 'name' => 'name', + 'size_in_bytes' => 453, + 'url' => 'foo', + 'archive_download_url' => 'foo', + 'expired' => false, + 'created_at' => '2020-01-10T14:59:22Z', + 'expires_at' => '2020-01-21T14:59:22Z', + ], + ]; + + /** @var Artifacts|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/1/artifacts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->runArtifacts('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldRemoveArtifact() + { + $expectedValue = 'response'; + + /** @var Artifacts|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/artifacts/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 1)); + } + + protected function getApiClass() + { + return Artifacts::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/SecretsTest.php b/test/Github/Tests/Api/Repository/Actions/SecretsTest.php new file mode 100644 index 00000000000..670e623b688 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/SecretsTest.php @@ -0,0 +1,136 @@ + 'GH_TOKEN', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'GIST_ID', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/secrets') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSecret() + { + $expectedArray = ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 'secretName')); + } + + /** + * @test + */ + public function shouldCreateSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'secretName', [ + 'encrypted_value' => 'encryptedValue', + ])); + } + + /** + * @test + */ + public function shouldUpdateSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'secretName', [ + 'key_id' => 'keyId', 'encrypted_value' => 'encryptedValue', + ])); + } + + /** + * @test + */ + public function shouldRemoveSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'secretName')); + } + + /** + * @test + */ + public function shouldGetPublicKey() + { + $expectedArray = ['key_id' => 'key_id', 'key' => 'foo']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/secret-key') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->publicKey('KnpLabs', 'php-github-api')); + } + + protected function getApiClass() + { + return Secrets::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php b/test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php new file mode 100644 index 00000000000..67c8eade4bd --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/SelfHostedRunnersTest.php @@ -0,0 +1,115 @@ + 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ], + [ + 'id' => 2, + 'name' => 'iMac', + 'os' => 'macos', + 'status' => 'offline', + ], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runners') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunner() + { + $expectedArray = [ + 'id' => 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runners/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldRemoveSelfHostedRunner() + { + $expectedValue = 'response'; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/runners/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunnerApps() + { + $expectedArray = [ + ['os' => 'osx', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'win', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm64', 'download_url' => 'download_url', 'filename' => 'filename'], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runners/downloads') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->applications('KnpLabs', 'php-github-api')); + } + + protected function getApiClass() + { + return SelfHostedRunners::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php new file mode 100644 index 00000000000..4af8b52ebc9 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowJobsTest.php @@ -0,0 +1,57 @@ + 'id', 'run_id' => 'run_id', 'status' => 'completed', 'conclusion' => 'success'], + ]; + + /** @var WorkflowJobs|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/1/jobs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldShowWorkflowJob() + { + $expectedArray = [ + 'id' => 'id', 'run_id' => 'run_id', 'status' => 'completed', 'conclusion' => 'success', + ]; + + /** @var WorkflowJobs|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/jobs/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 1)); + } + + protected function getApiClass() + { + return WorkflowJobs::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php new file mode 100644 index 00000000000..27155148ce0 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php @@ -0,0 +1,205 @@ + 'id', + 'event' => 'push', + 'status' => 'queued', + ], + ]; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetWorkflowRuns() + { + $expectedArray = [ + [ + 'id' => 'id', + 'name' => 'CI', + 'event' => 'push', + 'status' => 'completed', + 'conclusion' => 'success', + 'workflow_id' => 3441570, + ], + ]; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/3441570/runs') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->listRuns('KnpLabs', 'php-github-api', 3441570)); + } + + /** + * @test + */ + public function shouldShowWorkflowRun() + { + $expectedArray = ['id' => 'id', 'name' => 'CI']; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldDeleteWorkflowRun() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldGetWorkflowRunUsage() + { + $expectedArray = [ + 'billable' => [ + 'UBUNTU' => ['total_ms' => 180000, 'jobs' => 1], + 'MACOS' => ['total_ms' => 240000, 'jobs' => 1], + 'WINDOWS' => ['total_ms' => 300000, 'jobs' => 1], + ], + 'run_duration_ms' => 500000, + ]; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/timing') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->usage('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldRerunWorkflowRun() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/rerun') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->rerun('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldCancelWorkflowRun() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/cancel') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->cancel('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldDownloadWorkflowRunLogs() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/logs') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->downloadLogs('KnpLabs', 'php-github-api', 374473304)); + } + + /** + * @test + */ + public function shouldDeleteWorkflowRunLogs() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/logs') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteLogs('KnpLabs', 'php-github-api', 374473304)); + } + + protected function getApiClass() + { + return WorkflowRuns::class; + } +} diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php new file mode 100644 index 00000000000..a018f396531 --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php @@ -0,0 +1,96 @@ + 'id', + 'node_id' => 'node_id', + 'name' => 'CI', + 'path' => '.github/workflows/ci.yml', + 'state' => 'active', + 'created_at' => '2020-11-07T15:09:45.000Z', + 'updated_at' => '2020-11-07T15:09:45.000Z', + ], + ]; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldShowWorkflow() + { + $expectedArray = [ + 'id' => 'id', + 'node_id' => 'node_id', + 'name' => 'CI', + 'path' => '.github/workflows/ci.yml', + 'state' => 'active', + 'created_at' => '2020-11-07T15:09:45.000Z', + 'updated_at' => '2020-11-07T15:09:45.000Z', + ]; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldGetWorkflowUsage() + { + $expectedArray = [ + 'billable' => [ + 'UBUNTU' => ['total_ms' => 180000, 'jobs' => 1], + 'MACOS' => ['total_ms' => 240000, 'jobs' => 1], + 'WINDOWS' => ['total_ms' => 300000, 'jobs' => 1], + ], + ]; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/1/timing') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->usage('KnpLabs', 'php-github-api', 1)); + } + + protected function getApiClass() + { + return Workflows::class; + } +} From 295f272d3dc1b5aa6b6d9426c0600410d999de96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20DE=C4=9EER?= Date: Thu, 3 Dec 2020 16:14:49 +0300 Subject: [PATCH 803/951] feat(repo): added automated security endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emre DEĞER chore(repo): fixed ci issues Signed-off-by: Emre DEĞER --- doc/repos.md | 16 ++++++++++++ lib/Github/Api/Repo.php | 30 ++++++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 41 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 0c7068987d5..7b361aba9b2 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -271,6 +271,22 @@ $languages = $client->api('repo')->languages('ornicar', 'php-github-api'); Returns a list of languages. +### Enable automated security fixes + +https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes + +```php +$client->api('repo')->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api'); +``` + +### Disable automated security fixes + +https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes + +```php +$client->api('repo')->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api'); +``` + ### Get the contributors of a repository ```php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b9b02ea0b30..47a3aa1795e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -693,6 +693,36 @@ public function milestones($username, $repository, array $parameters = []) return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones', $parameters); } + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes + * + * @param string $username + * @param string $repository + * + * @return array|string + */ + public function enableAutomatedSecurityFixes(string $username, string $repository) + { + $this->acceptHeaderValue = 'application/vnd.github.london-preview+json'; + + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/automated-security-fixes'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes + * + * @param string $username + * @param string $repository + * + * @return array|string + */ + public function disableAutomatedSecurityFixes(string $username, string $repository) + { + $this->acceptHeaderValue = 'application/vnd.github.london-preview+json'; + + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/automated-security-fixes'); + } + public function projects() { return new Projects($this->client); diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 88434750883..35033e7da20 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -2,6 +2,9 @@ namespace Github\Tests\Api; +use Github\Api\Repo; +use PHPUnit\Framework\MockObject\MockObject; + class RepoTest extends TestCase { /** @@ -264,6 +267,44 @@ public function shouldGetRepositoryMilestones() $this->assertEquals($expectedArray, $api->milestones('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldEnableAutomatedSecurityFixes() + { + $expectedResponse = 'response'; + + /** @var Repo|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/automated-security-fixes') + ->will($this->returnValue($expectedResponse)); + + $this->assertEquals($expectedResponse, $api->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldDisableAutomatedSecurityFixes() + { + $expectedResponse = 'response'; + + /** @var Repo|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/automated-security-fixes') + ->will($this->returnValue($expectedResponse)); + + $this->assertEquals($expectedResponse, $api->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api')); + } + /** * @test */ From 9b0a7c3c9caa72d81cba59683ea9974195f5d483 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 9 Dec 2020 07:40:52 +0000 Subject: [PATCH 804/951] feature #907 [3.x] Re-worked pagination to not mutate the api classes (GrahamCampbell) This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- This re-works pagination to avoid mutating the API classes. It took a few attempts to get the implementation details right. Let me explain why I chose to use clone: 1. If we were to use `new static(...)`, then I would have had to have made the abstract api constructor final. This could cause problems for people mocking the api classes, and also limits the possibility to thunk up arguments to the api classes, say if we want to introduce an api class which takes an extra parameter which is always used (this is common place in the gitlab fork of this library). 2. Is there another way to do things without making the constructor final or using clone? Well, we could have every api object implement perPage for themselves. This is kinda cumbersome though, and I don't think we want to do this. --- This PR partially addresses #904. So, I think cloning then setting the private property, within the abstract api class is the way to go, and nicely separates responsibilities. Classes that extend the abstract api class cannot mutate the property, and outsiders also cannot either. They have to call perPage which gives a fresh instance (one we've cloned). Commits ------- 54c652c30868d663da2792c5e52e95b890ab00b6 Re-worked pagination to not mutate the api classes 4ba3e48a9708e039f2d7211f06a2c68d84e82ad2 Avoid needing getPerPage and perPage decf105c7ca44cabc8bf924ff67902dbe3b793a0 Restored test coverage --- composer.json | 3 +- lib/Github/Api/AbstractApi.php | 66 +++----- lib/Github/Api/ApiInterface.php | 15 -- lib/Github/Api/CurrentUser.php | 14 +- lib/Github/Api/CurrentUser/Starring.php | 2 +- lib/Github/Api/Enterprise.php | 8 +- lib/Github/Api/Gist/Comments.php | 2 +- lib/Github/Api/Gists.php | 4 +- lib/Github/Api/GitData.php | 10 +- lib/Github/Api/GitData/Blobs.php | 2 +- lib/Github/Api/Issue.php | 14 +- lib/Github/Api/Issue/Comments.php | 2 +- lib/Github/Api/Organization.php | 8 +- lib/Github/Api/Project/AbstractProjectApi.php | 2 +- lib/Github/Api/Project/Columns.php | 2 +- lib/Github/Api/PullRequest.php | 8 +- lib/Github/Api/PullRequest/Comments.php | 2 +- lib/Github/Api/Repo.php | 38 ++--- lib/Github/Api/Repository/Comments.php | 2 +- lib/Github/Api/Repository/Contents.php | 2 +- lib/Github/Api/Repository/Releases.php | 2 +- lib/Github/Api/Repository/Stargazers.php | 2 +- lib/Github/Client.php | 6 +- .../HttpClient/Message/ResponseMediator.php | 12 +- lib/Github/ResultPager.php | 143 +++++++++--------- lib/Github/ResultPagerInterface.php | 37 +++-- test/Github/Tests/ResultPagerTest.php | 42 +++-- 27 files changed, 217 insertions(+), 233 deletions(-) delete mode 100644 lib/Github/Api/ApiInterface.php diff --git a/composer.json b/composer.json index f33d730c767..4fc6a11b63a 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "psr/cache": "^1.0", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0", + "symfony/polyfill-php80": "^1.17" }, "require-dev": { "symfony/cache": "^5.1.8", diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 666ccf1e4d5..17aa8ce21a0 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -6,79 +6,59 @@ use Github\HttpClient\Message\ResponseMediator; /** - * Abstract class for Api classes. - * * @author Joseph Bielawski + * @author Graham Campbell */ -abstract class AbstractApi implements ApiInterface +abstract class AbstractApi { /** - * The client. + * The client instance. * * @var Client */ - protected $client; + private $client; /** - * The requested page (GitHub pagination). + * The per page parameter. * - * @var null|int + * @var int|null */ - private $page; + private $perPage; /** - * Number of items per page (GitHub pagination). + * Create a new API instance. * - * @var null|int - */ - protected $perPage; - - /** * @param Client $client + * + * @return void */ public function __construct(Client $client) { $this->client = $client; } - public function configure() - { - } - - /** - * @return null|int - */ - public function getPage() - { - return $this->page; - } - /** - * @param null|int $page + * Get the client instance. + * + * @return Client */ - public function setPage($page) + protected function getClient() { - $this->page = (null === $page ? $page : (int) $page); - - return $this; + return $this->client; } /** - * @return null|int + * Get the API version. + * + * @return string */ - public function getPerPage() + protected function getApiVersion() { - return $this->perPage; + return $this->client->getApiVersion(); } - /** - * @param null|int $perPage - */ - public function setPerPage($perPage) + public function configure() { - $this->perPage = (null === $perPage ? $perPage : (int) $perPage); - - return $this; } /** @@ -92,12 +72,10 @@ public function setPerPage($perPage) */ protected function get($path, array $parameters = [], array $requestHeaders = []) { - if (null !== $this->page && !isset($parameters['page'])) { - $parameters['page'] = $this->page; - } if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; } + if (array_key_exists('ref', $parameters) && null === $parameters['ref']) { unset($parameters['ref']); } diff --git a/lib/Github/Api/ApiInterface.php b/lib/Github/Api/ApiInterface.php deleted file mode 100644 index 49d5167c29d..00000000000 --- a/lib/Github/Api/ApiInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - - */ -interface ApiInterface -{ - public function getPerPage(); - - public function setPerPage($perPage); -} diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 18e197f8c77..70600a855a8 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -35,7 +35,7 @@ public function update(array $params) */ public function emails() { - return new Emails($this->client); + return new Emails($this->getClient()); } /** @@ -43,7 +43,7 @@ public function emails() */ public function follow() { - return new Followers($this->client); + return new Followers($this->getClient()); } public function followers($page = 1) @@ -71,7 +71,7 @@ public function issues(array $params = [], $includeOrgIssues = true) */ public function keys() { - return new PublicKeys($this->client); + return new PublicKeys($this->getClient()); } /** @@ -79,7 +79,7 @@ public function keys() */ public function notifications() { - return new Notifications($this->client); + return new Notifications($this->getClient()); } /** @@ -87,7 +87,7 @@ public function notifications() */ public function memberships() { - return new Memberships($this->client); + return new Memberships($this->getClient()); } /** @@ -147,7 +147,7 @@ public function repositories($type = 'owner', $sort = 'full_name', $direction = */ public function watchers() { - return new Watchers($this->client); + return new Watchers($this->getClient()); } /** @@ -155,7 +155,7 @@ public function watchers() */ public function starring() { - return new Starring($this->client); + return new Starring($this->getClient()); } /** diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index 5fb6435f1f6..6d706c8741c 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -26,7 +26,7 @@ class Starring extends AbstractApi public function configure($bodyType = null) { if ('star' === $bodyType) { - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->getApiVersion()); } return $this; diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index 3dbbee3ea2b..b3daf95a177 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -22,7 +22,7 @@ class Enterprise extends AbstractApi */ public function stats() { - return new Stats($this->client); + return new Stats($this->getClient()); } /** @@ -30,7 +30,7 @@ public function stats() */ public function license() { - return new License($this->client); + return new License($this->getClient()); } /** @@ -38,7 +38,7 @@ public function license() */ public function console() { - return new ManagementConsole($this->client); + return new ManagementConsole($this->getClient()); } /** @@ -46,6 +46,6 @@ public function console() */ public function userAdmin() { - return new UserAdmin($this->client); + return new UserAdmin($this->getClient()); } } diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 251ec7305ab..d32476f722f 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -29,7 +29,7 @@ public function configure($bodyType = null) $bodyType = 'raw'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->getApiVersion(), $bodyType); return $this; } diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 69adef426fe..e88481f05bc 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -32,7 +32,7 @@ public function configure($bodyType = null) $bodyType = 'raw'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->getApiVersion(), $bodyType); return $this; } @@ -177,6 +177,6 @@ public function unstar($id) */ public function comments() { - return new Comments($this->client); + return new Comments($this->getClient()); } } diff --git a/lib/Github/Api/GitData.php b/lib/Github/Api/GitData.php index d431b788704..b7a9f48c344 100644 --- a/lib/Github/Api/GitData.php +++ b/lib/Github/Api/GitData.php @@ -22,7 +22,7 @@ class GitData extends AbstractApi */ public function blobs() { - return new Blobs($this->client); + return new Blobs($this->getClient()); } /** @@ -30,7 +30,7 @@ public function blobs() */ public function commits() { - return new Commits($this->client); + return new Commits($this->getClient()); } /** @@ -38,7 +38,7 @@ public function commits() */ public function references() { - return new References($this->client); + return new References($this->getClient()); } /** @@ -46,7 +46,7 @@ public function references() */ public function tags() { - return new Tags($this->client); + return new Tags($this->getClient()); } /** @@ -54,6 +54,6 @@ public function tags() */ public function trees() { - return new Trees($this->client); + return new Trees($this->getClient()); } } diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index c6269e86663..0562bfe5cba 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -26,7 +26,7 @@ class Blobs extends AbstractApi public function configure($bodyType = null) { if ('raw' === $bodyType) { - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->client->getApiVersion()); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.raw', $this->getApiVersion()); } return $this; diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 875f305f127..08f93d749c0 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -37,7 +37,7 @@ public function configure($bodyType = null) $bodyType = 'raw'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->getApiVersion(), $bodyType); return $this; } @@ -176,7 +176,7 @@ public function unlock($username, $repository, $id) */ public function comments() { - return new Comments($this->client); + return new Comments($this->getClient()); } /** @@ -188,7 +188,7 @@ public function comments() */ public function events() { - return new Events($this->client); + return new Events($this->getClient()); } /** @@ -200,7 +200,7 @@ public function events() */ public function labels() { - return new Labels($this->client); + return new Labels($this->getClient()); } /** @@ -212,7 +212,7 @@ public function labels() */ public function milestones() { - return new Milestones($this->client); + return new Milestones($this->getClient()); } /** @@ -224,7 +224,7 @@ public function milestones() */ public function assignees() { - return new Assignees($this->client); + return new Assignees($this->getClient()); } /** @@ -236,6 +236,6 @@ public function assignees() */ public function timeline() { - return new Timeline($this->client); + return new Timeline($this->getClient()); } } diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 396f5060893..392fb5e76ad 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -31,7 +31,7 @@ public function configure($bodyType = null) $bodyType = 'full'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->getApiVersion(), $bodyType); return $this; } diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 46dd975ca0a..aad0d9b57d8 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -82,7 +82,7 @@ public function repositories($organization, $type = 'all', $page = 1, $sort = nu */ public function members() { - return new Members($this->client); + return new Members($this->getClient()); } /** @@ -90,7 +90,7 @@ public function members() */ public function hooks() { - return new Hooks($this->client); + return new Hooks($this->getClient()); } /** @@ -98,7 +98,7 @@ public function hooks() */ public function teams() { - return new Teams($this->client); + return new Teams($this->getClient()); } /** @@ -106,7 +106,7 @@ public function teams() */ public function outsideCollaborators() { - return new OutsideCollaborators($this->client); + return new OutsideCollaborators($this->getClient()); } /** diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php index 15274d7dbc4..986dab45ca6 100644 --- a/lib/Github/Api/Project/AbstractProjectApi.php +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -40,6 +40,6 @@ public function deleteProject($id) public function columns() { - return new Columns($this->client); + return new Columns($this->getClient()); } } diff --git a/lib/Github/Api/Project/Columns.php b/lib/Github/Api/Project/Columns.php index 22e5cbafcb8..5146ac223af 100644 --- a/lib/Github/Api/Project/Columns.php +++ b/lib/Github/Api/Project/Columns.php @@ -68,6 +68,6 @@ public function move($id, array $params) public function cards() { - return new Cards($this->client); + return new Cards($this->getClient()); } } diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index fcc46c84104..e9453ae7f69 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -32,7 +32,7 @@ class PullRequest extends AbstractApi public function configure($bodyType = null, $apiVersion = null) { if (null === $apiVersion) { - $apiVersion = $this->client->getApiVersion(); + $apiVersion = $this->getApiVersion(); } if (!in_array($bodyType, ['text', 'html', 'full', 'diff', 'patch'])) { @@ -110,17 +110,17 @@ public function status($username, $repository, $id) public function comments() { - return new Comments($this->client); + return new Comments($this->getClient()); } public function reviews() { - return new Review($this->client); + return new Review($this->getClient()); } public function reviewRequests() { - return new ReviewRequest($this->client); + return new ReviewRequest($this->getClient()); } /** diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 3b71d490771..199f58632a3 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -28,7 +28,7 @@ class Comments extends AbstractApi public function configure($bodyType = null, $apiVersion = null) { if ($apiVersion !== 'squirrel-girl-preview') { - $apiVersion = $this->client->getApiVersion(); + $apiVersion = $this->getApiVersion(); } if (!in_array($bodyType, ['text', 'html', 'full'])) { diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 842e4aaf36d..b806c50455b 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -290,7 +290,7 @@ public function dispatch($username, $repository, $eventType, array $clientPayloa */ public function collaborators() { - return new Collaborators($this->client); + return new Collaborators($this->getClient()); } /** @@ -302,7 +302,7 @@ public function collaborators() */ public function comments() { - return new Comments($this->client); + return new Comments($this->getClient()); } /** @@ -314,7 +314,7 @@ public function comments() */ public function commits() { - return new Commits($this->client); + return new Commits($this->getClient()); } /** @@ -329,7 +329,7 @@ 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->client); + return new Checks($this->getClient()); } /** @@ -337,7 +337,7 @@ public function checks() */ public function checkRuns(): CheckRuns { - return new CheckRuns($this->client); + return new CheckRuns($this->getClient()); } /** @@ -345,7 +345,7 @@ public function checkRuns(): CheckRuns */ public function checkSuites(): CheckSuites { - return new CheckSuites($this->client); + return new CheckSuites($this->getClient()); } /** @@ -357,7 +357,7 @@ public function checkSuites(): CheckSuites */ public function contents() { - return new Contents($this->client); + return new Contents($this->getClient()); } /** @@ -369,7 +369,7 @@ public function contents() */ public function downloads() { - return new Downloads($this->client); + return new Downloads($this->getClient()); } /** @@ -381,7 +381,7 @@ public function downloads() */ public function releases() { - return new Releases($this->client); + return new Releases($this->getClient()); } /** @@ -393,7 +393,7 @@ public function releases() */ public function keys() { - return new DeployKeys($this->client); + return new DeployKeys($this->getClient()); } /** @@ -405,7 +405,7 @@ public function keys() */ public function forks() { - return new Forks($this->client); + return new Forks($this->getClient()); } /** @@ -417,7 +417,7 @@ public function forks() */ public function stargazers() { - return new Stargazers($this->client); + return new Stargazers($this->getClient()); } /** @@ -429,7 +429,7 @@ public function stargazers() */ public function hooks() { - return new Hooks($this->client); + return new Hooks($this->getClient()); } /** @@ -441,7 +441,7 @@ public function hooks() */ public function labels() { - return new Labels($this->client); + return new Labels($this->getClient()); } /** @@ -453,7 +453,7 @@ public function labels() */ public function statuses() { - return new Statuses($this->client); + return new Statuses($this->getClient()); } /** @@ -486,7 +486,7 @@ public function branches($username, $repository, $branch = null) */ public function protection() { - return new Protection($this->client); + return new Protection($this->getClient()); } /** @@ -609,17 +609,17 @@ public function milestones($username, $repository, array $parameters = []) public function projects() { - return new Projects($this->client); + return new Projects($this->getClient()); } public function traffic() { - return new Traffic($this->client); + return new Traffic($this->getClient()); } public function pages() { - return new Pages($this->client); + return new Pages($this->getClient()); } /** diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index 53feb72cd31..0b31f55ebf7 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -31,7 +31,7 @@ public function configure($bodyType = null) $bodyType = 'full'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->getApiVersion(), $bodyType); return $this; } diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 98c85723c2f..dec82ba7a71 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -33,7 +33,7 @@ public function configure($bodyType = null) $bodyType = 'raw'; } - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->getApiVersion(), $bodyType); return $this; } diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 9d869b72d4a..10dfe09d290 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -122,6 +122,6 @@ public function remove($username, $repository, $id) */ public function assets() { - return new Assets($this->client); + return new Assets($this->getClient()); } } diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index e71777741c7..3bf7b6ae06a 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -27,7 +27,7 @@ class Stargazers extends AbstractApi public function configure($bodyType = null) { if ('star' === $bodyType) { - $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->client->getApiVersion()); + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.star+json', $this->getApiVersion()); } return $this; diff --git a/lib/Github/Client.php b/lib/Github/Client.php index a77a9b8f010..c3402b6484b 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -2,7 +2,7 @@ namespace Github; -use Github\Api\ApiInterface; +use Github\Api\AbstractApi; use Github\Exception\BadMethodCallException; use Github\Exception\InvalidArgumentException; use Github\HttpClient\Builder; @@ -154,7 +154,7 @@ public static function createWithHttpClient(ClientInterface $httpClient) * * @throws InvalidArgumentException * - * @return ApiInterface + * @return AbstractApi */ public function api($name) { @@ -378,7 +378,7 @@ public function removeCache() * @param string $name * @param array $args * - * @return ApiInterface + * @return AbstractApi */ public function __call($name, $args) { diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 4664d4f018d..858f0e9600d 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -28,19 +28,21 @@ public static function getContent(ResponseInterface $response) /** * @param ResponseInterface $response * - * @return array|void + * @return array */ public static function getPagination(ResponseInterface $response) { - if (!$response->hasHeader('Link')) { - return; + $header = self::getHeader($response, 'Link'); + + if (null === $header) { + return []; } - $header = self::getHeader($response, 'Link'); $pagination = []; foreach (explode(',', $header) as $link) { preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match); + /** @var string[] $match */ if (3 === count($match)) { $pagination[$match[2]] = $match[1]; } @@ -79,7 +81,7 @@ public static function getApiLimit(ResponseInterface $response) * * @return string|null */ - public static function getHeader(ResponseInterface $response, $name) + public static function getHeader(ResponseInterface $response, string $name) { $headers = $response->getHeader($name); diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index defcde23e6a..9cfb5cba403 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -2,36 +2,49 @@ namespace Github; -use Github\Api\ApiInterface; -use Github\Api\Search; +use Github\Api\AbstractApi; use Github\HttpClient\Message\ResponseMediator; +use ValueError; /** * Pager class for supporting pagination in github classes. * * @author Ramon de la Fuente * @author Mitchel Verschoof + * @author Graham Campbell */ class ResultPager implements ResultPagerInterface { /** - * The GitHub Client to use for pagination. + * The default number of entries to request per page. * - * @var \Github\Client + * @var int */ - protected $client; + private const PER_PAGE = 100; /** - * Comes from pagination headers in Github API results. + * The client to use for pagination. * - * @var array + * @var Client */ - protected $pagination; + private $client; /** - * The Github client to use for pagination. + * The number of entries to request per page. * - * This must be the same instance that you got the Api instance from. + * @var int + */ + private $perPage; + + /** + * The pagination result from the API. + * + * @var array + */ + private $pagination; + + /** + * Create a new result pager instance. * * Example code: * @@ -39,65 +52,68 @@ class ResultPager implements ResultPagerInterface * $api = $client->api('someApi'); * $pager = new \Github\ResultPager($client); * - * @param \Github\Client $client + * @param Client $client + * @param int|null $perPage + * + * @return void */ - public function __construct(Client $client) + public function __construct(Client $client, int $perPage = null) { + if (null !== $perPage && ($perPage < 1 || $perPage > 100)) { + throw new ValueError(sprintf('%s::__construct(): Argument #2 ($perPage) must be between 1 and 100, or null', self::class)); + } + $this->client = $client; + $this->perPage = $perPage ?? self::PER_PAGE; + $this->pagination = []; } /** * {@inheritdoc} */ - public function getPagination() + public function fetch(AbstractApi $api, string $method, array $parameters = []) { - return $this->pagination; + $paginatorPerPage = $this->perPage; + $closure = \Closure::bind(function (AbstractApi $api) use ($paginatorPerPage) { + $clone = clone $api; + $clone->perPage = $paginatorPerPage; + + return $clone; + }, null, AbstractApi::class); + + $api = $closure($api); + $result = $api->$method(...$parameters); + + $this->postFetch(); + + return $result; } /** * {@inheritdoc} */ - public function fetch(ApiInterface $api, $method, array $parameters = []) + public function fetchAll(AbstractApi $api, string $method, array $parameters = []) { - $result = $this->callApi($api, $method, $parameters); - $this->postFetch(); - - return $result; + return iterator_to_array($this->fetchAllLazy($api, $method, $parameters)); } /** * {@inheritdoc} */ - public function fetchAll(ApiInterface $api, $method, array $parameters = []) + public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []) { - $isSearch = $api instanceof Search; - - // get the perPage from the api - $perPage = $api->getPerPage(); + $result = $this->fetch($api, $method, $parameters); - // set parameters per_page to GitHub max to minimize number of requests - $api->setPerPage(100); - - try { - $result = $this->callApi($api, $method, $parameters); - $this->postFetch(); - - if ($isSearch) { - $result = isset($result['items']) ? $result['items'] : $result; - } + foreach ($result['items'] ?? $result as $item) { + yield $item; + } - while ($this->hasNext()) { - $next = $this->fetchNext(); + while ($this->hasNext()) { + $result = $this->fetchNext(); - if ($isSearch) { - $result = array_merge($result, $next['items']); - } else { - $result = array_merge($result, $next); - } + foreach ($result['items'] ?? $result as $item) { + yield $item; } - } finally { - // restore the perPage - $api->setPerPage($perPage); } return $result; @@ -116,7 +132,7 @@ public function postFetch() */ public function hasNext() { - return $this->has('next'); + return isset($this->pagination['next']); } /** @@ -132,7 +148,7 @@ public function fetchNext() */ public function hasPrevious() { - return $this->has('prev'); + return isset($this->pagination['prev']); } /** @@ -159,42 +175,21 @@ public function fetchLast() return $this->get('last'); } - /** - * @param string $key - * - * @return bool - */ - protected function has($key) - { - return !empty($this->pagination) && isset($this->pagination[$key]); - } - /** * @param string $key * * @return array */ - protected function get($key) + protected function get(string $key) { - if ($this->has($key)) { - $result = $this->client->getHttpClient()->get($this->pagination[$key]); - $this->postFetch(); - - return ResponseMediator::getContent($result); + if (!isset($this->pagination[$key])) { + return []; } - return []; - } + $result = $this->client->getHttpClient()->get($this->pagination[$key]); - /** - * @param ApiInterface $api - * @param string $method - * @param array $parameters - * - * @return mixed - */ - protected function callApi(ApiInterface $api, $method, array $parameters) - { - return call_user_func_array([$api, $method], $parameters); + $this->postFetch(); + + return ResponseMediator::getContent($result); } } diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 80660247900..5faf1cb0f53 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -2,44 +2,53 @@ namespace Github; -use Github\Api\ApiInterface; +use Github\Api\AbstractApi; /** * Pager interface. * * @author Ramon de la Fuente * @author Mitchel Verschoof + * @author Graham Campbell */ interface ResultPagerInterface { - /** - * @return null|array pagination result of last request - */ - public function getPagination(); - /** * Fetch a single result (page) from an api call. * - * @param ApiInterface $api the Api instance - * @param string $method the method name to call on the Api instance - * @param array $parameters the method parameters in an array + * @param AbstractApi $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array * * @return array returns the result of the Api::$method() call */ - public function fetch(ApiInterface $api, $method, array $parameters = []); + public function fetch(AbstractApi $api, string $method, array $parameters = []); /** * Fetch all results (pages) from an api call. * * Use with care - there is no maximum. * - * @param ApiInterface $api the Api instance - * @param string $method the method name to call on the Api instance - * @param array $parameters the method parameters in an array + * @param AbstractApi $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array * * @return array returns a merge of the results of the Api::$method() call */ - public function fetchAll(ApiInterface $api, $method, array $parameters = []); + public function fetchAll(AbstractApi $api, string $method, array $parameters = []); + + /** + * Lazily fetch all results (pages) from an api call. + * + * Use with care - there is no maximum. + * + * @param AbstractApi $api the Api instance + * @param string $method the method name to call on the Api instance + * @param array $parameters the method parameters in an array + * + * @return \Generator returns a merge of the results of the Api::$method() call + */ + public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []); /** * Method that performs the actual work to refresh the pagination property. diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index e8892501d44..d7d176f4b78 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -2,7 +2,6 @@ namespace Github\Tests; -use Github\Api\ApiInterface; use Github\Api\Organization\Members; use Github\Api\Search; use Github\ResultPager; @@ -11,20 +10,26 @@ use Psr\Http\Client\ClientInterface; /** - * ResultPagerTest. - * * @author Ramon de la Fuente * @author Mitchel Verschoof * @author Tobias Nyholm */ class ResultPagerTest extends \PHPUnit\Framework\TestCase { + public function provideFetchCases() + { + return [ + ['fetchAll'], + ['fetchAllLazy'], + ]; + } + /** - * @test + * @test provideFetchCases * - * description fetchAll + * @dataProvider provideFetchCases */ - public function shouldGetAllResults() + public function shouldGetAllResults(string $fetchMethod) { $amountLoops = 3; $content = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; @@ -49,7 +54,14 @@ public function shouldGetAllResults() // Run fetchAll on result paginator $paginator = new ResultPager($client); - $result = $paginator->fetchAll($memberApi, $method, $parameters); + + $result = $paginator->$fetchMethod($memberApi, $method, $parameters); + + if (is_array($result)) { + $this->assertSame('fetchAll', $fetchMethod); + } else { + $result = iterator_to_array($result); + } $this->assertCount($amountLoops * count($content), $result); } @@ -99,19 +111,21 @@ public function shouldGetAllSearchResults() public function testFetch() { $result = 'foo'; - $method = 'bar'; + $method = 'all'; $parameters = ['baz']; - $api = $this->getMockBuilder(ApiInterface::class) + $api = $this->getMockBuilder(Members::class) + ->disableOriginalConstructor() + ->setMethods(['all']) ->getMock(); + $api->expects($this->once()) + ->method('all') + ->with(...$parameters) + ->willReturn($result); $paginator = $this->getMockBuilder(ResultPager::class) ->disableOriginalConstructor() - ->setMethods(['callApi', 'postFetch']) + ->setMethods(['postFetch']) ->getMock(); - $paginator->expects($this->once()) - ->method('callApi') - ->with($api, $method, $parameters) - ->willReturn($result); $paginator->expects($this->once()) ->method('postFetch'); From 60d0d5fd450aae8fa147eea53f1fee4b0f59a57f Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 11 Dec 2020 20:39:25 +0100 Subject: [PATCH 805/951] Update changelog for 2.18.0 release --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d35102f1e2..57ffed25919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 2.18.0 + +### Added +- Add parameters to PullRequest commits method ([seanmtaylor](https://github.com/seanmtaylor)) [#938](https://github.com/KnpLabs/php-github-api/issues/938) +- Actions (#872) ([lexor](https://github.com/lexor)) [#939](https://github.com/KnpLabs/php-github-api/issues/939) +- automated security endpoints (#868) ([lexor](https://github.com/lexor)) [#944](https://github.com/KnpLabs/php-github-api/issues/944) + +### Changed +- Update apps.md ([clarkeash](https://github.com/clarkeash)) [#936](https://github.com/KnpLabs/php-github-api/issues/936) + +### Fixed +- Throw exception for graphql errors ([acrobat](https://github.com/acrobat)) [#941](https://github.com/KnpLabs/php-github-api/issues/941) + ## 2.17.0 ### Added From a54aecbe7d327e55c4899b2ca211e8135cbdf402 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 12 Dec 2020 18:11:10 +0000 Subject: [PATCH 806/951] Fixed bad merge --- lib/Github/Api/Organization.php | 2 +- lib/Github/Api/Repo.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index dad4fa94641..d3e7646651d 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -107,7 +107,7 @@ public function teams() */ public function secrets(): Secrets { - return new Secrets($this->client); + return new Secrets($this->getClient()); } /** diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 7c6a0407b7d..c99ec7b80c9 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -359,7 +359,7 @@ public function checkSuites(): CheckSuites */ public function artifacts(): Artifacts { - return new Artifacts($this->client); + return new Artifacts($this->getClient()); } /** @@ -367,7 +367,7 @@ public function artifacts(): Artifacts */ public function workflows(): Workflows { - return new Workflows($this->client); + return new Workflows($this->getClient()); } /** @@ -375,7 +375,7 @@ public function workflows(): Workflows */ public function workflowRuns(): WorkflowRuns { - return new WorkflowRuns($this->client); + return new WorkflowRuns($this->getClient()); } /** @@ -383,7 +383,7 @@ public function workflowRuns(): WorkflowRuns */ public function workflowJobs(): WorkflowJobs { - return new WorkflowJobs($this->client); + return new WorkflowJobs($this->getClient()); } /** @@ -391,7 +391,7 @@ public function workflowJobs(): WorkflowJobs */ public function selfHostedRunners(): SelfHostedRunners { - return new SelfHostedRunners($this->client); + return new SelfHostedRunners($this->getClient()); } /** @@ -399,7 +399,7 @@ public function selfHostedRunners(): SelfHostedRunners */ public function secrets(): Secrets { - return new Secrets($this->client); + return new Secrets($this->getClient()); } /** From 215d5fa6388050a1478e0e6163c537b498f7c83d Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 12 Dec 2020 18:16:23 +0000 Subject: [PATCH 807/951] Added some additional scalar types and return types --- lib/Github/Api/AbstractApi.php | 27 +++++++++++-------- lib/Github/Api/AcceptHeaderTrait.php | 18 +++++++------ lib/Github/Api/CurrentUser/Starring.php | 2 +- lib/Github/Api/Gist/Comments.php | 2 +- lib/Github/Api/Gists.php | 2 +- lib/Github/Api/GitData/Blobs.php | 2 +- lib/Github/Api/Issue.php | 2 +- lib/Github/Api/Issue/Comments.php | 2 +- lib/Github/Api/Project/AbstractProjectApi.php | 2 +- lib/Github/Api/Project/Cards.php | 2 +- lib/Github/Api/PullRequest.php | 2 +- lib/Github/Api/PullRequest/Comments.php | 2 +- lib/Github/Api/Repository/Comments.php | 2 +- lib/Github/Api/Repository/Contents.php | 2 +- lib/Github/Api/Repository/Stargazers.php | 2 +- lib/Github/Client.php | 23 ++++++++-------- .../Exception/ApiLimitExceedException.php | 18 ++++++------- .../Exception/BadMethodCallException.php | 2 -- lib/Github/Exception/ErrorException.php | 2 -- .../Exception/InvalidArgumentException.php | 2 -- .../Exception/MissingArgumentException.php | 12 ++++----- lib/Github/Exception/RuntimeException.php | 2 -- lib/Github/Exception/SsoRequiredException.php | 13 +++++---- ...oFactorAuthenticationRequiredException.php | 12 +++++---- lib/Github/HttpClient/Builder.php | 16 +++++------ .../HttpClient/Message/ResponseMediator.php | 6 ++--- .../HttpClient/Plugin/Authentication.php | 2 +- lib/Github/HttpClient/Plugin/History.php | 6 ++--- lib/Github/HttpClient/Plugin/PathPrepend.php | 2 +- lib/Github/ResultPager.php | 26 +++++++++--------- lib/Github/ResultPagerInterface.php | 21 ++++++++------- test/Github/Tests/ResultPagerTest.php | 2 +- 32 files changed, 121 insertions(+), 117 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index 17aa8ce21a0..ce70bbe22ce 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -4,6 +4,7 @@ use Github\Client; use Github\HttpClient\Message\ResponseMediator; +use Psr\Http\Message\ResponseInterface; /** * @author Joseph Bielawski @@ -42,7 +43,7 @@ public function __construct(Client $client) * * @return Client */ - protected function getClient() + protected function getClient(): Client { return $this->client; } @@ -52,13 +53,17 @@ protected function getClient() * * @return string */ - protected function getApiVersion() + protected function getApiVersion(): string { return $this->client->getApiVersion(); } + /** + * @return $this + */ public function configure() { + return $this; } /** @@ -70,7 +75,7 @@ public function configure() * * @return array|string */ - protected function get($path, array $parameters = [], array $requestHeaders = []) + protected function get(string $path, array $parameters = [], array $requestHeaders = []) { if (null !== $this->perPage && !isset($parameters['per_page'])) { $parameters['per_page'] = $this->perPage; @@ -96,9 +101,9 @@ protected function get($path, array $parameters = [], array $requestHeaders = [] * @param array $parameters HEAD parameters. * @param array $requestHeaders Request headers. * - * @return \Psr\Http\Message\ResponseInterface + * @return ResponseInterface */ - protected function head($path, array $parameters = [], array $requestHeaders = []) + protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface { if (array_key_exists('ref', $parameters) && null === $parameters['ref']) { unset($parameters['ref']); @@ -116,7 +121,7 @@ protected function head($path, array $parameters = [], array $requestHeaders = [ * * @return array|string */ - protected function post($path, array $parameters = [], array $requestHeaders = []) + protected function post(string $path, array $parameters = [], array $requestHeaders = []) { return $this->postRaw( $path, @@ -134,7 +139,7 @@ protected function post($path, array $parameters = [], array $requestHeaders = [ * * @return array|string */ - protected function postRaw($path, $body, array $requestHeaders = []) + protected function postRaw(string $path, $body, array $requestHeaders = []) { $response = $this->client->getHttpClient()->post( $path, @@ -154,7 +159,7 @@ protected function postRaw($path, $body, array $requestHeaders = []) * * @return array|string */ - protected function patch($path, array $parameters = [], array $requestHeaders = []) + protected function patch(string $path, array $parameters = [], array $requestHeaders = []) { $response = $this->client->getHttpClient()->patch( $path, @@ -174,7 +179,7 @@ protected function patch($path, array $parameters = [], array $requestHeaders = * * @return array|string */ - protected function put($path, array $parameters = [], array $requestHeaders = []) + protected function put(string $path, array $parameters = [], array $requestHeaders = []) { $response = $this->client->getHttpClient()->put( $path, @@ -194,7 +199,7 @@ protected function put($path, array $parameters = [], array $requestHeaders = [] * * @return array|string */ - protected function delete($path, array $parameters = [], array $requestHeaders = []) + protected function delete(string $path, array $parameters = [], array $requestHeaders = []) { $response = $this->client->getHttpClient()->delete( $path, @@ -212,7 +217,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders = * * @return string|null */ - protected function createJsonBody(array $parameters) + protected function createJsonBody(array $parameters): ?string { return (count($parameters) === 0) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0); } diff --git a/lib/Github/Api/AcceptHeaderTrait.php b/lib/Github/Api/AcceptHeaderTrait.php index 3d22824fdba..6a990a56144 100644 --- a/lib/Github/Api/AcceptHeaderTrait.php +++ b/lib/Github/Api/AcceptHeaderTrait.php @@ -2,6 +2,8 @@ namespace Github\Api; +use Psr\Http\Message\ResponseInterface; + /** * A trait to make sure we add accept headers on all requests. * @@ -12,37 +14,37 @@ trait AcceptHeaderTrait /** @var string */ protected $acceptHeaderValue; - protected function get($path, array $parameters = [], array $requestHeaders = []) + protected function get(string $path, array $parameters = [], array $requestHeaders = []) { return parent::get($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function head($path, array $parameters = [], array $requestHeaders = []) + protected function head(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface { return parent::head($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function post($path, array $parameters = [], array $requestHeaders = []) + protected function post(string $path, array $parameters = [], array $requestHeaders = []) { return parent::post($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function postRaw($path, $body, array $requestHeaders = []) + protected function postRaw(string $path, $body, array $requestHeaders = []) { return parent::postRaw($path, $body, $this->mergeHeaders($requestHeaders)); } - protected function patch($path, array $parameters = [], array $requestHeaders = []) + protected function patch(string $path, array $parameters = [], array $requestHeaders = []) { return parent::patch($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function put($path, array $parameters = [], array $requestHeaders = []) + protected function put(string $path, array $parameters = [], array $requestHeaders = []) { return parent::put($path, $parameters, $this->mergeHeaders($requestHeaders)); } - protected function delete($path, array $parameters = [], array $requestHeaders = []) + protected function delete(string $path, array $parameters = [], array $requestHeaders = []) { return parent::delete($path, $parameters, $this->mergeHeaders($requestHeaders)); } @@ -52,7 +54,7 @@ protected function delete($path, array $parameters = [], array $requestHeaders = * * @return array */ - private function mergeHeaders(array $headers = []) + private function mergeHeaders(array $headers = []): array { $default = []; if ($this->acceptHeaderValue) { diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php index 6d706c8741c..ee2c50233e3 100644 --- a/lib/Github/Api/CurrentUser/Starring.php +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -21,7 +21,7 @@ class Starring extends AbstractApi * * @param string $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index d32476f722f..31587d94016 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -21,7 +21,7 @@ class Comments extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index e88481f05bc..42bbdb9c97b 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -24,7 +24,7 @@ class Gists extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index 0562bfe5cba..3b7357f3dd9 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -21,7 +21,7 @@ class Blobs extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 08f93d749c0..764f5e442a9 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -29,7 +29,7 @@ class Issue extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 392fb5e76ad..b0fe878797f 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -23,7 +23,7 @@ class Comments extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php index 986dab45ca6..049d67562c0 100644 --- a/lib/Github/Api/Project/AbstractProjectApi.php +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -14,7 +14,7 @@ abstract class AbstractProjectApi extends AbstractApi * * @see https://developer.github.com/v3/repos/projects/#projects * - * @return self + * @return $this */ public function configure() { diff --git a/lib/Github/Api/Project/Cards.php b/lib/Github/Api/Project/Cards.php index 758e7708b08..0d670f93863 100644 --- a/lib/Github/Api/Project/Cards.php +++ b/lib/Github/Api/Project/Cards.php @@ -15,7 +15,7 @@ class Cards extends AbstractApi * * @see https://developer.github.com/v3/repos/projects/#projects * - * @return self + * @return $this */ public function configure() { diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index e9453ae7f69..ce1c2b1d901 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -27,7 +27,7 @@ class PullRequest extends AbstractApi * @param string|null $bodyType * @param string|null $apiVersion * - * @return self + * @return $this */ public function configure($bodyType = null, $apiVersion = null) { diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index 199f58632a3..3ded9456cf3 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -23,7 +23,7 @@ class Comments extends AbstractApi * @param string|null $bodyType * @param string|null $apiVersion * - * @return self + * @return $this */ public function configure($bodyType = null, $apiVersion = null) { diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index 0b31f55ebf7..40eb2b53388 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -23,7 +23,7 @@ class Comments extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index dec82ba7a71..bc78503b2f9 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -25,7 +25,7 @@ class Contents extends AbstractApi * * @param string|null $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Api/Repository/Stargazers.php b/lib/Github/Api/Repository/Stargazers.php index 3bf7b6ae06a..bef73b9a6bd 100644 --- a/lib/Github/Api/Repository/Stargazers.php +++ b/lib/Github/Api/Repository/Stargazers.php @@ -22,7 +22,7 @@ class Stargazers extends AbstractApi * * @param string $bodyType * - * @return self + * @return $this */ public function configure($bodyType = null) { diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c3402b6484b..1a101a34a8f 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -15,6 +15,7 @@ use Http\Discovery\Psr17FactoryDiscovery; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\ResponseInterface; /** * Simple yet very cool PHP GitHub client. @@ -142,7 +143,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul * * @return Client */ - public static function createWithHttpClient(ClientInterface $httpClient) + public static function createWithHttpClient(ClientInterface $httpClient): self { $builder = new Builder($httpClient); @@ -156,7 +157,7 @@ public static function createWithHttpClient(ClientInterface $httpClient) * * @return AbstractApi */ - public function api($name) + public function api($name): AbstractApi { switch ($name) { case 'me': @@ -311,7 +312,7 @@ public function api($name) * * @return void */ - public function authenticate($tokenOrLogin, $password = null, $authMethod = null) + public function authenticate($tokenOrLogin, $password = null, $authMethod = null): void { if (null === $authMethod && (self::AUTH_JWT === $password || self::AUTH_ACCESS_TOKEN === $password)) { $authMethod = $password; @@ -333,7 +334,7 @@ public function authenticate($tokenOrLogin, $password = null, $authMethod = null * * @return void */ - private function setEnterpriseUrl($enterpriseUrl) + private function setEnterpriseUrl($enterpriseUrl): void { $builder = $this->getHttpClientBuilder(); $builder->removePlugin(Plugin\AddHostPlugin::class); @@ -346,7 +347,7 @@ private function setEnterpriseUrl($enterpriseUrl) /** * @return string */ - public function getApiVersion() + public function getApiVersion(): string { return $this->apiVersion; } @@ -359,7 +360,7 @@ public function getApiVersion() * * @return void */ - public function addCache(CacheItemPoolInterface $cachePool, array $config = []) + public function addCache(CacheItemPoolInterface $cachePool, array $config = []): void { $this->getHttpClientBuilder()->addCache($cachePool, $config); } @@ -369,7 +370,7 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) * * @return void */ - public function removeCache() + public function removeCache(): void { $this->getHttpClientBuilder()->removeCache(); } @@ -380,7 +381,7 @@ public function removeCache() * * @return AbstractApi */ - public function __call($name, $args) + public function __call($name, $args): AbstractApi { try { return $this->api($name); @@ -392,7 +393,7 @@ public function __call($name, $args) /** * @return null|\Psr\Http\Message\ResponseInterface */ - public function getLastResponse() + public function getLastResponse(): ?ResponseInterface { return $this->responseHistory->getLastResponse(); } @@ -400,7 +401,7 @@ public function getLastResponse() /** * @return HttpMethodsClientInterface */ - public function getHttpClient() + public function getHttpClient(): HttpMethodsClientInterface { return $this->getHttpClientBuilder()->getHttpClient(); } @@ -408,7 +409,7 @@ public function getHttpClient() /** * @return Builder */ - protected function getHttpClientBuilder() + protected function getHttpClientBuilder(): Builder { return $this->httpClientBuilder; } diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index f2dd9b874d6..5c1dd4d8a17 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -2,9 +2,9 @@ namespace Github\Exception; +use Throwable; + /** - * ApiLimitExceedException. - * * @author Joseph Bielawski */ class ApiLimitExceedException extends RuntimeException @@ -15,12 +15,12 @@ class ApiLimitExceedException extends RuntimeException private $reset; /** - * @param int $limit - * @param int $reset - * @param int $code - * @param \Throwable|null $previous + * @param int $limit + * @param int $reset + * @param int $code + * @param Throwable|null $previous */ - public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = null) + public function __construct(int $limit = 5000, int $reset = 1800, int $code = 0, Throwable $previous = null) { $this->limit = (int) $limit; $this->reset = (int) $reset; @@ -31,7 +31,7 @@ public function __construct($limit = 5000, $reset = 1800, $code = 0, $previous = /** * @return int */ - public function getLimit() + public function getLimit(): int { return $this->limit; } @@ -39,7 +39,7 @@ public function getLimit() /** * @return int */ - public function getResetTime() + public function getResetTime(): int { return $this->reset; } diff --git a/lib/Github/Exception/BadMethodCallException.php b/lib/Github/Exception/BadMethodCallException.php index 83e05437b11..22753d082f3 100644 --- a/lib/Github/Exception/BadMethodCallException.php +++ b/lib/Github/Exception/BadMethodCallException.php @@ -3,8 +3,6 @@ namespace Github\Exception; /** - * BadMethodCallException. - * * @author James Brooks */ class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface diff --git a/lib/Github/Exception/ErrorException.php b/lib/Github/Exception/ErrorException.php index 61f61f36f18..b569f730779 100644 --- a/lib/Github/Exception/ErrorException.php +++ b/lib/Github/Exception/ErrorException.php @@ -3,8 +3,6 @@ namespace Github\Exception; /** - * ErrorException. - * * @author Joseph Bielawski */ class ErrorException extends \ErrorException implements ExceptionInterface diff --git a/lib/Github/Exception/InvalidArgumentException.php b/lib/Github/Exception/InvalidArgumentException.php index 558b3b0f3dc..75de2cd7515 100644 --- a/lib/Github/Exception/InvalidArgumentException.php +++ b/lib/Github/Exception/InvalidArgumentException.php @@ -3,8 +3,6 @@ namespace Github\Exception; /** - * InvalidArgumentException. - * * @author Joseph Bielawski */ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index 7a14bb51ae7..4cd3aeca81d 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -2,19 +2,19 @@ namespace Github\Exception; +use Throwable; + /** - * MissingArgumentException. - * * @author Joseph Bielawski */ class MissingArgumentException extends ErrorException { /** - * @param string|array $required - * @param int $code - * @param \Throwable|null $previous + * @param string|array $required + * @param int $code + * @param Throwable|null $previous */ - public function __construct($required, $code = 0, $previous = null) + public function __construct($required, int $code = 0, Throwable $previous = null) { if (is_string($required)) { $required = [$required]; diff --git a/lib/Github/Exception/RuntimeException.php b/lib/Github/Exception/RuntimeException.php index 676cb95736a..827632e97f5 100644 --- a/lib/Github/Exception/RuntimeException.php +++ b/lib/Github/Exception/RuntimeException.php @@ -3,8 +3,6 @@ namespace Github\Exception; /** - * RuntimeException. - * * @author Joseph Bielawski */ class RuntimeException extends \RuntimeException implements ExceptionInterface diff --git a/lib/Github/Exception/SsoRequiredException.php b/lib/Github/Exception/SsoRequiredException.php index 6a47eea7738..1725270a036 100644 --- a/lib/Github/Exception/SsoRequiredException.php +++ b/lib/Github/Exception/SsoRequiredException.php @@ -2,20 +2,19 @@ namespace Github\Exception; -/** - * SsoRequiredException. - */ +use Throwable; + class SsoRequiredException extends RuntimeException { /** @var string */ private $url; /** - * @param string $url - * @param int $code - * @param \Throwable|null $previous + * @param string $url + * @param int $code + * @param Throwable|null $previous */ - public function __construct($url, $code = 0, $previous = null) + public function __construct(string $url, int $code = 0, Throwable $previous = null) { $this->url = $url; diff --git a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php index 0e63b277ce6..c57e67b8e1d 100644 --- a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php +++ b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php @@ -2,17 +2,19 @@ namespace Github\Exception; +use Throwable; + class TwoFactorAuthenticationRequiredException extends RuntimeException { /** @var string */ private $type; /** - * @param string $type - * @param int $code - * @param \Throwable|null $previous + * @param string $type + * @param int $code + * @param Throwable|null $previous */ - public function __construct($type, $code = 0, $previous = null) + public function __construct(string $type, int $code = 0, Throwable $previous = null) { $this->type = $type; parent::__construct('Two factor authentication is enabled on this account', $code, $previous); @@ -21,7 +23,7 @@ public function __construct($type, $code = 0, $previous = null) /** * @return string */ - public function getType() + public function getType(): string { return $this->type; } diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index bbf35d1b4bf..a8713de13bc 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -90,7 +90,7 @@ public function __construct( /** * @return HttpMethodsClientInterface */ - public function getHttpClient() + public function getHttpClient(): HttpMethodsClientInterface { if ($this->httpClientModified) { $this->httpClientModified = false; @@ -117,7 +117,7 @@ public function getHttpClient() * * @return void */ - public function addPlugin(Plugin $plugin) + public function addPlugin(Plugin $plugin): void { $this->plugins[] = $plugin; $this->httpClientModified = true; @@ -130,7 +130,7 @@ public function addPlugin(Plugin $plugin) * * @return void */ - public function removePlugin($fqcn) + public function removePlugin(string $fqcn): void { foreach ($this->plugins as $idx => $plugin) { if ($plugin instanceof $fqcn) { @@ -145,7 +145,7 @@ public function removePlugin($fqcn) * * @return void */ - public function clearHeaders() + public function clearHeaders(): void { $this->headers = []; @@ -158,7 +158,7 @@ public function clearHeaders() * * @return void */ - public function addHeaders(array $headers) + public function addHeaders(array $headers): void { $this->headers = array_merge($this->headers, $headers); @@ -172,7 +172,7 @@ public function addHeaders(array $headers) * * @return void */ - public function addHeaderValue($header, $headerValue) + public function addHeaderValue(string $header, string $headerValue): void { if (!isset($this->headers[$header])) { $this->headers[$header] = $headerValue; @@ -192,7 +192,7 @@ public function addHeaderValue($header, $headerValue) * * @return void */ - public function addCache(CacheItemPoolInterface $cachePool, array $config = []) + public function addCache(CacheItemPoolInterface $cachePool, array $config = []): void { if (!isset($config['cache_key_generator'])) { $config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept', 'Content-type']); @@ -206,7 +206,7 @@ public function addCache(CacheItemPoolInterface $cachePool, array $config = []) * * @return void */ - public function removeCache() + public function removeCache(): void { $this->cachePlugin = null; $this->httpClientModified = true; diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 858f0e9600d..7759f4cbacc 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -30,7 +30,7 @@ public static function getContent(ResponseInterface $response) * * @return array */ - public static function getPagination(ResponseInterface $response) + public static function getPagination(ResponseInterface $response): array { $header = self::getHeader($response, 'Link'); @@ -56,7 +56,7 @@ public static function getPagination(ResponseInterface $response) * * @return string|null */ - public static function getApiLimit(ResponseInterface $response) + public static function getApiLimit(ResponseInterface $response): ?string { $remainingCallsHeader = self::getHeader($response, 'X-RateLimit-Remaining'); @@ -81,7 +81,7 @@ public static function getApiLimit(ResponseInterface $response) * * @return string|null */ - public static function getHeader(ResponseInterface $response, string $name) + public static function getHeader(ResponseInterface $response, string $name): ?string { $headers = $response->getHeader($name); diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 48131099672..862a6c72736 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -35,7 +35,7 @@ class Authentication implements Plugin * @param string|null $password GitHub password/secret (optionally can contain $method) * @param string|null $method One of the AUTH_* class constants */ - public function __construct($tokenOrLogin, $password, $method) + public function __construct(string $tokenOrLogin, ?string $password, ?string $method) { $this->tokenOrLogin = $tokenOrLogin; $this->password = $password; diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index eaf3f19cc5b..cf43449b461 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -22,7 +22,7 @@ class History implements Journal /** * @return ResponseInterface|null */ - public function getLastResponse() + public function getLastResponse(): ?ResponseInterface { return $this->lastResponse; } @@ -30,7 +30,7 @@ public function getLastResponse() /** * @return void */ - public function addSuccess(RequestInterface $request, ResponseInterface $response) + public function addSuccess(RequestInterface $request, ResponseInterface $response): void { $this->lastResponse = $response; } @@ -38,7 +38,7 @@ public function addSuccess(RequestInterface $request, ResponseInterface $respons /** * @return void */ - public function addFailure(RequestInterface $request, ClientExceptionInterface $exception) + public function addFailure(RequestInterface $request, ClientExceptionInterface $exception): void { } } diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 8bde96125c4..15753960276 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -21,7 +21,7 @@ class PathPrepend implements Plugin /** * @param string $path */ - public function __construct($path) + public function __construct(string $path) { $this->path = $path; } diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 9cfb5cba403..181cdbf0bb0 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -2,6 +2,8 @@ namespace Github; +use Closure; +use Generator; use Github\Api\AbstractApi; use Github\HttpClient\Message\ResponseMediator; use ValueError; @@ -71,10 +73,10 @@ public function __construct(Client $client, int $perPage = null) /** * {@inheritdoc} */ - public function fetch(AbstractApi $api, string $method, array $parameters = []) + public function fetch(AbstractApi $api, string $method, array $parameters = []): array { $paginatorPerPage = $this->perPage; - $closure = \Closure::bind(function (AbstractApi $api) use ($paginatorPerPage) { + $closure = Closure::bind(function (AbstractApi $api) use ($paginatorPerPage) { $clone = clone $api; $clone->perPage = $paginatorPerPage; @@ -92,7 +94,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []) /** * {@inheritdoc} */ - public function fetchAll(AbstractApi $api, string $method, array $parameters = []) + public function fetchAll(AbstractApi $api, string $method, array $parameters = []): array { return iterator_to_array($this->fetchAllLazy($api, $method, $parameters)); } @@ -100,7 +102,7 @@ public function fetchAll(AbstractApi $api, string $method, array $parameters = [ /** * {@inheritdoc} */ - public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []) + public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []): Generator { $result = $this->fetch($api, $method, $parameters); @@ -122,7 +124,7 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters /** * {@inheritdoc} */ - public function postFetch() + public function postFetch(): void { $this->pagination = ResponseMediator::getPagination($this->client->getLastResponse()); } @@ -130,7 +132,7 @@ public function postFetch() /** * {@inheritdoc} */ - public function hasNext() + public function hasNext(): bool { return isset($this->pagination['next']); } @@ -138,7 +140,7 @@ public function hasNext() /** * {@inheritdoc} */ - public function fetchNext() + public function fetchNext(): array { return $this->get('next'); } @@ -146,7 +148,7 @@ public function fetchNext() /** * {@inheritdoc} */ - public function hasPrevious() + public function hasPrevious(): bool { return isset($this->pagination['prev']); } @@ -154,7 +156,7 @@ public function hasPrevious() /** * {@inheritdoc} */ - public function fetchPrevious() + public function fetchPrevious(): array { return $this->get('prev'); } @@ -162,7 +164,7 @@ public function fetchPrevious() /** * {@inheritdoc} */ - public function fetchFirst() + public function fetchFirst(): array { return $this->get('first'); } @@ -170,7 +172,7 @@ public function fetchFirst() /** * {@inheritdoc} */ - public function fetchLast() + public function fetchLast(): array { return $this->get('last'); } @@ -180,7 +182,7 @@ public function fetchLast() * * @return array */ - protected function get(string $key) + protected function get(string $key): array { if (!isset($this->pagination[$key])) { return []; diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 5faf1cb0f53..350f8453e05 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -2,6 +2,7 @@ namespace Github; +use Generator; use Github\Api\AbstractApi; /** @@ -22,7 +23,7 @@ interface ResultPagerInterface * * @return array returns the result of the Api::$method() call */ - public function fetch(AbstractApi $api, string $method, array $parameters = []); + public function fetch(AbstractApi $api, string $method, array $parameters = []): array; /** * Fetch all results (pages) from an api call. @@ -35,7 +36,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []); * * @return array returns a merge of the results of the Api::$method() call */ - public function fetchAll(AbstractApi $api, string $method, array $parameters = []); + public function fetchAll(AbstractApi $api, string $method, array $parameters = []): array; /** * Lazily fetch all results (pages) from an api call. @@ -48,54 +49,54 @@ public function fetchAll(AbstractApi $api, string $method, array $parameters = [ * * @return \Generator returns a merge of the results of the Api::$method() call */ - public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []); + public function fetchAllLazy(AbstractApi $api, string $method, array $parameters = []): Generator; /** * Method that performs the actual work to refresh the pagination property. * * @return void */ - public function postFetch(); + public function postFetch(): void; /** * Check to determine the availability of a next page. * * @return bool */ - public function hasNext(); + public function hasNext(): bool; /** * Check to determine the availability of a previous page. * * @return bool */ - public function hasPrevious(); + public function hasPrevious(): bool; /** * Fetch the next page. * * @return array */ - public function fetchNext(); + public function fetchNext(): array; /** * Fetch the previous page. * * @return array */ - public function fetchPrevious(); + public function fetchPrevious(): array; /** * Fetch the first page. * * @return array */ - public function fetchFirst(); + public function fetchFirst(): array; /** * Fetch the last page. * * @return array */ - public function fetchLast(); + public function fetchLast(): array; } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index d7d176f4b78..b29626bf5b0 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -110,7 +110,7 @@ public function shouldGetAllSearchResults() public function testFetch() { - $result = 'foo'; + $result = ['foo']; $method = 'all'; $parameters = ['baz']; $api = $this->getMockBuilder(Members::class) From b3c26f5082adfad8f9f7c1a35e191a6519a7d4b7 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 20 Dec 2020 21:03:03 +0100 Subject: [PATCH 808/951] Mark some classes as final --- lib/Github/HttpClient/Message/ResponseMediator.php | 3 +++ lib/Github/HttpClient/Plugin/Authentication.php | 1 + lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 1 + lib/Github/HttpClient/Plugin/History.php | 1 + lib/Github/HttpClient/Plugin/PathPrepend.php | 1 + 5 files changed, 7 insertions(+) diff --git a/lib/Github/HttpClient/Message/ResponseMediator.php b/lib/Github/HttpClient/Message/ResponseMediator.php index 67cc7016c54..2d5c8664a76 100644 --- a/lib/Github/HttpClient/Message/ResponseMediator.php +++ b/lib/Github/HttpClient/Message/ResponseMediator.php @@ -5,6 +5,9 @@ use Github\Exception\ApiLimitExceedException; use Psr\Http\Message\ResponseInterface; +/** + * @final since 2.19 + */ class ResponseMediator { /** diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 669fb1d8965..a3851240b80 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -12,6 +12,7 @@ * Add authentication to the request. * * @author Tobias Nyholm + * @final since 2.19 */ class Authentication implements Plugin { diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 4a68aa3921f..70373e00ea1 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -17,6 +17,7 @@ /** * @author Joseph Bielawski * @author Tobias Nyholm + * @final since 2.19 */ class GithubExceptionThrower implements Plugin { diff --git a/lib/Github/HttpClient/Plugin/History.php b/lib/Github/HttpClient/Plugin/History.php index c23621b87ed..73f056ba58c 100644 --- a/lib/Github/HttpClient/Plugin/History.php +++ b/lib/Github/HttpClient/Plugin/History.php @@ -10,6 +10,7 @@ * A plugin to remember the last response. * * @author Tobias Nyholm + * @final since 2.19 */ class History implements Journal { diff --git a/lib/Github/HttpClient/Plugin/PathPrepend.php b/lib/Github/HttpClient/Plugin/PathPrepend.php index 3c55f72f13c..049056355d8 100644 --- a/lib/Github/HttpClient/Plugin/PathPrepend.php +++ b/lib/Github/HttpClient/Plugin/PathPrepend.php @@ -10,6 +10,7 @@ * Prepend the URI with a string. * * @author Tobias Nyholm + * @final since 2.19 */ class PathPrepend implements Plugin { From fd4396304dfa62674ad049390789bc4307fe54c1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 21 Dec 2020 15:06:29 +0100 Subject: [PATCH 809/951] Fixed issues with ResultPager and various github responses --- composer.json | 1 + lib/Github/ResultPager.php | 18 ++++-- test/Github/Tests/ResultPagerTest.php | 79 ++++++++++++++++++++++++--- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 4fc6a11b63a..5777b97367a 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ ], "require": { "php": "^7.2.5 || ^8.0", + "ext-json": "*", "php-http/cache-plugin": "^1.7.1", "php-http/client-common": "^2.3", "php-http/discovery": "^1.12", diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 9cfb5cba403..9bc231e9974 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -104,19 +104,25 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters { $result = $this->fetch($api, $method, $parameters); - foreach ($result['items'] ?? $result as $item) { - yield $item; + foreach ($result['items'] ?? $result as $key => $item) { + if (is_string($key)) { + yield $key => $item; + } else { + yield $item; + } } while ($this->hasNext()) { $result = $this->fetchNext(); - foreach ($result['items'] ?? $result as $item) { - yield $item; + foreach ($result['items'] ?? $result as $key => $item) { + if (is_string($key)) { + yield $key => $item; + } else { + yield $item; + } } } - - return $result; } /** diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index d7d176f4b78..8eda28175de 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -2,10 +2,15 @@ namespace Github\Tests; +use Github\Api\Issue; use Github\Api\Organization\Members; +use Github\Api\Repository\Statuses; use Github\Api\Search; +use Github\Client; use Github\ResultPager; use Github\Tests\Mock\PaginatedResponse; +use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use Http\Client\HttpClient; use Psr\Http\Client\ClientInterface; @@ -37,14 +42,14 @@ public function shouldGetAllResults(string $fetchMethod) // httpClient mock $httpClientMock = $this->getMockBuilder(ClientInterface::class) - ->setMethods(['sendRequest']) + ->onlyMethods(['sendRequest']) ->getMock(); $httpClientMock ->expects($this->exactly($amountLoops)) ->method('sendRequest') ->will($this->returnValue($response)); - $client = \Github\Client::createWithHttpClient($httpClientMock); + $client = Client::createWithHttpClient($httpClientMock); // memberApi Mock $memberApi = new Members($client); @@ -91,14 +96,14 @@ public function shouldGetAllSearchResults() // httpClient mock $httpClientMock = $this->getMockBuilder(ClientInterface::class) - ->setMethods(['sendRequest']) + ->onlyMethods(['sendRequest']) ->getMock(); $httpClientMock ->expects($this->exactly($amountLoops)) ->method('sendRequest') - ->will($this->returnValue($response)); + ->willReturn($response); - $client = \Github\Client::createWithHttpClient($httpClientMock); + $client = Client::createWithHttpClient($httpClientMock); $searchApi = new Search($client); $method = 'users'; @@ -115,7 +120,7 @@ public function testFetch() $parameters = ['baz']; $api = $this->getMockBuilder(Members::class) ->disableOriginalConstructor() - ->setMethods(['all']) + ->onlyMethods(['all']) ->getMock(); $api->expects($this->once()) ->method('all') @@ -124,7 +129,7 @@ public function testFetch() $paginator = $this->getMockBuilder(ResultPager::class) ->disableOriginalConstructor() - ->setMethods(['postFetch']) + ->onlyMethods(['postFetch']) ->getMock(); $paginator->expects($this->once()) @@ -132,4 +137,64 @@ public function testFetch() $this->assertEquals($result, $paginator->fetch($api, $method, $parameters)); } + + public function testFetchAllPreserveKeys() + { + $content = [ + 'state' => 'success', + 'statuses' => [ + ['description' => 'status 1', 'state' => 'success'], + ['description' => 'status 2', 'state' => 'failure'], + ], + 'sha' => '43068834af7e501778708ed13106de95f782328c', + ]; + + $response = new Response(200, ['Content-Type'=>'application/json'], Utils::streamFor(json_encode($content))); + + // httpClient mock + $httpClientMock = $this->getMockBuilder(HttpClient::class) + ->onlyMethods(['sendRequest']) + ->getMock(); + $httpClientMock + ->method('sendRequest') + ->willReturn($response); + + $client = Client::createWithHttpClient($httpClientMock); + + $api = new Statuses($client); + $paginator = new ResultPager($client); + $result = $paginator->fetchAll($api, 'combined', ['knplabs', 'php-github-api', '43068834af7e501778708ed13106de95f782328c']); + + $this->assertArrayHasKey('state', $result); + $this->assertArrayHasKey('statuses', $result); + $this->assertCount(2, $result['statuses']); + } + + public function testFetchAllWithoutKeys() + { + $content = [ + ['title' => 'issue 1'], + ['title' => 'issue 2'], + ['title' => 'issue 3'], + ]; + + $response = new PaginatedResponse(3, $content); + + // httpClient mock + $httpClientMock = $this->getMockBuilder(HttpClient::class) + ->onlyMethods(['sendRequest']) + ->getMock(); + $httpClientMock + ->expects($this->exactly(3)) + ->method('sendRequest') + ->willReturn($response); + + $client = Client::createWithHttpClient($httpClientMock); + + $api = new Issue($client); + $paginator = new ResultPager($client); + $result = $paginator->fetchAll($api, 'all', ['knplabs', 'php-github-api']); + + $this->assertCount(9, $result); + } } From dc00db714761a6b3a3dfc91cebee12e5261070d9 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 11 Dec 2020 20:25:39 +0100 Subject: [PATCH 810/951] 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; - } -} From 3a27f922aaedecd0879674f44e05f632e590e2de Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 21 Dec 2020 18:33:52 +0100 Subject: [PATCH 811/951] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 05c818c8654..482a030b46e 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "2.18.x-dev", + "dev-2.x": "2.19.x-dev", "dev-master": "3.0.x-dev" } } From 271b3ca6f7b315c3dae1fcf2be8bb2912a93587d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 21 Dec 2020 19:32:50 +0100 Subject: [PATCH 812/951] Update changelog for 2.19.0 release --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ffed25919..a5728ab245b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.19.0 + +### Added +- Mark some classes as final ([acrobat](https://github.com/acrobat)) [#954](https://github.com/KnpLabs/php-github-api/issues/954) + ## 2.18.0 ### Added From 40571b9298b14244a77df50bef06dc510cd4ffa7 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 21 Dec 2020 21:49:31 +0100 Subject: [PATCH 813/951] Add 3.x changelog --- CHANGELOG-3.X.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CHANGELOG-3.X.md diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md new file mode 100644 index 00000000000..382b1947441 --- /dev/null +++ b/CHANGELOG-3.X.md @@ -0,0 +1,23 @@ +# Changelog + +## 3.0.0 + +### Added +- Switch to PSR18 client implementation and bump httplug minimum version to ^2.0 ([GrahamCampbell](https://github.com/GrahamCampbell)) [#885](https://github.com/KnpLabs/php-github-api/issues/885) +- Switch to PSR-17 and remove deprecated code ([GrahamCampbell](https://github.com/GrahamCampbell)) [#888](https://github.com/KnpLabs/php-github-api/issues/888) +- Allow PHP8 ([acrobat](https://github.com/acrobat)) [#934](https://github.com/KnpLabs/php-github-api/issues/934) +- [3.x] Make PHP 7.2.5 the minimum version ([GrahamCampbell](https://github.com/GrahamCampbell)) [#942](https://github.com/KnpLabs/php-github-api/issues/942) +- [3.x] Re-worked pagination to not mutate the api classes ([GrahamCampbell](https://github.com/GrahamCampbell)) [#907](https://github.com/KnpLabs/php-github-api/issues/907) +- Prepare 3.0 release and remove remaining deprecated code ([acrobat](https://github.com/acrobat)) [#948](https://github.com/KnpLabs/php-github-api/issues/948) + +### Changed +- Remove BC check on 3.x ([GrahamCampbell](https://github.com/GrahamCampbell)) [#900](https://github.com/KnpLabs/php-github-api/issues/900) +- Fixed 2.x -> master merge ([GrahamCampbell](https://github.com/GrahamCampbell)) [#901](https://github.com/KnpLabs/php-github-api/issues/901) +- [3.x] Fix the HTTP methods client ([GrahamCampbell](https://github.com/GrahamCampbell)) [#910](https://github.com/KnpLabs/php-github-api/issues/910) +- fix typo ([michielkempen](https://github.com/michielkempen)) [#920](https://github.com/KnpLabs/php-github-api/issues/920) +- [3.x] Fixed bad merge ([GrahamCampbell](https://github.com/GrahamCampbell)) [#950](https://github.com/KnpLabs/php-github-api/issues/950) +- [3.x] Added some additional scalar types and return types ([GrahamCampbell](https://github.com/GrahamCampbell)) [#949](https://github.com/KnpLabs/php-github-api/issues/949) + +### Fixed +- [3.x] Use RFC3986 for building URI query strings ([GrahamCampbell](https://github.com/GrahamCampbell)) [#906](https://github.com/KnpLabs/php-github-api/issues/906) +- Fixed issues with ResultPager and various github responses ([acrobat](https://github.com/acrobat)) [#956](https://github.com/KnpLabs/php-github-api/issues/956) From 0e05e6ff7e4617379b3741cbd27a402e80441ce1 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 22 Dec 2020 10:17:43 +0100 Subject: [PATCH 814/951] Cleanup 3.0.0 changelog --- CHANGELOG-3.X.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 382b1947441..544e4e8ba59 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -7,17 +7,11 @@ - Switch to PSR-17 and remove deprecated code ([GrahamCampbell](https://github.com/GrahamCampbell)) [#888](https://github.com/KnpLabs/php-github-api/issues/888) - Allow PHP8 ([acrobat](https://github.com/acrobat)) [#934](https://github.com/KnpLabs/php-github-api/issues/934) - [3.x] Make PHP 7.2.5 the minimum version ([GrahamCampbell](https://github.com/GrahamCampbell)) [#942](https://github.com/KnpLabs/php-github-api/issues/942) -- [3.x] Re-worked pagination to not mutate the api classes ([GrahamCampbell](https://github.com/GrahamCampbell)) [#907](https://github.com/KnpLabs/php-github-api/issues/907) +- [3.x] Re-worked pagination to not mutate the api classes ([GrahamCampbell](https://github.com/GrahamCampbell)) [#907](https://github.com/KnpLabs/php-github-api/issues/907) & ([acrobat](https://github.com/acrobat)) [#956](https://github.com/KnpLabs/php-github-api/issues/956) - Prepare 3.0 release and remove remaining deprecated code ([acrobat](https://github.com/acrobat)) [#948](https://github.com/KnpLabs/php-github-api/issues/948) ### Changed - Remove BC check on 3.x ([GrahamCampbell](https://github.com/GrahamCampbell)) [#900](https://github.com/KnpLabs/php-github-api/issues/900) -- Fixed 2.x -> master merge ([GrahamCampbell](https://github.com/GrahamCampbell)) [#901](https://github.com/KnpLabs/php-github-api/issues/901) - [3.x] Fix the HTTP methods client ([GrahamCampbell](https://github.com/GrahamCampbell)) [#910](https://github.com/KnpLabs/php-github-api/issues/910) - fix typo ([michielkempen](https://github.com/michielkempen)) [#920](https://github.com/KnpLabs/php-github-api/issues/920) -- [3.x] Fixed bad merge ([GrahamCampbell](https://github.com/GrahamCampbell)) [#950](https://github.com/KnpLabs/php-github-api/issues/950) - [3.x] Added some additional scalar types and return types ([GrahamCampbell](https://github.com/GrahamCampbell)) [#949](https://github.com/KnpLabs/php-github-api/issues/949) - -### Fixed -- [3.x] Use RFC3986 for building URI query strings ([GrahamCampbell](https://github.com/GrahamCampbell)) [#906](https://github.com/KnpLabs/php-github-api/issues/906) -- Fixed issues with ResultPager and various github responses ([acrobat](https://github.com/acrobat)) [#956](https://github.com/KnpLabs/php-github-api/issues/956) From 9b3e97f69b9915da2868548e820ab20892fbab2d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 22 Dec 2020 10:19:47 +0100 Subject: [PATCH 815/951] Re-enable roave bc check for 3.x --- .github/workflows/ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b4799abe62..3fbe6bd1c5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,13 +31,12 @@ jobs: roave_bc_check: name: Roave BC Check runs-on: ubuntu-latest - # BC check disabled until 3.0.0 is tagged steps: - run: echo true -# - uses: actions/checkout@v2 -# -# - name: Roave BC Check -# uses: docker://nyholm/roave-bc-check-ga + - uses: actions/checkout@v2 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga phpstan: name: PHPStan From 79a0993afd411d8b2807c6a5a9771b7b248a9e10 Mon Sep 17 00:00:00 2001 From: agares Date: Mon, 8 Feb 2021 20:36:51 +0100 Subject: [PATCH 816/951] bug #968 Add accept header for the checks API (Agares) This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- Fixes #967. This PR adds the Accept header back for the Checks API. This is required to make this work on GitHub Enterprise 2.22 (the latest stable version), which still considers this API a preview. Commits ------- d31106835197fd13904cb398a067cc476a08c721 Add accept header for the checks API 2ab07f34cb4de2a5cca72a74144a1af62c23f809 Change to the old way of setting headers --- lib/Github/Api/Repository/Checks/CheckRuns.php | 15 +++++++++++++++ lib/Github/Api/Repository/Checks/CheckSuites.php | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Github/Api/Repository/Checks/CheckRuns.php b/lib/Github/Api/Repository/Checks/CheckRuns.php index 6f91997e8b4..d1e456212ce 100644 --- a/lib/Github/Api/Repository/Checks/CheckRuns.php +++ b/lib/Github/Api/Repository/Checks/CheckRuns.php @@ -3,12 +3,15 @@ namespace Github\Api\Repository\Checks; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks */ class CheckRuns extends AbstractApi { + use AcceptHeaderTrait; + /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run * @@ -16,6 +19,8 @@ class CheckRuns extends AbstractApi */ public function create(string $username, string $repository, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs', $params); } @@ -26,6 +31,8 @@ public function create(string $username, string $repository, array $params = []) */ public function show(string $username, string $repository, int $checkRunId) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId); } @@ -36,6 +43,8 @@ public function show(string $username, string $repository, int $checkRunId) */ public function update(string $username, string $repository, int $checkRunId, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId, $params); } @@ -46,6 +55,8 @@ public function update(string $username, string $repository, int $checkRunId, ar */ public function annotations(string $username, string $repository, int $checkRunId) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId.'/annotations'); } @@ -56,6 +67,8 @@ public function annotations(string $username, string $repository, int $checkRunI */ public function allForCheckSuite(string $username, string $repository, int $checkSuiteId, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId.'/check-runs', $params); } @@ -66,6 +79,8 @@ public function allForCheckSuite(string $username, string $repository, int $chec */ public function allForReference(string $username, string $repository, string $ref, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); } } diff --git a/lib/Github/Api/Repository/Checks/CheckSuites.php b/lib/Github/Api/Repository/Checks/CheckSuites.php index d597fed54e7..ca6b432eb83 100644 --- a/lib/Github/Api/Repository/Checks/CheckSuites.php +++ b/lib/Github/Api/Repository/Checks/CheckSuites.php @@ -3,12 +3,15 @@ namespace Github\Api\Repository\Checks; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks */ class CheckSuites extends AbstractApi { + use AcceptHeaderTrait; + /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-suite * @@ -16,6 +19,8 @@ class CheckSuites extends AbstractApi */ public function create(string $username, string $repository, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites', $params); } @@ -26,6 +31,8 @@ public function create(string $username, string $repository, array $params = []) */ public function updatePreferences(string $username, string $repository, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/preferences', $params); } @@ -36,6 +43,8 @@ public function updatePreferences(string $username, string $repository, array $p */ public function getCheckSuite(string $username, string $repository, int $checkSuiteId) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId); } @@ -46,6 +55,8 @@ public function getCheckSuite(string $username, string $repository, int $checkSu */ public function rerequest(string $username, string $repository, int $checkSuiteId) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId.'/rerequest'); } @@ -56,6 +67,8 @@ public function rerequest(string $username, string $repository, int $checkSuiteI */ public function allForReference(string $username, string $repository, string $ref, array $params = []) { + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-suites', $params); } } From 61366b26679156c4a71b1157ffe83bee6519cb89 Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Mon, 15 Feb 2021 12:56:18 +0100 Subject: [PATCH 817/951] Add workflow dispatch and allow workflow names. --- doc/repo/actions/workflow_runs.md | 2 +- doc/repo/actions/workflows.md | 12 ++++- .../Api/Repository/Actions/WorkflowRuns.php | 6 +-- .../Api/Repository/Actions/Workflows.php | 49 +++++++++++++++---- .../Api/Repository/Actions/WorkflowsTest.php | 20 ++++++++ 5 files changed, 73 insertions(+), 16 deletions(-) diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md index 88c6da7c621..6da31b62735 100644 --- a/doc/repo/actions/workflow_runs.md +++ b/doc/repo/actions/workflow_runs.md @@ -14,7 +14,7 @@ $workflowRuns = $client->api('repo')->workflowRuns()->all('KnpLabs', 'php-github https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs ```php -$runs = $client->api('repo')->workflowRuns()->listRuns('KnpLabs', 'php-github-api', $workflowId); +$runs = $client->api('repo')->workflowRuns()->listRuns('KnpLabs', 'php-github-api', $workflow); ``` ### Get a workflow run diff --git a/doc/repo/actions/workflows.md b/doc/repo/actions/workflows.md index d6689d90aa2..1d86f9efb09 100644 --- a/doc/repo/actions/workflows.md +++ b/doc/repo/actions/workflows.md @@ -14,7 +14,7 @@ $workflows = $client->api('repo')->workflows()->all('KnpLabs', 'php-github-api') https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow ```php -$workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', $workflowId); +$workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', $workflow); ``` ### Get workflow usage @@ -22,5 +22,13 @@ $workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage ```php -$usage = $client->api('repo')->workflows()->usage('KnpLabs', 'php-github-api', $workflowId); +$usage = $client->api('repo')->workflows()->usage('KnpLabs', 'php-github-api', $workflow); +``` + +### Dispatch a workflow + +https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event + +```php +$client->api('repo')->workflows()->dispatches('KnpLabs', 'php-github-api', $workflow, 'main'); ``` diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php index 27213826207..cc5f1a117c3 100644 --- a/lib/Github/Api/Repository/Actions/WorkflowRuns.php +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -28,14 +28,14 @@ public function all(string $username, string $repository, array $parameters = [] * * @param string $username * @param string $repository - * @param string $workflowId + * @param string $workflow * @param array $parameters * * @return array */ - public function listRuns(string $username, string $repository, string $workflowId, array $parameters = []) + public function listRuns(string $username, string $repository, string $workflow, array $parameters = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId.'/runs', $parameters); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.rawurlencode($workflow).'/runs', $parameters); } /** diff --git a/lib/Github/Api/Repository/Actions/Workflows.php b/lib/Github/Api/Repository/Actions/Workflows.php index 3843c59a0ba..cf067d4ac17 100644 --- a/lib/Github/Api/Repository/Actions/Workflows.php +++ b/lib/Github/Api/Repository/Actions/Workflows.php @@ -26,28 +26,57 @@ public function all(string $username, string $repository, array $parameters = [] /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow * - * @param string $username - * @param string $repository - * @param int $workflowId + * @param string $username + * @param string $repository + * @param string|int $workflow * * @return array */ - public function show(string $username, string $repository, int $workflowId) + public function show(string $username, string $repository, $workflow) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId); + if (is_string($workflow)) { + $workflow = rawurlencode($workflow); + } + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflow); } /** * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage * - * @param string $username - * @param string $repository - * @param int $workflowId + * @param string $username + * @param string $repository + * @param string|int $workflow * * @return array|string */ - public function usage(string $username, string $repository, int $workflowId) + public function usage(string $username, string $repository, $workflow) + { + if (is_string($workflow)) { + $workflow = rawurlencode($workflow); + } + + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflow.'/timing'); + } + + /** + * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event + * + * @param string $username + * @param string $repository + * @param string|int $workflow + * @param string $ref + * @param array $inputs + * + * @return array|string empty + */ + public function dispatches(string $username, string $repository, $workflow, string $ref, array $inputs = null) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflowId.'/timing'); + if (is_string($workflow)) { + $workflow = rawurlencode($workflow); + } + $parameters = array_filter(['ref' => $ref, 'inputs' => $inputs]); + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/workflows/'.$workflow.'/dispatches', $parameters); } } diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php index a018f396531..7413fc5d7c0 100644 --- a/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowsTest.php @@ -89,6 +89,26 @@ public function shouldGetWorkflowUsage() $this->assertEquals($expectedArray, $api->usage('KnpLabs', 'php-github-api', 1)); } + /** + * @test + */ + public function shouldDispatchWorkflow() + { + // empty + $expectedArray = []; + + /** @var Workflows|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/workflows/1/dispatches') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->dispatches('KnpLabs', 'php-github-api', 1, 'main')); + } + protected function getApiClass() { return Workflows::class; From 1acf33e0c3b3610925779d05c77c77db15c2ad0e Mon Sep 17 00:00:00 2001 From: Joachim Meyer Date: Tue, 9 Mar 2021 15:12:11 +0100 Subject: [PATCH 818/951] Update new GitHub doc links in repo. Remove free-pro-team@latest from the links, as this is no longer used in the online docs. --- doc/organization/actions/secrets.md | 18 +++++++-------- doc/repo/actions/artifacts.md | 10 ++++----- doc/repo/actions/secrets.md | 12 +++++----- doc/repo/actions/self_hosted_runners.md | 8 +++---- doc/repo/actions/workflow_jobs.md | 6 ++--- doc/repo/actions/workflow_runs.md | 18 +++++++-------- doc/repo/actions/workflows.md | 8 +++---- doc/repo/check_runs.md | 12 +++++----- doc/repo/check_suites.md | 10 ++++----- doc/repos.md | 4 ++-- .../Api/Organization/Actions/Secrets.php | 22 +++++++++---------- lib/Github/Api/Repo.php | 18 +++++++-------- .../Api/Repository/Actions/Artifacts.php | 12 +++++----- lib/Github/Api/Repository/Actions/Secrets.php | 14 ++++++------ .../Repository/Actions/SelfHostedRunners.php | 10 ++++----- .../Api/Repository/Actions/WorkflowJobs.php | 8 +++---- .../Api/Repository/Actions/WorkflowRuns.php | 20 ++++++++--------- .../Api/Repository/Actions/Workflows.php | 10 ++++----- .../Api/Repository/Checks/CheckRuns.php | 14 ++++++------ .../Api/Repository/Checks/CheckSuites.php | 12 +++++----- 20 files changed, 123 insertions(+), 123 deletions(-) diff --git a/doc/organization/actions/secrets.md b/doc/organization/actions/secrets.md index 113a37997ac..04b10877fa2 100644 --- a/doc/organization/actions/secrets.md +++ b/doc/organization/actions/secrets.md @@ -3,7 +3,7 @@ ### List organization secrets -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-organization-secrets +https://docs.github.com/en/rest/reference/actions#list-organization-secrets ```php $secrets = $client->organization()->secrets()->all('KnpLabs'); @@ -11,7 +11,7 @@ $secrets = $client->organization()->secrets()->all('KnpLabs'); ### Get an organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-secret +https://docs.github.com/en/rest/reference/actions#get-an-organization-secret ```php $secret = $client->organization()->secrets()->show('KnpLabs', $secretName); @@ -19,7 +19,7 @@ $secret = $client->organization()->secrets()->show('KnpLabs', $secretName); ### Create an organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret +https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret ```php $client->organization()->secrets()->create('KnpLabs', $secretName, [ @@ -31,7 +31,7 @@ $client->organization()->secrets()->create('KnpLabs', $secretName, [ ### Update an organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret +https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret ```php $client->organization()->secrets()->update('KnpLabs', $secretName, [ @@ -43,7 +43,7 @@ $client->organization()->secrets()->update('KnpLabs', $secretName, [ ### Delete an organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-organization-secret +https://docs.github.com/en/rest/reference/actions#delete-an-organization-secret ```php $client->organization()->secrets()->remove('KnpLabs', $secretName); @@ -51,7 +51,7 @@ $client->organization()->secrets()->remove('KnpLabs', $secretName); ### List selected repositories for organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-selected-repositories-for-an-organization-secret +https://docs.github.com/en/rest/reference/actions#list-selected-repositories-for-an-organization-secret ```php $client->organization()->secrets()->selectedRepositories('KnpLabs', $secretName); @@ -59,7 +59,7 @@ $client->organization()->secrets()->selectedRepositories('KnpLabs', $secretName) ### Set selected repositories for an organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#set-selected-repositories-for-an-organization-secret +https://docs.github.com/en/rest/reference/actions#set-selected-repositories-for-an-organization-secret ```php $client->organization()->secrets()->setSelectedRepositories('KnpLabs', 'secretName', [ @@ -69,7 +69,7 @@ $client->organization()->secrets()->setSelectedRepositories('KnpLabs', 'secretNa ### Remove selected repository from an organization secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#remove-selected-repository-from-an-organization-secret +https://docs.github.com/en/rest/reference/actions#remove-selected-repository-from-an-organization-secret ```php $client->organization()->secrets()->addSecret('KnpLabs', $repositoryId, $secretName); @@ -77,7 +77,7 @@ $client->organization()->secrets()->addSecret('KnpLabs', $repositoryId, $secretN ### Get an organization public key -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-public-key +https://docs.github.com/en/rest/reference/actions#get-an-organization-public-key ```php $client->organization()->secrets()->publicKey('KnpLabs'); diff --git a/doc/repo/actions/artifacts.md b/doc/repo/actions/artifacts.md index b457f12c806..0cc5d071bc5 100644 --- a/doc/repo/actions/artifacts.md +++ b/doc/repo/actions/artifacts.md @@ -3,7 +3,7 @@ ### List artifacts for a repository -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-artifacts-for-a-repository +https://docs.github.com/en/rest/reference/actions#list-artifacts-for-a-repository ```php $artifacts = $client->api('repo')->artifacts()->all('KnpLabs'); @@ -11,7 +11,7 @@ $artifacts = $client->api('repo')->artifacts()->all('KnpLabs'); ### List workflow run artifacts -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-run-artifacts +https://docs.github.com/en/rest/reference/actions#list-workflow-run-artifacts ```php $runArtifacts = $client->api('repo')->artifacts()->runArtifacts('KnpLabs', 'php-github-api', $runId); @@ -19,7 +19,7 @@ $runArtifacts = $client->api('repo')->artifacts()->runArtifacts('KnpLabs', 'php- ### Get an artifact -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-artifact +https://docs.github.com/en/rest/reference/actions#get-an-artifact ```php $artifact = $client->api('repo')->artifacts()->show('KnpLabs', 'php-github-api', $artifactId); @@ -27,7 +27,7 @@ $artifact = $client->api('repo')->artifacts()->show('KnpLabs', 'php-github-api', ### Delete an artifact -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-artifact +https://docs.github.com/en/rest/reference/actions#delete-an-artifact ```php $client->api('repo')->artifacts()->delete('KnpLabs', 'php-github-api', $artifactId); @@ -36,7 +36,7 @@ $client->api('repo')->artifacts()->delete('KnpLabs', 'php-github-api', $artifact ### Download an artifact -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact +https://docs.github.com/en/rest/reference/actions#download-an-artifact ```php $artifactFile = $client->api('repo')->artifacts()->download('KnpLabs', 'php-github-api', $artifactId, $format = 'zip'); diff --git a/doc/repo/actions/secrets.md b/doc/repo/actions/secrets.md index 037409fd53e..b57a9be5858 100644 --- a/doc/repo/actions/secrets.md +++ b/doc/repo/actions/secrets.md @@ -3,7 +3,7 @@ ### List repository secrets -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-secrets +https://docs.github.com/en/rest/reference/actions#list-repository-secrets ```php $secrets = $client->api('repo')->secrets()->all('KnpLabs', 'php-github-api'); @@ -11,7 +11,7 @@ $secrets = $client->api('repo')->secrets()->all('KnpLabs', 'php-github-api'); ### Get a repository secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-secret +https://docs.github.com/en/rest/reference/actions#get-a-repository-secret ```php $secret = $client->api('repo')->secrets()->show('KnpLabs', 'php-github-api', $secretName); @@ -19,7 +19,7 @@ $secret = $client->api('repo')->secrets()->show('KnpLabs', 'php-github-api', $se ### Create a repository secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret +https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret ```php $client->api('repo')->secrets()->create('KnpLabs', 'php-github-api', $secretName, [ @@ -29,7 +29,7 @@ $client->api('repo')->secrets()->create('KnpLabs', 'php-github-api', $secretName ### Update a repository secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret +https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret ```php $client->api('repo')->secrets()->update('KnpLabs', 'php-github-api', $secretName, [ @@ -39,7 +39,7 @@ $client->api('repo')->secrets()->update('KnpLabs', 'php-github-api', $secretName ### Delete a repository secret -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-repository-secret +https://docs.github.com/en/rest/reference/actions#delete-a-repository-secret ```php $client->api('repo')->secrets()->remove('KnpLabs', 'php-github-api', $secretName); @@ -47,7 +47,7 @@ $client->api('repo')->secrets()->remove('KnpLabs', 'php-github-api', $secretName ### Get a repository public key -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-public-key +https://docs.github.com/en/rest/reference/actions#get-a-repository-public-key ```php $publicKey = $client->api('repo')->secrets()->publicKey('KnpLabs', 'php-github-api'); diff --git a/doc/repo/actions/self_hosted_runners.md b/doc/repo/actions/self_hosted_runners.md index 1c09767d6cd..2a02ca363d3 100644 --- a/doc/repo/actions/self_hosted_runners.md +++ b/doc/repo/actions/self_hosted_runners.md @@ -3,7 +3,7 @@ # List self-hosted runners for a repository -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-self-hosted-runners-for-a-repository +https://docs.github.com/en/rest/reference/actions#list-self-hosted-runners-for-a-repository ```php $runners = $client->api('repo')->selfHostedRunners()->all('KnpLabs', 'php-github-api'); @@ -11,7 +11,7 @@ $runners = $client->api('repo')->selfHostedRunners()->all('KnpLabs', 'php-github # Get a self-hosted runner for a repository -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-self-hosted-runner-for-a-repository +https://docs.github.com/en/rest/reference/actions#get-a-self-hosted-runner-for-a-repository ```php $runner = $client->api('repo')->selfHostedRunners()->show('KnpLabs', 'php-github-api', $runnerId); @@ -19,7 +19,7 @@ $runner = $client->api('repo')->selfHostedRunners()->show('KnpLabs', 'php-github # Delete a self-hosted runner from a repository -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository +https://docs.github.com/en/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository ```php $client->api('repo')->selfHostedRunners()->remove('KnpLabs', 'php-github-api', $runnerId); @@ -27,7 +27,7 @@ $client->api('repo')->selfHostedRunners()->remove('KnpLabs', 'php-github-api', $ # List runner applications for a repository -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-runner-applications-for-a-repository +https://docs.github.com/en/rest/reference/actions#list-runner-applications-for-a-repository ```php $applications = $client->api('repo')->selfHostedRunners()->applications('KnpLabs', 'php-github-api'); diff --git a/doc/repo/actions/workflow_jobs.md b/doc/repo/actions/workflow_jobs.md index 151c59c5e95..2e17678a7be 100644 --- a/doc/repo/actions/workflow_jobs.md +++ b/doc/repo/actions/workflow_jobs.md @@ -3,7 +3,7 @@ ### List jobs for a workflow run -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-jobs-for-a-workflow-run +https://docs.github.com/en/rest/reference/actions#list-jobs-for-a-workflow-run ```php $client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $runId); @@ -11,7 +11,7 @@ $client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $runId); ### Get a job for a workflow run -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-job-for-a-workflow-run +https://docs.github.com/en/rest/reference/actions#get-a-job-for-a-workflow-run ```php $job = $client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $jobId); @@ -19,7 +19,7 @@ $job = $client->api('repo')->workflowJobs()->all('KnpLabs', 'php-github-api', $j ### Download job logs for a workflow run -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-job-logs-for-a-workflow-run +https://docs.github.com/en/rest/reference/actions#download-job-logs-for-a-workflow-run ```php $jobLogs = $client->api('repo')->workflowJobs()->downloadLogs('KnpLabs', 'php-github-api', $jobId); diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md index 6da31b62735..0c119c3e137 100644 --- a/doc/repo/actions/workflow_runs.md +++ b/doc/repo/actions/workflow_runs.md @@ -3,7 +3,7 @@ ### List workflow runs for a repository -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs-for-a-repository +https://docs.github.com/en/rest/reference/actions#list-workflow-runs-for-a-repository ```php $workflowRuns = $client->api('repo')->workflowRuns()->all('KnpLabs', 'php-github-api'); @@ -11,7 +11,7 @@ $workflowRuns = $client->api('repo')->workflowRuns()->all('KnpLabs', 'php-github ### List workflow runs -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs +https://docs.github.com/en/rest/reference/actions#list-workflow-runs ```php $runs = $client->api('repo')->workflowRuns()->listRuns('KnpLabs', 'php-github-api', $workflow); @@ -19,7 +19,7 @@ $runs = $client->api('repo')->workflowRuns()->listRuns('KnpLabs', 'php-github-ap ### Get a workflow run -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow-run +https://docs.github.com/en/rest/reference/actions#get-a-workflow-run ```php $workflowRun = $client->api('repo')->workflowRuns()->show('KnpLabs', 'php-github-api', $runId); @@ -27,7 +27,7 @@ $workflowRun = $client->api('repo')->workflowRuns()->show('KnpLabs', 'php-github ### Delete a workflow run -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run +https://docs.github.com/en/rest/reference/actions#delete-a-workflow-run ```php $client->api('repo')->workflowRuns()->remove('KnpLabs', 'php-github-api', $runId); @@ -35,7 +35,7 @@ $client->api('repo')->workflowRuns()->remove('KnpLabs', 'php-github-api', $runId ### Re-run a workflow -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#re-run-a-workflow +https://docs.github.com/en/rest/reference/actions#re-run-a-workflow ```php $client->api('repo')->workflowRuns()->rerun('KnpLabs', 'php-github-api', $runId); @@ -43,7 +43,7 @@ $client->api('repo')->workflowRuns()->rerun('KnpLabs', 'php-github-api', $runId) ### Cancel a workflow run -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#cancel-a-workflow-run +https://docs.github.com/en/rest/reference/actions#cancel-a-workflow-run ```php $client->api('repo')->workflowRuns()->cancel('KnpLabs', 'php-github-api', $runId); @@ -51,7 +51,7 @@ $client->api('repo')->workflowRuns()->cancel('KnpLabs', 'php-github-api', $runId ### Get workflow run usage -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-run-usage +https://docs.github.com/en/rest/reference/actions#get-workflow-run-usage ```php $workflowUsage = $client->api('repo')->workflowRuns()->usage('KnpLabs', 'php-github-api', $runId); @@ -59,7 +59,7 @@ $workflowUsage = $client->api('repo')->workflowRuns()->usage('KnpLabs', 'php-git ### Download workflow run logs -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-workflow-run-logs +https://docs.github.com/en/rest/reference/actions#download-workflow-run-logs ```php $logs = $client->api('repo')->workflowRuns()->downloadLogs('KnpLabs', 'php-github-api', $runId); @@ -69,7 +69,7 @@ file_put_contents('logs.zip', $logs); ### Delete workflow run logs -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-workflow-run-logs +https://docs.github.com/en/rest/reference/actions#delete-workflow-run-logs ```php $client->api('repo')->workflowRuns()->deleteLogs('KnpLabs', 'php-github-api', $runId); diff --git a/doc/repo/actions/workflows.md b/doc/repo/actions/workflows.md index 1d86f9efb09..cbd3484b4d2 100644 --- a/doc/repo/actions/workflows.md +++ b/doc/repo/actions/workflows.md @@ -3,7 +3,7 @@ ### List repository workflows -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows +https://docs.github.com/en/rest/reference/actions#list-repository-workflows ```php $workflows = $client->api('repo')->workflows()->all('KnpLabs', 'php-github-api'); @@ -11,7 +11,7 @@ $workflows = $client->api('repo')->workflows()->all('KnpLabs', 'php-github-api') ### Get a workflow -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow +https://docs.github.com/en/rest/reference/actions#get-a-workflow ```php $workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', $workflow); @@ -19,7 +19,7 @@ $workflow = $client->api('repo')->workflows()->show('KnpLabs', 'php-github-api', ### Get workflow usage -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage +https://docs.github.com/en/rest/reference/actions#get-workflow-usage ```php $usage = $client->api('repo')->workflows()->usage('KnpLabs', 'php-github-api', $workflow); @@ -27,7 +27,7 @@ $usage = $client->api('repo')->workflows()->usage('KnpLabs', 'php-github-api', $ ### Dispatch a workflow -https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event +https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event ```php $client->api('repo')->workflows()->dispatches('KnpLabs', 'php-github-api', $workflow, 'main'); diff --git a/doc/repo/check_runs.md b/doc/repo/check_runs.md index 87109e07e69..b0aa4926691 100644 --- a/doc/repo/check_runs.md +++ b/doc/repo/check_runs.md @@ -3,7 +3,7 @@ ### Create a check run -[Visit GitHub for a full of list of parameters and their descriptions.](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run) +[Visit GitHub for a full of list of parameters and their descriptions.](https://docs.github.com/en/rest/reference/checks#create-a-check-run) ```php $params = [ @@ -17,7 +17,7 @@ $check = $client->api('repo')->checkRuns()->create('KnpLabs', 'php-github-api', ### Get a check run -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-run +https://docs.github.com/en/rest/reference/checks#get-a-check-run ```php $check = $client->api('repo')->checkRuns()->show('KnpLabs', 'php-github-api', $checkRunId); @@ -25,7 +25,7 @@ $check = $client->api('repo')->checkRuns()->show('KnpLabs', 'php-github-api', $c ### Update an existing check run -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-a-check-run +https://docs.github.com/en/rest/reference/checks#update-a-check-run ```php $params = [ @@ -38,7 +38,7 @@ $check = $client->api('repo')->checkRuns()->update('KnpLabs', 'php-github-api', ### List check run annotations -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations +https://docs.github.com/en/rest/reference/checks#list-check-run-annotations ```php $annotations = $client->api('repo')->checkRuns()->annotations('KnpLabs', 'php-github-api', $checkRunId); @@ -46,7 +46,7 @@ $annotations = $client->api('repo')->checkRuns()->annotations('KnpLabs', 'php-gi ### List check runs for a check suite -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-in-a-check-suite +https://docs.github.com/en/rest/reference/checks#list-check-runs-in-a-check-suite ```php $params = [/*...*/]; @@ -55,7 +55,7 @@ $checks = $client->api('repo')->checkRuns()->allForCheckSuite('KnpLabs', 'php-gi ### List check runs for a Git reference -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-for-a-git-reference +https://docs.github.com/en/rest/reference/checks#list-check-runs-for-a-git-reference ```php $params = [/*...*/]; diff --git a/doc/repo/check_suites.md b/doc/repo/check_suites.md index 7131674b510..b91c8199813 100644 --- a/doc/repo/check_suites.md +++ b/doc/repo/check_suites.md @@ -3,7 +3,7 @@ ### Create a check suite -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-suite +https://docs.github.com/en/rest/reference/checks#create-a-check-suite ```php $params = [ @@ -14,7 +14,7 @@ $check = $client->api('repo')->checkSuites()->create('KnpLabs', 'php-github-api' ### Update check suite preferences -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-repository-preferences-for-check-suites +https://docs.github.com/en/rest/reference/checks#update-repository-preferences-for-check-suites ```php $params = [/*...*/]; @@ -23,7 +23,7 @@ $check = $client->api('repo')->checkSuites()->updatePreferences('KnpLabs', 'php- ### Get a check suite -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-suite +https://docs.github.com/en/rest/reference/checks#get-a-check-suite ```php $check = $client->api('repo')->checkSuites()->getCheckSuite('KnpLabs', 'php-github-api', $checkSuiteId); @@ -31,7 +31,7 @@ $check = $client->api('repo')->checkSuites()->getCheckSuite('KnpLabs', 'php-gith ### Rerequest a check suite -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#rerequest-a-check-suite +https://docs.github.com/en/rest/reference/checks#rerequest-a-check-suite ```php $annotations = $client->api('repo')->checkSuites()->rerequest('KnpLabs', 'php-github-api', $checkSuiteId); @@ -40,7 +40,7 @@ $annotations = $client->api('repo')->checkSuites()->rerequest('KnpLabs', 'php-gi ### List check suites for a Git reference -https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-suites-for-a-git-reference +https://docs.github.com/en/rest/reference/checks#list-check-suites-for-a-git-reference ```php $params = [/*...*/]; diff --git a/doc/repos.md b/doc/repos.md index 7b361aba9b2..0a4d234a695 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -273,7 +273,7 @@ Returns a list of languages. ### Enable automated security fixes -https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes +https://docs.github.com/en/rest/reference/repos#enable-automated-security-fixes ```php $client->api('repo')->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api'); @@ -281,7 +281,7 @@ $client->api('repo')->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api'); ### Disable automated security fixes -https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes +https://docs.github.com/en/rest/reference/repos#disable-automated-security-fixes ```php $client->api('repo')->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api'); diff --git a/lib/Github/Api/Organization/Actions/Secrets.php b/lib/Github/Api/Organization/Actions/Secrets.php index 7a08212907f..2f73c10e624 100644 --- a/lib/Github/Api/Organization/Actions/Secrets.php +++ b/lib/Github/Api/Organization/Actions/Secrets.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#secrets + * @link https://docs.github.com/en/rest/reference/actions#secrets */ class Secrets extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-organization-secrets + * @link https://docs.github.com/en/rest/reference/actions#list-organization-secrets * * @param string $organization * @@ -22,7 +22,7 @@ public function all(string $organization) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#get-an-organization-secret * * @param string $organization * @param string $secretName @@ -35,7 +35,7 @@ public function show(string $organization, string $secretName) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret * * @param string $organization * @param string $secretName @@ -49,7 +49,7 @@ public function create(string $organization, string $secretName, array $paramete } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret * * @param string $organization * @param string $secretName @@ -63,7 +63,7 @@ public function update(string $organization, string $secretName, array $paramete } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#delete-an-organization-secret * * @param string $organization * @param string $secretName @@ -76,7 +76,7 @@ public function remove(string $organization, string $secretName) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-selected-repositories-for-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#list-selected-repositories-for-an-organization-secret * * @param string $organization * @param string $secretName @@ -89,7 +89,7 @@ public function selectedRepositories(string $organization, string $secretName) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#set-selected-repositories-for-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#set-selected-repositories-for-an-organization-secret * * @param string $organization * @param string $secretName @@ -103,7 +103,7 @@ public function setSelectedRepositories(string $organization, string $secretName } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#add-selected-repository-to-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#add-selected-repository-to-an-organization-secret * * @param string $organization * @param string $repositoryId @@ -117,7 +117,7 @@ public function addSecret(string $organization, string $repositoryId, string $se } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#remove-selected-repository-from-an-organization-secret + * @link https://docs.github.com/en/rest/reference/actions#remove-selected-repository-from-an-organization-secret * * @param string $organization * @param string $repositoryId @@ -131,7 +131,7 @@ public function removeSecret(string $organization, string $repositoryId, string } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-organization-public-key + * @link https://docs.github.com/en/rest/reference/actions#get-an-organization-public-key * * @param string $organization * diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 4698ebbc031..fcaa196d264 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -323,7 +323,7 @@ public function commits() } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-runs + * @link https://docs.github.com/en/rest/reference/checks#check-runs */ public function checkRuns(): CheckRuns { @@ -331,7 +331,7 @@ public function checkRuns(): CheckRuns } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-suites + * @link https://docs.github.com/en/rest/reference/checks#check-suites */ public function checkSuites(): CheckSuites { @@ -347,7 +347,7 @@ public function artifacts(): Artifacts } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflows + * @link https://docs.github.com/en/rest/reference/actions#workflows */ public function workflows(): Workflows { @@ -355,7 +355,7 @@ public function workflows(): Workflows } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-runs + * @link https://docs.github.com/en/rest/reference/actions#workflow-runs */ public function workflowRuns(): WorkflowRuns { @@ -363,7 +363,7 @@ public function workflowRuns(): WorkflowRuns } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-jobs + * @link https://docs.github.com/en/rest/reference/actions#workflow-jobs */ public function workflowJobs(): WorkflowJobs { @@ -371,7 +371,7 @@ public function workflowJobs(): WorkflowJobs } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#self-hosted-runners + * @link https://docs.github.com/en/rest/reference/actions#self-hosted-runners */ public function selfHostedRunners(): SelfHostedRunners { @@ -379,7 +379,7 @@ public function selfHostedRunners(): SelfHostedRunners } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#secrets + * @link https://docs.github.com/en/rest/reference/actions#secrets */ public function secrets(): Secrets { @@ -646,7 +646,7 @@ public function milestones($username, $repository, array $parameters = []) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes + * @link https://docs.github.com/en/rest/reference/repos#enable-automated-security-fixes * * @param string $username * @param string $repository @@ -661,7 +661,7 @@ public function enableAutomatedSecurityFixes(string $username, string $repositor } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes + * @link https://docs.github.com/en/rest/reference/repos#disable-automated-security-fixes * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Actions/Artifacts.php b/lib/Github/Api/Repository/Actions/Artifacts.php index b81d560b00d..84f3b0604af 100644 --- a/lib/Github/Api/Repository/Actions/Artifacts.php +++ b/lib/Github/Api/Repository/Actions/Artifacts.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#artifacts + * @link https://docs.github.com/en/rest/reference/actions#artifacts */ class Artifacts extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-artifacts-for-a-repository + * @link https://docs.github.com/en/rest/reference/actions#list-artifacts-for-a-repository * * @param string $username * @param string $repository @@ -24,7 +24,7 @@ public function all(string $username, string $repository, array $parameters = [] } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-run-artifacts + * @link https://docs.github.com/en/rest/reference/actions#list-workflow-run-artifacts * * @param string $username * @param string $repository @@ -38,7 +38,7 @@ public function runArtifacts(string $username, string $repository, int $runId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-an-artifact + * @link https://docs.github.com/en/rest/reference/actions#get-an-artifact * * @param string $username * @param string $repository @@ -52,7 +52,7 @@ public function show(string $username, string $repository, int $artifactId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-an-artifact + * @link https://docs.github.com/en/rest/reference/actions#delete-an-artifact * * @param string $username * @param string $repository @@ -66,7 +66,7 @@ public function remove(string $username, string $repository, int $artifactId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact + * @link https://docs.github.com/en/rest/reference/actions#download-an-artifact * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Actions/Secrets.php b/lib/Github/Api/Repository/Actions/Secrets.php index 4c38de203dc..dad57e77160 100644 --- a/lib/Github/Api/Repository/Actions/Secrets.php +++ b/lib/Github/Api/Repository/Actions/Secrets.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#secrets + * @link https://docs.github.com/en/rest/reference/actions#secrets */ class Secrets extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-secrets + * @link https://docs.github.com/en/rest/reference/actions#list-repository-secrets * * @param string $username * @param string $repository @@ -23,7 +23,7 @@ public function all(string $username, string $repository) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-secret + * @link https://docs.github.com/en/rest/reference/actions#get-a-repository-secret * * @param string $username * @param string $repository @@ -37,7 +37,7 @@ public function show(string $username, string $repository, string $secretName) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + * @link https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret * * @param string $username * @param string $repository @@ -52,7 +52,7 @@ public function create(string $username, string $repository, string $secretName, } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-or-update-a-repository-secret + * @link https://docs.github.com/en/rest/reference/actions#create-or-update-a-repository-secret * * @param string $username * @param string $repository @@ -67,7 +67,7 @@ public function update(string $username, string $repository, string $secretName, } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-repository-secret + * @link https://docs.github.com/en/rest/reference/actions#delete-a-repository-secret * * @param string $username * @param string $repository @@ -81,7 +81,7 @@ public function remove(string $username, string $repository, string $secretName) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-repository-public-key + * @link https://docs.github.com/en/rest/reference/actions#get-a-repository-public-key * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Actions/SelfHostedRunners.php b/lib/Github/Api/Repository/Actions/SelfHostedRunners.php index 4a20b1169bf..7eb1a9d4e39 100644 --- a/lib/Github/Api/Repository/Actions/SelfHostedRunners.php +++ b/lib/Github/Api/Repository/Actions/SelfHostedRunners.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#self-hosted-runners + * @link https://docs.github.com/en/rest/reference/actions#self-hosted-runners */ class SelfHostedRunners extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-self-hosted-runners-for-a-repository + * @link https://docs.github.com/en/rest/reference/actions#list-self-hosted-runners-for-a-repository * * @param string $username * @param string $repository @@ -23,7 +23,7 @@ public function all(string $username, string $repository) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-self-hosted-runner-for-a-repository + * @link https://docs.github.com/en/rest/reference/actions#get-a-self-hosted-runner-for-a-repository * * @param string $username * @param string $repository @@ -37,7 +37,7 @@ public function show(string $username, string $repository, int $runnerId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository + * @link https://docs.github.com/en/rest/reference/actions#delete-a-self-hosted-runner-from-a-repository * * @param string $username * @param string $repository @@ -51,7 +51,7 @@ public function remove(string $username, string $repository, int $runnerId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-runner-applications-for-a-repository + * @link https://docs.github.com/en/rest/reference/actions#list-runner-applications-for-a-repository * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Actions/WorkflowJobs.php b/lib/Github/Api/Repository/Actions/WorkflowJobs.php index edcb806ee6c..3167d3dbf81 100644 --- a/lib/Github/Api/Repository/Actions/WorkflowJobs.php +++ b/lib/Github/Api/Repository/Actions/WorkflowJobs.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-jobs + * @link https://docs.github.com/en/rest/reference/actions#workflow-jobs */ class WorkflowJobs extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-jobs-for-a-workflow-run + * @link https://docs.github.com/en/rest/reference/actions#list-jobs-for-a-workflow-run * * @param string $username * @param string $repository @@ -25,7 +25,7 @@ public function all(string $username, string $repository, int $runId, array $par } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-job-for-a-workflow-run + * @link https://docs.github.com/en/rest/reference/actions#get-a-job-for-a-workflow-run * * @param string $username * @param string $repository @@ -39,7 +39,7 @@ public function show(string $username, string $repository, int $jobId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-job-logs-for-a-workflow-run + * @link https://docs.github.com/en/rest/reference/actions#download-job-logs-for-a-workflow-run * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php index cc5f1a117c3..06d3e559605 100644 --- a/lib/Github/Api/Repository/Actions/WorkflowRuns.php +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflow-runs + * @link https://docs.github.com/en/rest/reference/actions#workflow-runs */ class WorkflowRuns extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs-for-a-repository + * @link https://docs.github.com/en/rest/reference/actions#list-workflow-runs-for-a-repository * * @param string $username * @param string $repository @@ -24,7 +24,7 @@ public function all(string $username, string $repository, array $parameters = [] } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs + * @link https://docs.github.com/en/rest/reference/actions#list-workflow-runs * * @param string $username * @param string $repository @@ -39,7 +39,7 @@ public function listRuns(string $username, string $repository, string $workflow, } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow-run + * @link https://docs.github.com/en/rest/reference/actions#get-a-workflow-run * * @param string $username * @param string $repository @@ -54,7 +54,7 @@ public function show(string $username, string $repository, int $runId, array $pa } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run + * @link https://docs.github.com/en/rest/reference/actions#delete-a-workflow-run * * @param string $username * @param string $repository @@ -68,7 +68,7 @@ public function remove(string $username, string $repository, int $runId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#re-run-a-workflow + * @link https://docs.github.com/en/rest/reference/actions#re-run-a-workflow * * @param string $username * @param string $repository @@ -82,7 +82,7 @@ public function rerun(string $username, string $repository, int $runId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#cancel-a-workflow-run + * @link https://docs.github.com/en/rest/reference/actions#cancel-a-workflow-run * * @param string $username * @param string $repository @@ -96,7 +96,7 @@ public function cancel(string $username, string $repository, int $runId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-run-usage + * @link https://docs.github.com/en/rest/reference/actions#get-workflow-run-usage * * @param string $username * @param string $repository @@ -110,7 +110,7 @@ public function usage(string $username, string $repository, int $runId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-workflow-run-logs + * @link https://docs.github.com/en/rest/reference/actions#download-workflow-run-logs * * @param string $username * @param string $repository @@ -124,7 +124,7 @@ public function downloadLogs(string $username, string $repository, int $runId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-workflow-run-logs + * @link https://docs.github.com/en/rest/reference/actions#delete-workflow-run-logs * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Actions/Workflows.php b/lib/Github/Api/Repository/Actions/Workflows.php index cf067d4ac17..e425f9d2651 100644 --- a/lib/Github/Api/Repository/Actions/Workflows.php +++ b/lib/Github/Api/Repository/Actions/Workflows.php @@ -5,12 +5,12 @@ use Github\Api\AbstractApi; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#workflows + * @link https://docs.github.com/en/rest/reference/actions#workflows */ class Workflows extends AbstractApi { /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows + * @link https://docs.github.com/en/rest/reference/actions#list-repository-workflows * * @param string $username * @param string $repository @@ -24,7 +24,7 @@ public function all(string $username, string $repository, array $parameters = [] } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-a-workflow + * @link https://docs.github.com/en/rest/reference/actions#get-a-workflow * * @param string $username * @param string $repository @@ -42,7 +42,7 @@ public function show(string $username, string $repository, $workflow) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#get-workflow-usage + * @link https://docs.github.com/en/rest/reference/actions#get-workflow-usage * * @param string $username * @param string $repository @@ -60,7 +60,7 @@ public function usage(string $username, string $repository, $workflow) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#create-a-workflow-dispatch-event + * @link https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event * * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Checks/CheckRuns.php b/lib/Github/Api/Repository/Checks/CheckRuns.php index d1e456212ce..37968a01816 100644 --- a/lib/Github/Api/Repository/Checks/CheckRuns.php +++ b/lib/Github/Api/Repository/Checks/CheckRuns.php @@ -6,14 +6,14 @@ use Github\Api\AcceptHeaderTrait; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks + * @link https://docs.github.com/en/rest/reference/checks */ class CheckRuns extends AbstractApi { use AcceptHeaderTrait; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run + * @link https://docs.github.com/en/rest/reference/checks#create-a-check-run * * @return array */ @@ -25,7 +25,7 @@ public function create(string $username, string $repository, array $params = []) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-run + * @link https://docs.github.com/en/rest/reference/checks#get-a-check-run * * @return array */ @@ -37,7 +37,7 @@ public function show(string $username, string $repository, int $checkRunId) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-a-check-run + * @link https://docs.github.com/en/rest/reference/checks#update-a-check-run * * @return array */ @@ -49,7 +49,7 @@ public function update(string $username, string $repository, int $checkRunId, ar } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations + * @link https://docs.github.com/en/rest/reference/checks#list-check-run-annotations * * @return array */ @@ -61,7 +61,7 @@ public function annotations(string $username, string $repository, int $checkRunI } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-in-a-check-suite + * @link https://docs.github.com/en/rest/reference/checks#list-check-runs-in-a-check-suite * * @return array */ @@ -73,7 +73,7 @@ public function allForCheckSuite(string $username, string $repository, int $chec } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-for-a-git-reference + * @link https://docs.github.com/en/rest/reference/checks#list-check-runs-for-a-git-reference * * @return array */ diff --git a/lib/Github/Api/Repository/Checks/CheckSuites.php b/lib/Github/Api/Repository/Checks/CheckSuites.php index ca6b432eb83..40c83a566c1 100644 --- a/lib/Github/Api/Repository/Checks/CheckSuites.php +++ b/lib/Github/Api/Repository/Checks/CheckSuites.php @@ -6,14 +6,14 @@ use Github\Api\AcceptHeaderTrait; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks + * @link https://docs.github.com/en/rest/reference/checks */ class CheckSuites extends AbstractApi { use AcceptHeaderTrait; /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-suite + * @link https://docs.github.com/en/rest/reference/checks#create-a-check-suite * * @return array */ @@ -25,7 +25,7 @@ public function create(string $username, string $repository, array $params = []) } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-repository-preferences-for-check-suites + * @link https://docs.github.com/en/rest/reference/checks#update-repository-preferences-for-check-suites * * @return array */ @@ -37,7 +37,7 @@ public function updatePreferences(string $username, string $repository, array $p } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-suite + * @link https://docs.github.com/en/rest/reference/checks#get-a-check-suite * * @return array */ @@ -49,7 +49,7 @@ public function getCheckSuite(string $username, string $repository, int $checkSu } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#rerequest-a-check-suite + * @link https://docs.github.com/en/rest/reference/checks#rerequest-a-check-suite * * @return array */ @@ -61,7 +61,7 @@ public function rerequest(string $username, string $repository, int $checkSuiteI } /** - * @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-suites-for-a-git-reference + * @link https://docs.github.com/en/rest/reference/checks#list-check-suites-for-a-git-reference * * @return array */ From 1a650c10a18bc389bfcd1f45976031a19ea110de Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Tue, 29 Dec 2020 11:48:05 +0000 Subject: [PATCH 819/951] ExceptionThrower: adjust rate limit detection --- .../Plugin/GithubExceptionThrower.php | 2 +- .../Plugin/GithubExceptionThrowerTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 70373e00ea1..21e6dd3434f 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -37,7 +37,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla // If error: $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); - if (null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { + if ((429 === $response->getStatusCode()) && null !== $remaining && 1 > $remaining && 'rate_limit' !== substr($request->getRequestTarget(), 1, 10)) { $limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); $reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 9c1de98d59d..b367fe15779 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -177,6 +177,25 @@ public static function responseProvider() ), 'exception' => new \Github\Exception\RuntimeException('Field "xxxx" doesn\'t exist on type "Issue", Field "dummy" doesn\'t exist on type "PullRequest"'), ], + 'Grapql requires authentication' => [ + 'response' => new Response( + 401, + [ + 'content-type' => 'application/json', + 'X-RateLimit-Limit' => 0, + 'X-RateLimit-Remaining' => 0, + 'X-RateLimit-Reset' => 1609245810, + 'X-RateLimit-Used' => 0, + ], + json_encode( + [ + 'message' => 'This endpoint requires you to be authenticated.', + 'documentation_url' => 'https://docs.github.com/v3/#authentication', + ] + ) + ), + 'exception' => new \Github\Exception\RuntimeException('This endpoint requires you to be authenticated.', 401), + ], ]; } } From 90e695e8978d510a83cc23065c3c566e39c1421a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 11 Mar 2021 21:11:17 +0100 Subject: [PATCH 820/951] Update changelog for 2.19.1 release --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5728ab245b..58ed13d0ad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.19.1 + +### Fixed +- ExceptionThrower: adjust rate limit detection ([glaubinix](https://github.com/glaubinix)) [#959](https://github.com/KnpLabs/php-github-api/issues/959) + ## 2.19.0 ### Added From 95a5ced277a62e9a1253b12b9435e637603a2cbf Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 11 Mar 2021 21:13:37 +0100 Subject: [PATCH 821/951] Update changelog for 3.1.0 release --- CHANGELOG-3.X.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 544e4e8ba59..2a59ff99c36 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,19 @@ # Changelog +## 3.1.0 + +### Added +- Add workflow dispatch and allow workflow names. ([fodinabor](https://github.com/fodinabor)) [#969](https://github.com/KnpLabs/php-github-api/issues/969) + +### Changed +- Re-enable roave bc check for 3.x ([acrobat](https://github.com/acrobat)) [#958](https://github.com/KnpLabs/php-github-api/issues/958) +- Cleanup 3.0.0 changelog ([acrobat](https://github.com/acrobat)) [#957](https://github.com/KnpLabs/php-github-api/issues/957) +- Update new GitHub doc links in repo. ([fodinabor](https://github.com/fodinabor)) [#974](https://github.com/KnpLabs/php-github-api/issues/974) + +### Fixed +- Add accept header for the checks API ([Agares](https://github.com/Agares)) [#968](https://github.com/KnpLabs/php-github-api/issues/968) +- ExceptionThrower: adjust rate limit detection ([glaubinix](https://github.com/glaubinix)) [#959](https://github.com/KnpLabs/php-github-api/issues/959) + ## 3.0.0 ### Added From eeda6f10124abd01611a323d685c60b14d128d94 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 14 Mar 2021 23:51:35 +0000 Subject: [PATCH 822/951] Fixed branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c6e2a7a476a..864d25c0219 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.19.x-dev", - "dev-master": "3.0.x-dev" + "dev-master": "3.1.x-dev" } } } From 5fb3a4dc4c0e81bbb6a499a4cc0d09dbf8f8db46 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 25 Mar 2021 13:13:13 +0100 Subject: [PATCH 823/951] fix typo --- doc/repo/deployments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/deployments.md b/doc/repo/deployments.md index 740bac4dd0c..b22df27eca6 100644 --- a/doc/repo/deployments.md +++ b/doc/repo/deployments.md @@ -21,7 +21,7 @@ $deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api', arra $deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id); ``` -#### Create a new deployments. +#### Create a new deployment. The `ref` parameter is required. From 533a79801d37593058381b801478065b937dfb89 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 25 Mar 2021 19:03:17 +0100 Subject: [PATCH 824/951] bug #979 Deployments: use proper media-type for in_progress/queued, inactive state (staabm) This PR was squashed before being merged into the 3.1.x-dev branch. Discussion ---------- closes https://github.com/KnpLabs/php-github-api/issues/978 Commits ------- 5ffefdc214895bc9669cc3899b60586c5d6babda Deployments: use correct media-type for in_progress/queued, inactive bf3eb1f715254c6c05035f82a8c670c12f705a1c Update Deployment.php ca128f6bf94cf955be2dfb34d6a75bfce8073a0d cs --- lib/Github/Api/Deployment.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 6fa8700a6da..454d59db0be 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -11,6 +11,8 @@ */ class Deployment extends AbstractApi { + use AcceptHeaderTrait; + /** * List deployments for a particular repository. * @@ -88,6 +90,15 @@ public function updateStatus($username, $repository, $id, array $params) throw new MissingArgumentException(['state']); } + // adjust media-type per github docs + // https://docs.github.com/en/rest/reference/repos#create-a-deployment-status + if ($params['state'] === 'inactive') { + $this->acceptHeaderValue = 'application/vnd.github.ant-man-preview+json'; + } + if ($params['state'] === 'in_progress' || $params['state'] === 'queued') { + $this->acceptHeaderValue = 'application/vnd.github.flash-preview+json'; + } + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses', $params); } From 0c2815f2719b8dbf9d36b8a45c52478cae16dede Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 25 Mar 2021 19:03:17 +0100 Subject: [PATCH 825/951] bug #979 Deployments: use proper media-type for in_progress/queued, inactive state (staabm) This PR was squashed before being merged into the 3.1.x-dev branch. Discussion ---------- closes https://github.com/KnpLabs/php-github-api/issues/978 Commits ------- 5ffefdc214895bc9669cc3899b60586c5d6babda Deployments: use correct media-type for in_progress/queued, inactive bf3eb1f715254c6c05035f82a8c670c12f705a1c Update Deployment.php ca128f6bf94cf955be2dfb34d6a75bfce8073a0d cs --- lib/Github/Api/Deployment.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 6fa8700a6da..454d59db0be 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -11,6 +11,8 @@ */ class Deployment extends AbstractApi { + use AcceptHeaderTrait; + /** * List deployments for a particular repository. * @@ -88,6 +90,15 @@ public function updateStatus($username, $repository, $id, array $params) throw new MissingArgumentException(['state']); } + // adjust media-type per github docs + // https://docs.github.com/en/rest/reference/repos#create-a-deployment-status + if ($params['state'] === 'inactive') { + $this->acceptHeaderValue = 'application/vnd.github.ant-man-preview+json'; + } + if ($params['state'] === 'in_progress' || $params['state'] === 'queued') { + $this->acceptHeaderValue = 'application/vnd.github.flash-preview+json'; + } + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses', $params); } From e182f74b74cb45c10649ceeb82cff95d768d5e71 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 27 Mar 2021 10:07:05 +0100 Subject: [PATCH 826/951] Improved bc check --- .github/workflows/backwards-compatibility.yml | 18 ++++++++++++++++++ .github/workflows/ci.yml | 9 --------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/backwards-compatibility.yml diff --git a/.github/workflows/backwards-compatibility.yml b/.github/workflows/backwards-compatibility.yml new file mode 100644 index 00000000000..1dd4c3a4e05 --- /dev/null +++ b/.github/workflows/backwards-compatibility.yml @@ -0,0 +1,18 @@ +name: "BC check" + +on: + pull_request: + +jobs: + roave_bc_check: + name: "Roave BC check" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Roave BC Check + uses: docker://nyholm/roave-bc-check-ga + with: + args: --from=${{ github.event.pull_request.base.sha }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index daffb5b9ac4..78fdec578ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,15 +28,6 @@ jobs: - name: Run phpunit run: vendor/bin/phpunit --verbose - roave_bc_check: - name: Roave BC Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga - phpstan: name: PHPStan runs-on: ubuntu-latest From 8343f247a272349b4f22f9a31469c20859dafa1a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 27 Mar 2021 12:25:11 +0100 Subject: [PATCH 827/951] Correctly link to github actions docs and fix backlinks --- doc/README.md | 7 +++++++ doc/repo/actions/artifacts.md | 4 ++-- doc/repo/actions/secrets.md | 4 ++-- doc/repo/actions/self_hosted_runners.md | 4 ++-- doc/repo/actions/workflow_jobs.md | 4 ++-- doc/repo/actions/workflow_runs.md | 4 ++-- doc/repo/actions/workflows.md | 4 ++-- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/doc/README.md b/doc/README.md index 361cdaaba8b..acae0d3a441 100644 --- a/doc/README.md +++ b/doc/README.md @@ -48,6 +48,13 @@ v3 APIs: * [Reviews](pull_request/reviews.md) * [Rate Limits](rate_limits.md) * [Repositories](repos.md) + * Actions + * [Artifacts](repo/actions/artifacts.md) + * [Secrets](repo/actions/secrets.md) + * [Self hosted runners](repo/actions/self_hosted_runners.md) + * [Workflow jobs](repo/actions/workflow_jobs.md) + * [Workflow runs](repo/actions/workflow_runs.md) + * [Workflows](repo/actions/workflows.md) * [Check Runs](repo/check_runs.md) * [Check Suites](repo/check_suites.md) * [Contents](repo/contents.md) diff --git a/doc/repo/actions/artifacts.md b/doc/repo/actions/artifacts.md index b457f12c806..c20d37309c0 100644 --- a/doc/repo/actions/artifacts.md +++ b/doc/repo/actions/artifacts.md @@ -1,5 +1,5 @@ -## Repo / Artifacts API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +## Repo / Actions / Artifacts API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) ### List artifacts for a repository diff --git a/doc/repo/actions/secrets.md b/doc/repo/actions/secrets.md index 037409fd53e..a3718aff931 100644 --- a/doc/repo/actions/secrets.md +++ b/doc/repo/actions/secrets.md @@ -1,5 +1,5 @@ -## Repo / Secrets API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +## Repo / Actions / Secrets API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) ### List repository secrets diff --git a/doc/repo/actions/self_hosted_runners.md b/doc/repo/actions/self_hosted_runners.md index 1c09767d6cd..1f754a4802b 100644 --- a/doc/repo/actions/self_hosted_runners.md +++ b/doc/repo/actions/self_hosted_runners.md @@ -1,5 +1,5 @@ -## Repo / Self Hosted Runners API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +## Repo / Actions / Self Hosted Runners API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) # List self-hosted runners for a repository diff --git a/doc/repo/actions/workflow_jobs.md b/doc/repo/actions/workflow_jobs.md index 151c59c5e95..12dbbff98f6 100644 --- a/doc/repo/actions/workflow_jobs.md +++ b/doc/repo/actions/workflow_jobs.md @@ -1,5 +1,5 @@ -## Repo / Workflow Jobs API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +## Repo / Actions / Workflow Jobs API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) ### List jobs for a workflow run diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md index 88c6da7c621..66438567d48 100644 --- a/doc/repo/actions/workflow_runs.md +++ b/doc/repo/actions/workflow_runs.md @@ -1,5 +1,5 @@ -## Repo / Workflow Runs API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +## Repo / Actions / Workflow Runs API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) ### List workflow runs for a repository diff --git a/doc/repo/actions/workflows.md b/doc/repo/actions/workflows.md index d6689d90aa2..3e47bbb2b49 100644 --- a/doc/repo/actions/workflows.md +++ b/doc/repo/actions/workflows.md @@ -1,5 +1,5 @@ -## Repo / Workflows API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +## Repo / Actions / Workflows API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) ### List repository workflows From d34314347006a4b5f64ff70bbef8c2656a95e44e Mon Sep 17 00:00:00 2001 From: Andrew MacRobert Date: Sun, 28 Mar 2021 05:29:13 -0400 Subject: [PATCH 828/951] bug #953 [952] doc - Specify lcobucci/jwt version, fix deprecation (amacrobert-meq, acrobat) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Fixes #952 Commits ------- 1b853a393edb43226afe9860990079294c9ace46 [952] doc - Specify lcobucci/jwt version, fix deprecation 408f0b7f061136642166162a599500c5ea056c5c Merge branch '2.x' into 952-integration-doc-update 25ba522926da869cf6d1564c2d6515804d082bdd Apply latest changes b6ebc9b65a6f0229912b397f485c8514c3b96f9b Merge remote-tracking branch 'upstream/2.x' into amacrobert-meq--952-integration-doc-update --- doc/security.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/security.md b/doc/security.md index 10608a7eb51..6f0d4cf5533 100644 --- a/doc/security.md +++ b/doc/security.md @@ -55,30 +55,30 @@ and installation access token which is then usable with `Github\Client::AUTH_ACC authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail. It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. -The following sample code authenticates as an installation using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.3.2) +The following sample code authenticates as an installation using [lcobucci/jwt 3.4](https://github.com/lcobucci/jwt/tree/3.4) to generate a JSON Web Token (JWT). ```php -use Http\Adapter\Guzzle6\Client as GuzzleClient; -use Lcobucci\JWT\Builder; -use Lcobucci\JWT\Signer\Key; +use Lcobucci\JWT\Configuration; +use Lcobucci\JWT\Signer\Key\LocalFileReference; use Lcobucci\JWT\Signer\Rsa\Sha256; -$builder = new Github\HttpClient\Builder(new GuzzleClient()); $github = new Github\Client($builder, 'machine-man-preview'); -$jwt = (new Builder) - ->setIssuer($integrationId) - ->setIssuedAt(time()) - ->setExpiration(time() + 60) - // `file://` prefix for file path or file contents itself - ->sign(new Sha256(), new Key('file:///path/to/integration.private-key.pem')) - ->getToken(); +$config = Configuration::forSymmetricSigner( + new Sha256(), + LocalFileReference::file('path/to/integration.private-key.pem') +); -$github->authenticate($jwt, null, Github\Client::AUTH_JWT); +$now = new \DateTimeImmutable(); +$jwt = $config->builder() + ->issuedBy($integrationId) + ->issuedAt($now) + ->expiresAt($now->modify('+1 minute')) + ->getToken($config->signer(), $config->signingKey()) +; -$token = $github->api('apps')->createInstallationToken($installationId); -$github->authenticate($token['token'], null, Github\Client::AUTH_ACCESS_TOKEN); +$github->authenticate($jwt, null, Github\Client::AUTH_JWT) ``` The `$integrationId` you can find in the about section of your github app. From 251e5b7e5c6e08a9c3b7f1adba3c26262a67f041 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 12:16:51 +0200 Subject: [PATCH 829/951] Replace deprecated organization team repository add/remove urls --- lib/Github/Api/Organization/Teams.php | 6 +++--- test/Github/Tests/Api/Organization/TeamsTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 8b84028db24..10e95228476 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -149,15 +149,15 @@ public function repository($team, $organization, $repository) public function addRepository($team, $organization, $repository, $params = []) { - if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin'])) { + if (isset($params['permission']) && !in_array($params['permission'], ['pull', 'push', 'admin', 'maintain', 'triage'])) { $params['permission'] = 'pull'; } - return $this->put('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository), $params); + return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository), $params); } public function removeRepository($team, $organization, $repository) { - return $this->delete('/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository)); + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/repos/'.rawurlencode($organization).'/'.rawurlencode($repository)); } } diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 3538113ad61..45c98cb9a1d 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -161,7 +161,7 @@ public function shouldAddTeamRepository() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/teams/KnpWorld/repos/l3l0/l3l0Repo') + ->with('/orgs/l3l0/teams/KnpWorld/repos/l3l0/l3l0Repo') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->addRepository('KnpWorld', 'l3l0', 'l3l0Repo')); @@ -177,7 +177,7 @@ public function shouldRemoveTeamRepository() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/teams/KnpWorld/repos/l3l0/l3l0Repo') + ->with('/orgs/l3l0/teams/KnpWorld/repos/l3l0/l3l0Repo') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->removeRepository('KnpWorld', 'l3l0', 'l3l0Repo')); From 0f1f10fa2d11f1265480f8fa27a484fc707f04cf Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 10:20:23 +0200 Subject: [PATCH 830/951] Add deprecations to the PR review methods to allow cleanup --- composer.json | 3 ++- lib/Github/Api/PullRequest/Review.php | 6 ++++++ lib/Github/Api/PullRequest/ReviewRequest.php | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 864d25c0219..cb858e180f0 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0", - "symfony/polyfill-php80": "^1.17" + "symfony/polyfill-php80": "^1.17", + "symfony/deprecation-contracts": "^2.2" }, "require-dev": { "symfony/cache": "^5.1.8", diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 249477f0478..ed586ddf6fc 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -20,6 +20,8 @@ class Review extends AbstractApi public function configure() { + trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "%s" is deprecated and will be removed.', __METHOD__); + return $this; } @@ -37,6 +39,10 @@ public function configure() */ public function all($username, $repository, $pullRequest, array $params = []) { + if (!empty($params)) { + trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "$params" parameter is deprecated, to paginate the results use the "ResultPager" instead.'); + } + $parameters = array_merge([ 'page' => 1, 'per_page' => 30, diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php index 540307559e2..d95913ccde3 100644 --- a/lib/Github/Api/PullRequest/ReviewRequest.php +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -14,6 +14,8 @@ class ReviewRequest extends AbstractApi public function configure() { + trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "%s" is deprecated and will be removed.', __METHOD__); + return $this; } @@ -29,6 +31,10 @@ public function configure() */ public function all($username, $repository, $pullRequest, array $params = []) { + if (!empty($params)) { + trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "$params" parameter is deprecated, to paginate the results use the "ResultPager" instead.'); + } + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', $params); } From cf7ca9a2652d76dc4c395f3b5db3dd2d5f387cac Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 13:06:32 +0200 Subject: [PATCH 831/951] Deprecate ResultPager::postFetch method --- UPGRADE-4.0.md | 5 +++++ composer.json | 8 +++++--- lib/Github/ResultPager.php | 17 +++++++++++++---- lib/Github/ResultPagerInterface.php | 2 ++ phpunit.xml.dist | 4 ++++ test/Github/Tests/ResultPagerTest.php | 17 +++++++++++++++++ 6 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 UPGRADE-4.0.md diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md new file mode 100644 index 00000000000..9192a02a726 --- /dev/null +++ b/UPGRADE-4.0.md @@ -0,0 +1,5 @@ +## UPGRADE from 3.x to 4.0 + +### ResultPager + +* `\Github\ResultPagerInterface::postFetch` is deprecated, and the method will be removed from the ResultPager interface/class. diff --git a/composer.json b/composer.json index 864d25c0219..ef03d2e3d64 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0", - "symfony/polyfill-php80": "^1.17" + "symfony/polyfill-php80": "^1.17", + "symfony/deprecation-contracts": "^2.2" }, "require-dev": { "symfony/cache": "^5.1.8", @@ -39,7 +40,8 @@ "phpstan/phpstan": "^0.12.57", "phpstan/extension-installer": "^1.0.5", "phpstan/phpstan-deprecation-rules": "^0.12.5", - "phpunit/phpunit": "^8.5 || ^9.4" + "phpunit/phpunit": "^8.5 || ^9.4", + "symfony/phpunit-bridge": "^5.2" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } @@ -50,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.19.x-dev", - "dev-master": "3.1.x-dev" + "dev-master": "3.2.x-dev" } } } diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index 5f9c40d0911..cfd1d605e4f 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -86,7 +86,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []): $api = $closure($api); $result = $api->$method(...$parameters); - $this->postFetch(); + $this->postFetch(true); return $result; } @@ -130,9 +130,13 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters /** * {@inheritdoc} */ - public function postFetch(): void + public function postFetch(/* $skipDeprecation = false */): void { - $this->pagination = ResponseMediator::getPagination($this->client->getLastResponse()); + if (func_num_args() === 0 || (func_num_args() > 0 && false === func_get_arg(0))) { + trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "%s" method is deprecated and will be removed.', __METHOD__); + } + + $this->setPagination(); } /** @@ -196,8 +200,13 @@ protected function get(string $key): array $result = $this->client->getHttpClient()->get($this->pagination[$key]); - $this->postFetch(); + $this->postFetch(true); return ResponseMediator::getContent($result); } + + private function setPagination(): void + { + $this->pagination = ResponseMediator::getPagination($this->client->getLastResponse()); + } } diff --git a/lib/Github/ResultPagerInterface.php b/lib/Github/ResultPagerInterface.php index 350f8453e05..bf7618ee411 100644 --- a/lib/Github/ResultPagerInterface.php +++ b/lib/Github/ResultPagerInterface.php @@ -54,6 +54,8 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters /** * Method that performs the actual work to refresh the pagination property. * + * @deprecated since 3.2 and will be removed in 4.0. + * * @return void */ public function postFetch(): void; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3b6dc204b03..98d2e51cc8f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,4 +27,8 @@ ./lib/Github/ + + + + diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 41327c5d9d1..2839e16f3df 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -13,6 +13,7 @@ use GuzzleHttp\Psr7\Utils; use Http\Client\HttpClient; use Psr\Http\Client\ClientInterface; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @author Ramon de la Fuente @@ -21,6 +22,8 @@ */ class ResultPagerTest extends \PHPUnit\Framework\TestCase { + use ExpectDeprecationTrait; + public function provideFetchCases() { return [ @@ -197,4 +200,18 @@ public function testFetchAllWithoutKeys() $this->assertCount(9, $result); } + + /** + * @group legacy + */ + public function testPostFetchDeprecation() + { + $this->expectDeprecation('Since KnpLabs/php-github-api 3.2: The "Github\ResultPager::postFetch" method is deprecated and will be removed.'); + + $clientMock = $this->createMock(Client::class); + $clientMock->method('getLastResponse')->willReturn(new PaginatedResponse(3, [])); + + $paginator = new ResultPager($clientMock); + $paginator->postFetch(); + } } From eec9015fdb37f3fb88ba25bafdac4225b23ee7dd Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 13:41:43 +0200 Subject: [PATCH 832/951] Add missing repo hooks documentation --- doc/repo/hooks.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 doc/repo/hooks.md diff --git a/doc/repo/hooks.md b/doc/repo/hooks.md new file mode 100644 index 00000000000..1f89ed40405 --- /dev/null +++ b/doc/repo/hooks.md @@ -0,0 +1,46 @@ +## Repo / Hooks API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +For extended info see the [Github documentation](https://docs.github.com/en/rest/reference/repos#webhooks) + +### List repository webhooks + +```php +$hooks = $client->api('repo')->hooks()->all('twbs', 'bootstrap'); +``` + +### Get a repository webhook + +```php +$hook = $client->api('repo')->hooks()->show('twbs', 'bootstrap', $hookId); +``` + +### Create a repository webhook + +```php +$client->api('repo')->hooks()->create('twbs', 'bootstrap', $parameters); +``` + +### Update a repository webhook + +```php +$client->api('repo')->hooks()->update('twbs', 'bootstrap', $hookId, $parameters); +``` + +### Delete a repository webhook + +```php +$client->api('repo')->hooks()->remove('twbs', 'bootstrap', $hookId); +``` + +### Ping a repository webhook + +```php +$client->api('repo')->hooks()->ping('twbs', 'bootstrap', $hookId); +``` + +### Test the push repository webhook + +```php +$client->api('repo')->hooks()->test('twbs', 'bootstrap', $hookId); +``` From 2cc80c5e2a79d3447c2d5868e95e10f2f9316d00 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 13:45:31 +0200 Subject: [PATCH 833/951] Fix incorrect public key documentation --- doc/currentuser/publickeys.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/currentuser/publickeys.md b/doc/currentuser/publickeys.md index f0eb72ad421..a9d19018f2d 100644 --- a/doc/currentuser/publickeys.md +++ b/doc/currentuser/publickeys.md @@ -6,7 +6,7 @@ Wraps [GitHub User Public Keys API](https://developer.github.com/v3/users/keys/# ### List your public keys ```php -$keys = $client->user()->keys()->all(); +$keys = $client->me()->keys()->all(); ``` Returns a list of public keys for the authenticated user. @@ -14,7 +14,7 @@ Returns a list of public keys for the authenticated user. ### Shows a public key for the authenticated user. ```php -$key = $client->user()->keys()->show(1234); +$key = $client->me()->keys()->show(1234); ``` ### Add a public key to the authenticated user. @@ -22,7 +22,7 @@ $key = $client->user()->keys()->show(1234); > Requires [authentication](../security.md). ```php -$key = $client->user()->keys()->create(array('title' => 'key title', 'key' => 12345)); +$key = $client->me()->keys()->create(array('title' => 'key title', 'key' => 12345)); ``` Adds a key with title 'key title' to the authenticated user and returns a the created key for the user. @@ -32,5 +32,5 @@ Adds a key with title 'key title' to the authenticated user and returns a the cr > Requires [authentication](../security.md). ```php -$client->user()->keys()->remove(12345); +$client->me()->keys()->remove(12345); ``` From f3ea9b3204451be08d8e66c0d95f00c43cd526da Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 14:06:56 +0200 Subject: [PATCH 834/951] Fixed incorrect parameters in apps docs --- doc/apps.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/apps.md b/doc/apps.md index 7133ceb117a..f7a61328092 100644 --- a/doc/apps.md +++ b/doc/apps.md @@ -31,23 +31,21 @@ $installations = $client->api('current_user')->installations(); List repositories that are accessible to the authenticated installation. ```php -$repositories = $client->api('apps')->listRepositories(456); +$repositories = $client->api('apps')->listRepositories($userId); ``` ### List repositories for a given installation and user ```php -$repositories = $client->api('current_user')->repositoriesByInstallation(456); +$repositories = $client->api('current_user')->repositoriesByInstallation($installationId, $parameters); ``` ### Add repository to installation -Add a single repository to an installation. ```php -$client->api('apps')->addRepository(123); +$client->api('apps')->addRepository($installationId, $repositoryId); ``` ### Remove repository from installation -Remove a single repository from an installation. ```php -$client->api('apps')->removeRepository(123); +$client->api('apps')->removeRepository($installationId, $repositoryId); ``` From c03fd120032547f7eef59397353b258087b6114d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 14:59:06 +0200 Subject: [PATCH 835/951] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 482a030b46e..cc214a2f354 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.19.x-dev", - "dev-master": "3.0.x-dev" + "dev-master": "3.2.x-dev" } } } From ad3b8e6084729adff5c804bc7058afc57ba04224 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 15:11:08 +0200 Subject: [PATCH 836/951] Update changelog for 2.19.2 release --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58ed13d0ad2..bb85c6b2418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 2.19.2 + +### Changed +- Improved bc check ([acrobat](https://github.com/acrobat)) [#982](https://github.com/KnpLabs/php-github-api/issues/982) +- Correctly link to github actions docs and fix backlinks ([acrobat](https://github.com/acrobat)) [#983](https://github.com/KnpLabs/php-github-api/issues/983) +- Add missing repo hooks documentation ([acrobat](https://github.com/acrobat)) [#987](https://github.com/KnpLabs/php-github-api/issues/987) +- Fix incorrect public key documentation ([acrobat](https://github.com/acrobat)) [#988](https://github.com/KnpLabs/php-github-api/issues/988) +- Fixed incorrect parameters in apps docs ([acrobat](https://github.com/acrobat)) [#989](https://github.com/KnpLabs/php-github-api/issues/989) + +### Fixed +- Deployments: use proper media-type for in_progress/queued, inactive state ([staabm](https://github.com/staabm)) [#979](https://github.com/KnpLabs/php-github-api/issues/979) +- backported #979 into 2.x ([staabm](https://github.com/staabm)) [#981](https://github.com/KnpLabs/php-github-api/issues/981) +- [952] doc - Specify lcobucci/jwt version, fix deprecation ([amacrobert-meq](https://github.com/amacrobert-meq), [acrobat](https://github.com/acrobat)) [#953](https://github.com/KnpLabs/php-github-api/issues/953) +- Replace deprecated organization team repository add/remove urls ([acrobat](https://github.com/acrobat)) [#985](https://github.com/KnpLabs/php-github-api/issues/985) + ## 2.19.1 ### Fixed From dc61c89ed6a03d90f769a885620563c4df7625c4 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 28 Mar 2021 17:37:17 +0200 Subject: [PATCH 837/951] Allow binary content downloads of assets --- doc/repo/assets.md | 6 ++++++ lib/Github/Api/Repository/Assets.php | 11 +++++++++-- lib/Github/Client.php | 5 ++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/repo/assets.md b/doc/repo/assets.md index 3df3eae2b72..93234929074 100644 --- a/doc/repo/assets.md +++ b/doc/repo/assets.md @@ -13,6 +13,12 @@ $assets = $client->api('repo')->releases()->assets()->all('twbs', 'bootstrap', $ $asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId); ``` +### Download binary content of asset + +```php +$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId, true); +``` + ### Create an asset ```php diff --git a/lib/Github/Api/Repository/Assets.php b/lib/Github/Api/Repository/Assets.php index 39cdc5da913..043016e7801 100644 --- a/lib/Github/Api/Repository/Assets.php +++ b/lib/Github/Api/Repository/Assets.php @@ -3,6 +3,7 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\ErrorException; use Github\Exception\MissingArgumentException; @@ -13,6 +14,8 @@ */ class Assets extends AbstractApi { + use AcceptHeaderTrait; + /** * Get all release's assets in selected repository * GET /repos/:owner/:repo/releases/:id/assets. @@ -36,10 +39,14 @@ public function all($username, $repository, $id) * @param string $repository the name of the repo * @param int $id the id of the asset * - * @return array + * @return array|string */ - public function show($username, $repository, $id) + public function show($username, $repository, $id, bool $returnBinaryContent = false) { + if ($returnBinaryContent) { + $this->acceptHeaderValue = 'application/octet-stream'; + } + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.$id); } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 1a101a34a8f..6ea5072ab7f 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -119,6 +119,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul { $this->responseHistory = new History(); $this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder(); + $this->apiVersion = $apiVersion ?: 'v3'; $builder->addPlugin(new GithubExceptionThrower()); $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); @@ -126,11 +127,9 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('https://api.github.com'))); $builder->addPlugin(new Plugin\HeaderDefaultsPlugin([ 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', + 'Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion), ])); - $this->apiVersion = $apiVersion ?: 'v3'; - $builder->addHeaderValue('Accept', sprintf('application/vnd.github.%s+json', $this->apiVersion)); - if ($enterpriseUrl) { $this->setEnterpriseUrl($enterpriseUrl); } From 71a299b586b012faa4735dd62ab306da011b5a50 Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Wed, 31 Mar 2021 13:45:26 +0200 Subject: [PATCH 838/951] phpdoc: fix typo --- lib/Github/Api/Deployment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 454d59db0be..c9be14b0197 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -78,7 +78,7 @@ public function create($username, $repository, array $params) * @param int $id the deployment number * @param array $params The information about the deployment update. * Must include a "state" field of pending, success, error, or failure. - * May also be given a target_url and description, ßee link for more details. + * May also be given a target_url and description, see link for more details. * * @throws MissingArgumentException * From e9576a6073b559b18385431220ebd51026cae531 Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Sun, 4 Apr 2021 19:48:08 +0200 Subject: [PATCH 839/951] bug #992 fixed php warning in GithubExceptionThrower (clxmstaab, acrobat) This PR was squashed before being merged into the 2.x branch. Discussion ---------- fixes ``` Warning: Illegal string offset 'code' in GithubExceptionThrower.php on line 59 ``` when deleting a deployment which is not yet set to inactive, see https://github.com/KnpLabs/php-github-api/pull/991 I guess the warning beeing fixed is not explicitly related to the new endpoint added in #991 but I experienced it in this case. Commits ------- 2afb40cd9e775668fe3329c9179df39e3d625b8e fixed php warning in GithubExceptionThrower 2b353115fbefe0d792175852828d1d47059248ae added testcase a54c2233142b9f71559e0491e69f1c2c0eb78a06 Update lib/Github/HttpClient/Plugin/GithubExceptionThrower.php e000f001037a2d89ede35a3b8ec2d8cc2a1dac5b Update GithubExceptionThrower.php 0e0265fab5a0592f253ff6d87e55663db4626d4a fix CS 1ae94ab478cac73f5465cde685caa08fdd370c73 Improve single message errors and testcase --- .../Plugin/GithubExceptionThrower.php | 8 +++++++- .../Plugin/GithubExceptionThrowerTest.php | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 21e6dd3434f..7a4bc1e0ba8 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -59,7 +59,7 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla if (422 === $response->getStatusCode() && isset($content['errors'])) { $errors = []; foreach ($content['errors'] as $error) { - switch ($error['code']) { + switch ($error['code'] ?? null) { case 'missing': $errors[] = sprintf('The %s %s does not exist, for resource "%s"', $error['field'], $error['value'], $error['resource']); break; @@ -81,6 +81,12 @@ public function doHandleRequest(RequestInterface $request, callable $next, calla break; default: + if (is_string($error)) { + $errors[] = $error; + + break; + } + if (isset($error['message'])) { $errors[] = $error['message']; } diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index b367fe15779..e57f2cce70e 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -37,7 +37,7 @@ public function testHandleRequest(ResponseInterface $response, ExceptionInterfac if ($exception) { $this->expectException(get_class($exception)); $this->expectExceptionCode($exception->getCode()); - $this->expectExceptionMessage($exception->getMessage()); + $this->expectExceptionMessageRegExp('/'.preg_quote($exception->getMessage(), '/').'$/'); } $plugin->doHandleRequest( @@ -196,6 +196,22 @@ public static function responseProvider() ), 'exception' => new \Github\Exception\RuntimeException('This endpoint requires you to be authenticated.', 401), ], + 'Cannot delete active deployment' => [ + 'response' => new Response( + 422, + [ + 'content-type' => 'application/json', + ], + json_encode( + [ + 'message' => 'Validation Failed', + 'errors' => ['We cannot delete an active deployment unless it is the only deployment in a given environment.'], + 'documentation_url' => 'https://docs.github.com/rest/reference/repos#delete-a-deployment', + ] + ) + ), + 'exception' => new \Github\Exception\ValidationFailedException('Validation Failed: We cannot delete an active deployment unless it is the only deployment in a given environment.', 422), + ], ]; } } From 014521cda7833901ae1e95d90702e36929b91ffa Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 4 Apr 2021 19:55:22 +0200 Subject: [PATCH 840/951] Fix upmerged usage of deprecated phpunit assert --- .../Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 4563b403eff..4f6f9a5615b 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -49,7 +49,7 @@ function (RequestInterface $request) use ($promise) { if ($exception) { $this->expectException(get_class($exception)); $this->expectExceptionCode($exception->getCode()); - $this->expectExceptionMessageRegExp('/'.preg_quote($exception->getMessage(), '/').'$/'); + $this->expectExceptionMessageMatches('/'.preg_quote($exception->getMessage(), '/').'$/'); } $result->wait(); From 4fa7f3e0a55ae266b9ada3d4ff3ef7ae0bb9cbc9 Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Wed, 7 Apr 2021 11:20:05 +0200 Subject: [PATCH 841/951] feature #991 Deployments: added missing 'delete deployment' endpoint (clxmstaab) This PR was squashed before being merged into the 2.x branch. Discussion ---------- this api endpoint was missing completely from the client. this is the only missing feature in 2.x for me, so it would be really cool this could be merged into 2.x. my php constraints do not allow me to update to 3.x yet. this PR added the endpoint as described in https://docs.github.com/en/rest/reference/repos#delete-a-deployment Commits ------- 095f4633eed4d3d20f7dad7b5c2f046410774b02 Deployments: added missing 'delete deployment' endpoint 6ee0e0b7bdc26e23b2216c6670308bc8f14719b5 added test 06787a1a8d12505063f3778fe3142739fdba4d9c cs 53d5ea3c6380040ccc2200cac5bea47d40d1300f Update deployments.md fc3e323701779fe3db2ef307d2cbdabc858f7b68 removed phpdocs, use native typehints --- doc/repo/deployments.md | 14 ++++++++++++-- lib/Github/Api/Deployment.php | 15 +++++++++++++++ test/Github/Tests/Api/DeploymentTest.php | 16 +++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/doc/repo/deployments.md b/doc/repo/deployments.md index 740bac4dd0c..8c2ae1a8675 100644 --- a/doc/repo/deployments.md +++ b/doc/repo/deployments.md @@ -21,7 +21,7 @@ $deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api', arra $deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id); ``` -#### Create a new deployments. +#### Create a new deployment. The `ref` parameter is required. @@ -31,9 +31,19 @@ $data = $client->api('deployment')->create('KnpLabs', 'php-github-api', array('r Please note that once a deployment is created it cannot be edited. Only status updates can be created. +#### Delete a existing deployment. + +```php +$deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id); +``` + +Please note that a deployment can only be deleted when in inactive state. +Consider transitioning the status to `inactive` beforehand using `updateStatus`. + + #### Create a new status update. -The `state` parameter is required. At the time of writing, this must be pending, success, error, or failure. +The `state` parameter is required. At the time of writing, this must be pending, queued, in_progress, success, inactive, error, or failure. ```php $data = $client->api('deployment')->updateStatus('KnpLabs', 'php-github-api', 1, array('state' => 'error', 'description' => 'syntax error')); diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index c9be14b0197..f6127357ee9 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -68,6 +68,21 @@ public function create($username, $repository, array $params) return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } + /** + * Delete a deployment for the given username and repo. + * + * @link https://docs.github.com/en/rest/reference/repos#delete-a-deployment + * + * Important: Deployments can only be deleted when in inactive state + * @see updateStatus + * + * @return mixed null on success, array on error with 'message' + */ + public function remove(string $username, string $repository, int $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id); + } + /** * Updates a deployment by creating a new status update. * diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 223f3e2fd33..88e8c923ce1 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -51,7 +51,7 @@ public function shouldGetAllDeploymentsWithFilterParameters() /** * @test */ - public function shouldShowProject() + public function shouldShowDeployment() { $expectedValue = ['id' => 123, 'ref' => 'master']; @@ -64,6 +64,20 @@ public function shouldShowProject() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); } + /** + * @test + */ + public function shouldDeleteDeployment() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/deployments/123') + ->will($this->returnValue(null)); + + $this->assertNull($api->remove('KnpLabs', 'php-github-api', 123)); + } + /** * @test */ From 6e13e98c4116819ee7d08510376deb4cfa3d50e8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 7 Apr 2021 11:21:19 +0200 Subject: [PATCH 842/951] Bump 2.x branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cc214a2f354..42def40ee1b 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-2.x": "2.19.x-dev", + "dev-2.x": "2.20.x-dev", "dev-master": "3.2.x-dev" } } From cd3e91d47bbee5bb6db17e74f488d658034bc6e7 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Fri, 9 Apr 2021 16:46:39 +0200 Subject: [PATCH 843/951] Fix typo --- UPGRADE-3.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 8e0e3f5fa59..738343d6c37 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -13,7 +13,7 @@ * `Github\HttpClient\Plugin\History` * `Github\HttpClient\Plugin\PathPrepend` -### Authetication methods +### Authentication 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. From 939869394c6414768547685945fdba4fe3f061b5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 16 Apr 2021 11:36:20 +0200 Subject: [PATCH 844/951] Update changelog for 2.20.0 release --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb85c6b2418..47980eff62f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 2.20.0 + +### Added +- Deployments: added missing 'delete deployment' endpoint ([clxmstaab](https://github.com/clxmstaab)) [#991](https://github.com/KnpLabs/php-github-api/issues/991) + +### Changed +- phpdoc: fix typo ([clxmstaab](https://github.com/clxmstaab)) [#993](https://github.com/KnpLabs/php-github-api/issues/993) + +### Fixed +- fixed php warning in GithubExceptionThrower ([clxmstaab](https://github.com/clxmstaab), [acrobat](https://github.com/acrobat)) [#992](https://github.com/KnpLabs/php-github-api/issues/992) + ## 2.19.2 ### Changed From 54ddd41b56251d80b6a9bef3d6ec7c6ee4f7bcdc Mon Sep 17 00:00:00 2001 From: Ricardo Aragon Date: Fri, 23 Apr 2021 04:34:52 -0400 Subject: [PATCH 845/951] feature #1000 Events list per authenticated user for all repos (richard015ar) This PR was squashed before being merged into the 3.2.x-dev branch. Discussion ---------- This change add a list of events for all repos for an authenticated user: https://docs.github.com/en/rest/reference/activity#list-events-for-the-authenticated-user. It is pretty useful if you want to get a list of different [types of events](https://docs.github.com/en/developers/webhooks-and-events/github-event-types) without specify any repo. Commits ------- b565d6d7122f7e8c1edc80a4b249e9be99978d23 Add list events for an authenticated user method 10a85ea86fd61d2228b4d272d590b1d8aa9a6a31 Add docs and tests for List Events by Authenticated User method 3938a4220420a5919be545ffd055ea8ffaa69e53 Fix lint for comment block 5534e255ad103fda2ce4b2b83eab9d72a04093e1 Fix lint for comment block c520754fc31d5e16f4cec84afa708e7d1c7412cb Add API unit test. Remove perPage and page parameters for events method 42f1f423fa4737e69c58a3c438eb6f030a2eb1d7 Add unit test for API --- doc/activity.md | 9 ++++++++- doc/users.md | 11 +++++++++++ lib/Github/Api/User.php | 12 +++++++++++ test/Github/Tests/Api/UserTest.php | 23 ++++++++++++++++++++++ test/Github/Tests/Integration/UserTest.php | 21 ++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/doc/activity.md b/doc/activity.md index 7cad30ef5f7..c15690e9fe3 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -31,6 +31,13 @@ $activity = $client->api('current_user')->starring()->all(); ``` Returns an array of starred repos. +### Get list of private and public events for an authenticated user for all repos + +```php +$activity = $client->api('user')->events('ornicar'); +``` +Returns an array of private and public events created for all repos related to the user. + ### Get repos that a authenticated user has starred with creation date Support for getting the star creation timestamp in the response, using the custom `Accept: application/vnd.github.v3.star+json` header. @@ -100,4 +107,4 @@ $owner = "KnpLabs"; $repo = "php-github-api"; $activity = $client->api('current_user')->watchers()->unwatch($owner, $repo); ``` -Throws an Exception in case of failure or NULL in case of success. \ No newline at end of file +Throws an Exception in case of failure or NULL in case of success. diff --git a/doc/users.md b/doc/users.md index 3bc20c39bc3..5bac98a7d16 100644 --- a/doc/users.md +++ b/doc/users.md @@ -148,6 +148,17 @@ $users = $client->api('current_user')->starring()->all(); Returns an array of starred repos. +### Get the authenticated user activity + +> Requires [authentication](security.md). + +```php +$activity = $client->api('user')->events('ornicar'); +``` + +Returns an array of private and public events created for all repos related to the user. +> See [more](activity.md). + ### Get the authenticated user emails > Requires [authentication](security.md). diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index b36ae47123b..c1ccc89e8c1 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -234,4 +234,16 @@ public function publicEvents($username) { return $this->get('/users/'.rawurlencode($username).'/events/public'); } + + /** + * List events performed by an authenticated user. + * + * @link https://docs.github.com/en/rest/reference/activity#list-events-for-the-authenticated-user + * + * @return array + */ + public function events(string $username) + { + return $this->get('/users/'.rawurlencode($username).'/events'); + } } diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 491a58f8602..0be80a28f01 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -228,6 +228,29 @@ public function shouldGetUserGists() $this->assertEquals($expectedArray, $api->gists('l3l0')); } + /** + * @test + */ + public function shouldGetAuthorizedUserEvents() + { + $expectedArray = [ + [ + 'id' => 1, + 'actor' => [ + 'id' => 1, + 'login' => 'l3l0', + ], + ], + ]; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/users/l3l0/events') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->events('l3l0')); + } + /** * @return string */ diff --git a/test/Github/Tests/Integration/UserTest.php b/test/Github/Tests/Integration/UserTest.php index 57dbeceeefc..7b8f9f0c364 100644 --- a/test/Github/Tests/Integration/UserTest.php +++ b/test/Github/Tests/Integration/UserTest.php @@ -138,4 +138,25 @@ public function shouldGetReposBeingStarred() $this->assertArrayHasKey('git_url', $repo); $this->assertArrayHasKey('svn_url', $repo); } + + /** + * @test + */ + public function shouldGetEventsForAuthenticatedUserBeignWatched() + { + $username = 'l3l0'; + + $events = $this->client->api('user')->events($username); + $event = array_pop($events); + + $this->assertArrayHasKey('id', $event); + $this->assertArrayHasKey('type', $event); + $this->assertArrayHasKey('actor', $event); + $this->assertArrayHasKey('login', $event['actor']); + $this->assertArrayHasKey('repo', $event); + $this->assertArrayHasKey('name', $event['repo']); + $this->assertArrayHasKey('payload', $event); + $this->assertArrayHasKey('public', $event); + $this->assertArrayHasKey('created_at', $event); + } } From 1dce0d33292eb2c4d33e2f9354b4043caf14588e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 28 Apr 2021 20:12:19 +0200 Subject: [PATCH 846/951] Update changelog for 3.2.0 release --- CHANGELOG-3.X.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 2a59ff99c36..1d2c156d762 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,32 @@ # Changelog +## 3.2.0 + +### Added +- Deprecate ResultPager::postFetch method ([acrobat](https://github.com/acrobat)) [#986](https://github.com/KnpLabs/php-github-api/issues/986) +- Add deprecations to the PR review methods to allow cleanup ([acrobat](https://github.com/acrobat)) [#984](https://github.com/KnpLabs/php-github-api/issues/984) +- Allow binary content downloads of assets ([acrobat](https://github.com/acrobat)) [#990](https://github.com/KnpLabs/php-github-api/issues/990) +- Deployments: added missing 'delete deployment' endpoint ([clxmstaab](https://github.com/clxmstaab)) [#991](https://github.com/KnpLabs/php-github-api/issues/991) +- Events list per authenticated user for all repos ([richard015ar](https://github.com/richard015ar)) [#1000](https://github.com/KnpLabs/php-github-api/issues/1000) + +### Changed +- Fixed branch alias ([GrahamCampbell](https://github.com/GrahamCampbell)) [#975](https://github.com/KnpLabs/php-github-api/issues/975) +- fix typo ([staabm](https://github.com/staabm)) [#977](https://github.com/KnpLabs/php-github-api/issues/977) +- Improved bc check ([acrobat](https://github.com/acrobat)) [#982](https://github.com/KnpLabs/php-github-api/issues/982) +- Correctly link to github actions docs and fix backlinks ([acrobat](https://github.com/acrobat)) [#983](https://github.com/KnpLabs/php-github-api/issues/983) +- Add missing repo hooks documentation ([acrobat](https://github.com/acrobat)) [#987](https://github.com/KnpLabs/php-github-api/issues/987) +- Fix incorrect public key documentation ([acrobat](https://github.com/acrobat)) [#988](https://github.com/KnpLabs/php-github-api/issues/988) +- Fixed incorrect parameters in apps docs ([acrobat](https://github.com/acrobat)) [#989](https://github.com/KnpLabs/php-github-api/issues/989) +- phpdoc: fix typo ([clxmstaab](https://github.com/clxmstaab)) [#993](https://github.com/KnpLabs/php-github-api/issues/993) +- Fix upmerged usage of deprecated phpunit assert ([acrobat](https://github.com/acrobat)) [#995](https://github.com/KnpLabs/php-github-api/issues/995) +- Fix typo ([romainneutron](https://github.com/romainneutron)) [#997](https://github.com/KnpLabs/php-github-api/issues/997) + +### Fixed +- Deployments: use proper media-type for in_progress/queued, inactive state ([staabm](https://github.com/staabm)) [#979](https://github.com/KnpLabs/php-github-api/issues/979) +- [952] doc - Specify lcobucci/jwt version, fix deprecation ([amacrobert-meq](https://github.com/amacrobert-meq), [acrobat](https://github.com/acrobat)) [#953](https://github.com/KnpLabs/php-github-api/issues/953) +- Replace deprecated organization team repository add/remove urls ([acrobat](https://github.com/acrobat)) [#985](https://github.com/KnpLabs/php-github-api/issues/985) +- fixed php warning in GithubExceptionThrower ([clxmstaab](https://github.com/clxmstaab), [acrobat](https://github.com/acrobat)) [#992](https://github.com/KnpLabs/php-github-api/issues/992) + ## 3.1.0 ### Added From 486f0e6fac8e1148bbf2d42ba14e8196c86832b8 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 29 Apr 2021 10:03:12 +0200 Subject: [PATCH 847/951] Update readme and add example for different http client usage --- README.md | 55 +++++++++++++++++++++++++++++------------------- doc/customize.md | 23 +++++++++++++++++--- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6c3609177fa..80251bc3286 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # PHP GitHub API -[![Build Status](https://travis-ci.org/KnpLabs/php-github-api.svg?branch=master)](https://travis-ci.org/KnpLabs/php-github-api) +![Build Status](https://github.com/KnpLabs/php-github-api/actions/workflows/ci.yml/badge.svg) [![StyleCI](https://styleci.io/repos/3948501/shield?style=flat)](https://styleci.io/repos/3948501) [![Latest Stable Version](https://poser.pugx.org/knplabs/github-api/v/stable)](https://packagist.org/packages/knplabs/github-api) [![Total Downloads](https://poser.pugx.org/knplabs/github-api/downloads)](https://packagist.org/packages/knplabs/github-api) -[![Latest Unstable Version](https://poser.pugx.org/knplabs/github-api/v/unstable)](https://packagist.org/packages/knplabs/github-api) [![Monthly Downloads](https://poser.pugx.org/knplabs/github-api/d/monthly)](https://packagist.org/packages/knplabs/github-api) [![Daily Downloads](https://poser.pugx.org/knplabs/github-api/d/daily)](https://packagist.org/packages/knplabs/github-api) @@ -19,34 +18,46 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements -* PHP >= 7.1 +* PHP >= 7.2 * A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) * A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation) -## Install +## Quick install Via [Composer](https://getcomposer.org). -### PHP 7.1+: +This command will get you up and running quickly with a guzzle http client. ```bash -composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0 +composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 ``` -### PHP 7.2+: +## Advanced install + +We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io). + +### Using a different http client ```bash -composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 +composer require knplabs/github-api:^3.0 symfony/http-client nyholm/psr7 ``` -### Laravel 6+: +To set up the github client with this http client -```bash -composer require graham-campbell/github:^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 +```php +use Github\Client; +use Symfony\Component\HttpClient\HttplugClient; + +$client = Client::createWithHttpClient(new HttplugClient()); ``` -We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell). +Read more about [using different clients in our docs](doc/customize.md). + +## Framework integrations + +### Laravel +To integrate this library in laravel [Graham Campbell](https://github.com/GrahamCampbell) created [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub). See the [installation instructions](https://github.com/GrahamCampbell/Laravel-GitHub#installation) to get started in laravel. ## Basic usage of `php-github-api` client @@ -60,7 +71,7 @@ $client = new \Github\Client(); $repositories = $client->api('user')->repositories('ornicar'); ``` -From `$client` object, you can access to all GitHub. +From `$client` object, you have access to all available GitHub api endpoints. ## Cache usage @@ -105,18 +116,18 @@ See the [`doc` directory](doc/) for more detailed documentation. Please read [this post](https://knplabs.com/en/blog/news-for-our-foss-projects-maintenance) first. This library is maintained by the following people (alphabetically sorted) : -- @acrobat -- @Nyholm +- [@acrobat](https://github.com/acrobat) +- [@Nyholm](https://github.com/Nyholm) ## Contributors -- Thanks to [Thibault Duplessis aka. ornicar](http://github.com/ornicar) for his first version of this library. -- Thanks to [Joseph Bielawski aka. stloyd](http://github.com/stloyd) for his contributions and support. -- Thanks to [noloh](http://github.com/noloh) for his contribution on the Object API. -- Thanks to [bshaffer](http://github.com/bshaffer) for his contribution on the Repo API. -- Thanks to [Rolf van de Krol](http://github.com/rolfvandekrol) for his countless contributions. -- Thanks to [Nicolas Pastorino](http://github.com/jeanvoye) for his contribution on the Pull Request API. -- Thanks to [Edoardo Rivello](http://github.com/erivello) for his contribution on the Gists API. +- Thanks to [Thibault Duplessis aka. ornicar](https://github.com/ornicar) for his first version of this library. +- Thanks to [Joseph Bielawski aka. stloyd](https://github.com/stloyd) for his contributions and support. +- Thanks to [noloh](https://github.com/noloh) for his contribution on the Object API. +- Thanks to [bshaffer](https://github.com/bshaffer) for his contribution on the Repo API. +- Thanks to [Rolf van de Krol](https://github.com/rolfvandekrol) for his countless contributions. +- Thanks to [Nicolas Pastorino](https://github.com/jeanvoye) for his contribution on the Pull Request API. +- Thanks to [Edoardo Rivello](https://github.com/erivello) for his contribution on the Gists API. - Thanks to [Miguel Piedrafita](https://github.com/m1guelpf) for his contribution to the v4 & Apps API. - Thanks to [Emre DEGER](https://github.com/lexor) for his contribution to the Actions API. diff --git a/doc/customize.md b/doc/customize.md index f25f4e40dc8..1d5ae51e766 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -4,16 +4,33 @@ ### Inject a new HTTP client instance -`php-github-api` relies on `php-http/discovery` to find an installed HTTP client. You may specify a HTTP client -yourself by calling `\Github\Client::setHttpClient`. A HTTP client must implement `Http\Client\HttpClient`. A list of +`php-github-api` relies on `php-http/discovery` to find an installed HTTP client. You may specify an HTTP client +yourself by calling `\Github\Client::setHttpClient`. An HTTP client must implement `Http\Client\HttpClient`. A list of community provided clients is found here: https://packagist.org/providers/php-http/client-implementation -You can inject a HTTP client through the `Github\Client` constructor: +You can inject an HTTP client through the `Github\Client` constructor: ```php $client = Github\Client::createWithHttpClient(new Http\Adapter\Guzzle6\Client()); ``` +#### Example + +To use the symfony http client + +```bash +composer require symfony/http-client nyholm/psr7 +``` + +To set up the github client with this http client + +```php +use Github\Client; +use Symfony\Component\HttpClient\HttplugClient; + +$client = Client::createWithHttpClient(new HttplugClient()); +``` + ### Configure the HTTP client Wanna change, let's say, the HTTP client User Agent? You need to create a Plugin that modifies the From 2e635fcbc90e224f332cc0ae23e96127d301b4ee Mon Sep 17 00:00:00 2001 From: Necmettin Karakaya Date: Fri, 30 Apr 2021 19:27:58 +0800 Subject: [PATCH 848/951] feature #1001 Allow costume accept headers for GraphQL Endpoint. (Necmttn) This PR was squashed before being merged into the 3.2.x-dev branch. Discussion ---------- Github has multiple different accept headers for different purposes. Currently, there's no easy way to add/remove the `Accept` header to the client. ref: https://docs.github.com/en/graphql/overview/schema-previews Commits ------- 63622816442f8018fefb77b63f4e58f1fe7ac76c Allow costume accept headers for GraphQL Endpoint. dcd725e11de1a2870714182bea4b16f5fdd0b668 Update graphql.md 902e9add10ed99f86d35137421ee3aeaa274f667 Update lib/Github/Api/GraphQL.php 081953c82766e5cf639ddea7a3cdf29da20bde1b Update lib/Github/Api/GraphQL.php --- doc/graphql.md | 13 +++++++++++++ lib/Github/Api/GraphQL.php | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/graphql.md b/doc/graphql.md index 4151012342c..99e653bf87a 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -19,6 +19,19 @@ $client->authenticate($token, null, Github\Client::AUTH_ACCESS_TOKEN); $result = $client->api('graphql')->execute($query); ``` +#### Use different `Accept` Headers +You can preview upcoming features and changes to the GitHub GraphQL schema before they are added to the GitHub GraphQL API. +To access a schema preview, you'll need to provide a custom media type in the Accept header for your requests. Feature documentation for each preview specifies which custom media type to provide. More info about [Schema Previews](https://docs.github.com/en/graphql/overview/schema-previews). + +To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) with different `Accept` header you can pass third argument to execute method. + +```php +$result = $client->api('graphql')->execute($query, [], 'application/vnd.github.starfox-preview+json') +``` +> default accept header is `application/vnd.github.v4+json` + + + #### Use variables [Variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) allow specifying of requested data without dynamical change of a query on a client side. diff --git a/lib/Github/Api/GraphQL.php b/lib/Github/Api/GraphQL.php index 9d66b5123fb..02499ad8ef7 100644 --- a/lib/Github/Api/GraphQL.php +++ b/lib/Github/Api/GraphQL.php @@ -18,12 +18,13 @@ class GraphQL extends AbstractApi /** * @param string $query * @param array $variables + * @param string $acceptHeaderValue * * @return array */ - public function execute($query, array $variables = []) + public function execute($query, array $variables = [], string $acceptHeaderValue = 'application/vnd.github.v4+json') { - $this->acceptHeaderValue = 'application/vnd.github.v4+json'; + $this->acceptHeaderValue = $acceptHeaderValue; $params = [ 'query' => $query, ]; From 4d4cb9c252799cbc97921bf5377ee804e4d18ec1 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 3 May 2021 00:53:05 +0100 Subject: [PATCH 849/951] Bumped branch alias after new feature merged --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3f36a8341e0..328128743ff 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.2.x-dev" + "dev-master": "3.3.x-dev" } } } From 433ea4ef5ad23c18d138ec0d77cac5dd92c642d3 Mon Sep 17 00:00:00 2001 From: Yurun Date: Thu, 6 May 2021 14:04:23 +0800 Subject: [PATCH 850/951] Fix publicKey --- lib/Github/Api/Organization/Actions/Secrets.php | 2 +- lib/Github/Api/Repository/Actions/Secrets.php | 2 +- test/Github/Tests/Api/Organization/Actions/SecretsTest.php | 2 +- test/Github/Tests/Api/Repository/Actions/SecretsTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Organization/Actions/Secrets.php b/lib/Github/Api/Organization/Actions/Secrets.php index 7a08212907f..b6140faf35e 100644 --- a/lib/Github/Api/Organization/Actions/Secrets.php +++ b/lib/Github/Api/Organization/Actions/Secrets.php @@ -139,6 +139,6 @@ public function removeSecret(string $organization, string $repositoryId, string */ public function publicKey(string $organization) { - return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/secret-key'); + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/public-key'); } } diff --git a/lib/Github/Api/Repository/Actions/Secrets.php b/lib/Github/Api/Repository/Actions/Secrets.php index 4c38de203dc..6ba0e4ec9a1 100644 --- a/lib/Github/Api/Repository/Actions/Secrets.php +++ b/lib/Github/Api/Repository/Actions/Secrets.php @@ -90,6 +90,6 @@ public function remove(string $username, string $repository, string $secretName) */ public function publicKey(string $username, string $repository) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/secret-key'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/secrets/public-key'); } } diff --git a/test/Github/Tests/Api/Organization/Actions/SecretsTest.php b/test/Github/Tests/Api/Organization/Actions/SecretsTest.php index cf10c066c99..324b706975d 100644 --- a/test/Github/Tests/Api/Organization/Actions/SecretsTest.php +++ b/test/Github/Tests/Api/Organization/Actions/SecretsTest.php @@ -206,7 +206,7 @@ public function shouldGetPublicKey() $api ->expects($this->once()) ->method('get') - ->with('/orgs/KnpLabs/actions/secrets/secret-key') + ->with('/orgs/KnpLabs/actions/secrets/public-key') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->publicKey('KnpLabs')); diff --git a/test/Github/Tests/Api/Repository/Actions/SecretsTest.php b/test/Github/Tests/Api/Repository/Actions/SecretsTest.php index 670e623b688..5a5e20a4616 100644 --- a/test/Github/Tests/Api/Repository/Actions/SecretsTest.php +++ b/test/Github/Tests/Api/Repository/Actions/SecretsTest.php @@ -123,7 +123,7 @@ public function shouldGetPublicKey() $api ->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/actions/secrets/secret-key') + ->with('/repos/KnpLabs/php-github-api/actions/secrets/public-key') ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->publicKey('KnpLabs', 'php-github-api')); From aeeda1917873d8aaf970f5fbd8aa050529a5e9ed Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 13 May 2021 10:04:29 +0200 Subject: [PATCH 851/951] Added comment on AbstractApi::$perPage --- lib/Github/Api/AbstractApi.php | 2 +- .../Tests/Integration/ResultPagerTest.php | 20 ------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/lib/Github/Api/AbstractApi.php b/lib/Github/Api/AbstractApi.php index ce70bbe22ce..71f71cce5d6 100644 --- a/lib/Github/Api/AbstractApi.php +++ b/lib/Github/Api/AbstractApi.php @@ -20,7 +20,7 @@ abstract class AbstractApi private $client; /** - * The per page parameter. + * The per page parameter. It is used by the ResultPager. * * @var int|null */ diff --git a/test/Github/Tests/Integration/ResultPagerTest.php b/test/Github/Tests/Integration/ResultPagerTest.php index 447c52913ed..4dd24e37904 100644 --- a/test/Github/Tests/Integration/ResultPagerTest.php +++ b/test/Github/Tests/Integration/ResultPagerTest.php @@ -9,24 +9,6 @@ */ class ResultPagerTest extends TestCase { - /** - * @test - */ - public function shouldPaginateGetRequests() - { - $repositoriesApi = $this->client->api('user'); - $repositoriesApi->setPerPage(10); - - $pager = $this->createPager(); - - $repositories = $pager->fetch($repositoriesApi, 'repositories', ['KnpLabs']); - $this->assertCount(10, $repositories); - - $repositoriesApi->setPerPage(20); - $repositories = $pager->fetch($repositoriesApi, 'repositories', ['KnpLabs']); - $this->assertCount(20, $repositories); - } - /** * @test * @@ -43,10 +25,8 @@ public function shouldPaginateGetRequests() public function shouldGetAllResultsFromSearchApi() { $searchApi = $this->client->search(); - $searchApi->setPerPage(10); $pager = $this->createPager(); - $users = $pager->fetch($searchApi, 'users', ['location:Kyiv']); $this->assertCount(10, $users); } From 46e9538850ed0c2981bbdeabfa86f0958f844482 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Thu, 20 May 2021 21:55:32 +0200 Subject: [PATCH 852/951] feature #1006 Add endpoint for approve workflow run (Nyholm) This PR was squashed before being merged into the 3.3.x-dev branch. Discussion ---------- See https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request Commits ------- b987f199040136ff046d29ecea65bfa24161ea69 Add endpoint for approve workflow run cd1b74b29af669cb26faebcfbbeebb40f55a3b83 Bugfix ec0ae3b6106c0976354f031aa592c6a56adb2d13 Use asertSame() --- doc/repo/actions/workflow_runs.md | 8 ++++++++ .../Api/Repository/Actions/WorkflowRuns.php | 16 ++++++++++++++++ .../Repository/Actions/WorkflowRunsTest.php | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md index 59b09f4c657..4b879ca5b98 100644 --- a/doc/repo/actions/workflow_runs.md +++ b/doc/repo/actions/workflow_runs.md @@ -74,3 +74,11 @@ https://docs.github.com/en/rest/reference/actions#delete-workflow-run-logs ```php $client->api('repo')->workflowRuns()->deleteLogs('KnpLabs', 'php-github-api', $runId); ``` + +### Approve workflow run + +https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request + +```php +$client->api('repo')->workflowRuns()->approve('KnpLabs', 'php-github-api', $runId); +``` diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php index 06d3e559605..d6f95f1ed94 100644 --- a/lib/Github/Api/Repository/Actions/WorkflowRuns.php +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -136,4 +136,20 @@ public function deleteLogs(string $username, string $repository, int $runId) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs'); } + + /** + * @link https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request + * + * @param string $username + * @param string $repository + * @param int $runId + * + * @return array|string + * + * @experimental This endpoint is currently in beta. + */ + public function approve(string $username, string $repository, int $runId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/approve'); + } } diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php index 27155148ce0..1c5af0badc9 100644 --- a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php @@ -198,6 +198,24 @@ public function shouldDeleteWorkflowRunLogs() $this->assertEquals($expectedValue, $api->deleteLogs('KnpLabs', 'php-github-api', 374473304)); } + /** + * @test + */ + public function shouldApproveWorkflowRunLogs() + { + $expectedValue = 'response'; + + /** @var WorkflowRuns|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/approve') + ->will($this->returnValue($expectedValue)); + + $this->assertSame($expectedValue, $api->approve('KnpLabs', 'php-github-api', 374473304)); + } + protected function getApiClass() { return WorkflowRuns::class; From 0442abd1361956e3a87e71683154c5c33c5a0dad Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 20 May 2021 22:28:41 +0200 Subject: [PATCH 853/951] Update changelog for 3.3.0 release --- CHANGELOG-3.X.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 1d2c156d762..25db0b810ab 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,19 @@ # Changelog +## 3.3.0 + +### Added +- Allow costume accept headers for GraphQL Endpoint. ([Necmttn](https://github.com/Necmttn)) [#1001](https://github.com/KnpLabs/php-github-api/issues/1001) +- Add endpoint for approve workflow run ([Nyholm](https://github.com/Nyholm)) [#1006](https://github.com/KnpLabs/php-github-api/issues/1006) + +### Changed +- Update readme and add example for different http client usage ([acrobat](https://github.com/acrobat)) [#1002](https://github.com/KnpLabs/php-github-api/issues/1002) +- Bumped branch alias after new feature merged ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1004](https://github.com/KnpLabs/php-github-api/issues/1004) +- Add comment on AbstractApi::$perPage() ([Nyholm](https://github.com/Nyholm)) [#1007](https://github.com/KnpLabs/php-github-api/issues/1007) + +### Fixed +- Fix publicKey ([Yurunsoft](https://github.com/Yurunsoft)) [#1005](https://github.com/KnpLabs/php-github-api/issues/1005) + ## 3.2.0 ### Added From 467a9d5dc928bfeb8ec4f3d2b5fcdfb7cdeeac38 Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Sun, 23 May 2021 23:48:10 +0200 Subject: [PATCH 854/951] Fix up typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 80251bc3286..de79112b4f8 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] Via [Composer](https://getcomposer.org). -This command will get you up and running quickly with a guzzle http client. +This command will get you up and running quickly with a Guzzle HTTP client. ```bash composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 @@ -42,7 +42,7 @@ We are decoupled from any HTTP messaging client with help by [HTTPlug](https://h composer require knplabs/github-api:^3.0 symfony/http-client nyholm/psr7 ``` -To set up the github client with this http client +To set up the Github client with this HTTP client ```php use Github\Client; From 02d6c81480b99284cfe7cce7fd314e0f3c95a617 Mon Sep 17 00:00:00 2001 From: Martin Bean Date: Fri, 18 Jun 2021 20:39:38 +0100 Subject: [PATCH 855/951] feature #994 Add create a repository using a template endpoint (martinbean) This PR was squashed before being merged into the 3.3.x-dev branch. Discussion ---------- Adds methods to [create a repository using a template][1], and also contributes a few test cases for the various options. Resolves #976 [1]: https://docs.github.com/en/rest/reference/repos#create-a-repository-using-a-template Commits ------- 58b294f856eb74488a9fdd8e8549cc66bc023ae1 Add create a repository using a template endpoint 9fabcf701f26561b74f7a9e4d6d9c185d27508fd Make parameters array instead c70f39f6ab0e546b9eabfdf52c78aeb311f83d60 Document create repository from template 79ebd98dbb64142acebf95114d7cf46afc56f84b Type-hint parameters --- doc/repos.md | 11 +++++++++++ lib/Github/Api/Repo.php | 12 ++++++++++++ test/Github/Tests/Api/RepoTest.php | 26 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 0a4d234a695..ab412dc77c2 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -370,3 +370,14 @@ Example when you want to configure custom github action workflows. ```php $client->api('repo')->dispatch('KnpLabs', 'php-github-api', 'acme-event', ['foo'=>'bar']); ``` + +### Create a repository using a template + +Create a new repository using a repository template. + +```php +$client->api('repo')->createFromTemplate('template-owner', 'template-repo', [ + 'name' => 'name-of-new-repo', + 'owner' => 'name-of-new-repo-owner', // can be user or org +]); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index fcaa196d264..15e51b38bd2 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -793,4 +793,16 @@ public function transfer($username, $repository, $newOwner, $teamId = []) { return $this->post('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/transfer', ['new_owner' => $newOwner, 'team_id' => $teamId]); } + + /** + * Create a repository using a template. + * + * @link https://developer.github.com/v3/repos/#create-a-repository-using-a-template + * + * @return array + */ + public function createFromTemplate(string $templateOwner, string $templateRepo, array $parameters = []) + { + return $this->post('/repos/'.rawurldecode($templateOwner).'/'.rawurldecode($templateRepo).'/generate', $parameters); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 083d7201aa8..3761b2efb7e 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -626,6 +626,32 @@ public function shouldTransferRepository() $this->assertEquals($expectedArray, $api->transfer('KnpLabs', 'php-github-api', 'github', [1234, 1235])); } + /** + * @test + */ + public function shouldCreateRepositoryUsingTemplate() + { + $expectedArray = [ + 'id' => 1, + 'name' => 'newrepo', + 'full_name' => 'johndoe/newrepo', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/acme/template/generate', [ + 'name' => 'newrepo', + 'owner' => 'johndoe', + ]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->createFromTemplate('acme', 'template', [ + 'name' => 'newrepo', + 'owner' => 'johndoe', + ])); + } + /** * @return string */ From fd8954b274708d2b5bfc246a399682cad736096f Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 18 Jun 2021 21:40:43 +0200 Subject: [PATCH 856/951] Bump branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 328128743ff..d65a6e02d0c 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.3.x-dev" + "dev-master": "3.4.x-dev" } } } From d73a1e0f24d697d1b4b528acd6fc445bea1a751e Mon Sep 17 00:00:00 2001 From: bery Date: Fri, 9 Jul 2021 17:24:32 +0200 Subject: [PATCH 857/951] Allow fetching repo readme for a specific ref As per Github's API it is possible to fetch a readme file for specific branch or tag https://docs.github.com/en/rest/reference/repos#get-a-repository-readme --- lib/Github/Api/Repo.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 15e51b38bd2..30ee37ff6e4 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -257,12 +257,13 @@ public function remove($username, $repository) * @param string $username the user who owns the repository * @param string $repository the name of the repository * @param string $format one of formats: "raw", "html", or "v3+json" + * @param array $params additional query params like "ref" to fetch readme for branch/tag * * @return string|array the readme content */ - public function readme($username, $repository, $format = 'raw') + public function readme($username, $repository, $format = 'raw', $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', [], [ + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', $params, [ 'Accept' => "application/vnd.github.$format", ]); } From de9637945acd615f1290f3a8f7db7fa998ae3a83 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 11 Jul 2021 20:56:43 +0100 Subject: [PATCH 858/951] minor #1017 Update integration authentication documentation for usage with lcobucci/jwt ^4 (glaubinix) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- The security docs were mentioning `lcobucci/jwt:^3.4` which doesn't support php 8. Updated the security docs to reflect all necessary changes to work with `lcobucci/jwt:^4.1` Passing `ChainedFormatter::withUnixTimestampDates()` to the builder method is necessary because otherwise all dates will be format via `$date->format('U.u')` as microseconds. GitHub expects unix timestamps and will return a 401 response with `'Expiration time' claim ('exp') must be a numeric value representing the future time at which the assertion expires`. Commits ------- 917192c14a61237e2352fb7a906a0a1ef04815ec Update integration authentication documentation for usage with lcobucci/jwt ^4 73dea747e8fd469cecfdef16ac57ecacfa0cd5e7 Docs: add builder to JWT authentication --- doc/security.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/security.md b/doc/security.md index b7e94783890..b62ca4c05fc 100644 --- a/doc/security.md +++ b/doc/security.md @@ -37,14 +37,18 @@ and installation access token which is then usable with `Github\Client::AUTH_ACC authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail. It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. -The following sample code authenticates as an installation using [lcobucci/jwt 3.4](https://github.com/lcobucci/jwt/tree/3.4) +The following sample code authenticates as an installation using [lcobucci/jwt 4.1](https://github.com/lcobucci/jwt/tree/4.1.x) to generate a JSON Web Token (JWT). ```php +use Github\HttpClient\Builder; use Lcobucci\JWT\Configuration; +use Lcobucci\JWT\Encoding\ChainedFormatter; use Lcobucci\JWT\Signer\Key\LocalFileReference; use Lcobucci\JWT\Signer\Rsa\Sha256; +$builder = new Builder(); + $github = new Github\Client($builder, 'machine-man-preview'); $config = Configuration::forSymmetricSigner( @@ -53,14 +57,14 @@ $config = Configuration::forSymmetricSigner( ); $now = new \DateTimeImmutable(); -$jwt = $config->builder() +$jwt = $config->builder(ChainedFormatter::withUnixTimestampDates()) ->issuedBy($integrationId) ->issuedAt($now) ->expiresAt($now->modify('+1 minute')) ->getToken($config->signer(), $config->signingKey()) ; -$github->authenticate($jwt, null, Github\Client::AUTH_JWT) +$github->authenticate($jwt->toString(), null, Github\Client::AUTH_JWT) ``` The `$integrationId` you can find in the about section of your github app. From c593113de147c0db86ec4903e365d45327564fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Klabbers?= Date: Tue, 13 Jul 2021 19:06:09 +0200 Subject: [PATCH 859/951] feature #1018 allow assigning role to organisation members (luceos) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- This PR allows you to assign the `admin` role to new members of the organisation. Ref: https://docs.github.com/en/rest/reference/orgs#set-organization-membership-for-a-user Commits ------- eb4e3c2ef738386cac0c7d96e486f267a8f13eda allow assigning roles to organisation members 480b9193151b1d93bed1266ba0183b96f27710cc remove default value and role check --- lib/Github/Api/Organization/Members.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization/Members.php b/lib/Github/Api/Organization/Members.php index 3639e3ba57d..023e3f8d545 100644 --- a/lib/Github/Api/Organization/Members.php +++ b/lib/Github/Api/Organization/Members.php @@ -58,9 +58,9 @@ public function conceal($organization, $username) /* * Add user to organization */ - public function add($organization, $username) + public function add($organization, $username, array $params = []) { - return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username)); + return $this->put('/orgs/'.rawurlencode($organization).'/memberships/'.rawurlencode($username), $params); } public function addMember($organization, $username) From 2e58baace31b6463431fb54dccd5b8fd96cd873d Mon Sep 17 00:00:00 2001 From: pitonic Date: Tue, 13 Jul 2021 13:18:51 -0400 Subject: [PATCH 860/951] feature #1020 Branch lists . ( ? query per_page) (pitonic) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- For function "branches" added: parameters for the query string. example to use: ``` return $this->client->api('repo')->branches($this->id, $repo, null , [ 'page' =>2, 'per_page' => 100 ]); ``` Commits ------- ab3d87b10cfd830720e1e3ea983d8109188639a7 added: parameters for the query string 44c39238b084aa07c236b2aacc4a67df25f6c448 fixed formating --- lib/Github/Api/Repo.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 30ee37ff6e4..b5d11debf68 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -503,17 +503,18 @@ public function statuses() * @param string $username the username * @param string $repository the name of the repository * @param string $branch the name of the branch + * @param array $parameters parameters for the query string * * @return array list of the repository branches */ - public function branches($username, $repository, $branch = null) + public function branches($username, $repository, $branch = null, array $parameters = []) { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches'; if (null !== $branch) { $url .= '/'.rawurlencode($branch); } - return $this->get($url); + return $this->get($url, $parameters); } /** From 2e36702b083df81047e626479d69125751c9fb9a Mon Sep 17 00:00:00 2001 From: Tom Sowerby Date: Thu, 19 Aug 2021 16:21:17 +0100 Subject: [PATCH 861/951] Update result_pager.md Quick update to the docs as I notice this method has been removed in v3. --- doc/result_pager.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/result_pager.md b/doc/result_pager.md index 3eb0a115f5f..b13432cb569 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -63,7 +63,3 @@ $paginator->hasPrevious(); $paginator->fetchPrevious(); ``` -If you want to retrieve the pagination links (available after the call to fetch): -```php -$paginator->getPagination(); -``` From cad499e4f2b1f25f94dfb2113b689c9e07b4f217 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 15 Sep 2021 22:30:53 +0200 Subject: [PATCH 862/951] feature #1025 Php8.1 support (acrobat) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- Commits ------- 1b8b3bab407e87183a123f810d15cb914c2ed764 Test against php 8.1 bd57aec7c83b784cea30d919bccc41dd3594228f Fixed php 8.1 warnings and phpunit 10 depercation --- .github/workflows/ci.yml | 2 +- test/Github/Tests/Api/PullRequestTest.php | 14 +++++++------- .../Plugin/GithubExceptionThrowerTest.php | 8 +++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83e62d87e29..175c5f09a0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0'] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v2 diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 90505535ff9..fe5b87c9d6d 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -144,15 +144,15 @@ public function shouldShowStatusesFromPullRequest() $expectedArray['_links']['statuses']['href'] = '/repos/ezsystems/ezpublish/pulls/15/statuses'; $api = $this->getApiMock(); - $api->expects($this->at(0)) - ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls/15') - ->will($this->returnValue($expectedArray)); - $api->expects($this->at(1)) + $api->expects($this->exactly(2)) ->method('get') - ->with('/repos/ezsystems/ezpublish/pulls/15/statuses') - ->will($this->returnValue($expectedArray)); + ->withConsecutive( + [$this->equalTo('/repos/ezsystems/ezpublish/pulls/15')], + [$this->equalTo('/repos/ezsystems/ezpublish/pulls/15/statuses')] + ) + ->willReturn($expectedArray) + ; $this->assertEquals($expectedArray, $api->status('ezsystems', 'ezpublish', '15')); } diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 4f6f9a5615b..99973521980 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -4,6 +4,7 @@ use Github\Exception\ExceptionInterface; use Github\HttpClient\Plugin\GithubExceptionThrower; +use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Http\Client\Promise\HttpFulfilledPromise; use Http\Client\Promise\HttpRejectedPromise; @@ -17,14 +18,11 @@ class GithubExceptionThrowerTest extends TestCase { /** - * @param ResponseInterface $response - * @param ExceptionInterface|\Exception|null $exception * @dataProvider responseProvider */ - public function testHandleRequest(ResponseInterface $response, ExceptionInterface $exception = null) + public function testHandleRequest(ResponseInterface $response, ExceptionInterface $exception = null): void { - /** @var RequestInterface $request */ - $request = $this->getMockForAbstractClass(RequestInterface::class); + $request = new Request('GET', 'https://api.github.com/issues'); $promise = new HttpFulfilledPromise($response); From bfa97f673dd3ea0fa57134204565ef7c404deec4 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Thu, 23 Sep 2021 00:06:20 +0200 Subject: [PATCH 863/951] fix(doc): links to doc in CurrentUser class --- lib/Github/Api/CurrentUser.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 70600a855a8..b5cbc89a376 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -54,7 +54,7 @@ public function followers($page = 1) } /** - * @link http://developer.github.com/v3/issues/#list-issues + * @link https://docs.github.com/en/rest/reference/issues#list-user-account-issues-assigned-to-the-authenticated-user * * @param array $params * @param bool $includeOrgIssues @@ -91,7 +91,7 @@ public function memberships() } /** - * @link http://developer.github.com/v3/orgs/#list-user-organizations + * @link https://docs.github.com/en/rest/reference/orgs#list-organizations-for-the-authenticated-user * * @return array */ @@ -111,7 +111,7 @@ public function teams() } /** - * @link http://developer.github.com/v3/repos/#list-your-repositories + * @link https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user * * @param string $type role in the repository * @param string $sort sort by @@ -159,7 +159,7 @@ public function starring() } /** - * @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched + * @link https://docs.github.com/en/rest/reference/activity#list-repositories-watched-by-the-authenticated-user */ public function subscriptions() { @@ -167,7 +167,7 @@ public function subscriptions() } /** - * @link https://developer.github.com/v3/apps/installations/#list-app-installations-accessible-to-the-user-access-token + * @link https://docs.github.com/en/rest/reference/apps#list-app-installations-accessible-to-the-user-access-token * * @param array $params */ From 5d77c8195dcb51f52a0b50e6181bc4a7c81c15d8 Mon Sep 17 00:00:00 2001 From: John Noel Date: Sun, 26 Sep 2021 16:30:33 +0100 Subject: [PATCH 864/951] Allow psr/cache 2.0 as well as 1.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d65a6e02d0c..71924b18e59 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php-http/discovery": "^1.12", "php-http/httplug": "^2.2", "php-http/multipart-stream-builder": "^1.1.2", - "psr/cache": "^1.0", + "psr/cache": "^1.0|^2.0", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0", From de92500d4ca47743d81f39296f74104891ca88de Mon Sep 17 00:00:00 2001 From: David Peach Date: Fri, 1 Oct 2021 08:48:43 +0100 Subject: [PATCH 865/951] bug #1030 Add accept header for creating repo from template (davidpeach) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- This still requires an accept header as per the docs: https://docs.github.com/en/rest/reference/repos#create-a-repository-using-a-template-preview-notices Commits ------- 34e33707af1ca963b636855f7dde4138aad89c7f Add accept header for creating repo from template 91b39118798ad4fc1a90ee4dd9804b3c00c4a2d7 Update Repo.php --- lib/Github/Api/Repo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b5d11debf68..dfbd39b991a 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -805,6 +805,9 @@ public function transfer($username, $repository, $newOwner, $teamId = []) */ public function createFromTemplate(string $templateOwner, string $templateRepo, array $parameters = []) { + //This api is in preview mode, so set the correct accept-header + $this->acceptHeaderValue = 'application/vnd.github.baptiste-preview+json'; + return $this->post('/repos/'.rawurldecode($templateOwner).'/'.rawurldecode($templateRepo).'/generate', $parameters); } } From fe559892cf6f19980d058900c14b8a623c89ffe9 Mon Sep 17 00:00:00 2001 From: Quentin Ra <54904135+QuentinRa@users.noreply.github.com> Date: Sun, 3 Oct 2021 18:52:25 +0200 Subject: [PATCH 866/951] feature #1031 adding code_with_match (#1024) (QuentinRa) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- Hi! As described in #1024, I added a function `code_with_match`. Commits ------- 32acac4549e8ee6d16bbb195a45fb885544347dd adding code_with_match (#1024) 179532a2f785787ddc0a52d0de9e513e41ff79f5 adding a new line c3be9515e3d81b0c3fc2f5f05a242cb9ed8ea7a3 changes requested f89811e2091f8a5716fb4a2f2c2af562a207e73c removing the whole phpdoc comment --- doc/search.md | 8 +++++- lib/Github/Api/Search.php | 15 ++++++++++ test/Github/Tests/Api/SearchTest.php | 43 ++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/doc/search.md b/doc/search.md index 0a674808001..24dbbef2302 100644 --- a/doc/search.md +++ b/doc/search.md @@ -13,13 +13,19 @@ $repos = $client->api('search')->repositories('github language:php'); Returns a list of repositories found by such criteria. ### Search code - + ```php $files = $client->api('search')->code('@todo language:php'); ``` Returns a list of files found by such criteria (containing "@todo" and language==php). +```php +$files = $client->api('search')->codeWithMatch('@todo language:php'); +``` + +Same as code, with additional data to highlight the matching fragments (see [Text match metadata](https://docs.github.com/en/rest/reference/search#text-match-metadata)). + ### Search issues ```php diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 24bd59bbf83..96a51ea6a46 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -61,6 +61,21 @@ public function code($q, $sort = 'updated', $order = 'desc') return $this->get('/search/code', ['q' => $q, 'sort' => $sort, 'order' => $order]); } + /** + * Search code by filter (q), but will return additional data to highlight + * the matched results. + * + * @link https://docs.github.com/en/rest/reference/search#text-match-metadata + * + * @return array list of code found + */ + public function codeWithMatch(string $q, string $sort = 'updated', string $order = 'desc'): array + { + $this->acceptHeaderValue = 'application/vnd.github.v3.text-match+json'; + + return $this->code($q, $sort, $order); + } + /** * Search users by filter (q). * diff --git a/test/Github/Tests/Api/SearchTest.php b/test/Github/Tests/Api/SearchTest.php index a44c7b7499e..feecb7b5a74 100644 --- a/test/Github/Tests/Api/SearchTest.php +++ b/test/Github/Tests/Api/SearchTest.php @@ -133,6 +133,49 @@ public function shouldSearchCodeRegardingSortAndOrder() ); } + /** + * @test + */ + public function shouldSearchCodeWithMatchByQuery() + { + $expectedArray = [['total_count' => '0']]; + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/code', + ['q' => 'query text', 'sort' => 'updated', 'order' => 'desc'] + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->codeWithMatch('query text')); + } + + /** + * @test + */ + public function shouldSearchCodeWithMatchRegardingSortAndOrder() + { + $expectedArray = [['total_count' => '0']]; + + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with( + '/search/code', + ['q' => 'query text', 'sort' => 'created', 'order' => 'asc'] + ) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->codeWithMatch('query text', 'created', 'asc') + ); + } + /** * @test */ From f6123b0f04fbd779de095e9b23521891a53c46ae Mon Sep 17 00:00:00 2001 From: Alexandre PAVY Date: Sun, 3 Oct 2021 23:14:26 +0200 Subject: [PATCH 867/951] Added dir parameter for Repo readme --- lib/Github/Api/Repo.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index dfbd39b991a..750775a0458 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -257,13 +257,20 @@ public function remove($username, $repository) * @param string $username the user who owns the repository * @param string $repository the name of the repository * @param string $format one of formats: "raw", "html", or "v3+json" + * @param string $dir The alternate path to look for a README file * @param array $params additional query params like "ref" to fetch readme for branch/tag * * @return string|array the readme content */ - public function readme($username, $repository, $format = 'raw', $params = []) + public function readme($username, $repository, $format = 'raw', $dir = null, $params = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme', $params, [ + $path = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme'; + + if (null !== $dir) { + $path .= '/'.rawurlencode($dir); + } + + return $this->get($path, $params, [ 'Accept' => "application/vnd.github.$format", ]); } From 87838df3c1d4c3cd2d6ddd09444ce49c5ca0039f Mon Sep 17 00:00:00 2001 From: Henrik Gemal Date: Mon, 25 Oct 2021 16:02:26 +0200 Subject: [PATCH 868/951] Fix incorrect phpdoc Fixes #1033 --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 750775a0458..5119d772b8e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -626,7 +626,7 @@ public function subscribers($username, $repository, $page = 1) * @param string $head The head to merge. This can be a branch name or a commit SHA1. * @param string $message Commit message to use for the merge commit. If omitted, a default message will be used. * - * @return array|null + * @return array|string */ public function merge($username, $repository, $base, $head, $message = null) { From de2f27846139e7b4b92dcad9ff77660d0dc5dfad Mon Sep 17 00:00:00 2001 From: Paolo Rossi Date: Tue, 2 Nov 2021 07:51:42 +0100 Subject: [PATCH 869/951] feature #1036 refs #955: deprecate Client::AUTH_* constants and replace them with AuthMethod::AUTH_* const (ipalo) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- Contribution for #955 Commits ------- 11c2d9f7ab51a5e1d1cf16817e092fe15c48a157 refs #955: deprecate Client::AUTH_* constants and replace them with AuthMethod::AUTH_* const f4774d0c897768256e28538f1883fa747551988b refs #955: revert the Client::AUTH_* deletion (BC) e7f1ab951ba8df11c013b7dd4bcedbb0924548d7 refs #955: fix CR issues c9cf54e65f7010821d224dfc96ada2a226ce9e81 refs #955: add upgrade to v4.0 notes ec6656c7209df6674852463c4250402e3d6e395a refs #955: set public all constants --- UPGRADE-4.0.md | 6 ++++ doc/currentuser/repositories.md | 6 ++-- doc/graphql.md | 6 ++-- doc/security.md | 18 +++++------ lib/Github/AuthMethod.php | 30 +++++++++++++++++++ lib/Github/Client.php | 14 ++++++--- .../HttpClient/Plugin/Authentication.php | 8 ++--- test/Github/Tests/ClientTest.php | 11 +++---- test/Github/Tests/Functional/CacheTest.php | 7 +++-- .../HttpClient/Plugin/AuthenticationTest.php | 8 ++--- 10 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 lib/Github/AuthMethod.php diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 9192a02a726..6ede78deb51 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -3,3 +3,9 @@ ### ResultPager * `\Github\ResultPagerInterface::postFetch` is deprecated, and the method will be removed from the ResultPager interface/class. + +### Authentication methods + +* `Github\Client::AUTH_CLIENT_ID` is deprecated, use `Github\AuthMethod::CLIENT_ID` instead. +* `Github\Client::AUTH_ACCESS_TOKEN` is deprecated, use `Github\AuthMethod::ACCESS_TOKEN` instead. +* `Github\Client::AUTH_JWT` is deprecated, use `Github\AuthMethod::JWT` instead. diff --git a/doc/currentuser/repositories.md b/doc/currentuser/repositories.md index a3e2922b20f..9b5e1d85e94 100644 --- a/doc/currentuser/repositories.md +++ b/doc/currentuser/repositories.md @@ -19,12 +19,12 @@ There are three values that can be passed into the `repositories` method: `type` | sort | `full_name` | `created`, `updated`, `pushed`, `full_name` | direction | `asc` | `asc`, `desc` -> See https://developer.github.com/v3/repos/#list-your-repositories for possible values and additional information +> See https://developer.github.com/v3/repos/#list-your-repositories for possible values and additional information #### Code Example: ```php -$client = new \Github\Client(); -$client->authenticate($github_token, null, \Github\Client::AUTH_ACCESS_TOKEN); +$client = new \Github\Client(); +$client->authenticate($github_token, null, \Github\AuthMethod::ACCESS_TOKEN); $client->currentUser()->repositories(); ``` diff --git a/doc/graphql.md b/doc/graphql.md index 99e653bf87a..83481868544 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -14,7 +14,7 @@ $rateLimits = $client->api('graphql')->execute($query); To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticated]((../security.md)). ```php -$client->authenticate($token, null, Github\Client::AUTH_ACCESS_TOKEN); +$client->authenticate($token, null, Github\AuthMethod::ACCESS_TOKEN); $result = $client->api('graphql')->execute($query); ``` @@ -28,7 +28,7 @@ To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) with diffe ```php $result = $client->api('graphql')->execute($query, [], 'application/vnd.github.starfox-preview+json') ``` -> default accept header is `application/vnd.github.v4+json` +> default accept header is `application/vnd.github.v4+json` @@ -51,7 +51,7 @@ $variables = [ 'organizationLogin' => 'KnpLabs' ]; -$client->authenticate('', null, Github\Client::AUTH_ACCESS_TOKEN); +$client->authenticate('', null, Github\AuthMethod::ACCESS_TOKEN); $orgInfo = $client->api('graphql')->execute($query, $variables); ``` diff --git a/doc/security.md b/doc/security.md index b62ca4c05fc..7a79ee6674c 100644 --- a/doc/security.md +++ b/doc/security.md @@ -17,23 +17,23 @@ $client->authenticate($usernameOrToken, $password, $method); and guess what should contain `$password`. The `$method` can contain one of the three allowed values: #### Supported methods -* `Github\Client::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret -* `Github\Client::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header -* `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app +* `Github\AuthMethod::CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret +* `Github\AuthMethod::ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header +* `Github\AuthMethod::JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app -The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_ACCESS_TOKEN`, `Github\Client::AUTH_ACCESS_TOKEN` and -`Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in +The required value of `$password` depends on the chosen `$method`. For `Github\AuthMethod::CLIENT_ID`, `Github\AuthMethod::ACCESS_TOKEN` and +`Github\AuthMethod::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in this particular case). -The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header. +The `Github\AuthMethod::JWT` authentication method sends the specified JSON Web Token in an Authorization header. After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, all further requests are done as the given user. ### Authenticating as an Integration -To authenticate as an integration you need to supply a JSON Web Token with `Github\Client::AUTH_JWT` to request -and installation access token which is then usable with `Github\Client::AUTH_ACCESS_TOKEN`. [Github´s integration +To authenticate as an integration you need to supply a JSON Web Token with `Github\AuthMethod::JWT` to request +and installation access token which is then usable with `Github\AuthMethod::ACCESS_TOKEN`. [Github´s integration authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail. It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. @@ -64,7 +64,7 @@ $jwt = $config->builder(ChainedFormatter::withUnixTimestampDates()) ->getToken($config->signer(), $config->signingKey()) ; -$github->authenticate($jwt->toString(), null, Github\Client::AUTH_JWT) +$github->authenticate($jwt->toString(), null, Github\AuthMethod::JWT) ``` The `$integrationId` you can find in the about section of your github app. diff --git a/lib/Github/AuthMethod.php b/lib/Github/AuthMethod.php new file mode 100644 index 00000000000..4a390699a3c --- /dev/null +++ b/lib/Github/AuthMethod.php @@ -0,0 +1,30 @@ +method) { - case Client::AUTH_CLIENT_ID: + case AuthMethod::CLIENT_ID: return sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)); - case Client::AUTH_ACCESS_TOKEN: + case AuthMethod::ACCESS_TOKEN: return sprintf('token %s', $this->tokenOrLogin); - case Client::AUTH_JWT: + case AuthMethod::JWT: return sprintf('Bearer %s', $this->tokenOrLogin); default: throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index d1eb5737acf..c4980b8edc5 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -3,6 +3,7 @@ namespace Github\Tests; use Github\Api; +use Github\AuthMethod; use Github\Client; use Github\Exception\BadMethodCallException; use Github\Exception\InvalidArgumentException; @@ -68,9 +69,9 @@ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $me public function getAuthenticationFullData() { return [ - ['token', null, Client::AUTH_ACCESS_TOKEN], - ['client_id', 'client_secret', Client::AUTH_CLIENT_ID], - ['token', null, Client::AUTH_JWT], + ['token', null, AuthMethod::ACCESS_TOKEN], + ['client_id', 'client_secret', AuthMethod::CLIENT_ID], + ['token', null, AuthMethod::JWT], ]; } @@ -84,7 +85,7 @@ public function shouldAuthenticateUsingGivenParameters() ->getMock(); $builder->expects($this->once()) ->method('addPlugin') - ->with($this->equalTo(new Authentication('token', null, Client::AUTH_ACCESS_TOKEN))); + ->with($this->equalTo(new Authentication('token', null, AuthMethod::ACCESS_TOKEN))); $builder->expects($this->once()) ->method('removePlugin') @@ -98,7 +99,7 @@ public function shouldAuthenticateUsingGivenParameters() ->method('getHttpClientBuilder') ->willReturn($builder); - $client->authenticate('token', Client::AUTH_ACCESS_TOKEN); + $client->authenticate('token', AuthMethod::ACCESS_TOKEN); } /** diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index 58afe5f61f3..ec9be6b12e0 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -2,6 +2,7 @@ namespace Github\Tests\Functional; +use Github\AuthMethod; use Github\Client; use GuzzleHttp\Psr7\Response; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -25,7 +26,7 @@ public function shouldServeCachedResponse() $github = Client::createWithHttpClient($mockClient); $github->addCache(new ArrayAdapter(), ['default_ttl'=>600]); - $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); + $github->authenticate('fake_token_aaa', AuthMethod::ACCESS_TOKEN); $userA = $github->currentUser()->show(); $this->assertEquals('nyholm', $userA['login']); @@ -45,11 +46,11 @@ public function shouldVaryOnAuthorization() $github = Client::createWithHttpClient($mockClient); $github->addCache(new ArrayAdapter(), ['default_ttl'=>600]); - $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); + $github->authenticate('fake_token_aaa', AuthMethod::ACCESS_TOKEN); $userA = $github->currentUser()->show(); $this->assertEquals('nyholm', $userA['login']); - $github->authenticate('fake_token_bbb', Client::AUTH_ACCESS_TOKEN); + $github->authenticate('fake_token_bbb', AuthMethod::ACCESS_TOKEN); $userB = $github->currentUser()->show(); $this->assertEquals('octocat', $userB['login'], 'We must vary on the Authorization header.'); } diff --git a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php index e8c3d24a6a6..be937684d01 100644 --- a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php +++ b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php @@ -2,7 +2,7 @@ namespace Github\Tests\HttpClient\Plugin; -use Github\Client; +use Github\AuthMethod; use Github\HttpClient\Plugin\Authentication; use GuzzleHttp\Psr7\Request; use Http\Promise\FulfilledPromise; @@ -41,9 +41,9 @@ public function testAuthenticationMethods($tokenOrLogin, $password, $method, $ex public function getAuthenticationData() { return [ - ['access_token', null, Client::AUTH_ACCESS_TOKEN, 'token access_token'], - ['client_id', 'client_secret', Client::AUTH_CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))], - ['jwt_token', null, Client::AUTH_JWT, 'Bearer jwt_token'], + ['access_token', null, AuthMethod::ACCESS_TOKEN, 'token access_token'], + ['client_id', 'client_secret', AuthMethod::CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))], + ['jwt_token', null, AuthMethod::JWT, 'Bearer jwt_token'], ]; } } From a78ae66aca391f8ccb41254c617afc49b6ca67b9 Mon Sep 17 00:00:00 2001 From: Michael Gerdemann Date: Fri, 19 Nov 2021 08:13:44 +0100 Subject: [PATCH 870/951] feat: Add `visibility` option to repo create --- lib/Github/Api/Repo.php | 6 ++-- test/Github/Tests/Api/RepoTest.php | 48 ++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 5119d772b8e..4d8c012ff3e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -181,6 +181,7 @@ public function showById($id) * @param int $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization. * @param bool $autoInit `true` to create an initial commit with empty README, `false` for no initial commit * @param bool $hasProjects `true` to enable projects for this repository or false to disable them. + * @param string|null $visibility * * @return array returns repository data */ @@ -195,7 +196,8 @@ public function create( $hasDownloads = false, $teamId = null, $autoInit = false, - $hasProjects = true + $hasProjects = true, + $visibility = null ) { $path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos'; @@ -203,7 +205,7 @@ public function create( 'name' => $name, 'description' => $description, 'homepage' => $homepage, - 'private' => !$public, + 'visibility' => $visibility ?? ($public ? 'public' : 'private'), 'has_issues' => $hasIssues, 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 3761b2efb7e..a934bc6b906 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -95,7 +95,7 @@ public function shouldCreateRepositoryUsingNameOnly() 'name' => 'l3l0Repo', 'description' => '', 'homepage' => '', - 'private' => false, + 'visibility' => 'public', 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, @@ -121,7 +121,7 @@ public function shouldCreateRepositoryForOrganization() 'name' => 'KnpLabsRepo', 'description' => '', 'homepage' => '', - 'private' => false, + 'visibility' => 'public', 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, @@ -133,6 +133,48 @@ public function shouldCreateRepositoryForOrganization() $this->assertEquals($expectedArray, $api->create('KnpLabsRepo', '', '', true, 'KnpLabs')); } + /** + * @test + */ + public function shouldCreateRepositoryWithInternalVisibility() + { + $expectedArray = ['id' => 1, 'name' => 'KnpLabsRepo']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/user/repos', [ + 'name' => 'KnpLabsRepo', + 'description' => '', + 'homepage' => '', + 'has_issues' => false, + 'has_wiki' => false, + 'has_downloads' => false, + 'auto_init' => false, + 'has_projects' => true, + 'visibility' => 'internal', + ]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->create( + 'KnpLabsRepo', + '', + '', + false, + null, + false, + false, + false, + null, + false, + true, + 'internal' + ) + ); + } + /** * @test */ @@ -329,7 +371,7 @@ public function shouldCreateUsingAllParams() 'name' => 'l3l0Repo', 'description' => 'test', 'homepage' => 'http://l3l0.eu', - 'private' => true, + 'visibility' => 'private', 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, From 65081387852031579d8006c5fec7119291b84e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20K=C3=B3nya?= <40911283+kdaniel95@users.noreply.github.com> Date: Fri, 3 Dec 2021 11:06:31 +0100 Subject: [PATCH 871/951] feature #1041 Feature get authenticated app (kdaniel95) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- https://docs.github.com/en/rest/reference/apps#get-the-authenticated-app Create endpoint to get authenticated app. Commits ------- 090a967592728b9c3551780fadf8d985373c677c Feat: Get authenticated app ce3d0fd95f1df8e9534d8365631b41cbbc83f0b8 Fix endpoint doc d666ddb76688d1a3609c7a4c88befe49e21c2198 Fix StyleCI issues bb14d054d888e54776fe533692436309cea31b43 Merge remote-tracking branch 'origin/feature-get-authenticated-app' into feature-get-authenticated-app --- doc/apps.md | 6 ++++++ lib/Github/Api/Apps.php | 12 ++++++++++++ test/Github/Tests/Api/AppTest.php | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/doc/apps.md b/doc/apps.md index f7a61328092..14de9e4434d 100644 --- a/doc/apps.md +++ b/doc/apps.md @@ -49,3 +49,9 @@ $client->api('apps')->addRepository($installationId, $repositoryId); ```php $client->api('apps')->removeRepository($installationId, $repositoryId); ``` + +### Get authenticated app + +```php +$authenticatedApp = $client->api('apps')->getAuthenticatedApp(); +``` diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index bb2a2c463f9..9e9a4b6a741 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -186,4 +186,16 @@ public function removeRepository($installationId, $repositoryId) return $this->delete('/installations/'.$installationId.'/repositories/'.$repositoryId); } + + /** + * Get the currently authenticated app. + * + * @link https://docs.github.com/en/rest/reference/apps#get-the-authenticated-app + * + * @return array + */ + public function getAuthenticatedApp() + { + return $this->get('/app'); + } } diff --git a/test/Github/Tests/Api/AppTest.php b/test/Github/Tests/Api/AppTest.php index e5d5fcf57b4..28fa447b9a2 100644 --- a/test/Github/Tests/Api/AppTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -160,6 +160,23 @@ public function shouldRemoveRepositoryToInstallation() $api->removeRepository('1234', '5678'); } + /** + * @test + */ + public function shouldGetAuthenticatedApp() + { + $api = $this->getApiMock(); + + $result = ['authenticatedApp1']; + + $api->expects($this->once()) + ->method('get') + ->with('/app') + ->willReturn($result); + + $this->assertEquals($result, $api->getAuthenticatedApp()); + } + /** * @return string */ From bddf0f5e686a2dc72ca0ec642e3b487b08d841ce Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Wed, 8 Dec 2021 08:25:22 +0100 Subject: [PATCH 872/951] Update changelog for 3.4.0 release --- CHANGELOG-3.X.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 25db0b810ab..3a0963c16dc 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,30 @@ # Changelog +## 3.4.0 + +### Added +- Add create a repository using a template endpoint ([martinbean](https://github.com/martinbean)) [#994](https://github.com/KnpLabs/php-github-api/issues/994) +- Allow fetching repo readme for a specific ref ([bery](https://github.com/bery)) [#1019](https://github.com/KnpLabs/php-github-api/issues/1019) +- allow assigning role to organisation members ([luceos](https://github.com/luceos)) [#1018](https://github.com/KnpLabs/php-github-api/issues/1018) +- Branch lists . ( ? query per_page) ([pitonic](https://github.com/pitonic)) [#1020](https://github.com/KnpLabs/php-github-api/issues/1020) +- Php8.1 support ([acrobat](https://github.com/acrobat)) [#1025](https://github.com/KnpLabs/php-github-api/issues/1025) +- Allow psr/cache 2.0 as well as 1.0 ([johnnoel](https://github.com/johnnoel)) [#1029](https://github.com/KnpLabs/php-github-api/issues/1029) +- adding code_with_match (#1024) ([QuentinRa](https://github.com/QuentinRa)) [#1031](https://github.com/KnpLabs/php-github-api/issues/1031) +- Added dir parameter for Repo readme ([AlexandrePavy](https://github.com/AlexandrePavy)) [#1032](https://github.com/KnpLabs/php-github-api/issues/1032) +- refs #955: deprecate Client::AUTH_* constants and replace them with AuthMethod::AUTH_* const ([ipalo](https://github.com/ipalo)) [#1036](https://github.com/KnpLabs/php-github-api/issues/1036) +- feat: Add `visibility` option to repo create ([gerdemann](https://github.com/gerdemann)) [#1038](https://github.com/KnpLabs/php-github-api/issues/1038) +- Feature get authenticated app ([kdaniel95](https://github.com/kdaniel95)) [#1041](https://github.com/KnpLabs/php-github-api/issues/1041) + +### Changed +- Fix up typos ([dereuromark](https://github.com/dereuromark)) [#1011](https://github.com/KnpLabs/php-github-api/issues/1011) +- Update integration authentication documentation for usage with lcobucci/jwt ^4 ([glaubinix](https://github.com/glaubinix)) [#1017](https://github.com/KnpLabs/php-github-api/issues/1017) +- Update result_pager.md ([tomsowerby](https://github.com/tomsowerby)) [#1023](https://github.com/KnpLabs/php-github-api/issues/1023) +- fix(doc): links to doc in CurrentUser class ([Nek-](https://github.com/Nek-)) [#1026](https://github.com/KnpLabs/php-github-api/issues/1026) +- Fix incorrect phpdoc ([gemal](https://github.com/gemal)) [#1034](https://github.com/KnpLabs/php-github-api/issues/1034) + +### Fixed +- Add accept header for creating repo from template ([davidpeach](https://github.com/davidpeach)) [#1030](https://github.com/KnpLabs/php-github-api/issues/1030) + ## 3.3.0 ### Added From ce386210cb0cb5adc32a5fa5f11a6d413bf5b2e5 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Fri, 31 Dec 2021 08:31:14 +0100 Subject: [PATCH 873/951] Fix internal doc link --- doc/graphql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/graphql.md b/doc/graphql.md index 83481868544..e9ba581c506 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -11,7 +11,7 @@ $rateLimits = $client->api('graphql')->execute($query); #### Authentication -To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticated]((../security.md)). +To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticated](security.md). ```php $client->authenticate($token, null, Github\AuthMethod::ACCESS_TOKEN); From 59ed2862aa304ea225645d08f31a7f0427e0a28d Mon Sep 17 00:00:00 2001 From: Stephen Stack Date: Tue, 18 Jan 2022 12:17:53 +0000 Subject: [PATCH 874/951] added support for psr\cache 3.0 - OK (704 tests, 1245 assertions) --- composer.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 71924b18e59..16533bc38f7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php-http/discovery": "^1.12", "php-http/httplug": "^2.2", "php-http/multipart-stream-builder": "^1.1.2", - "psr/cache": "^1.0|^2.0", + "psr/cache": "^1.0|^2.0|^3.0", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0", @@ -54,5 +54,10 @@ "dev-2.x": "2.20.x-dev", "dev-master": "3.4.x-dev" } + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } From 52280d9321b58082b51bcb5b389bf7af85383efb Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Thu, 20 Jan 2022 16:12:00 +0000 Subject: [PATCH 875/951] Symfony: allow deprecation-contracts version 3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 16533bc38f7..b54537bd1f5 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0", "symfony/polyfill-php80": "^1.17", - "symfony/deprecation-contracts": "^2.2" + "symfony/deprecation-contracts": "^2.2|^3.0" }, "require-dev": { "symfony/cache": "^5.1.8", From b56a3feba87215253d0b0db27259a701068bdfe8 Mon Sep 17 00:00:00 2001 From: Asher Goldberg <43661200+asher-goldberg@users.noreply.github.com> Date: Sun, 23 Jan 2022 06:31:58 -0500 Subject: [PATCH 876/951] bug #1048 Fix Client URL Prepending For GraphQL Endpoint on Enterprise (asher-goldberg, acrobat) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- fixes #1047 This checks if `v4` is passed into the Client and an Enterprise URL is set then the prepend will only be `/api`. (The class default is `v3` if no version is provided so can't just pass an empty string). TL;DR - this now allows this package to run GraphQL calls on Enterprise `$client = new Client(null, 'v4', 'https://enterpriseurl');` Commits ------- 0d989bbcff6a63e9f24784c3c0215263666245b0 Fix prepend on Enteprrise for V4 a44fa2b8d067f68518796bbbc76fc5ba3d828d04 Allow codestyle fix --- 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..74255c9a9f3 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 9906308d0c0e0b551e5fd461e026592de66fe311 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 23 Jan 2022 12:32:47 +0100 Subject: [PATCH 877/951] Update changelog for 3.5.0 release --- CHANGELOG-3.X.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 3a0963c16dc..30dcb73d2ec 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,17 @@ # Changelog +## 3.5.0 + +### Added +- added support for psr\cache 3.0 ([rconfig](https://github.com/rconfig)) [#1046](https://github.com/KnpLabs/php-github-api/issues/1046) +- Symfony: allow deprecation-contracts version 3 ([glaubinix](https://github.com/glaubinix)) [#1049](https://github.com/KnpLabs/php-github-api/issues/1049) + +### Changed +- Fix internal doc link ([staudenmeir](https://github.com/staudenmeir)) [#1044](https://github.com/KnpLabs/php-github-api/issues/1044) + +### Fixed +- Fix Client URL Prepending For GraphQL Endpoint on Enterprise ([asher-goldberg](https://github.com/asher-goldberg), [acrobat](https://github.com/acrobat)) [#1048](https://github.com/KnpLabs/php-github-api/issues/1048) + ## 3.4.0 ### Added From ed63fb6b5ba2936614c985b80515603d990fa42a Mon Sep 17 00:00:00 2001 From: Vit Horacek <36083550+mountiny@users.noreply.github.com> Date: Sat, 12 Feb 2022 21:09:16 +0000 Subject: [PATCH 878/951] Include optional params parameter for Commits compare With the current API, we cannot paginate compare basehead function call. The Github API limits the response to only 250 commits so for larger diffs we have no option. --- lib/Github/Api/Repository/Commits.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 8195e4baf0f..383905d28f2 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -16,14 +16,14 @@ public function all($username, $repository, array $params) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits', $params); } - public function compare($username, $repository, $base, $head, $mediaType = null) + public function compare($username, $repository, $base, $head, $mediaType = null, array $params = []) { $headers = []; if (null !== $mediaType) { $headers['Accept'] = $mediaType; } - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), [], $headers); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/compare/'.rawurlencode($base).'...'.rawurlencode($head), $params, $headers); } public function show($username, $repository, $sha) From 4916a9401a27618673a26bf3c713d9d8da28ff2d Mon Sep 17 00:00:00 2001 From: mruell <46520365+mruell@users.noreply.github.com> Date: Fri, 18 Feb 2022 19:29:41 +0100 Subject: [PATCH 879/951] bug #1051 Boolean private needed to create private repo! (mruell) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- Apparently there was an GitHub API change. When private is not set to `true` the visibility `private` is ignored Commits ------- bc93867eed5815ab9567f8e01f240a3b3f6b7b47 Boolean private needed to create private repo as seen in: https://docs.github.com/en/rest/reference/repos#create-an-organization-repository a1f96868c572d01a99eeca93d21b56a24b90f09d Fix tests --- lib/Github/Api/Repo.php | 1 + test/Github/Tests/Api/RepoTest.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 4d8c012ff3e..12fe726b450 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -205,6 +205,7 @@ public function create( 'name' => $name, 'description' => $description, 'homepage' => $homepage, + 'private' => ($visibility ?? ($public ? 'public' : 'private')) === 'private', 'visibility' => $visibility ?? ($public ? 'public' : 'private'), 'has_issues' => $hasIssues, 'has_wiki' => $hasWiki, diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index a934bc6b906..7ba181dd53f 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -96,6 +96,7 @@ public function shouldCreateRepositoryUsingNameOnly() 'description' => '', 'homepage' => '', 'visibility' => 'public', + 'private' => false, 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, @@ -122,6 +123,7 @@ public function shouldCreateRepositoryForOrganization() 'description' => '', 'homepage' => '', 'visibility' => 'public', + 'private' => false, 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, @@ -153,6 +155,7 @@ public function shouldCreateRepositoryWithInternalVisibility() 'auto_init' => false, 'has_projects' => true, 'visibility' => 'internal', + 'private' => false, ]) ->will($this->returnValue($expectedArray)); @@ -372,6 +375,7 @@ public function shouldCreateUsingAllParams() 'description' => 'test', 'homepage' => 'http://l3l0.eu', 'visibility' => 'private', + 'private' => true, 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, From 37b167998e8e1f318b3d99633675cfa007540565 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 19 Feb 2022 12:15:46 +0100 Subject: [PATCH 880/951] Update changelog for 3.5.1 release --- CHANGELOG-3.X.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 30dcb73d2ec..8155111b104 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,10 @@ # Changelog +## 3.5.1 + +### Fixed +- Boolean private needed to create private repo! ([mruell](https://github.com/mruell)) [#1051](https://github.com/KnpLabs/php-github-api/issues/1051) + ## 3.5.0 ### Added From 4d53365668c5633a12e0c86a1644462e94d24451 Mon Sep 17 00:00:00 2001 From: Andrew Ellis Date: Tue, 1 Mar 2022 15:41:06 -0700 Subject: [PATCH 881/951] fix(Apps): use /orgs/ORG/installation Signed-off-by: Andrew Ellis --- lib/Github/Api/Apps.php | 2 +- test/Github/Tests/Api/AppTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 9e9a4b6a741..62df3a3cf82 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -82,7 +82,7 @@ public function getInstallationForOrganization($org) { $this->configurePreviewHeader(); - return $this->get('/org/'.rawurldecode($org).'/installation'); + return $this->get('/orgs/'.rawurldecode($org).'/installation'); } /** diff --git a/test/Github/Tests/Api/AppTest.php b/test/Github/Tests/Api/AppTest.php index 28fa447b9a2..b813a11dd1f 100644 --- a/test/Github/Tests/Api/AppTest.php +++ b/test/Github/Tests/Api/AppTest.php @@ -66,7 +66,7 @@ public function shouldGetInstallationForOrganization() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/org/1234/installation') + ->with('/orgs/1234/installation') ->willReturn($result); $this->assertEquals($result, $api->getInstallationForOrganization('1234')); From 38146135651a9ed8c98778648849894799e842e4 Mon Sep 17 00:00:00 2001 From: Rafik Abdulwahab <97947131+pheeque1@users.noreply.github.com> Date: Wed, 23 Mar 2022 15:47:15 +0100 Subject: [PATCH 882/951] Update incorrect documentation The `find` method is no longer used and has been removed in the latest version. --- doc/users.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/users.md b/doc/users.md index 5bac98a7d16..dbc6a6bb302 100644 --- a/doc/users.md +++ b/doc/users.md @@ -6,11 +6,7 @@ Wrap [GitHub User API](http://developer.github.com/v3/users/). ### Search for users by keyword -```php -$users = $client->api('user')->find('KnpLabs'); -``` - -Returns an array of found users. +Use the [Search API](https://github.com/KnpLabs/php-github-api/blob/master/doc/search.md#search-users) to find users by keyword. ### Lists all users, in the order they signed up, since the last user you've seen From 5629ba3846298a48199061d1e0acd8f6c840e3c5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 24 Mar 2022 09:57:22 +0100 Subject: [PATCH 883/951] Fix ResponseMediator test after update in guzzle/psr-7 --- composer.json | 3 ++- .../HttpClient/Message/ResponseMediatorTest.php | 15 +++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index b54537bd1f5..ce6d0072118 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,8 @@ }, "config": { "allow-plugins": { - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "composer/package-versions-deprecated": true } } } diff --git a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php index c14eac8a297..8c1bfd29243 100644 --- a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php +++ b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php @@ -54,18 +54,13 @@ public function testGetContentInvalidJson() public function testGetPagination() { - $header = <<<'TEXT' -; rel="first", -; rel="next", -; rel="prev", -; rel="last", -TEXT; + $header = '; rel="first",; rel="next",; rel="prev",; rel="last",'; $pagination = [ - 'first' => 'http://github.com', - 'next' => 'http://github.com', - 'prev' => 'http://github.com', - 'last' => 'http://github.com', + 'first' => 'https://github.com', + 'next' => 'https://github.com', + 'prev' => 'https://github.com', + 'last' => 'https://github.com', ]; // response mock From 7f283177b96eb626e5cf6038d8771859a0af4b02 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 24 Mar 2022 10:08:32 +0100 Subject: [PATCH 884/951] Update changelog for 3.6.0 release --- CHANGELOG-3.X.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 8155111b104..b8516f0b6a8 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,16 @@ # Changelog +## 3.6.0 + +### Added +- Include optional params parameter for Commits compare method ([mountiny](https://github.com/mountiny)) [#1053](https://github.com/KnpLabs/php-github-api/issues/1053) + +### Changed +- Update incorrect documentation ([pheeque1](https://github.com/pheeque1)) [#1058](https://github.com/KnpLabs/php-github-api/issues/1058) + +### Fixed +- fix(Apps): use /orgs/ORG/installation ([ellisio](https://github.com/ellisio)) [#1056](https://github.com/KnpLabs/php-github-api/issues/1056) + ## 3.5.1 ### Fixed From 8ab22f61666477b9f67066be44af14ac64ad4fe3 Mon Sep 17 00:00:00 2001 From: Elliot Date: Wed, 6 Apr 2022 09:20:33 +0100 Subject: [PATCH 885/951] Updates ReviewRequest Create with type Array As per docs this query returns an array. Specific docs link added in docblock too. --- lib/Github/Api/PullRequest/ReviewRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php index d95913ccde3..7d77f3e5fd6 100644 --- a/lib/Github/Api/PullRequest/ReviewRequest.php +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -39,7 +39,7 @@ public function all($username, $repository, $pullRequest, array $params = []) } /** - * @link https://developer.github.com/v3/pulls/review_requests/#create-a-review-request + * @link https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request * * @param string $username * @param string $repository @@ -47,7 +47,7 @@ public function all($username, $repository, $pullRequest, array $params = []) * @param array $reviewers * @param array $teamReviewers * - * @return string + * @return array */ public function create($username, $repository, $pullRequest, array $reviewers = [], array $teamReviewers = []) { From 40ba3e7c9df728b1e2d8f5577190d1022a7f2d48 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 2 Jun 2022 18:43:02 +0200 Subject: [PATCH 886/951] added phpdocs --- lib/Github/Api/PullRequest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index ce1c2b1d901..22922c1ee92 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -108,16 +108,25 @@ public function status($username, $repository, $id) return $this->get($link); } + /** + * @return Comments + */ public function comments() { return new Comments($this->getClient()); } + /** + * @return Review + */ public function reviews() { return new Review($this->getClient()); } + /** + * @return ReviewRequest + */ public function reviewRequests() { return new ReviewRequest($this->getClient()); From c67780893b0cb14222e845b08bfe0c1b0cc68125 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 2 Jun 2022 18:45:53 +0200 Subject: [PATCH 887/951] added missing magic method phpdocs for deployments --- lib/Github/Client.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ecd4aec7904..56d68d59cec 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -62,6 +62,8 @@ * @method Api\Authorizations authorizations() * @method Api\Meta meta() * @method Api\GraphQL graphql() + * @method Api\Deployment deployment() + * @method Api\Deployment deployments() * * @author Joseph Bielawski * From 3cdd4be64f6f649b4c99e79790dd00dfc8a8057d Mon Sep 17 00:00:00 2001 From: mruell <46520365+mruell@users.noreply.github.com> Date: Sun, 12 Jun 2022 19:37:04 +0200 Subject: [PATCH 888/951] feature #1062 Fix issue https://github.com/KnpLabs/php-github-api/issues/1061 (mruell) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- Commits ------- bc93867eed5815ab9567f8e01f240a3b3f6b7b47 Boolean private needed to create private repo as seen in: https://docs.github.com/en/rest/reference/repos#create-an-organization-repository a1f96868c572d01a99eeca93d21b56a24b90f09d Fix tests 74a46eeb9002dcd2b3a340ef5004b179b3bc9fdb Merge branch 'KnpLabs:master' into master 11d92e73ab2d63e54410640fbf0d6cdbe292dcf5 Fix issue d2780b50b0169c540ad5edee1b2c60a9831a01a9 Fix tests --- lib/Github/Api/Repo.php | 5 ++++- test/Github/Tests/Api/RepoTest.php | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 12fe726b450..5760a587bed 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -206,7 +206,6 @@ public function create( 'description' => $description, 'homepage' => $homepage, 'private' => ($visibility ?? ($public ? 'public' : 'private')) === 'private', - 'visibility' => $visibility ?? ($public ? 'public' : 'private'), 'has_issues' => $hasIssues, 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, @@ -214,6 +213,10 @@ public function create( 'has_projects' => $hasProjects, ]; + if ($visibility) { + $parameters['visibility'] = $visibility; + } + if ($organization && $teamId) { $parameters['team_id'] = $teamId; } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 7ba181dd53f..9cfa7f84a88 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -95,7 +95,6 @@ public function shouldCreateRepositoryUsingNameOnly() 'name' => 'l3l0Repo', 'description' => '', 'homepage' => '', - 'visibility' => 'public', 'private' => false, 'has_issues' => false, 'has_wiki' => false, @@ -122,7 +121,6 @@ public function shouldCreateRepositoryForOrganization() 'name' => 'KnpLabsRepo', 'description' => '', 'homepage' => '', - 'visibility' => 'public', 'private' => false, 'has_issues' => false, 'has_wiki' => false, @@ -374,7 +372,6 @@ public function shouldCreateUsingAllParams() 'name' => 'l3l0Repo', 'description' => 'test', 'homepage' => 'http://l3l0.eu', - 'visibility' => 'private', 'private' => true, 'has_issues' => false, 'has_wiki' => false, From c230ab0162afeaec4318276e6a470af4b52da5fe Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 12 Jun 2022 19:59:07 +0200 Subject: [PATCH 889/951] Update changelog for 3.7.0 release --- CHANGELOG-3.X.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index b8516f0b6a8..6e413c1c5f7 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,15 @@ # Changelog +## 3.7.0 + +### Added +- added phpdocs ([staabm](https://github.com/staabm)) [#1068](https://github.com/KnpLabs/php-github-api/issues/1068) +- added missing magic method phpdocs for deployments ([staabm](https://github.com/staabm)) [#1069](https://github.com/KnpLabs/php-github-api/issues/1069) +- Fix issue https://github.com/KnpLabs/php-github-api/issues/1061 ([mruell](https://github.com/mruell)) [#1062](https://github.com/KnpLabs/php-github-api/issues/1062) + +### Changed +- Updates ReviewRequest Create method to return type Array ([ejntaylor](https://github.com/ejntaylor)) [#1060](https://github.com/KnpLabs/php-github-api/issues/1060) + ## 3.6.0 ### Added From 55e881aa02e04453f27d2344d9ccbf1de6af3164 Mon Sep 17 00:00:00 2001 From: Matthew Nessworthy Date: Mon, 13 Jun 2022 12:52:57 +0200 Subject: [PATCH 890/951] API rate limit error status can be 403 --- .../Plugin/GithubExceptionThrower.php | 15 ++++++++ .../Plugin/GithubExceptionThrowerTest.php | 34 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 4603f629881..78628c6740f 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -120,6 +120,21 @@ public function handleRequest(RequestInterface $request, callable $next, callabl throw new SsoRequiredException($url); } + $remaining = ResponseMediator::getHeader($response, 'X-RateLimit-Remaining'); + if ((403 === $response->getStatusCode()) && null !== $remaining && 1 > $remaining && isset($content['message']) && (0 === strpos($content['message'], 'API rate limit exceeded'))) { + $limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); + $reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); + + throw new ApiLimitExceedException($limit, $reset); + } + + $reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); + if ((403 === $response->getStatusCode()) && 0 < $reset && isset($content['message']) && (0 === strpos($content['message'], 'You have exceeded a secondary rate limit.'))) { + $limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); + + throw new ApiLimitExceedException($limit, $reset); + } + throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode()); }); } diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index 99973521980..f8090ef622c 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -75,6 +75,40 @@ public static function responseProvider() ), 'exception' => new \Github\Exception\ApiLimitExceedException(5000), ], + 'Rate Limit Exceeded via 403 status' => [ + 'response' => new Response( + 403, + [ + 'Content-Type' => 'application/json', + 'X-RateLimit-Remaining' => 0, + 'X-RateLimit-Limit' => 5000, + 'X-RateLimit-Reset' => 1609245810, + ], + json_encode( + [ + 'message' => 'API rate limit exceeded for installation ID xxxxxxx.', + ] + ) + ), + 'exception' => new \Github\Exception\ApiLimitExceedException(5000), + ], + 'Secondary Rate Limit Exceeded via 403 status' => [ + 'response' => new Response( + 403, + [ + 'Content-Type' => 'application/json', + 'X-RateLimit-Remaining' => 100, + 'X-RateLimit-Limit' => 5000, + 'X-RateLimit-Reset' => 1609245810, + ], + json_encode( + [ + 'message' => 'You have exceeded a secondary rate limit. Please wait a few minutes before you try again.', + ] + ) + ), + 'exception' => new \Github\Exception\ApiLimitExceedException(5000), + ], 'Two Factor Authentication Required' => [ 'response' => new Response( 401, From 83b8a32867d7dc293d89c852062540f5f709726e Mon Sep 17 00:00:00 2001 From: Henrik Gemal Date: Fri, 17 Jun 2022 15:04:10 +0200 Subject: [PATCH 891/951] bug #1071 dont require encoding (gemal) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- fixes #1042 Commits ------- 89c71de08c47c8f78ff68fd3597ad08bb0a0e4b4 dont require encoding 35c97c280e5b19a842bf6273d1bd532f9a6fdb1b Update BlobsTest.php --- lib/Github/Api/GitData/Blobs.php | 4 ++-- test/Github/Tests/Api/GitData/BlobsTest.php | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/Github/Api/GitData/Blobs.php b/lib/Github/Api/GitData/Blobs.php index 3b7357f3dd9..31aacda5674 100644 --- a/lib/Github/Api/GitData/Blobs.php +++ b/lib/Github/Api/GitData/Blobs.php @@ -59,8 +59,8 @@ public function show($username, $repository, $sha) */ public function create($username, $repository, array $params) { - if (!isset($params['content'], $params['encoding'])) { - throw new MissingArgumentException(['content', 'encoding']); + if (!isset($params['content'])) { + throw new MissingArgumentException('content'); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/blobs', $params); diff --git a/test/Github/Tests/Api/GitData/BlobsTest.php b/test/Github/Tests/Api/GitData/BlobsTest.php index 368d47c3cc2..4b87ed33e41 100644 --- a/test/Github/Tests/Api/GitData/BlobsTest.php +++ b/test/Github/Tests/Api/GitData/BlobsTest.php @@ -68,21 +68,6 @@ public function shouldCreateBlob() $this->assertEquals($expectedValue, $api->create('l3l0', 'l3l0repo', $data)); } - /** - * @test - */ - public function shouldNotCreateBlobWithoutEncoding() - { - $this->expectException(MissingArgumentException::class); - $data = ['content' => 'some cotent']; - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('post'); - - $api->create('l3l0', 'l3l0repo', $data); - } - /** * @test */ From 2354dce31f0a5544eb99f5d9ef07ca8f48a009dc Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Mon, 20 Jun 2022 12:06:00 +1200 Subject: [PATCH 892/951] Add method to use generate release notes endpoint --- lib/Github/Api/Repository/Releases.php | 14 +++++++++++++ .../Tests/Api/Repository/ReleasesTest.php | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 10dfe09d290..6cd7fda4f0a 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -68,6 +68,20 @@ public function show($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.$id); } + /** + * Generate release notes content for a release. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + */ + public function generateNotes($username, $repository, array $params) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/generate-notes', $params); + } + /** * Create new release in selected repository. * diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index 8668195c1e6..dda8999a163 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -76,6 +76,26 @@ public function shouldGetSingleRepositoryRelease() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); } + /** + * @test + */ + public function shouldGenerateReleaseNotes() + { + $expectedValue = [ + 'name' => 'Release v1.0.0 is now available!', + 'body' => '##Changes in Release v1.0.0 ... ##Contributors @monalisa', + ]; + $data = ['tag_name' => 'some-tag']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/releases/generate-notes') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->generateNotes('KnpLabs', 'php-github-api', $data)); + } + /** * @test */ From 72b353383097c4518a184dfbfb43efe75a5601b6 Mon Sep 17 00:00:00 2001 From: secalith-code <109801896+secalith-code@users.noreply.github.com> Date: Thu, 28 Jul 2022 20:19:06 +0200 Subject: [PATCH 893/951] Update security.md --- doc/security.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/security.md b/doc/security.md index 7a79ee6674c..7aed2f9806c 100644 --- a/doc/security.md +++ b/doc/security.md @@ -64,7 +64,7 @@ $jwt = $config->builder(ChainedFormatter::withUnixTimestampDates()) ->getToken($config->signer(), $config->signingKey()) ; -$github->authenticate($jwt->toString(), null, Github\AuthMethod::JWT) +$github->authenticate($jwt->toString(), null, Github\AuthMethod::JWT); ``` The `$integrationId` you can find in the about section of your github app. From e15ee949f315900fa50c6044281685aaafa4dee9 Mon Sep 17 00:00:00 2001 From: Cameron Eagans Date: Mon, 1 Aug 2022 12:57:07 -0600 Subject: [PATCH 894/951] feature #1066 Fix typehint for repository dispatch method (cweagans) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- Closes https://github.com/KnpLabs/php-github-api/issues/1065 Commits ------- 714798ce7bde498dafae276ac54194cbd1e05144 Fix typehint for repository dispatch method 5005773664c5f0be14c6d6b7d6c2a5bce90e7671 styleci fixes --- lib/Github/Api/Repo.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 5760a587bed..f5762279e7a 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -286,14 +286,19 @@ public function readme($username, $repository, $format = 'raw', $dir = null, $pa * * @link https://developer.github.com/v3/repos/#create-a-repository-dispatch-event * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string $eventType A custom webhook event name + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $eventType A custom webhook event name + * @param array|object $clientPayload The payload to pass to Github. * * @return mixed null on success, array on error with 'message' */ - public function dispatch($username, $repository, $eventType, array $clientPayload) + public function dispatch($username, $repository, $eventType, $clientPayload) { + if (is_array($clientPayload)) { + $clientPayload = (object) $clientPayload; + } + return $this->post(\sprintf('/repos/%s/%s/dispatches', rawurlencode($username), rawurlencode($repository)), [ 'event_type' => $eventType, 'client_payload' => $clientPayload, From a43662d7c9d4032768ec829dde2cf143878a4104 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 1 Aug 2022 20:58:16 +0200 Subject: [PATCH 895/951] Update changelog for 3.8.0 release --- CHANGELOG-3.X.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 6e413c1c5f7..6117a31c262 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,18 @@ # Changelog +## 3.8.0 + +### Added +- API rate limit error status can be 403 ([matthewnessworthy](https://github.com/matthewnessworthy)) [#1072](https://github.com/KnpLabs/php-github-api/issues/1072) +- Add method to use generate release notes endpoint ([GuySartorelli](https://github.com/GuySartorelli)) [#1074](https://github.com/KnpLabs/php-github-api/issues/1074) +- Fix typehint for repository dispatch method ([cweagans](https://github.com/cweagans)) [#1066](https://github.com/KnpLabs/php-github-api/issues/1066) + +### Changed +- Update security.md ([secalith-code](https://github.com/secalith-code)) [#1076](https://github.com/KnpLabs/php-github-api/issues/1076) + +### Fixed +- dont require encoding ([gemal](https://github.com/gemal)) [#1071](https://github.com/KnpLabs/php-github-api/issues/1071) + ## 3.7.0 ### Added From 0158c304ae7c1c44ef261baf51e7c412585aa1db Mon Sep 17 00:00:00 2001 From: Thomas Genin Date: Mon, 15 Aug 2022 15:35:56 +0200 Subject: [PATCH 896/951] feature #1075 Add the ability to download raw file, needed when size > 1MB (genintho) This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- API DOC https://docs.github.com/en/rest/repos/contents The API call to return the content of a file return an empty content if a file is bigger than 1MB. To be able to download that file, we need to provide the header `application/vnd.github.VERSION.raw`. When doing so, the API return a the raw file, instead of a JSON object with some attributes + the file content. Because the API has a different behavior, I preferred to create a dedicated method as opposed to provide accept more option in the download method and having a bunch of if/else. Note: a 3rd behavior exists for that API call when downloading markdown and passing the `application/vnd.github.VERSION.html` header, which is not supported by this code change. Commits ------- 520ffb9c2c6887bb5c25c32f515a8f93077635c0 Add the ability to download raw file, needed when size > 1MB ff458a2cab21cd3939eb48a2da98c0400768fb07 Restore modification committed by mistake e7c393ffae6dbbfd70d455eafc887d0b85619f40 Style fix --- lib/Github/Api/Repository/Contents.php | 34 +++++++++++++++---- .../Tests/Api/Repository/ContentsTest.php | 17 ++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index bc78503b2f9..4f9693dcbe1 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -61,14 +61,15 @@ public function readme($username, $repository, $reference = null) * * @link http://developer.github.com/v3/repos/contents/ * - * @param string $username the user who owns the repository - * @param string $repository the name of the repository - * @param string|null $path path to file or directory - * @param string|null $reference reference to a branch or commit + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string|null $path path to file or directory + * @param string|null $reference reference to a branch or commit + * @param array $requestHeaders request headers * * @return array|string information for file | information for each item in directory */ - public function show($username, $repository, $path = null, $reference = null) + public function show($username, $repository, $path = null, $reference = null, $requestHeaders = []) { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents'; if (null !== $path) { @@ -77,7 +78,7 @@ public function show($username, $repository, $path = null, $reference = null) return $this->get($url, [ 'ref' => $reference, - ]); + ], $requestHeaders); } /** @@ -294,4 +295,25 @@ public function download($username, $repository, $path, $reference = null) return base64_decode($file['content']) ?: null; } + + /** + * Get the raw content of a file in a repository. + * + * Use this method instead of the download method if your file is bigger than 1MB + * + * @see https://docs.github.com/en/rest/repos/contents + * + * @param string $username the user who owns the repository + * @param string $repository the name of the repository + * @param string $path path to file + * @param string|null $reference reference to a branch or commit + * + * @return array|string + */ + public function rawDownload($username, $repository, $path, $reference = null) + { + return $this->show($username, $repository, $path, $reference, [ + 'Accept' => 'application/vnd.github.VERSION.raw', + ]); + } } diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 122fbf5cdf9..1cc828c370d 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -319,6 +319,23 @@ public function shouldDownloadForSpacedPath() $this->assertEquals($expectedValue, $api->download('mads379', 'scala.tmbundle', 'Syntaxes/Simple Build Tool.tmLanguage')); } + /** + * @test + */ + public function shouldRawDownloadForGivenPath() + { + // The show() method return + $getValue = include __DIR__.'/fixtures/ContentsDownloadFixture.php'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', ['ref' => null]) + ->will($this->returnValue($getValue)); + + $this->assertEquals($getValue, $api->rawDownload('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php')); + } + /** * @return string */ From 6b3c7eafb6e42de97400f82bd3f84f61e1bf99ae Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 15 Aug 2022 15:37:19 +0200 Subject: [PATCH 897/951] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ce6d0072118..8d51cdd7421 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.4.x-dev" + "dev-master": "3.9.x-dev" } }, "config": { From e1c8cb9ee91545d018dc6107e1dc235504336ae1 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Fri, 26 Aug 2022 16:02:09 +0200 Subject: [PATCH 898/951] minor #1078 Fix return types in phpdoc for `Assignees` and `ReviewRequest` (rob006) This PR was squashed before being merged into the 3.9.x-dev branch. Discussion ---------- Commits ------- 628a74914f7d61451ef5fe4ba696f3fad6e65374 PHPDoc: fix return type in `Assignees::remove()` 3d40ebb3b42f15c3b521a595d1a0855bf3b7b760 PHPDoc: fix return type in `Assignees::add()` a8747acb0974807e7ea6920b141a02460a25d1ee PHPDoc: fix return type in `ReviewRequest::remove()` --- lib/Github/Api/Issue/Assignees.php | 4 ++-- lib/Github/Api/PullRequest/ReviewRequest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php index 8ae86d1cd99..46435650823 100644 --- a/lib/Github/Api/Issue/Assignees.php +++ b/lib/Github/Api/Issue/Assignees.php @@ -51,7 +51,7 @@ public function check($username, $repository, $assignee) * @throws InvalidArgumentException * @throws MissingArgumentException * - * @return string + * @return array */ public function add($username, $repository, $issue, array $parameters) { @@ -78,7 +78,7 @@ public function add($username, $repository, $issue, array $parameters) * * @throws MissingArgumentException * - * @return string + * @return array */ public function remove($username, $repository, $issue, array $parameters) { diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php index 7d77f3e5fd6..e9b9280a119 100644 --- a/lib/Github/Api/PullRequest/ReviewRequest.php +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -63,7 +63,7 @@ public function create($username, $repository, $pullRequest, array $reviewers = * @param array $reviewers * @param array $teamReviewers * - * @return string + * @return array */ public function remove($username, $repository, $pullRequest, array $reviewers = [], array $teamReviewers = []) { From 3467a347db3027815ca012461e0583c7d0284717 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Mon, 12 Sep 2022 14:13:43 -0400 Subject: [PATCH 899/951] feature #1082 Feat: Support new Team Repositories Endpoint (iBotPeaches) This PR was squashed before being merged into the 3.9.x-dev branch. Discussion ---------- * old - https://docs.github.com/en/rest/teams/teams#list-team-repositories-legacy * new - https://docs.github.com/en/rest/teams/teams#list-team-repositories Commits ------- ca597858d2dbd62c9fb7626da2dd0b975c159b7f refactor: support new team endpoint, fallback to legacy if no org 69e82d6f07c26c77eadd702686288f6f9bfa4cdb test: support new team endpoint, fallback to legacy if no org --- lib/Github/Api/Organization/Teams.php | 11 +++++++++-- test/Github/Tests/Api/Organization/TeamsTest.php | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 3af63b73679..20bb2791a7a 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -95,9 +95,16 @@ public function removeMember($team, $username, $organization) return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - public function repositories($team) + /** + * @link https://docs.github.com/en/rest/teams/teams#list-team-repositories + */ + public function repositories($team, $organization = '') { - return $this->get('/teams/'.rawurlencode($team).'/repos'); + if (empty($organization)) { + return $this->get('/teams/'.rawurlencode($team).'/repos'); + } + + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/repos'); } public function repository($team, $organization, $repository) diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 45c98cb9a1d..18b476986aa 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -126,6 +126,22 @@ public function shouldGetTeamRepositories() { $expectedValue = [['name' => 'l3l0repo']]; + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/teams/KnpWorld/repos') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->repositories('KnpWorld', 'KnpLabs')); + } + + /** + * @test + */ + public function shouldGetTeamRepositoriesViaLegacy() + { + $expectedValue = [['name' => 'l3l0repo']]; + $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') From 4e2900e736b9ac37f345423795b1037c951dae89 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 10 Oct 2022 16:13:43 +0100 Subject: [PATCH 900/951] App: add hook endpoints --- lib/Github/Api/App/Hook.php | 76 +++++++++++++++++ lib/Github/Api/Apps.php | 14 ++++ test/Github/Tests/Api/App/HookTest.php | 109 +++++++++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 lib/Github/Api/App/Hook.php create mode 100644 test/Github/Tests/Api/App/HookTest.php diff --git a/lib/Github/Api/App/Hook.php b/lib/Github/Api/App/Hook.php new file mode 100644 index 00000000000..e7475dce740 --- /dev/null +++ b/lib/Github/Api/App/Hook.php @@ -0,0 +1,76 @@ +get('/app/hook/config'); + } + + /** + * Update the hook configuration of an app. + * + * @link https://docs.github.com/en/rest/apps/webhooks#update-a-webhook-configuration-for-an-app + * + * @param array $params + * + * @return array + */ + public function updateConfig(array $params) + { + return $this->patch('/app/hook/config', $params); + } + + /** + * List deliveries for an app webhook. + * + * @link https://docs.github.com/en/rest/apps/webhooks#list-deliveries-for-an-app-webhook + * + * @return array + */ + public function deliveries() + { + return $this->get('/app/hook/deliveries'); + } + + /** + * Get a delivery for an app webhook. + * + * @link https://docs.github.com/en/rest/apps/webhooks#get-a-delivery-for-an-app-webhook + * + * @param int $delivery + * + * @return array + */ + public function delivery($delivery) + { + return $this->get('/app/hook/deliveries/'.$delivery); + } + + /** + * Redeliver a delivery for an app webhook. + * + * @link https://docs.github.com/en/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook + * + * @param int $delivery + * + * @return array + */ + public function redeliver($delivery) + { + return $this->post('/app/hook/deliveries/'.$delivery.'/attempts'); + } +} diff --git a/lib/Github/Api/Apps.php b/lib/Github/Api/Apps.php index 62df3a3cf82..15e1dfdcd4a 100644 --- a/lib/Github/Api/Apps.php +++ b/lib/Github/Api/Apps.php @@ -2,6 +2,8 @@ namespace Github\Api; +use Github\Api\App\Hook; + /** * @link https://developer.github.com/v3/apps/ * @@ -198,4 +200,16 @@ public function getAuthenticatedApp() { return $this->get('/app'); } + + /** + * Manage the hook of an app. + * + * @link https://docs.github.com/en/rest/apps/webhooks + * + * @return Hook + */ + public function hook() + { + return new Hook($this->getClient()); + } } diff --git a/test/Github/Tests/Api/App/HookTest.php b/test/Github/Tests/Api/App/HookTest.php new file mode 100644 index 00000000000..f2ed6ae5ab4 --- /dev/null +++ b/test/Github/Tests/Api/App/HookTest.php @@ -0,0 +1,109 @@ + 'json', + 'insecure_ssl' => 0, + 'secret' => '********', + 'url' => 'https://localhost/', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/app/hook/config', []) + ->willReturn($result); + + $this->assertEquals($result, $api->showConfig()); + } + + /** + * @test + */ + public function shouldUpdateHookConfiguration() + { + $parameters = [ + 'content_type' => 'json', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/app/hook/config', $parameters) + ->willReturn([]); + + $this->assertEquals([], $api->updateConfig($parameters)); + } + + /** + * @test + */ + public function shouldListHookDelivieries() + { + $result = []; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/app/hook/deliveries', []) + ->willReturn($result); + + $this->assertEquals($result, $api->deliveries()); + } + + /** + * @test + */ + public function shouldListHookDeliviery() + { + $result = []; + + $delivery = 1234567; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/app/hook/deliveries/'.$delivery, []) + ->willReturn($result); + + $this->assertEquals($result, $api->delivery($delivery)); + } + + /** + * @test + */ + public function shouldRedeliveryHook() + { + $result = []; + + $delivery = 1234567; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/app/hook/deliveries/'.$delivery.'/attempts', []) + ->willReturn($result); + + $this->assertEquals($result, $api->redeliver($delivery)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\App\Hook::class; + } +} From d3307477a77cad3b1aa6a99c78586625aff112e8 Mon Sep 17 00:00:00 2001 From: Andrew Dawes Date: Sat, 22 Oct 2022 19:11:28 +0200 Subject: [PATCH 901/951] Fixed several typos and grammar errors --- doc/activity.md | 6 +++--- doc/caching.md | 2 +- doc/currentuser/publickeys.md | 2 +- doc/customize.md | 2 +- doc/graphql.md | 2 +- doc/project/projects.md | 4 ++-- doc/pull_request/comments.md | 2 +- doc/repo/hooks.md | 2 +- doc/repos.md | 6 +++--- doc/request_response_info.md | 2 +- doc/result_pager.md | 4 ++-- doc/security.md | 4 ++-- doc/testing.md | 24 ++++++++++++------------ doc/two_factor_authentication.md | 2 +- doc/users.md | 2 +- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/doc/activity.md b/doc/activity.md index c15690e9fe3..48d7cfb423d 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -24,7 +24,7 @@ Returns an array of watched repos. > *** Requires [authentication](security.md). *** -### Get repos that a authenticated user has starred +### Get repos that an authenticated user has starred ```php $activity = $client->api('current_user')->starring()->all(); @@ -38,7 +38,7 @@ $activity = $client->api('user')->events('ornicar'); ``` Returns an array of private and public events created for all repos related to the user. -### Get repos that a authenticated user has starred with creation date +### Get repos that an authenticated user has starred with creation date Support for getting the star creation timestamp in the response, using the custom `Accept: application/vnd.github.v3.star+json` header. @@ -75,7 +75,7 @@ $activity = $client->api('current_user')->starring()->unstar($owner, $repo); Throws an Exception in case of failure or NULL in case of success. -### Get repos that a authenticated user is watching +### Get repos that an authenticated user is watching ```php $activity = $client->api('current_user')->watchers()->all(); diff --git a/doc/caching.md b/doc/caching.md index a95f92e9eea..1a004cc8781 100644 --- a/doc/caching.md +++ b/doc/caching.md @@ -26,5 +26,5 @@ $client->removeCache(); ``` Using cache, the client will get cached responses if resources haven't changed since last time, -**without** reaching the `X-Rate-Limit` [imposed by github](http://developer.github.com/v3/#rate-limiting). +**without** reaching the `X-Rate-Limit` [imposed by GitHub](http://developer.github.com/v3/#rate-limiting). diff --git a/doc/currentuser/publickeys.md b/doc/currentuser/publickeys.md index a9d19018f2d..444dd58fa0c 100644 --- a/doc/currentuser/publickeys.md +++ b/doc/currentuser/publickeys.md @@ -25,7 +25,7 @@ $key = $client->me()->keys()->show(1234); $key = $client->me()->keys()->create(array('title' => 'key title', 'key' => 12345)); ``` -Adds a key with title 'key title' to the authenticated user and returns a the created key for the user. +Adds a key with title 'key title' to the authenticated user and returns the created key for the user. ### Remove a public key from the authenticated user. diff --git a/doc/customize.md b/doc/customize.md index 1d5ae51e766..b475ee57322 100644 --- a/doc/customize.md +++ b/doc/customize.md @@ -22,7 +22,7 @@ To use the symfony http client composer require symfony/http-client nyholm/psr7 ``` -To set up the github client with this http client +To set up the GitHub client with this http client ```php use Github\Client; diff --git a/doc/graphql.md b/doc/graphql.md index e9ba581c506..dfe83639085 100644 --- a/doc/graphql.md +++ b/doc/graphql.md @@ -11,7 +11,7 @@ $rateLimits = $client->api('graphql')->execute($query); #### Authentication -To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticated](security.md). +To use [GitHub v4 API (GraphQL API)](http://developer.github.com/v4/) requests must [authenticate](security.md). ```php $client->authenticate($token, null, Github\AuthMethod::ACCESS_TOKEN); diff --git a/doc/project/projects.md b/doc/project/projects.md index 5763e0060e7..103bbe10c86 100644 --- a/doc/project/projects.md +++ b/doc/project/projects.md @@ -1,10 +1,10 @@ ## Repo / Projects API [Back to the "Repos API"](../) | [Back to the navigation](../README.md) -This api is currently only available to developers in Early Access. To access the API during the Early Access period, +This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. -Both repositories and organisations have projects. The api is only different for gettings all or a single project. +Both repositories and organisations have projects. The api is only different for getting all or a single project. All the example use the repository projects api but this also works form the organization api (`$client->api('org_projects')`) ```php diff --git a/doc/pull_request/comments.md b/doc/pull_request/comments.md index 87ca5f8e443..e996f804989 100644 --- a/doc/pull_request/comments.md +++ b/doc/pull_request/comments.md @@ -67,7 +67,7 @@ $comment = $client->api('pull_request')->comments()->update('KnpLabs', 'php-gith This returns the details of the updated comment. -### Remove a review comment from an pull request +### Remove a review comment from a pull request > Requires [authentication](../security.md). diff --git a/doc/repo/hooks.md b/doc/repo/hooks.md index 1f89ed40405..a4f9d9af655 100644 --- a/doc/repo/hooks.md +++ b/doc/repo/hooks.md @@ -1,7 +1,7 @@ ## Repo / Hooks API [Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) -For extended info see the [Github documentation](https://docs.github.com/en/rest/reference/repos#webhooks) +For extended info see the [GitHub documentation](https://docs.github.com/en/rest/reference/repos#webhooks) ### List repository webhooks diff --git a/doc/repos.md b/doc/repos.md index ab412dc77c2..a0f822ce446 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -310,8 +310,8 @@ $activity = $client->api('repo')->activity('ornicar', 'php-github-api'); Returns an array of commit activity group by week. ### `Moved` repositories -Github repositories can be moved to another org/user, but it remains the `id`. -In case if you can't no more find repo, you can retrieve it by `id`: +GitHub repositories can be moved to another org/user, but it remains the `id`. +In case you can't find the repo anymore, you can retrieve it by `id`: ```php use Github\HttpClient\Message\ResponseMediator; @@ -365,7 +365,7 @@ $repo = $client->api('repo')->transfer('KnpLabs', 'php-github-api', 'github', [1 ### Create a repository dispatch event -Example when you want to configure custom github action workflows. +Example when you want to configure custom GitHub action workflows. ```php $client->api('repo')->dispatch('KnpLabs', 'php-github-api', 'acme-event', ['foo'=>'bar']); diff --git a/doc/request_response_info.md b/doc/request_response_info.md index 880e7f85a22..32e30981ea4 100644 --- a/doc/request_response_info.md +++ b/doc/request_response_info.md @@ -3,7 +3,7 @@ ### Get response headers -Get the repsonse header for the latest request +Get the response header for the latest request ``` $headers = $githubClient->getLastResponse()->getHeaders(); diff --git a/doc/result_pager.md b/doc/result_pager.md index b13432cb569..f074f1cc4a1 100644 --- a/doc/result_pager.md +++ b/doc/result_pager.md @@ -3,7 +3,7 @@ ### Usage examples -#### Get all repositories of a organization +#### Get all repositories of an organization ```php $client = new Github\Client(); @@ -21,7 +21,7 @@ Parameters of the `fetchAll` method: * The method of the API object you're using * The parameters of the method -Parameters are passed to the API method via [call_user_func_array](https://www.php.net/manual/en/function.call-user-func-array.php). +Parameters are passed to the API method via [call_user_func_array](https://www.php.net/manual/en/function.call-user-func-array.php). ```php $parameters = array('github', 'all', 1); // $organization, $type, $page diff --git a/doc/security.md b/doc/security.md index 7aed2f9806c..a8596de20b1 100644 --- a/doc/security.md +++ b/doc/security.md @@ -33,7 +33,7 @@ further requests are done as the given user. ### Authenticating as an Integration To authenticate as an integration you need to supply a JSON Web Token with `Github\AuthMethod::JWT` to request -and installation access token which is then usable with `Github\AuthMethod::ACCESS_TOKEN`. [Github´s integration +and installation access token which is then usable with `Github\AuthMethod::ACCESS_TOKEN`. [GitHub´s integration authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail. It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`. @@ -67,5 +67,5 @@ $jwt = $config->builder(ChainedFormatter::withUnixTimestampDates()) $github->authenticate($jwt->toString(), null, Github\AuthMethod::JWT); ``` -The `$integrationId` you can find in the about section of your github app. +The `$integrationId` you can find in the about section of your GitHub app. The `$installationId` you can find by installing the app and using the id in the url. diff --git a/doc/testing.md b/doc/testing.md index ec2effb3b5c..36df32097eb 100644 --- a/doc/testing.md +++ b/doc/testing.md @@ -4,7 +4,7 @@ ### Run Test Suite -The code is unit tested, there are also some functional tests. To run tests on +The code is unit tested, there are also some functional tests. To run tests on your machine, from a CLI, run ```bash @@ -14,12 +14,12 @@ $ phpunit ### Write tests -It is always great if someone wants to contribute and extend the functionality of -the API client. But all new features must be properly tested. To test a new API -function, one should test its communication with the HTTP client. The code should -never make an actual call to Github. Testing could easily be done with mocking. +It is always great if someone wants to contribute and extend the functionality of +the API client. But all new features must be properly tested. To test a new API +function, one should test its communication with the HTTP client. The code should +never make an actual call to GitHub. Testing could easily be done with mocking. -If you want to write test for the function that shows you comments to a gist. +If you want to write test for the function that shows you comments to a gist. ```php class Comments extends AbstractApi @@ -32,7 +32,7 @@ class Comments extends AbstractApi } ``` -The test will look like this: +The test will look like this: ```php use Github\Tests\Api\TestCase; @@ -51,7 +51,7 @@ class CommentsTest extends TestCase // Get the API mock (see "getApiClass" below). $api = $this->getApiMock(); - + $api->expects($this->once()) // Expect one call ->method('get') // A GET request ->with('/gists/123/comments/456') // URI should be "/gists/123/comments/456" @@ -59,14 +59,14 @@ class CommentsTest extends TestCase // Call Comments::show $result = $api->show(123, 456); - - // Verify that the result is the "Server response" as we expect. + + // Verify that the result is the "Server response" as we expect. $this->assertEquals($expectedValue, $result); } - + protected function getApiClass() { - // Tell the "getAPIMock" what class to mock. + // Tell the "getAPIMock" what class to mock. return \Github\Api\Gist\Comments::class; } } diff --git a/doc/two_factor_authentication.md b/doc/two_factor_authentication.md index 46e84e0daa5..3b58de49abc 100644 --- a/doc/two_factor_authentication.md +++ b/doc/two_factor_authentication.md @@ -1,4 +1,4 @@ -## Two factor authentication +## Two-factor authentication [Back to the navigation](README.md) diff --git a/doc/users.md b/doc/users.md index dbc6a6bb302..48bb0d7dc15 100644 --- a/doc/users.md +++ b/doc/users.md @@ -33,7 +33,7 @@ $user = $client->api('user')->show('KnpLabs'); Returns an array of information about the user. -You can also use the User ID, but it will use an undocumented Github API +You can also use the User ID, but it will use an undocumented GitHub API ```php $user = $client->api('user')->showById(202732); From f1cb6b620426184f3351dcbcf3b1c32b83d53bca Mon Sep 17 00:00:00 2001 From: Mahmud Date: Mon, 24 Oct 2022 15:40:34 +0300 Subject: [PATCH 902/951] feature #1084 Add sync a fork branch with the upstream repository (DAGpro) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR was squashed before being merged into the 3.9.x-dev branch. Discussion ---------- | Q | A | ------------- | --- | New feature? | ✔️ | Fixed issues | #1083 Commits ------- 184826b93898f9fca03397891a35d46b92262635 Add sync a fork branch with the upstream repository c6b2d3966202586a4688192995e7b86ae2b445af Mark the default branch 06e6c9bab0d154ec232c833b57fa87ef4c0acffa Add tests and documentation for the mergeUpstream method 0de3d781a404198dde89473a4a64a74ac656d7e2 Make parameter required d5d9aff69d85343b05d36b0d608dd1dccf7d8aaf Add typings to the mergeUpstream method --- doc/repos.md | 9 +++++++++ lib/Github/Api/Repo.php | 15 +++++++++++++++ test/Github/Tests/Api/RepoTest.php | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index a0f822ce446..7e091e005fe 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -223,6 +223,15 @@ $repository = $client->api('repo')->forks()->create('ornicar', 'php-github-api') Creates a fork of the 'php-github-api' owned by 'ornicar' and returns the newly created repository. +### Merge upstream repository + +> Requires [authentication](security.md). + +```php +$repository = $client->api('repo')->mergeUpstream('ornicar', 'php-github-api', 'branchName'); +``` +Merge upstream a branch of a forked repository to keep it up-to-date with the upstream repository. + ### Get the tags of a repository ```php diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index f5762279e7a..7536d7007dd 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -535,6 +535,21 @@ public function branches($username, $repository, $branch = null, array $paramete return $this->get($url, $parameters); } + /** + * Sync a fork branch with the upstream repository. + * + * @link https://docs.github.com/en/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository + * + * @return array|string + */ + public function mergeUpstream(string $username, string $repository, string $branchName) + { + return $this->post( + '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/merge-upstream', + ['branch' => $branchName] + ); + } + /** * Manage the protection of a repository branch. * diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 9cfa7f84a88..b4603bcddf9 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -240,6 +240,26 @@ public function shouldGetRepositoryBranch() $this->assertEquals($expectedArray, $api->branches('KnpLabs', 'php-github-api', 'master')); } + /** + * @test + */ + public function shouldMergeUpstreamRepository() + { + $expectedArray = [ + 'message' => 'Successfully fetched and fast-forwarded from upstream upstreamRepo:main', + 'merge_type' => 'fast-forward', + 'merge_branch' => 'upstreamRepo:main', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/merge-upstream', ['branch' => 'main']) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->mergeUpstream('KnpLabs', 'php-github-api', 'main')); + } + /** * @test */ From 665ba275dbf36f9e9ef78876f27ca87796e3599c Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 24 Oct 2022 14:42:09 +0200 Subject: [PATCH 903/951] Update changelog for 3.9.0 release --- CHANGELOG-3.X.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 6117a31c262..5aa309b25b3 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,17 @@ # Changelog +## 3.9.0 + +### Added +- Add the ability to download raw file, needed when size > 1MB ([genintho](https://github.com/genintho)) [#1075](https://github.com/KnpLabs/php-github-api/issues/1075) +- Feat: Support new Team Repositories Endpoint ([iBotPeaches](https://github.com/iBotPeaches)) [#1082](https://github.com/KnpLabs/php-github-api/issues/1082) +- App: add hook endpoints ([glaubinix](https://github.com/glaubinix)) [#1086](https://github.com/KnpLabs/php-github-api/issues/1086) +- Add sync a fork branch with the upstream repository ([DAGpro](https://github.com/DAGpro)) [#1084](https://github.com/KnpLabs/php-github-api/issues/1084) + +### Changed +- Fix return types in phpdoc for `Assignees` and `ReviewRequest` ([rob006](https://github.com/rob006)) [#1078](https://github.com/KnpLabs/php-github-api/issues/1078) +- Fixed several typos and grammar errors ([AndrewDawes](https://github.com/AndrewDawes)) [#1088](https://github.com/KnpLabs/php-github-api/issues/1088) + ## 3.8.0 ### Added From 28029f21d714cba67426ef20bdec0fed5ce97b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Dartigues?= Date: Tue, 25 Oct 2022 12:14:22 +0545 Subject: [PATCH 904/951] minor #1090 Create authorization removed from docs (rafasashi) This PR was squashed before being merged into the 3.9.x-dev branch. Discussion ---------- Create authorization deprecated and removed in V3 ([2fe12b8](https://github.com/KnpLabs/php-github-api/commit/2fe12b82a7fe5896ae4f067d4c62326c4041602f)) Commits ------- 92e683afc9d9e9305e4058f09dcca06a22e65a1c Create authorization removed cbac8bf36f2e2b0c56774d3daae3c2b68bdedf98 Delete two_factor_authentication.md --- doc/authorizations.md | 12 ------------ doc/two_factor_authentication.md | 19 ------------------- 2 files changed, 31 deletions(-) delete mode 100644 doc/two_factor_authentication.md diff --git a/doc/authorizations.md b/doc/authorizations.md index 2865fd63e19..b037e402c27 100644 --- a/doc/authorizations.md +++ b/doc/authorizations.md @@ -15,18 +15,6 @@ $authorizations = $github->api('authorizations')->all(); $authorization = $github->api('authorizations')->show(1); ``` -#### Create an authorization - -```php -$data = array( - 'note' => 'This is an optional description' -); - -$authorization = $github->api('authorizations')->create($data); -``` - -Creates and returns an authorization. - #### Update an authorization You can update ``note``. diff --git a/doc/two_factor_authentication.md b/doc/two_factor_authentication.md deleted file mode 100644 index 3b58de49abc..00000000000 --- a/doc/two_factor_authentication.md +++ /dev/null @@ -1,19 +0,0 @@ -## Two-factor authentication -[Back to the navigation](README.md) - - -### Raising the exception - -```php -try { - $authorization = $github->api('authorizations')->create(); -} catch (Github\Exception\TwoFactorAuthenticationRequiredException $e) { - echo sprintf("Two factor authentication of type %s is required.", $e->getType()); -} -``` - -Once the code has been retrieved (by sms for example), you can create an authorization: - -``` -$authorization = $github->api('authorizations')->create(array('note' => 'Optional'), $code); -``` From 7245b02233934f5c90fbaf25aa4076bb37417801 Mon Sep 17 00:00:00 2001 From: Andreia Bohner Date: Wed, 1 Feb 2023 22:22:10 -0300 Subject: [PATCH 905/951] Add vulnerability alerts endpoints --- doc/repos.md | 24 +++++++++++++ lib/Github/Api/Repo.php | 45 +++++++++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 54 ++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 7e091e005fe..d7c30d490f4 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -390,3 +390,27 @@ $client->api('repo')->createFromTemplate('template-owner', 'template-repo', [ 'owner' => 'name-of-new-repo-owner', // can be user or org ]); ``` + +### Check if vulnerability alerts (dependabot alerts) are enabled for a repository + +https://developer.github.com/v3/repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository + +```php +$client->api('repo')->isVulnerabilityAlertsEnabled('KnpLabs', 'php-github-api'); +``` + +### Enable vulnerability alerts (dependabot alerts) + +https://developer.github.com/v3/repos/#enable-vulnerability-alerts + +```php +$client->api('repo')->enableVulnerabilityAlerts('KnpLabs', 'php-github-api'); +``` + +### Disable vulnerability alerts (dependabot alerts) + +https://developer.github.com/v3/repos/#disable-vulnerability-alerts + +```php +$client->api('repo')->disableVulnerabilityAlerts('KnpLabs', 'php-github-api'); +``` diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 7536d7007dd..42a5e16a610 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -843,4 +843,49 @@ public function createFromTemplate(string $templateOwner, string $templateRepo, return $this->post('/repos/'.rawurldecode($templateOwner).'/'.rawurldecode($templateRepo).'/generate', $parameters); } + + /** + * Check if vulnerability alerts are enabled for a repository. + * + * @link https://developer.github.com/v3/repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository + * + * @param string $username the username + * @param string $repository the repository + * + * @return array|string + */ + public function isVulnerabilityAlertsEnabled(string $username, string $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts'); + } + + /** + * Enable vulnerability alerts for a repository. + * + * @link https://developer.github.com/v3/repos/#enable-vulnerability-alerts + * + * @param string $username the username + * @param string $repository the repository + * + * @return array|string + */ + public function enableVulnerabilityAlerts(string $username, string $repository) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts'); + } + + /** + * Disable vulnerability alerts for a repository. + * + * @link https://developer.github.com/v3/repos/#disable-vulnerability-alerts + * + * @param string $username the username + * @param string $repository the repository + * + * @return array|string + */ + public function disableVulnerabilityAlerts(string $username, string $repository) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts'); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index b4603bcddf9..7d30bace2af 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -722,4 +722,58 @@ protected function getApiClass() { return \Github\Api\Repo::class; } + + /** + * @test + */ + public function shouldCheckVulnerabilityAlertsEnabled() + { + $expectedResponse = ''; + + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/vulnerability-alerts') + ->will($this->returnValue($expectedResponse)); + + $this->assertEquals($expectedResponse, $api->isVulnerabilityAlertsEnabled('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldEnableVulnerabilityAlerts() + { + $expectedResponse = ''; + + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/vulnerability-alerts') + ->will($this->returnValue($expectedResponse)); + + $this->assertEquals($expectedResponse, $api->enableVulnerabilityAlerts('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldDisableVulnerabilityAlerts() + { + $expectedResponse = ''; + + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/vulnerability-alerts') + ->will($this->returnValue($expectedResponse)); + + $this->assertEquals($expectedResponse, $api->disableVulnerabilityAlerts('KnpLabs', 'php-github-api')); + } } From 131e597d7897c920f48f42eca88ea5657cd19b26 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 5 Feb 2023 16:35:12 +0100 Subject: [PATCH 906/951] Setup dependabot for github action workflows --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000000..6d2d16a545f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From 782da176b1b16e86a19bebb2f8e3ba91993fc561 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 5 Feb 2023 15:37:15 +0000 Subject: [PATCH 907/951] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/backwards-compatibility.yml | 2 +- .github/workflows/ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backwards-compatibility.yml b/.github/workflows/backwards-compatibility.yml index 1dd4c3a4e05..cdb19e8dfe6 100644 --- a/.github/workflows/backwards-compatibility.yml +++ b/.github/workflows/backwards-compatibility.yml @@ -8,7 +8,7 @@ jobs: name: "Roave BC check" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 175c5f09a0e..4dfec2cdf92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -33,7 +33,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: From d120c79919378c7ae544439fbc8824d94f579b41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 5 Feb 2023 15:37:18 +0000 Subject: [PATCH 908/951] Bump ramsey/composer-install from 1 to 2 Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 1 to 2. - [Release notes](https://github.com/ramsey/composer-install/releases) - [Commits](https://github.com/ramsey/composer-install/compare/v1...v2) --- updated-dependencies: - dependency-name: ramsey/composer-install dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 175c5f09a0e..8a7a356223d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: coverage: none - name: Install Composer Dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 - name: Run phpunit run: vendor/bin/phpunit --verbose @@ -41,7 +41,7 @@ jobs: coverage: none - name: Install Composer Dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 - name: Run phpstan run: vendor/bin/phpstan analyse --no-progress From 32f79ea8436e19a7dc858dcda7a7c1d3fe0e7fd5 Mon Sep 17 00:00:00 2001 From: Sergkei Melingk Date: Thu, 9 Mar 2023 12:24:13 +0200 Subject: [PATCH 909/951] feature #1103 Added environments (Froxz) This PR was squashed before being merged into the 3.9.x-dev branch. Discussion ---------- Added support for environments #1102 Commits ------- 75c79306f76844d0d1916df1ea2890f81f76c539 Added environments 329c72fe2cb4b4a5f5e8bc78b830007d7b7be8c2 environment b163de2daab9d490bca111eb22671c3b8f960750 fixes e9da726b127d03f012348c074cc42dc5e12a30c4 fixes 536ac080141039b5b4082c4084942e419e92eb59 Fixed Tests 48da33703f488680d5a0985e8d0817f380eb282f Fixed tests 6c79b05de665277081fcae8e2d9cf825f12c0646 Removed trait for custom beta accept header, 7c97a2c7a4d68a47d6f052e6ec93d73036c60cb2 removed unready changes --- doc/README.md | 1 + doc/repo/environments.md | 28 +++++++++ lib/Github/Api/Environment.php | 70 ++++++++++++++++++++++ lib/Github/Client.php | 5 ++ test/Github/Tests/Api/EnvironmentTest.php | 71 +++++++++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 doc/repo/environments.md create mode 100644 lib/Github/Api/Environment.php create mode 100644 test/Github/Tests/Api/EnvironmentTest.php diff --git a/doc/README.md b/doc/README.md index acae0d3a441..3c1579f3269 100644 --- a/doc/README.md +++ b/doc/README.md @@ -59,6 +59,7 @@ v3 APIs: * [Check Suites](repo/check_suites.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) + * [Environments](repo/environments.md) * [Labels](repo/labels.md) * [Protection](repo/protection.md) * [Releases](repo/releases.md) diff --git a/doc/repo/environments.md b/doc/repo/environments.md new file mode 100644 index 00000000000..56387ef8bfc --- /dev/null +++ b/doc/repo/environments.md @@ -0,0 +1,28 @@ +## Repo / Environments API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) + +Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28). + +#### List all environments. + +```php +$environments = $client->api('environment')->all('KnpLabs', 'php-github-api'); +``` + +### Get one environment. + +```php +$environment = $client->api('environment')->show('KnpLabs', 'php-github-api', $name); +``` + +#### Create or update environment. + +```php +$data = $client->api('environment')->createOrUpdate('KnpLabs', 'php-github-api', $name); +``` + +#### Delete a existing environment. + +```php +$environment = $client->api('environment')->remove('KnpLabs', 'php-github-api', $name); +``` diff --git a/lib/Github/Api/Environment.php b/lib/Github/Api/Environment.php new file mode 100644 index 00000000000..057d1edf0d8 --- /dev/null +++ b/lib/Github/Api/Environment.php @@ -0,0 +1,70 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); + } + + /** + * Get a environment in selected repository. + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param string $name the name of the environment + * + * @return array + */ + public function show($username, $repository, $name) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); + } + + /** + * Create or update a environment for the given username and repo. + * + * @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#create-or-update-an-environment + * + * @param string $username the username + * @param string $repository the repository + * @param string $name the name of the environment + * @param array $params the new environment data + * + * @return array information about the environment + */ + public function createOrUpdate($username, $repository, $name, array $params = []) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); + } + + /** + * Delete a environment for the given username and repo. + * + * @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#delete-an-environment + * + * @return mixed null on success, array on error with 'message' + */ + public function remove(string $username, string $repository, string $name) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 56d68d59cec..c1eaa501faf 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -181,6 +181,11 @@ public function api($name): AbstractApi $api = new Api\Deployment($this); break; + case 'environment': + case 'environments': + $api = new Api\Environment($this); + break; + case 'ent': case 'enterprise': $api = new Api\Enterprise($this); diff --git a/test/Github/Tests/Api/EnvironmentTest.php b/test/Github/Tests/Api/EnvironmentTest.php new file mode 100644 index 00000000000..56efbc0afc8 --- /dev/null +++ b/test/Github/Tests/Api/EnvironmentTest.php @@ -0,0 +1,71 @@ +getApiMock(); + + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/environments'); + + $api->createOrUpdate('KnpLabs', 'php-github-api', 'production'); + } + + /** + * @test + */ + public function shouldGetAllEnvironments() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/environments'); + + $api->all('KnpLabs', 'php-github-api'); + } + + /** + * @test + */ + public function shouldShowEnvironment() + { + $expectedValue = 'production'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/environments/production') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'production')); + } + + /** + * @test + */ + public function shouldDeleteEnvironment() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/environments/production') + ->will($this->returnValue(null)); + + $this->assertNull($api->remove('KnpLabs', 'php-github-api', 'production')); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Environment::class; + } +} From 799aa2b8c9dd9b03e5c353339d083601407e3cc4 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 9 Mar 2023 11:26:52 +0100 Subject: [PATCH 910/951] Update changelog for 3.10.0 release --- CHANGELOG-3.X.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 5aa309b25b3..3ec12940b20 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,17 @@ # Changelog +## 3.10.0 + +### Added +- Add vulnerability alerts endpoints ([andreia](https://github.com/andreia)) [#1096](https://github.com/KnpLabs/php-github-api/issues/1096) +- Added environments ([Froxz](https://github.com/Froxz)) [#1103](https://github.com/KnpLabs/php-github-api/issues/1103) + +### Changed +- Create authorization removed from docs ([rafasashi](https://github.com/rafasashi)) [#1090](https://github.com/KnpLabs/php-github-api/issues/1090) +- Setup dependabot for github action workflows ([acrobat](https://github.com/acrobat)) [#1098](https://github.com/KnpLabs/php-github-api/issues/1098) +- Bump actions/checkout from 2 to 3 ([dependabot](https://github.com/dependabot)[[bot](https://github.com/bot)]) [#1099](https://github.com/KnpLabs/php-github-api/issues/1099) +- Bump ramsey/composer-install from 1 to 2 ([dependabot](https://github.com/dependabot)[[bot](https://github.com/bot)]) [#1100](https://github.com/KnpLabs/php-github-api/issues/1100) + ## 3.9.0 ### Added From fcc99dd95d762c091754a5233f479549bf5e91ac Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 9 Mar 2023 11:27:43 +0100 Subject: [PATCH 911/951] Update branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8d51cdd7421..886b5993221 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.9.x-dev" + "dev-master": "3.10.x-dev" } }, "config": { From 01bd3eed8161bfdbe0ca3f2520f28f79286b425e Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 9 Mar 2023 11:50:37 +0000 Subject: [PATCH 912/951] Test on PHP 8.2 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87f37d2af8f..31af3510052 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - uses: actions/checkout@v3 From 8168261aae9891a38974f8b2294a5ab7f9368a0f Mon Sep 17 00:00:00 2001 From: Sergkei Melingk Date: Thu, 9 Mar 2023 22:59:45 +0200 Subject: [PATCH 913/951] bug #1107 Bugfix creating env (Froxz) This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- Commits ------- 22cbc82fd8fb12a9206f0296d3fc67328b7255a5 Bugfix creating env ce974e1009ec36cd363113024c3d8ce3b7d8cc05 fixed tests 8b365a303bfeb3a4cfd08c429d832dbe21090465 added rawurlencode for $name --- lib/Github/Api/Environment.php | 6 +++--- test/Github/Tests/Api/EnvironmentTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/Environment.php b/lib/Github/Api/Environment.php index 057d1edf0d8..c154666daf3 100644 --- a/lib/Github/Api/Environment.php +++ b/lib/Github/Api/Environment.php @@ -36,7 +36,7 @@ public function all($username, $repository, array $params = []) */ public function show($username, $repository, $name) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($name)); } /** @@ -53,7 +53,7 @@ public function show($username, $repository, $name) */ public function createOrUpdate($username, $repository, $name, array $params = []) { - return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($name), $params); } /** @@ -65,6 +65,6 @@ public function createOrUpdate($username, $repository, $name, array $params = [] */ public function remove(string $username, string $repository, string $name) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($name)); } } diff --git a/test/Github/Tests/Api/EnvironmentTest.php b/test/Github/Tests/Api/EnvironmentTest.php index 56efbc0afc8..3b6f6f417fe 100644 --- a/test/Github/Tests/Api/EnvironmentTest.php +++ b/test/Github/Tests/Api/EnvironmentTest.php @@ -13,7 +13,7 @@ public function shouldCreateOrUpdateEnvironment() $api->expects($this->once()) ->method('put') - ->with('/repos/KnpLabs/php-github-api/environments'); + ->with('/repos/KnpLabs/php-github-api/environments/production'); $api->createOrUpdate('KnpLabs', 'php-github-api', 'production'); } From acc045397ae283b13473fd2d999ec1766667b365 Mon Sep 17 00:00:00 2001 From: Sergkei Melingk Date: Fri, 10 Mar 2023 13:16:59 +0200 Subject: [PATCH 914/951] feature #1104 Added environment variables & secrets (Froxz) This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- Added environment: [Secrets](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#list-environment-secrets) [Variables](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables) Commits ------- 7de0912505f3e47f920185f802ca260db1ae4fe6 Added environment variables & secrets d08d18df6c7111274831e44f921b36177adcca9a fixes for styleCI 3f4fff0f2ea254635853e93ccb3a5d4d60108173 removed rawurlencode for repo id 289c0ab0cd4b78937120011bd2325ab396d06a30 added link to secrets and varaibles cbf08fc221b7c9b703a3a04baf3432927ea9e9fb Removed validation of parameters --- doc/README.md | 2 + doc/environment/secrets.md | 46 +++++++ doc/environment/variables.md | 49 ++++++++ doc/repo/environments.md | 4 + lib/Github/Api/Environment.php | 19 +++ lib/Github/Api/Environment/Secrets.php | 80 ++++++++++++ lib/Github/Api/Environment/Variables.php | 81 ++++++++++++ .../Tests/Api/Environment/SecretsTest.php | 116 +++++++++++++++++ .../Tests/Api/Environment/VariablesTest.php | 118 ++++++++++++++++++ 9 files changed, 515 insertions(+) create mode 100644 doc/environment/secrets.md create mode 100644 doc/environment/variables.md create mode 100644 lib/Github/Api/Environment/Secrets.php create mode 100644 lib/Github/Api/Environment/Variables.php create mode 100644 test/Github/Tests/Api/Environment/SecretsTest.php create mode 100644 test/Github/Tests/Api/Environment/VariablesTest.php diff --git a/doc/README.md b/doc/README.md index 3c1579f3269..58547e32cda 100644 --- a/doc/README.md +++ b/doc/README.md @@ -59,6 +59,8 @@ v3 APIs: * [Check Suites](repo/check_suites.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) + * [Secrets](environment/secrets.md) + * [Variables](environment/variables.md) * [Environments](repo/environments.md) * [Labels](repo/labels.md) * [Protection](repo/protection.md) diff --git a/doc/environment/secrets.md b/doc/environment/secrets.md new file mode 100644 index 00000000000..a956945d61b --- /dev/null +++ b/doc/environment/secrets.md @@ -0,0 +1,46 @@ +## Environment / Secrets API +[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md) + +### List environment secrets + +https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28 + +```php +$secrets = $client->environment()->secrets()->all($repoId, $envName); +``` + +### Get an environment secret + +https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret + +```php +$secret = $client->environment()->secrets()->show($repoId, $envName, $secretName); +``` + +### Create or Update an environment secret + +https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret + +```php +$client->environment()->secrets()->createOrUpdate($repoId, $envName, $secretName, [ + 'encrypted_value' => $encryptedValue, + 'key_id' => $key_id +]); +``` + +### Delete an environment secret + +https://docs.github.com/en/rest/reference/actions#delete-an-organization-secret + +```php +$client->environment()->secrets()->remove($repoId, $envName, $secretName); +``` + +### Get an environment public key + +https://docs.github.com/en/rest/reference/actions#get-an-organization-public-key + +```php +$client->environment()->secrets()->publicKey($repoId, $envName); +``` + diff --git a/doc/environment/variables.md b/doc/environment/variables.md new file mode 100644 index 00000000000..d9de932589e --- /dev/null +++ b/doc/environment/variables.md @@ -0,0 +1,49 @@ +## Environment / Variables API +[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md) + +### List environment variables + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables + +```php +$variables = $client->environment()->variables()->all($repoId, $envName); +``` + +### Get an environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable + +```php +$variable = $client->environment()->variables()->show($repoId, $envName, $variableName); +``` + +### Create environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable + +```php +$client->environment()->variables()->create($repoId, $envName, [ + 'name' => $name, + 'value' => $value +]); +``` + +### Update environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable + +```php +$client->environment()->variables()->update($repoId, $envName, $variableName, [ + 'name' => $name, + 'value' => $value +]); +``` + +### Delete an environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable + +```php +$client->environment()->variables()->remove($repoId, $envName, $variableName); +``` + diff --git a/doc/repo/environments.md b/doc/repo/environments.md index 56387ef8bfc..2d3e23a8796 100644 --- a/doc/repo/environments.md +++ b/doc/repo/environments.md @@ -3,6 +3,10 @@ Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28). +Additional APIs: +* [Secrets API](environment/secrets.md) +* [Variables API](environment/variables.md) + #### List all environments. ```php diff --git a/lib/Github/Api/Environment.php b/lib/Github/Api/Environment.php index c154666daf3..099ca9e1e9b 100644 --- a/lib/Github/Api/Environment.php +++ b/lib/Github/Api/Environment.php @@ -2,6 +2,9 @@ namespace Github\Api; +use Github\Api\Environment\Secrets; +use Github\Api\Environment\Variables; + /** * Listing, creating and updating environments. * @@ -67,4 +70,20 @@ public function remove(string $username, string $repository, string $name) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($name)); } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#about-secrets-in-github-actions + */ + public function secrets(): Secrets + { + return new Secrets($this->getClient()); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#about-variables-in-github-actions + */ + public function variables(): Variables + { + return new Variables($this->getClient()); + } } diff --git a/lib/Github/Api/Environment/Secrets.php b/lib/Github/Api/Environment/Secrets.php new file mode 100644 index 00000000000..cef84c34958 --- /dev/null +++ b/lib/Github/Api/Environment/Secrets.php @@ -0,0 +1,80 @@ +get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets'); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret + * + * @param int $id + * @param string $name + * @param string $secretName + * + * @return array|string + */ + public function show(int $id, string $name, string $secretName) + { + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret + * + * @param int $id + * @param string $name + * @param string $secretName + * @param array $parameters + * + * @return array|string + */ + public function createOrUpdate(int $id, string $name, string $secretName, array $parameters = []) + { + return $this->put('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#delete-an-environment-secret + * + * @param int $id + * @param string $name + * @param string $secretName + * + * @return array|string + */ + public function remove(int $id, string $name, string $secretName) + { + return $this->delete('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-public-key + * + * @param int $id + * @param string $name + * + * @return array|string + */ + public function publicKey(int $id, string $name) + { + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/public-key'); + } +} diff --git a/lib/Github/Api/Environment/Variables.php b/lib/Github/Api/Environment/Variables.php new file mode 100644 index 00000000000..035a8f605a3 --- /dev/null +++ b/lib/Github/Api/Environment/Variables.php @@ -0,0 +1,81 @@ +get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables'); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable + * + * @param int $id + * @param string $name + * @param string $variableName + * + * @return array|string + */ + public function show(int $id, string $name, string $variableName) + { + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable + * + * @param int $id + * @param string $name + * @param array $parameters + * + * @return array|string + */ + public function create(int $id, string $name, array $parameters) + { + return $this->post('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable + * + * @param int $id + * @param string $name + * @param string $variableName + * @param array $parameters + * + * @return array|string + */ + public function update(int $id, string $name, string $variableName, array $parameters) + { + return $this->patch('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName), $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable + * + * @param int $id + * @param string $name + * @param string $variableName + * + * @return array|string + */ + public function remove(int $id, string $name, string $variableName) + { + return $this->delete('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); + } +} diff --git a/test/Github/Tests/Api/Environment/SecretsTest.php b/test/Github/Tests/Api/Environment/SecretsTest.php new file mode 100644 index 00000000000..0609a64f0f6 --- /dev/null +++ b/test/Github/Tests/Api/Environment/SecretsTest.php @@ -0,0 +1,116 @@ + 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/secrets') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all(3948501, 'production')); + } + + /** + * @test + */ + public function shouldGetEnvironmentSecret() + { + $expectedArray = []; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/secrets/secretName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show(3948501, 'production', 'secretName')); + } + + /** + * @test + */ + public function shouldUpdateOrCreateEnvironmentSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repositories/3948501/environments/production/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->createOrUpdate(3948501, 'production', 'secretName', [ + 'encrypted_value' => 'foo', 'key_id' => 'key_id', + ])); + } + + /** + * @test + */ + public function shouldRemoveEnvironmentSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repositories/3948501/environments/production/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(3948501, 'production', 'secretName')); + } + + /** + * @test + */ + public function shouldGetPublicKey() + { + $expectedArray = ['key_id' => 'key_id', 'key' => 'foo']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/secrets/public-key') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->publicKey(3948501, 'production')); + } + + protected function getApiClass() + { + return Secrets::class; + } +} diff --git a/test/Github/Tests/Api/Environment/VariablesTest.php b/test/Github/Tests/Api/Environment/VariablesTest.php new file mode 100644 index 00000000000..0fc01193fd1 --- /dev/null +++ b/test/Github/Tests/Api/Environment/VariablesTest.php @@ -0,0 +1,118 @@ + 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ]; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/variables') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all(3948501, 'production')); + } + + /** + * @test + */ + public function shouldGetEnvironmentVariable() + { + $expectedArray = []; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/variables/variableName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show(3948501, 'production', 'variableName')); + } + + /** + * @test + */ + public function shouldCreateEnvironmentVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repositories/3948501/environments/production/variables') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create(3948501, 'production', [ + 'name' => 'foo', 'value' => 'bar', + ])); + } + + /** + * @test + */ + public function shouldUpdateEnvironmentVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('patch') + ->with('/repositories/3948501/environments/production/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(3948501, 'production', 'variableName', [ + 'name' => 'variableName', 'value' => 'bar', + ])); + } + + /** + * @test + */ + public function shouldRemoveEnvironmentVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repositories/3948501/environments/production/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(3948501, 'production', 'variableName')); + } + + protected function getApiClass() + { + return Variables::class; + } +} From bdb9bfb336784c1e3210f17da8f6303c6b3100f0 Mon Sep 17 00:00:00 2001 From: Sergkei Melingk Date: Fri, 10 Mar 2023 13:18:04 +0200 Subject: [PATCH 915/951] feature #1106 Added Org & Repository variables (Froxz) This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- Commits ------- ff0fb37ddab2f78043528bf6efffb399d121763d Added Org & Repository varaibles 4a50d98e86fe100d58768baf203e69dd7b19c067 fixed type hint 7569055fc3bc64e0570cfbbcdfded7fbc546dea1 Fixes 37e12a62316c533bc78fd3a0cf770b607074bb1d added repo variables test 1da518f55c63b767b656f2e577efe28b965073ca StyleCI fixes 9f90a4a38857691b7d7b37161934bf7bbbcfc04e Removed params validation --- doc/README.md | 3 + doc/organization/actions/variables.md | 87 ++++++++ doc/repo/actions/variables.md | 48 +++++ lib/Github/Api/Organization.php | 9 + .../Api/Organization/Actions/Variables.php | 131 ++++++++++++ lib/Github/Api/Repo.php | 9 + .../Api/Repository/Actions/Variables.php | 81 +++++++ .../Organization/Actions/VariablesTest.php | 198 ++++++++++++++++++ test/Github/Tests/Api/OrganizationTest.php | 10 + test/Github/Tests/Api/RepoTest.php | 10 + .../Api/Repository/Actions/VariablesTest.php | 119 +++++++++++ 11 files changed, 705 insertions(+) create mode 100644 doc/organization/actions/variables.md create mode 100644 doc/repo/actions/variables.md create mode 100644 lib/Github/Api/Organization/Actions/Variables.php create mode 100644 lib/Github/Api/Repository/Actions/Variables.php create mode 100644 test/Github/Tests/Api/Organization/Actions/VariablesTest.php create mode 100644 test/Github/Tests/Api/Repository/Actions/VariablesTest.php diff --git a/doc/README.md b/doc/README.md index 58547e32cda..c5b9e8cf363 100644 --- a/doc/README.md +++ b/doc/README.md @@ -39,6 +39,8 @@ v3 APIs: * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) + * [Secrets](organization/actions/secrets.md) + * [Variables](organization/actions/variables.md) * [Projects](project/projects.md) * [Columns](project/columns.md) * [Cards](project/cards.md) @@ -51,6 +53,7 @@ v3 APIs: * Actions * [Artifacts](repo/actions/artifacts.md) * [Secrets](repo/actions/secrets.md) + * [Variables](repo/actions/variables.md) * [Self hosted runners](repo/actions/self_hosted_runners.md) * [Workflow jobs](repo/actions/workflow_jobs.md) * [Workflow runs](repo/actions/workflow_runs.md) diff --git a/doc/organization/actions/variables.md b/doc/organization/actions/variables.md new file mode 100644 index 00000000000..89c641007f3 --- /dev/null +++ b/doc/organization/actions/variables.md @@ -0,0 +1,87 @@ +## Organization / Variables API +[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md) + +### List organization variables + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-organization-variables + +```php +$variables = $client->organization()->variables()->all('KnpLabs'); +``` + +### Get an organization variable + +https://docs.github.com/en/rest/reference/actions#get-an-organization-secret + +```php +$variable = $client->organization()->variables()->show('KnpLabs', $variableName); +``` + +### Create an organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable + +```php +$client->organization()->variables()->create('KnpLabs', [ + 'name' => $name, + 'value' => $value, + 'visibility' => $visibility, + 'selected_repository_ids' => $selectedRepositoryIds, +]); +``` + +### Update an organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable + +```php +$client->organization()->variables()->update('KnpLabs', $variableName, [ + 'name' => $name, + 'value' => $value, + 'visibility' => $visibility, + 'selected_repository_ids' => $selectedRepositoryIds +]); +``` + +### Delete an organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable + +```php +$client->organization()->variables()->remove('KnpLabs', $variableName); +``` + +### List selected repositories for organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable + +```php +$client->organization()->variables()->selectedRepositories('KnpLabs', $variableName); +``` + +### Set selected repositories for an organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable + +```php +$client->organization()->variables()->setSelectedRepositories('KnpLabs', 'variableName', [ + 'selected_repository_ids' => [1, 2, 3], +]); +``` + +### Add selected repository to an organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable + +```php +$client->organization()->variables()->addRepository('KnpLabs', $repositoryId, $variableName); +``` + +### Remove selected repository from an organization variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable + +```php +$client->organization()->variables()->removeRepository('KnpLabs', $repositoryId, $variableName); +``` + diff --git a/doc/repo/actions/variables.md b/doc/repo/actions/variables.md new file mode 100644 index 00000000000..c6cc26ac1df --- /dev/null +++ b/doc/repo/actions/variables.md @@ -0,0 +1,48 @@ +## Repo / Actions / Variables API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) + +### List repository variables + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-repository-variables + +```php +$variables = $client->api('repo')->variables()->all('KnpLabs', 'php-github-api'); +``` + +### Get a repository variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable + +```php +$variable = $client->api('repo')->variables()->show('KnpLabs', 'php-github-api', $variableName); +``` + +### Create a repository variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable + +```php +$client->api('repo')->variables()->create('KnpLabs', 'php-github-api', [ + 'name' => $name, + 'value' => $value, +]); +``` + +### Update a repository variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable + +```php +$client->api('repo')->variables()->update('KnpLabs', 'php-github-api', $variableName, [ + 'name' => $name, + 'value' => $value, +]); +``` + +### Delete a repository variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable + +```php +$client->api('repo')->variables()->remove('KnpLabs', 'php-github-api', $variableName); +``` diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index d3e7646651d..d1997dabc7a 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -3,6 +3,7 @@ namespace Github\Api; use Github\Api\Organization\Actions\Secrets; +use Github\Api\Organization\Actions\Variables; use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; use Github\Api\Organization\OutsideCollaborators; @@ -110,6 +111,14 @@ public function secrets(): Secrets return new Secrets($this->getClient()); } + /** + * @return Variables + */ + public function variables(): Variables + { + return new Variables($this->getClient()); + } + /** * @return OutsideCollaborators */ diff --git a/lib/Github/Api/Organization/Actions/Variables.php b/lib/Github/Api/Organization/Actions/Variables.php new file mode 100644 index 00000000000..88c037238d3 --- /dev/null +++ b/lib/Github/Api/Organization/Actions/Variables.php @@ -0,0 +1,131 @@ +get('/orgs/'.rawurlencode($organization).'/actions/variables'); + } + + /** + * @link https://docs.github.com/en/rest/reference/actions#get-an-organization-secret + * + * @param string $organization + * @param string $variableName + * + * @return array|string + */ + public function show(string $organization, string $variableName) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable + * + * @param string $organization + * @param array $parameters + * + * @return array|string + */ + public function create(string $organization, array $parameters) + { + return $this->post('/orgs/'.rawurlencode($organization).'/actions/variables', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable + * + * @param string $organization + * @param string $variableName + * @param array $parameters + * + * @return array|string + */ + public function update(string $organization, string $variableName, array $parameters = []) + { + return $this->patch('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName), $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable + * + * @param string $organization + * @param string $variableName + * + * @return array|string + */ + public function remove(string $organization, string $variableName) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable + * + * @param string $organization + * @param string $variableName + * + * @return array|string + */ + public function selectedRepositories(string $organization, string $variableName) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories'); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable + * + * @param string $organization + * @param string $variableName + * @param array $parameters + * + * @return array|string + */ + public function setSelectedRepositories(string $organization, string $variableName, array $parameters = []) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable + * + * @param string $organization + * @param int $repositoryId + * @param string $variableName + * + * @return array|string + */ + public function addRepository(string $organization, int $repositoryId, string $variableName) + { + return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable + * + * @param string $organization + * @param int $repositoryId + * @param string $variableName + * + * @return array|string + */ + public function removeRepository(string $organization, int $repositoryId, string $variableName) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId); + } +} diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 42a5e16a610..bcfe13edb73 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -5,6 +5,7 @@ use Github\Api\Repository\Actions\Artifacts; use Github\Api\Repository\Actions\Secrets; use Github\Api\Repository\Actions\SelfHostedRunners; +use Github\Api\Repository\Actions\Variables; use Github\Api\Repository\Actions\WorkflowJobs; use Github\Api\Repository\Actions\WorkflowRuns; use Github\Api\Repository\Actions\Workflows; @@ -405,6 +406,14 @@ public function secrets(): Secrets return new Secrets($this->getClient()); } + /** + * @link https://docs.github.com/en/rest/reference/actions#secrets + */ + public function variables(): Variables + { + return new Variables($this->getClient()); + } + /** * Manage the content of a repository. * diff --git a/lib/Github/Api/Repository/Actions/Variables.php b/lib/Github/Api/Repository/Actions/Variables.php new file mode 100644 index 00000000000..7414e82810b --- /dev/null +++ b/lib/Github/Api/Repository/Actions/Variables.php @@ -0,0 +1,81 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables'); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable + * + * @param string $username + * @param string $repository + * @param string $variableName + * + * @return array|string + */ + public function show(string $username, string $repository, string $variableName) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables/'.rawurlencode($variableName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable + * + * @param string $username + * @param string $repository + * @param array $parameters + * + * @return array|string + */ + public function create(string $username, string $repository, array $parameters = []) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable + * + * @param string $username + * @param string $repository + * @param string $variableName + * @param array $parameters + * + * @return array|string + */ + public function update(string $username, string $repository, string $variableName, array $parameters = []) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables/'.rawurlencode($variableName), $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable + * + * @param string $username + * @param string $repository + * @param string $variableName + * + * @return array|string + */ + public function remove(string $username, string $repository, string $variableName) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables/'.rawurlencode($variableName)); + } +} diff --git a/test/Github/Tests/Api/Organization/Actions/VariablesTest.php b/test/Github/Tests/Api/Organization/Actions/VariablesTest.php new file mode 100644 index 00000000000..98d5072377e --- /dev/null +++ b/test/Github/Tests/Api/Organization/Actions/VariablesTest.php @@ -0,0 +1,198 @@ + 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'all'], + ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'private'], + ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at', 'visibility' => 'selected'], + ]; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/variables') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetOrganizationVariable() + { + $expectedArray = []; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/variables/variableName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'variableName')); + } + + /** + * @test + */ + public function shouldCreateOrganizationVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/orgs/KnpLabs/actions/variables') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', [ + 'name' => 'foo', 'value' => 'value', 'visibility' => 'all', + ])); + } + + /** + * @test + */ + public function shouldUpdateOrganizationVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('patch') + ->with('/orgs/KnpLabs/actions/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'variableName', [ + 'name' => 'foo', 'value' => 'value', 'visibility' => 'private', + ])); + } + + /** + * @test + */ + public function shouldRemoveOrganizationVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'variableName')); + } + + /** + * @test + */ + public function shouldGetSelectedRepositories() + { + $expectedArray = [1, 2, 3]; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/variables/variableName/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->selectedRepositories('KnpLabs', 'variableName')); + } + + /** + * @test + */ + public function shouldSetSelectedRepositories() + { + $expectedArray = [ + 'selected_repository_ids' => [1, 2, 3], + ]; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/variables/variableName/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->setSelectedRepositories('KnpLabs', 'variableName', [ + 'selected_repository_ids' => [1, 2, 3], + ])); + } + + /** + * @test + */ + public function shouldAddRepository() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/orgs/KnpLabs/actions/variables/variableName/repositories/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addRepository('KnpLabs', 1, 'variableName')); + } + + /** + * @test + */ + public function shouldRemoveRepository() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/variables/variableName/repositories/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeRepository('KnpLabs', 1, 'variableName')); + } + + protected function getApiClass() + { + return Variables::class; + } +} diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 04f389c0337..d13547bd663 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -88,6 +88,16 @@ public function shouldGetTeamsApiObject() $this->assertInstanceOf(\Github\Api\Organization\Teams::class, $api->teams()); } + /** + * @test + */ + public function shouldGetVariablesApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Organization\Actions\Variables::class, $api->variables()); + } + /** * @return string */ diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 7d30bace2af..7b84a6b52ac 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -570,6 +570,16 @@ public function shouldGetReleasesApiObject() $this->assertInstanceOf(\Github\Api\Repository\Releases::class, $api->releases()); } + /** + * @test + */ + public function shouldGetVariablesApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Repository\Actions\Variables::class, $api->variables()); + } + /** * @test */ diff --git a/test/Github/Tests/Api/Repository/Actions/VariablesTest.php b/test/Github/Tests/Api/Repository/Actions/VariablesTest.php new file mode 100644 index 00000000000..e362d31f7bc --- /dev/null +++ b/test/Github/Tests/Api/Repository/Actions/VariablesTest.php @@ -0,0 +1,119 @@ + 'GH_TOKEN', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'GIST_ID', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ]; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/variables') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetVariable() + { + $expectedArray = ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at']; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/actions/variables/variableName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api', 'variableName')); + } + + /** + * @test + */ + public function shouldCreateVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/actions/variables') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', [ + 'name' => 'name', + 'value' => 'value', + ])); + } + + /** + * @test + */ + public function shouldUpdateVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/actions/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'variableName', [ + 'name' => 'name', + 'value' => 'value', + ])); + } + + /** + * @test + */ + public function shouldRemoveVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/actions/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'variableName')); + } + + protected function getApiClass() + { + return Variables::class; + } +} From 00570ac2c22d5d4d074a7bb29103a5a5329e172f Mon Sep 17 00:00:00 2001 From: Sergkei Melingk Date: Fri, 10 Mar 2023 13:39:43 +0200 Subject: [PATCH 916/951] feature #1108 Deployment branch policies (Froxz) This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- * added Deployment branch policies * Moved environments under deployment Commits ------- 9734d230e6c5e98f4bed1c86696de1b47c3c87fb Deployment branch policies c72fdae237d59aeb058d18850a7e3cb012a65197 removed params validation a61fe843d39a4fd48408bb1c167dd6c07cdf6bb6 StyleCI fixes c30050c9c84eac1b81bddb0a9bb8f558b449f6c2 styleCI fixes 5d7048f8b3b34289cd53ac296060f43a8b74bee9 Merge branch 'master' into feature/deployment-branch-policies f657c3fd16a899b8c34294f028ebb739270618eb StyleCi fixes d9f0195fa677a571314408f77a3b5779488816bf Changes to docs --- doc/README.md | 7 +- .../deployments}/environment/secrets.md | 2 +- .../deployments}/environment/variables.md | 2 +- doc/repo/deployments/environments.md | 32 ++++++ doc/repo/deployments/policies.md | 38 ++++++++ doc/repo/environments.md | 32 ------ lib/Github/Api/Deployment.php | 18 ++++ .../Environments.php} | 5 +- lib/Github/Api/Deployment/Policies.php | 97 +++++++++++++++++++ lib/Github/Client.php | 5 - .../EnvironmentsTest.php} | 6 +- .../Tests/Api/Deployment/PoliciesTest.php | 91 +++++++++++++++++ test/Github/Tests/Api/DeploymentTest.php | 20 ++++ 13 files changed, 309 insertions(+), 46 deletions(-) rename doc/{ => repo/deployments}/environment/secrets.md (92%) rename doc/{ => repo/deployments}/environment/variables.md (92%) create mode 100644 doc/repo/deployments/environments.md create mode 100644 doc/repo/deployments/policies.md delete mode 100644 doc/repo/environments.md rename lib/Github/Api/{Environment.php => Deployment/Environments.php} (96%) create mode 100644 lib/Github/Api/Deployment/Policies.php rename test/Github/Tests/Api/{EnvironmentTest.php => Deployment/EnvironmentsTest.php} (92%) create mode 100644 test/Github/Tests/Api/Deployment/PoliciesTest.php diff --git a/doc/README.md b/doc/README.md index c5b9e8cf363..cecccfb90b7 100644 --- a/doc/README.md +++ b/doc/README.md @@ -62,9 +62,10 @@ v3 APIs: * [Check Suites](repo/check_suites.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) - * [Secrets](environment/secrets.md) - * [Variables](environment/variables.md) - * [Environments](repo/environments.md) + * [Policies](repo/deployments/policies.md) + * [Environments](repo/deployments/environments.md) + * [Secrets](repo/deployments/environment/secrets.md) + * [Variables](repo/deployments/environment/variables.md) * [Labels](repo/labels.md) * [Protection](repo/protection.md) * [Releases](repo/releases.md) diff --git a/doc/environment/secrets.md b/doc/repo/deployments/environment/secrets.md similarity index 92% rename from doc/environment/secrets.md rename to doc/repo/deployments/environment/secrets.md index a956945d61b..5c0c86b85d7 100644 --- a/doc/environment/secrets.md +++ b/doc/repo/deployments/environment/secrets.md @@ -1,5 +1,5 @@ ## Environment / Secrets API -[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md) +[Back to the "Environments API"](../environments.md) | [Back to the navigation](../README.md) ### List environment secrets diff --git a/doc/environment/variables.md b/doc/repo/deployments/environment/variables.md similarity index 92% rename from doc/environment/variables.md rename to doc/repo/deployments/environment/variables.md index d9de932589e..d645349a204 100644 --- a/doc/environment/variables.md +++ b/doc/repo/deployments/environment/variables.md @@ -1,5 +1,5 @@ ## Environment / Variables API -[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md) +[Back to the "Environments API"](../environments.md) | [Back to the navigation](../README.md) ### List environment variables diff --git a/doc/repo/deployments/environments.md b/doc/repo/deployments/environments.md new file mode 100644 index 00000000000..6cb409ae3b3 --- /dev/null +++ b/doc/repo/deployments/environments.md @@ -0,0 +1,32 @@ +## Deployment / Environments API +[Back to the "Deployment API"](../deployments.md) | [Back to the navigation](../index.md) + +Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28). + +Additional APIs: +* [Secrets API](environment/secrets.md) +* [Variables API](environment/variables.md) + +#### List all environments. + +```php +$environments = $client->deployment()->environment()->all('KnpLabs', 'php-github-api'); +``` + +### Get one environment. + +```php +$environment = $client->deployment()->environment()->show('KnpLabs', 'php-github-api', $name); +``` + +#### Create or update environment. + +```php +$data = $client->deployment()->environment()->createOrUpdate('KnpLabs', 'php-github-api', $name); +``` + +#### Delete a existing environment. + +```php +$environment = $client->deployment()->environment()->remove('KnpLabs', 'php-github-api', $name); +``` diff --git a/doc/repo/deployments/policies.md b/doc/repo/deployments/policies.md new file mode 100644 index 00000000000..442fc0c4acb --- /dev/null +++ b/doc/repo/deployments/policies.md @@ -0,0 +1,38 @@ +## Deployment / Branch policies API +[Back to the "Deployment API"](../deployments.md) | [Back to the navigation](../index.md) + +Provides information about deployment branch policies. Wraps [GitHub Deployment branch policies API](https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#about-deployment-branch-policies). + +#### List deployment branch policies. + +```php +$policies = $client->deployment()->policies()->all('KnpLabs', 'php-github-api', 'production'); +``` + +### Get one environment. + +```php +$policy = $client->deployment()->policies()->show('KnpLabs', 'php-github-api', 'production', $branchPolicyId); +``` + +#### Create policy. + +```php +$data = $client->deployment()->policies()->create('KnpLabs', 'php-github-api', 'production', [ + 'name' => 'name' +]); +``` + +#### Update policy. + +```php +$data = $client->deployment()->policies()->update('KnpLabs', 'php-github-api', 'production', $branchPolicyId, [ + 'name' => 'name' +]); +``` + +#### Delete a existing policy. + +```php +$policy = $client->deployment()->policies()->remove('KnpLabs', 'php-github-api', 'production', $branchPolicyId); +``` diff --git a/doc/repo/environments.md b/doc/repo/environments.md deleted file mode 100644 index 2d3e23a8796..00000000000 --- a/doc/repo/environments.md +++ /dev/null @@ -1,32 +0,0 @@ -## Repo / Environments API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) - -Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28). - -Additional APIs: -* [Secrets API](environment/secrets.md) -* [Variables API](environment/variables.md) - -#### List all environments. - -```php -$environments = $client->api('environment')->all('KnpLabs', 'php-github-api'); -``` - -### Get one environment. - -```php -$environment = $client->api('environment')->show('KnpLabs', 'php-github-api', $name); -``` - -#### Create or update environment. - -```php -$data = $client->api('environment')->createOrUpdate('KnpLabs', 'php-github-api', $name); -``` - -#### Delete a existing environment. - -```php -$environment = $client->api('environment')->remove('KnpLabs', 'php-github-api', $name); -``` diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index f6127357ee9..de5b0cb0eb9 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -2,6 +2,8 @@ namespace Github\Api; +use Github\Api\Deployment\Environments; +use Github\Api\Deployment\Policies; use Github\Exception\MissingArgumentException; /** @@ -130,4 +132,20 @@ public function getStatuses($username, $repository, $id) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses'); } + + /** + * @return Environments + */ + public function environments() + { + return new Environments($this->getClient()); + } + + /** + * @return Policies + */ + public function policies() + { + return new Policies($this->getClient()); + } } diff --git a/lib/Github/Api/Environment.php b/lib/Github/Api/Deployment/Environments.php similarity index 96% rename from lib/Github/Api/Environment.php rename to lib/Github/Api/Deployment/Environments.php index 099ca9e1e9b..191ec498eab 100644 --- a/lib/Github/Api/Environment.php +++ b/lib/Github/Api/Deployment/Environments.php @@ -1,7 +1,8 @@ get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies', $params); + } + + /** + * Get a deployment branch policy. + * + * @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#get-a-deployment-branch-policy + * + * @param string $username the username of the user who owns the repository + * @param string $repository the name of the repository + * @param string $environment the name of the environment. + * @param int $id the unique identifier of the branch policy. + * + * @return array + */ + public function show(string $username, string $repository, string $environment, int $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id); + } + + /** + * Creates a deployment branch policy for an environment. + * + * @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#create-a-deployment-branch-policy + * + * @param string $username the username of the user who owns the repository + * @param string $repository the name of the repository + * @param string $environment the name of the environment. + * + * @return array information about the deployment branch policy + */ + public function create(string $username, string $repository, string $environment, array $params) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies', $params); + } + + /** + * Updates a deployment branch policy for an environment. + * + * @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#update-a-deployment-branch-policy + * + * @param string $username the username of the user who owns the repository + * @param string $repository the name of the repository + * @param string $environment the name of the environment. + * @param int $id the unique identifier of the branch policy. + * + * @return array information about the deployment branch policy + */ + public function update(string $username, string $repository, string $environment, int $id, array $params) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id, $params); + } + + /** + * Delete a deployment branch policy. + * + * @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#delete-a-deployment-branch-policy + * + * @param string $username the username of the user who owns the repository + * @param string $repository the name of the repository + * @param string $environment the name of the environment. + * @param int $id the unique identifier of the branch policy. + * + * @return mixed null on success, array on error with 'message' + */ + public function remove(string $username, string $repository, string $environment, int $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index c1eaa501faf..56d68d59cec 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -181,11 +181,6 @@ public function api($name): AbstractApi $api = new Api\Deployment($this); break; - case 'environment': - case 'environments': - $api = new Api\Environment($this); - break; - case 'ent': case 'enterprise': $api = new Api\Enterprise($this); diff --git a/test/Github/Tests/Api/EnvironmentTest.php b/test/Github/Tests/Api/Deployment/EnvironmentsTest.php similarity index 92% rename from test/Github/Tests/Api/EnvironmentTest.php rename to test/Github/Tests/Api/Deployment/EnvironmentsTest.php index 3b6f6f417fe..ab761ab90cf 100644 --- a/test/Github/Tests/Api/EnvironmentTest.php +++ b/test/Github/Tests/Api/Deployment/EnvironmentsTest.php @@ -1,6 +1,8 @@ getApiMock(); + + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies'); + + $api->create('KnpLabs', 'php-github-api', 'production', [ + 'name' => 'name', + ]); + } + + /** + * @test + */ + public function shouldUpdatePolicy() + { + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies/1'); + + $api->update('KnpLabs', 'php-github-api', 'production', 1, [ + 'name' => 'name', + ]); + } + + /** + * @test + */ + public function shouldGetAllPolicies() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies'); + + $api->all('KnpLabs', 'php-github-api', 'production'); + } + + /** + * @test + */ + public function shouldShowPolicy() + { + $expectedValue = 'production'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'production', 1)); + } + + /** + * @test + */ + public function shouldDeletePolicy() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies/1') + ->will($this->returnValue(null)); + + $this->assertNull($api->remove('KnpLabs', 'php-github-api', 'production', 1)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Deployment\Policies::class; + } +} diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 88e8c923ce1..8741ee625f7 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -118,6 +118,26 @@ public function shouldGetAllStatuses() $api->getStatuses('KnpLabs', 'php-github-api', 1); } + /** + * @test + */ + public function shouldGetEnvironmentsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Deployment\Environments::class, $api->environments()); + } + + /** + * @test + */ + public function shouldGetPoliciesApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Deployment\Policies::class, $api->policies()); + } + /** * @return string */ From c68b874ac3267c3cc0544b726dbb4e49a72a9920 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Fri, 10 Mar 2023 12:40:14 +0100 Subject: [PATCH 917/951] Update changelog for 3.11.0 release --- CHANGELOG-3.X.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 3ec12940b20..b4f7fd83bdb 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,18 @@ # Changelog +## 3.11.0 + +### Added +- Added environment variables & secrets ([Froxz](https://github.com/Froxz)) [#1104](https://github.com/KnpLabs/php-github-api/issues/1104) +- Added Org & Repository variables ([Froxz](https://github.com/Froxz)) [#1106](https://github.com/KnpLabs/php-github-api/issues/1106) +- Deployment branch policies ([Froxz](https://github.com/Froxz)) [#1108](https://github.com/KnpLabs/php-github-api/issues/1108) + +### Changed +- Test on PHP 8.2 ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1105](https://github.com/KnpLabs/php-github-api/issues/1105) + +### Fixed +- Bugfix creating env ([Froxz](https://github.com/Froxz)) [#1107](https://github.com/KnpLabs/php-github-api/issues/1107) + ## 3.10.0 ### Added From b6fe0492dd7ed23b3424088abd9df81541a33671 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 10 Mar 2023 12:02:27 +0000 Subject: [PATCH 918/951] Fixed branch alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 886b5993221..ef8d0a84f38 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.10.x-dev" + "dev-master": "3.11.x-dev" } }, "config": { From 0e2399c93eb53be2243871c420eb1c6641cf0c7b Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Sun, 2 Apr 2023 23:51:46 +0530 Subject: [PATCH 919/951] feature #1101 feat: Support for Organization Runners (haridarshan, renovate[bot]) This PR was squashed before being merged into the 3.11.x-dev branch. Discussion ---------- Commits ------- 9d1ab1e7c9a5082fbb3e664b36194fa8426d9b57 feat: Support for Organization Runners 02bd5bc04e4bafab335af40fe453766816a89d21 fix: StyleCI ea2f3ececb90f030c066d687591d8e1c9166242a docs: Add Organization Self-Hosted runner doc 6df9b8fe3212f4dc60eaea090bc245c5a6afcbec docs: Add org runner link in README.md 70e7bbe13aa1cc692b832c390b897841eb51b655 Merge branch 'KnpLabs:master' into master 50a0ee1ceac5b8d86c555805454b43f6239146aa Merge branch 'master' into master 370927e8d59925a1bc807ebb16661378d63d2bdf Merge branch 'KnpLabs:master' into master 91c80431771f2440cce7d7aebf944fb66457daf9 chore: change argument of `all` method to `$parameters` array ca9467642c5230a8357d01f5bde840bdb87e9468 chore: fix StyleCi 5ff2a51502bd654d2c013be3abb1cb6c30511521 chore: minor fix 987a552a69ba8ba0e0387076e15365a21f04570a Add renovate.json 234a7a219772166a4d75234bb600cb5d0369fd80 Merge pull request #1 from haridarshan/renovate/configure be155523bd5368280c05584aa45879c446ef2a7c Update renovate.json 748354251877a9a5487dbf5ef10c2c845a9afe2f Delete renovate.json --- doc/README.md | 1 + .../actions/self_hosted_runners.md | 51 ++++++++ lib/Github/Api/Organization.php | 9 ++ .../Actions/SelfHostedRunners.php | 59 +++++++++ .../Actions/SelfHostedRunnersTest.php | 115 ++++++++++++++++++ test/Github/Tests/Api/OrganizationTest.php | 10 ++ 6 files changed, 245 insertions(+) create mode 100644 doc/organization/actions/self_hosted_runners.md create mode 100644 lib/Github/Api/Organization/Actions/SelfHostedRunners.php create mode 100644 test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php diff --git a/doc/README.md b/doc/README.md index cecccfb90b7..ee453269d35 100644 --- a/doc/README.md +++ b/doc/README.md @@ -39,6 +39,7 @@ v3 APIs: * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) + * [Self hosted runners](organization/actions/self_hosted_runners.md) * [Secrets](organization/actions/secrets.md) * [Variables](organization/actions/variables.md) * [Projects](project/projects.md) diff --git a/doc/organization/actions/self_hosted_runners.md b/doc/organization/actions/self_hosted_runners.md new file mode 100644 index 00000000000..f6e915cdce5 --- /dev/null +++ b/doc/organization/actions/self_hosted_runners.md @@ -0,0 +1,51 @@ +## Organization / Actions / Self Hosted Runners API +[Back to the "Organization API"](../../organization.md) | [Back to the navigation](../../README.md) + +# List self-hosted runners for an Organization + +https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization + +```php +$runners = $client->api('organization')->runners()->all('KnpLabs'); +``` + +# Get a self-hosted runner for an Organization + + https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization + +```php +$runner = $client->api('organization')->runners()->show('KnpLabs', $runnerId); +``` + +# Delete a self-hosted runner from an Organization + +https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization + +```php +$client->api('organization')->runners()->remove('KnpLabs', $runnerId); +``` + +# List runner applications for an Organization + +https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization + +```php +$applications = $client->api('organization')->selfHostedRunners()->applications('KnpLabs'); +``` + +# List of all runners with Pagination + +```php +$api = $github->api('organization')->runners(); +$paginator = new Github\ResultPager($github); +$parameters = array('KnpLabs'); +$runners = $paginator->fetchAll($api, 'all', $parameters); + +do { + foreach ($runners['runners'] as $runner) { + // code + } + $runners = $paginator->fetchNext(); +} +while($paginator->hasNext()); +``` diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index d1997dabc7a..0756fbaefe4 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -3,6 +3,7 @@ namespace Github\Api; use Github\Api\Organization\Actions\Secrets; +use Github\Api\Organization\Actions\SelfHostedRunners; use Github\Api\Organization\Actions\Variables; use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; @@ -140,4 +141,12 @@ public function issues($organization, array $params = [], $page = 1) { return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => $page], $params)); } + + /** + * @return SelfHostedRunners + */ + public function runners(): SelfHostedRunners + { + return new SelfHostedRunners($this->getClient()); + } } diff --git a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php new file mode 100644 index 00000000000..f0b989f5751 --- /dev/null +++ b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php @@ -0,0 +1,59 @@ +get('/orgs/'.rawurlencode($organization).'/actions/runners', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization + * + * @param string $organization + * @param int $runnerId + * + * @return array|string + */ + public function show(string $organization, int $runnerId) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization + * + * @param string $organization + * @param int $runnerId + * + * @return array|string + */ + public function remove(string $organization, int $runnerId) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization + * + * @param string $organization + * + * @return array|string + */ + public function applications(string $organization) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/downloads'); + } +} diff --git a/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php b/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php new file mode 100644 index 00000000000..e313a88202a --- /dev/null +++ b/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php @@ -0,0 +1,115 @@ + 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ], + [ + 'id' => 2, + 'name' => 'iMac', + 'os' => 'macos', + 'status' => 'offline', + ], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/runners') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunner() + { + $expectedArray = [ + 'id' => 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/runners/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 1)); + } + + /** + * @test + */ + public function shouldRemoveSelfHostedRunner() + { + $expectedValue = 'response'; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/runners/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 1)); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunnerApps() + { + $expectedArray = [ + ['os' => 'osx', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'win', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm64', 'download_url' => 'download_url', 'filename' => 'filename'], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/runners/downloads') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->applications('KnpLabs')); + } + + protected function getApiClass() + { + return SelfHostedRunners::class; + } +} diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index d13547bd663..2b920662691 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -88,6 +88,16 @@ public function shouldGetTeamsApiObject() $this->assertInstanceOf(\Github\Api\Organization\Teams::class, $api->teams()); } + /** + * @test + */ + public function shouldGetSelfHostedRunnersApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Organization\Actions\SelfHostedRunners::class, $api->runners()); + } + /** * @test */ From d005523078f4c31eabd964fd670f4c3f411d8c76 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Sep 2023 02:30:17 +0000 Subject: [PATCH 920/951] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/backwards-compatibility.yml | 2 +- .github/workflows/ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backwards-compatibility.yml b/.github/workflows/backwards-compatibility.yml index cdb19e8dfe6..af330f06daa 100644 --- a/.github/workflows/backwards-compatibility.yml +++ b/.github/workflows/backwards-compatibility.yml @@ -8,7 +8,7 @@ jobs: name: "Roave BC check" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31af3510052..7e09521e245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -33,7 +33,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: From 2a3a71b784ab7552b9134d3abed4ec1d0a83fe44 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Fri, 29 Sep 2023 13:41:14 -0700 Subject: [PATCH 921/951] allow psr/http-message v2 --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ef8d0a84f38..cbd418fbada 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "psr/cache": "^1.0|^2.0|^3.0", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0|^2.0", "symfony/polyfill-php80": "^1.17", "symfony/deprecation-contracts": "^2.2|^3.0" }, @@ -58,7 +58,8 @@ "config": { "allow-plugins": { "phpstan/extension-installer": true, - "composer/package-versions-deprecated": true + "composer/package-versions-deprecated": true, + "php-http/discovery": true } } } From 6fd7aacdabccb7489a72ac8df907721797b67f19 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 30 Sep 2023 18:02:27 +0200 Subject: [PATCH 922/951] Update changelog for 3.12.0 release --- CHANGELOG-3.X.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index b4f7fd83bdb..a0cfebd17d8 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,14 @@ # Changelog +## 3.12.0 + +### Added +- feat: Support for Organization Runners ([haridarshan](https://github.com/haridarshan), [renovate](https://github.com/renovate)[[bot](https://github.com/bot)]) [#1101](https://github.com/KnpLabs/php-github-api/issues/1101) +- allow psr/http-message v2 ([LordSimal](https://github.com/LordSimal)) [#1122](https://github.com/KnpLabs/php-github-api/issues/1122) + +### Changed +- Fixed branch alias ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1109](https://github.com/KnpLabs/php-github-api/issues/1109) + ## 3.11.0 ### Added From b50fc1f40bb5ac50957d32c5732fcde9167ac30a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 30 Sep 2023 18:42:04 +0200 Subject: [PATCH 923/951] Update changelog for 3.12.0 release --- CHANGELOG-3.X.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index a0cfebd17d8..e8f05acc917 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -9,6 +9,15 @@ ### Changed - Fixed branch alias ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1109](https://github.com/KnpLabs/php-github-api/issues/1109) +## 3.12.0 + +### Added +- feat: Support for Organization Runners ([haridarshan](https://github.com/haridarshan), [renovate](https://github.com/renovate)[[bot](https://github.com/bot)]) [#1101](https://github.com/KnpLabs/php-github-api/issues/1101) +- allow psr/http-message v2 ([LordSimal](https://github.com/LordSimal)) [#1122](https://github.com/KnpLabs/php-github-api/issues/1122) + +### Changed +- Fixed branch alias ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1109](https://github.com/KnpLabs/php-github-api/issues/1109) + ## 3.11.0 ### Added From 3bac0b8e80ad79699757e8a9bacef231ea2cd48e Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 30 Sep 2023 18:42:17 +0200 Subject: [PATCH 924/951] Update composer branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cbd418fbada..4145268c86a 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.11.x-dev" + "dev-master": "3.12-dev" } }, "config": { From a02113fa03c78fa9fe31bc80e9967c1434b5e80c Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:59:10 +0200 Subject: [PATCH 925/951] CHANGELOG-3.X: fix release 3.12.0 mentioned twice --- CHANGELOG-3.X.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index e8f05acc917..a0cfebd17d8 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -9,15 +9,6 @@ ### Changed - Fixed branch alias ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1109](https://github.com/KnpLabs/php-github-api/issues/1109) -## 3.12.0 - -### Added -- feat: Support for Organization Runners ([haridarshan](https://github.com/haridarshan), [renovate](https://github.com/renovate)[[bot](https://github.com/bot)]) [#1101](https://github.com/KnpLabs/php-github-api/issues/1101) -- allow psr/http-message v2 ([LordSimal](https://github.com/LordSimal)) [#1122](https://github.com/KnpLabs/php-github-api/issues/1122) - -### Changed -- Fixed branch alias ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1109](https://github.com/KnpLabs/php-github-api/issues/1109) - ## 3.11.0 ### Added From c1b440aa41eb285c297aee083fabcf1eb0bbe562 Mon Sep 17 00:00:00 2001 From: Serhii Petrov Date: Tue, 10 Oct 2023 10:39:54 +0300 Subject: [PATCH 926/951] Test against php 8.3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e09521e245..c1569cc97bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - uses: actions/checkout@v4 From 113f6b3c52f98eb0a09a94397a84214c2343a706 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Wed, 18 Oct 2023 01:52:42 +0530 Subject: [PATCH 927/951] feature #1114 feat: Secret Scanning Alerts (haridarshan) This PR was squashed before being merged into the 3.12-dev branch. Discussion ---------- Feature: - Secret Scanning Alerts Doc: - Secret Scanning doc Closes #1080 Commits ------- 98053b5af23849906cf25f00cb4e649fe0464e8d feat: Add Secret Scanning Alerts (Enterprise, Organization & Repository) 7b434a9752725a2533d6de089dafad942f13483e chore(styleci): apply styleci patch --- doc/README.md | 3 + doc/enterprise/secret-scanning.md | 10 ++ doc/organization/secret-scanning.md | 10 ++ doc/repo/secret-scanning.md | 37 +++++ lib/Github/Api/Enterprise.php | 9 ++ lib/Github/Api/Enterprise/SecretScanning.php | 21 +++ lib/Github/Api/Organization.php | 9 ++ .../Api/Organization/SecretScanning.php | 19 +++ lib/Github/Api/Repo.php | 9 ++ lib/Github/Api/Repository/SecretScanning.php | 64 +++++++++ .../Api/Enterprise/SecretScanningTest.php | 41 ++++++ .../Api/Organization/SecretScanningTest.php | 41 ++++++ .../Api/Repository/SecretScanningTest.php | 132 ++++++++++++++++++ 13 files changed, 405 insertions(+) create mode 100644 doc/enterprise/secret-scanning.md create mode 100644 doc/organization/secret-scanning.md create mode 100644 doc/repo/secret-scanning.md create mode 100644 lib/Github/Api/Enterprise/SecretScanning.php create mode 100644 lib/Github/Api/Organization/SecretScanning.php create mode 100644 lib/Github/Api/Repository/SecretScanning.php create mode 100644 test/Github/Tests/Api/Enterprise/SecretScanningTest.php create mode 100644 test/Github/Tests/Api/Organization/SecretScanningTest.php create mode 100644 test/Github/Tests/Api/Repository/SecretScanningTest.php diff --git a/doc/README.md b/doc/README.md index ee453269d35..37838e126a1 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,6 +14,7 @@ v3 APIs: * [Public keys](currentuser/publickeys.md) * [Memberships](currentuser/memberships.md) * [Enterprise](enterprise.md) + * [Secret Scanning Alert](enterprise/secret-scanning.md) * [Gists](gists.md) * [Comments](gists/comments.md) * GitData @@ -42,6 +43,7 @@ v3 APIs: * [Self hosted runners](organization/actions/self_hosted_runners.md) * [Secrets](organization/actions/secrets.md) * [Variables](organization/actions/variables.md) + * [Secret Scanning Alert](organization/secret-scanning.md) * [Projects](project/projects.md) * [Columns](project/columns.md) * [Cards](project/cards.md) @@ -74,6 +76,7 @@ v3 APIs: * [Stargazers](repo/stargazers.md) * [Statuses](repo/statuses.md) * [Tags](repo/tags.md) + * [Secret Scanning Alert](repo/secret-scanning.md) * [Search](search.md) * [Users](users.md) diff --git a/doc/enterprise/secret-scanning.md b/doc/enterprise/secret-scanning.md new file mode 100644 index 00000000000..ad7626c4709 --- /dev/null +++ b/doc/enterprise/secret-scanning.md @@ -0,0 +1,10 @@ +## Enterprise / Secret Scanning API +[Back to the "Enterprise API"](../../enterprise.md) | [Back to the navigation](../../README.md) + +# List secret-scanning alerts for an Enterprise + +https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-enterprise + +```php +$alerts = $client->api('enterprise')->secretScanning()->alerts('KnpLabs'); +``` diff --git a/doc/organization/secret-scanning.md b/doc/organization/secret-scanning.md new file mode 100644 index 00000000000..9ee5d4d972d --- /dev/null +++ b/doc/organization/secret-scanning.md @@ -0,0 +1,10 @@ +## Organization / Secret Scanning API +[Back to the "Organization API"](../../organization.md) | [Back to the navigation](../../README.md) + +# List secret-scanning alerts for an Organization + +https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-organization + +```php +$alerts = $client->api('organization')->secretScanning()->alerts('KnpLabs'); +``` diff --git a/doc/repo/secret-scanning.md b/doc/repo/secret-scanning.md new file mode 100644 index 00000000000..18f3ef20b28 --- /dev/null +++ b/doc/repo/secret-scanning.md @@ -0,0 +1,37 @@ +## Repository / Secret Scanning API +[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md) + +# List secret-scanning alerts for a repository + +https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-a-repository + +```php +$alerts = $client->api('repos')->secretScanning()->alerts('KnpLabs', 'php-github-api'); +``` + +# Get a secret-scanning alert + +https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#get-a-secret-scanning-alert + +```php +$alert = $client->api('repos')->secretScanning()->getAlert('KnpLabs', 'php-github-api', $alertNumber); +``` + +# Update a secret-scanning alert + +https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#update-a-secret-scanning-alert + +```php +$client->api('repos')->secretScanning()->updateAlert('KnpLabs', 'php-github-api', $alertNumber, [ + 'state' => 'resolved', + 'resolution' => 'wont-fix' +]); +``` + +# List Locations for a secret-scanning alert + +https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-locations-for-a-secret-scanning-alert + +```php +$locations = $client->api('repos')->secretScanning()->locations('KnpLabs', 'php-github-api', $alertNumber); +``` diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index b3daf95a177..62abaff577e 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -4,6 +4,7 @@ use Github\Api\Enterprise\License; use Github\Api\Enterprise\ManagementConsole; +use Github\Api\Enterprise\SecretScanning; use Github\Api\Enterprise\Stats; use Github\Api\Enterprise\UserAdmin; @@ -48,4 +49,12 @@ public function userAdmin() { return new UserAdmin($this->getClient()); } + + /** + * @return SecretScanning + */ + public function secretScanning(): SecretScanning + { + return new SecretScanning($this->getClient()); + } } diff --git a/lib/Github/Api/Enterprise/SecretScanning.php b/lib/Github/Api/Enterprise/SecretScanning.php new file mode 100644 index 00000000000..5d92c1d8a47 --- /dev/null +++ b/lib/Github/Api/Enterprise/SecretScanning.php @@ -0,0 +1,21 @@ +get('/enterprises/'.rawurlencode($enterprise).'/secret-scanning/alerts', $params); + } +} diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 0756fbaefe4..ada7e66836d 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -8,6 +8,7 @@ use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; use Github\Api\Organization\OutsideCollaborators; +use Github\Api\Organization\SecretScanning; use Github\Api\Organization\Teams; /** @@ -149,4 +150,12 @@ public function runners(): SelfHostedRunners { return new SelfHostedRunners($this->getClient()); } + + /** + * @return SecretScanning + */ + public function secretScanning(): SecretScanning + { + return new SecretScanning($this->getClient()); + } } diff --git a/lib/Github/Api/Organization/SecretScanning.php b/lib/Github/Api/Organization/SecretScanning.php new file mode 100644 index 00000000000..a323fd06fcc --- /dev/null +++ b/lib/Github/Api/Organization/SecretScanning.php @@ -0,0 +1,19 @@ +get('/orgs/'.rawurlencode($organization).'/secret-scanning/alerts', $params); + } +} diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index bcfe13edb73..d362830c2a7 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -24,6 +24,7 @@ use Github\Api\Repository\Projects; use Github\Api\Repository\Protection; use Github\Api\Repository\Releases; +use Github\Api\Repository\SecretScanning; use Github\Api\Repository\Stargazers; use Github\Api\Repository\Statuses; use Github\Api\Repository\Traffic; @@ -897,4 +898,12 @@ public function disableVulnerabilityAlerts(string $username, string $repository) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts'); } + + /** + * @return SecretScanning + */ + public function secretScanning(): SecretScanning + { + return new SecretScanning($this->getClient()); + } } diff --git a/lib/Github/Api/Repository/SecretScanning.php b/lib/Github/Api/Repository/SecretScanning.php new file mode 100644 index 00000000000..968d352c3ec --- /dev/null +++ b/lib/Github/Api/Repository/SecretScanning.php @@ -0,0 +1,64 @@ +get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/secret-scanning/alerts', $params); + } + + /** + * @link https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#get-a-secret-scanning-alert + * + * @param string $username + * @param string $repository + * @param int $alertNumber + * + * @return array|string + */ + public function getAlert(string $username, string $repository, int $alertNumber) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/secret-scanning/alerts/'.$alertNumber); + } + + /** + * @link https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#update-a-secret-scanning-alert + * + * @param string $username + * @param string $repository + * @param int $alertNumber + * @param array $params + * + * @return array|string + */ + public function updateAlert(string $username, string $repository, int $alertNumber, array $params = []) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/secret-scanning/alerts/'.$alertNumber, $params); + } + + /** + * @link https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-locations-for-a-secret-scanning-alert + * + * @param string $username + * @param string $repository + * @param int $alertNumber + * @param array $params + * + * @return array|string + */ + public function locations(string $username, string $repository, int $alertNumber, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/secret-scanning/alerts/'.$alertNumber.'/locations', $params); + } +} diff --git a/test/Github/Tests/Api/Enterprise/SecretScanningTest.php b/test/Github/Tests/Api/Enterprise/SecretScanningTest.php new file mode 100644 index 00000000000..cc5b14b6547 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/SecretScanningTest.php @@ -0,0 +1,41 @@ + 1, 'state' => 'resolved', 'resolution' => 'false_positive'], + ['number' => 2, 'state' => 'open', 'resolution' => null], + ['number' => 3, 'state' => 'resolved', 'resolution' => 'wont_fix'], + ['number' => 4, 'state' => 'resolved', 'resolution' => 'revoked'], + ]; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/enterprises/KnpLabs/secret-scanning/alerts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->alerts('KnpLabs', [ + 'state' => 'all', + ])); + } + + protected function getApiClass() + { + return \Github\Api\Enterprise\SecretScanning::class; + } +} diff --git a/test/Github/Tests/Api/Organization/SecretScanningTest.php b/test/Github/Tests/Api/Organization/SecretScanningTest.php new file mode 100644 index 00000000000..01b8f844007 --- /dev/null +++ b/test/Github/Tests/Api/Organization/SecretScanningTest.php @@ -0,0 +1,41 @@ + 1, 'state' => 'resolved', 'resolution' => 'false_positive'], + ['number' => 2, 'state' => 'open', 'resolution' => null], + ['number' => 3, 'state' => 'resolved', 'resolution' => 'wont_fix'], + ['number' => 4, 'state' => 'resolved', 'resolution' => 'revoked'], + ]; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/secret-scanning/alerts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->alerts('KnpLabs', [ + 'state' => 'all', + ])); + } + + protected function getApiClass() + { + return \Github\Api\Organization\SecretScanning::class; + } +} diff --git a/test/Github/Tests/Api/Repository/SecretScanningTest.php b/test/Github/Tests/Api/Repository/SecretScanningTest.php new file mode 100644 index 00000000000..e2e98dfa879 --- /dev/null +++ b/test/Github/Tests/Api/Repository/SecretScanningTest.php @@ -0,0 +1,132 @@ + 1, 'state' => 'resolved', 'resolution' => 'false_positive'], + ['number' => 2, 'state' => 'open', 'resolution' => null], + ['number' => 3, 'state' => 'resolved', 'resolution' => 'wont_fix'], + ['number' => 4, 'state' => 'resolved', 'resolution' => 'revoked'], + ]; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/secret-scanning/alerts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->alerts('KnpLabs', 'php-github-api', [ + 'state' => 'all', + ])); + } + + /** + * @test + */ + public function shouldGetAlert() + { + $expectedArray = ['number' => 1, 'state' => 'resolved', 'resolution' => 'false_positive']; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/secret-scanning/alerts/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->getAlert('KnpLabs', 'php-github-api', 1)); + } + + /** + * @test + */ + public function shouldUpdateAlert() + { + $expectedArray = ['number' => 1, 'state' => 'resolved', 'resolution' => 'false_positive']; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/secret-scanning/alerts/2') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->updateAlert('KnpLabs', 'php-github-api', 2, [ + 'state' => 'resolved', + 'resolution' => 'false_positive', + ])); + } + + /** + * @test + */ + public function shouldGetLocations() + { + $expectedArray = [ + [ + 'type' => 'commit', + 'details' => [ + 'path' => '/example/secrets.txt', + 'start_line' => 1, + 'end_line' => 1, + 'start_column' => 1, + 'end_column' => 64, + 'blob_sha' => 'af5626b4a114abcb82d63db7c8082c3c4756e51b', + 'blob_url' => 'https://HOSTNAME/repos/octocat/hello-world/git/blobs/af5626b4a114abcb82d63db7c8082c3c4756e51b', + 'commit_sha' => 'f14d7debf9775f957cf4f1e8176da0786431f72b', + 'commit_url' => 'https://HOSTNAME/repos/octocat/hello-world/git/commits/f14d7debf9775f957cf4f1e8176da0786431f72b', + ], + ], + [ + 'type' => 'commit', + 'details' => [ + 'path' => '/example/secrets.txt', + 'start_line' => 5, + 'end_line' => 5, + 'start_column' => 1, + 'end_column' => 64, + 'blob_sha' => '9def38117ab2d8355b982429aa924e268b4b0065', + 'blob_url' => 'https://HOSTNAME/repos/octocat/hello-world/git/blobs/9def38117ab2d8355b982429aa924e268b4b0065', + 'commit_sha' => '588483b99a46342501d99e3f10630cfc1219ea32', + 'commit_url' => 'https://HOSTNAME/repos/octocat/hello-world/git/commits/588483b99a46342501d99e3f10630cfc1219ea32', + ], + ], + ]; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/secret-scanning/alerts/2/locations') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->locations('KnpLabs', 'php-github-api', 2, [ + 'per_page' => 10, + ])); + } + + protected function getApiClass() + { + return \Github\Api\Repository\SecretScanning::class; + } +} From 14e8eed991e82eed591395188f8ac39f4019c63f Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 17 Oct 2023 22:33:22 +0200 Subject: [PATCH 928/951] Switch roave bc-checker from docker to local setup --- .github/workflows/backwards-compatibility.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backwards-compatibility.yml b/.github/workflows/backwards-compatibility.yml index af330f06daa..e6418f67a84 100644 --- a/.github/workflows/backwards-compatibility.yml +++ b/.github/workflows/backwards-compatibility.yml @@ -12,7 +12,13 @@ jobs: with: fetch-depth: 0 - - name: Roave BC Check - uses: docker://nyholm/roave-bc-check-ga + - name: Install PHP + uses: shivammathur/setup-php@v2 with: - args: --from=${{ github.event.pull_request.base.sha }} + php-version: '8.2' + + - name: Install roave/backward-compatibility-check + run: composer require --dev roave/backward-compatibility-check + + - name: Run roave/backward-compatibility-check + run: vendor/bin/roave-backward-compatibility-check --from=${{ github.event.pull_request.base.sha }} --format=github-actions From 10080cd18df0bda1f20dead87a025415ce1889af Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 17 Oct 2023 22:34:46 +0200 Subject: [PATCH 929/951] Apply style-ci fixes --- lib/Github/Api/CurrentUser/Watchers.php | 1 + lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 1 - test/Github/Tests/Api/Enterprise/StatsTest.php | 1 + test/Github/Tests/Api/Repository/AssetsTest.php | 1 + test/Github/Tests/Api/Repository/ContentsTest.php | 1 + test/Github/Tests/ClientTest.php | 3 +++ test/Github/Tests/Integration/IssueCommentTest.php | 3 +++ test/Github/Tests/Integration/RepoCommentTest.php | 3 +++ 8 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 1ef35972c3f..79c04b5df36 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -8,6 +8,7 @@ * @link https://developer.github.com/v3/activity/watching/ * * @author Joseph Bielawski + * * @revised Felipe Valtl de Mello */ class Watchers extends AbstractApi diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 78628c6740f..773c88501f2 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -88,7 +88,6 @@ public function handleRequest(RequestInterface $request, callable $next, callabl $errors[] = $error['message']; } break; - } } diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index d3a8a89883a..f97060e0a14 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -24,6 +24,7 @@ public function shouldShowStats() /** * @test + * * @dataProvider getTypes */ public function shouldShowStatsByType($type) diff --git a/test/Github/Tests/Api/Repository/AssetsTest.php b/test/Github/Tests/Api/Repository/AssetsTest.php index 029c10a380f..6cea75fe975 100644 --- a/test/Github/Tests/Api/Repository/AssetsTest.php +++ b/test/Github/Tests/Api/Repository/AssetsTest.php @@ -43,6 +43,7 @@ public function shouldGetSingleReleaseAsset() /** * @test + * * @requires PHP 5.3.4 */ public function shouldCreateReleaseAsset() diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index 1cc828c370d..ff89ffda8ac 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -71,6 +71,7 @@ public function getFailureStubsForExistsTest() * @param \PHPUnit_Framework_MockObject_Stub|\PHPUnit\Framework\MockObject\Stub\Exception * * @test + * * @dataProvider getFailureStubsForExistsTest */ public function shouldReturnFalseWhenFileIsNotFound($failureStub) diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 74255c9a9f3..e5992284404 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -40,6 +40,7 @@ public function shouldPassHttpClientInterfaceToConstructor() /** * @test + * * @dataProvider getAuthenticationFullData */ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method) @@ -115,6 +116,7 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet() /** * @test + * * @dataProvider getApiClassesProvider */ public function shouldGetApiInstance($apiName, $class) @@ -126,6 +128,7 @@ public function shouldGetApiInstance($apiName, $class) /** * @test + * * @dataProvider getApiClassesProvider */ public function shouldGetMagicApiInstance($apiName, $class) diff --git a/test/Github/Tests/Integration/IssueCommentTest.php b/test/Github/Tests/Integration/IssueCommentTest.php index 3db9ce8bb46..0cb39a1f8e3 100644 --- a/test/Github/Tests/Integration/IssueCommentTest.php +++ b/test/Github/Tests/Integration/IssueCommentTest.php @@ -31,6 +31,7 @@ public function shouldRetrieveCommentsForIssue() /** * @test + * * @depends shouldRetrieveCommentsForIssue */ public function shouldRetrieveSingleComment($commentId) @@ -72,6 +73,7 @@ public function shouldCreateCommentForIssue() /** * @test + * * @depends shouldCreateCommentForIssue */ public function shouldUpdateCommentByCommentId($commentId) @@ -94,6 +96,7 @@ public function shouldUpdateCommentByCommentId($commentId) /** * @test + * * @depends shouldUpdateCommentByCommentId */ public function shouldRemoveCommentByCommentId($commentId) diff --git a/test/Github/Tests/Integration/RepoCommentTest.php b/test/Github/Tests/Integration/RepoCommentTest.php index b2d5dec528a..352dac4b7ff 100644 --- a/test/Github/Tests/Integration/RepoCommentTest.php +++ b/test/Github/Tests/Integration/RepoCommentTest.php @@ -70,6 +70,7 @@ public function shouldCreateCommentForCommit() /** * @test + * * @depends shouldCreateCommentForCommit */ public function shouldShowCommentByCommentId($commentId) @@ -91,6 +92,7 @@ public function shouldShowCommentByCommentId($commentId) /** * @test + * * @depends shouldShowCommentByCommentId */ public function shouldUpdateCommentByCommentId($commentId) @@ -113,6 +115,7 @@ public function shouldUpdateCommentByCommentId($commentId) /** * @test + * * @depends shouldUpdateCommentByCommentId */ public function shouldRemoveCommentByCommentId($commentId) From 67398b01830751871c3268711e821deeda6e5184 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Wed, 18 Oct 2023 02:18:49 +0530 Subject: [PATCH 930/951] feature #1115 feat: User Migration (haridarshan) This PR was squashed before being merged into the 3.12-dev branch. Discussion ---------- Feature: - User Migrations Doc: - User Migrations doc Closes #795 Commits ------- 394817408ae5cc542815e181d6ee82f66c874740 feat: Add User Migrations Api fc5a76cd166cf3e3d42298383d8fca34faf8367b docs: Add migration list example with `ResultPager` and remove `per_page` 5389602c78e918781d8a3850de600244c87dea51 perf: remove `$params['repositories']` validation check 1bec9eb3ac20e46bece11563255bf9b35fa0370d test: remove `shouldNotStartMigration` test-case 69fc86460f80e3ca5db8181ffcaca7e2c27d550f chore(styleci): apply styleci patch --- doc/README.md | 1 + doc/user/migration.md | 79 ++++++++ lib/Github/Api/User.php | 10 + lib/Github/Api/User/Migration.php | 83 +++++++++ test/Github/Tests/Api/User/MigrationTest.php | 186 +++++++++++++++++++ 5 files changed, 359 insertions(+) create mode 100644 doc/user/migration.md create mode 100644 lib/Github/Api/User/Migration.php create mode 100644 test/Github/Tests/Api/User/MigrationTest.php diff --git a/doc/README.md b/doc/README.md index 37838e126a1..35929c2afc3 100644 --- a/doc/README.md +++ b/doc/README.md @@ -79,6 +79,7 @@ v3 APIs: * [Secret Scanning Alert](repo/secret-scanning.md) * [Search](search.md) * [Users](users.md) + * [Migrations](user/migration.md) Additional features: diff --git a/doc/user/migration.md b/doc/user/migration.md new file mode 100644 index 00000000000..a2c3eb14c5e --- /dev/null +++ b/doc/user/migration.md @@ -0,0 +1,79 @@ +## User / Migrations API +[Back to the "Users API"](../../users.md) | [Back to the navigation](../../README.md) + +# List user migrations + +https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-user-migrations + +```php +$api = $github->api('user')->migration(); +$paginator = new Github\ResultPager($github); +$parameters = []; +$migrations = $paginator->fetchAll($api, 'list', $parameters); + +do { + foreach ($migrations as $migration) { + // do something + } + $migrations = $paginator->fetchNext(); +} +while($paginator->hasNext()); +``` + +# Start a User Migration + +https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#start-a-user-migration + +```php +$client->users()->migration()->start([ + 'repositories' => [ + 'KnpLabs/php-github-api' + ], + 'lock_repositories' => true, + 'exclude_metadata' => false, + 'exclude_git_data' => false, + 'exclude_attachments' => true, + 'exclude_releases' => false, + 'exclude_owner_projects' => true, + 'org_metadata_only' => false, + 'exclude' => [ + 'Exclude attributes from the API response to improve performance' + ] +]); +``` + +# Get a User Migration Status + +https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#get-a-user-migration-status + +```php +$status = $client->user()->migration()->status(12, [ + 'exclude' => [ + 'exclude attributes' + ] +]); +``` + +# Delete a User Migration Archive + +https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#delete-a-user-migration-archive + +```php +$client->user()->migration()->deleteArchive(12); +``` + +# Unlock a User Repository + +https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#unlock-a-user-repository + +```php +$client->user()->migration()->unlockRepo(12, 'php-github-api'); +``` + +# List repositories for a User Migration + +https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration + +```php +$repos = $client->user()->migration()->repos(2); +``` diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index c1ccc89e8c1..d436a2b835e 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -2,6 +2,8 @@ namespace Github\Api; +use Github\Api\User\Migration; + /** * Searching users, getting user information. * @@ -246,4 +248,12 @@ public function events(string $username) { return $this->get('/users/'.rawurlencode($username).'/events'); } + + /** + * @return Migration + */ + public function migration(): Migration + { + return new Migration($this->getClient()); + } } diff --git a/lib/Github/Api/User/Migration.php b/lib/Github/Api/User/Migration.php new file mode 100644 index 00000000000..4e1b61ca244 --- /dev/null +++ b/lib/Github/Api/User/Migration.php @@ -0,0 +1,83 @@ +get('/user/migrations', $params); + } + + /** + * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#start-a-user-migration + * + * @param array $params + * + * @return array|string + */ + public function start(array $params) + { + return $this->post('/user/migrations', $params); + } + + /** + * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#get-a-user-migration-status + * + * @param int $migrationId + * @param array $params + * + * @return array|string + */ + public function status(int $migrationId, array $params = []) + { + return $this->get('/user/migrations/'.$migrationId, $params); + } + + /** + * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#delete-a-user-migration-archive + * + * @param int $migrationId + * + * @return array|string + */ + public function deleteArchive(int $migrationId) + { + return $this->delete('/user/migrations/'.$migrationId.'/archive'); + } + + /** + * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#unlock-a-user-repository + * + * @param int $migrationId + * @param string $repository + * + * @return array|string + */ + public function unlockRepo(int $migrationId, string $repository) + { + return $this->delete('/user/migrations/'.$migrationId.'/repos/'.rawurlencode($repository).'/lock'); + } + + /** + * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration + * + * @param int $migrationId + * @param array $params + * + * @return array|string + */ + public function repos(int $migrationId, array $params = []) + { + return $this->get('/user/migrations/'.$migrationId.'/repositories', $params); + } +} diff --git a/test/Github/Tests/Api/User/MigrationTest.php b/test/Github/Tests/Api/User/MigrationTest.php new file mode 100644 index 00000000000..3ee1620a3ae --- /dev/null +++ b/test/Github/Tests/Api/User/MigrationTest.php @@ -0,0 +1,186 @@ + 79, + 'state' => 'pending', + 'lock_repositories' => true, + 'repositories' => [ + [ + 'id' => 1296269, + 'name' => 'Hello-World', + 'full_name' => 'octocat/Hello-World', + ], + ], + ], + [ + 'id' => 2, + 'name' => 'pending', + 'lock_repositories' => false, + 'repositories' => [ + [ + 'id' => 123, + 'name' => 'php-github-api', + 'full_name' => 'KnpLabs/php-github-api', + ], + ], + ], + ]; + + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/user/migrations') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->list()); + } + + /** + * @test + */ + public function shouldStartMigration() + { + $expectedArray = [ + 'id' => 79, + 'state' => 'pending', + 'lock_repositories' => true, + 'repositories' => [ + [ + 'id' => 1296269, + 'name' => 'Hello-World', + 'full_name' => 'octocat/Hello-World', + ], + ], + ]; + + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('post') + ->with('/user/migrations') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->start([ + 'lock_repositories' => true, + 'repositories' => [ + 'KnpLabs/php-github-api', + ], + ])); + } + + /** + * @test + */ + public function shouldGetMigrationStatus() + { + $expectedArray = [ + 'id' => 79, + 'state' => 'exported', + 'lock_repositories' => true, + 'repositories' => [ + [ + 'id' => 1296269, + 'name' => 'Hello-World', + 'full_name' => 'octocat/Hello-World', + ], + ], + ]; + + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/user/migrations/79') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->status(79)); + } + + /** + * @test + */ + public function shouldDeleteMigrationArchive() + { + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('delete') + ->with('/user/migrations/79/archive') + ->will($this->returnValue(204)); + + $this->assertEquals(204, $api->deleteArchive(79)); + } + + /** + * @test + */ + public function shouldUnlockUserRepo() + { + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('delete') + ->with('/user/migrations/79/repos/php-github-api/lock') + ->will($this->returnValue(204)); + + $this->assertEquals(204, $api->unlockRepo(79, 'php-github-api')); + } + + /** + * @test + */ + public function shouldListRepos() + { + $expectedArray = [ + [ + 'id' => 1296269, + 'name' => 'Hello-World', + 'full_name' => 'test/Hello-World', + ], + [ + 'id' => 234324, + 'name' => 'Hello-World2', + 'full_name' => 'test/Hello-World2', + ], + ]; + + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->once()) + ->method('get') + ->with('/user/migrations/79/repositories') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->repos(79)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\User\Migration::class; + } +} From 9d19af334fb3baa2e1ae54c6ec0dcf09c6e5ab61 Mon Sep 17 00:00:00 2001 From: Mathieu De Zutter Date: Sun, 19 Nov 2023 21:54:17 +0100 Subject: [PATCH 931/951] bug #1126 Fix detection of secondary rate limit (mathieudz) This PR was squashed before being merged into the 3.12-dev branch. Discussion ---------- Actual error message is "You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later. If you reach out to GitHub Support for help, please include the request ID [...]" Commits ------- 661fccba2042061a3d9e27da72a4abb110070db1 Fix detection of secondary rate limit 7d8aeb65be07542af91763f5a0dcede351390929 Update secondary rate limit test with new message --- lib/Github/HttpClient/Plugin/GithubExceptionThrower.php | 2 +- .../Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php index 773c88501f2..9479aaaf2be 100644 --- a/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php +++ b/lib/Github/HttpClient/Plugin/GithubExceptionThrower.php @@ -128,7 +128,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl } $reset = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Reset'); - if ((403 === $response->getStatusCode()) && 0 < $reset && isset($content['message']) && (0 === strpos($content['message'], 'You have exceeded a secondary rate limit.'))) { + if ((403 === $response->getStatusCode()) && 0 < $reset && isset($content['message']) && (0 === strpos($content['message'], 'You have exceeded a secondary rate limit'))) { $limit = (int) ResponseMediator::getHeader($response, 'X-RateLimit-Limit'); throw new ApiLimitExceedException($limit, $reset); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index f8090ef622c..b2541ec0942 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -103,7 +103,7 @@ public static function responseProvider() ], json_encode( [ - 'message' => 'You have exceeded a secondary rate limit. Please wait a few minutes before you try again.', + 'message' => 'You have exceeded a secondary rate limit and have been temporarily blocked from content creation. Please retry your request again later. If you reach out to GitHub Support for help, please include the request ID #xxxxxxx.', ] ) ), From 47024f3483520c0fafdfc5c10d2a20d87b4c7ceb Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 19 Nov 2023 22:08:19 +0100 Subject: [PATCH 932/951] Update changelog for 3.13.0 release --- CHANGELOG-3.X.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index a0cfebd17d8..b396856bca9 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,18 @@ # Changelog +## 3.13.0 + +### Added +- Test against php 8.3 ([sergiy-petrov](https://github.com/sergiy-petrov)) [#1124](https://github.com/KnpLabs/php-github-api/issues/1124) +- feat: Secret Scanning Alerts ([haridarshan](https://github.com/haridarshan)) [#1114](https://github.com/KnpLabs/php-github-api/issues/1114) +- feat: User Migration ([haridarshan](https://github.com/haridarshan)) [#1115](https://github.com/KnpLabs/php-github-api/issues/1115) + +### Changed +- General chores ([acrobat](https://github.com/acrobat)) [#1125](https://github.com/KnpLabs/php-github-api/issues/1125) + +### Fixed +- Fix detection of secondary rate limit ([mathieudz](https://github.com/mathieudz)) [#1126](https://github.com/KnpLabs/php-github-api/issues/1126) + ## 3.12.0 ### Added From 9afaf87f99c6c2acde80b6925d1b97a70ece8cb5 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 19 Nov 2023 22:08:24 +0100 Subject: [PATCH 933/951] Update composer branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4145268c86a..957eedad381 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.12-dev" + "dev-master": "3.13-dev" } }, "config": { From 6f5b61de47696fea572cb00a776484821ebf8e62 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 02:47:59 +0000 Subject: [PATCH 934/951] Bump ramsey/composer-install from 2 to 3 Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 2 to 3. - [Release notes](https://github.com/ramsey/composer-install/releases) - [Commits](https://github.com/ramsey/composer-install/compare/v2...v3) --- updated-dependencies: - dependency-name: ramsey/composer-install dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1569cc97bf..923f2ce49c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: coverage: none - name: Install Composer Dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 - name: Run phpunit run: vendor/bin/phpunit --verbose @@ -41,7 +41,7 @@ jobs: coverage: none - name: Install Composer Dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 - name: Run phpstan run: vendor/bin/phpstan analyse --no-progress From 680eea2ce37588cc4e5776131e4b170d53da74b8 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 17 Mar 2024 20:56:20 +0000 Subject: [PATCH 935/951] Allow php-http/cache-plugin v2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 957eedad381..826e15c49b8 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": "^7.2.5 || ^8.0", "ext-json": "*", - "php-http/cache-plugin": "^1.7.1", + "php-http/cache-plugin": "^1.7.1|^2.0", "php-http/client-common": "^2.3", "php-http/discovery": "^1.12", "php-http/httplug": "^2.2", From 16235d0eaffe5100492e6c788c58346100b2d734 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 19 Mar 2024 15:52:45 +0100 Subject: [PATCH 936/951] Update changelog for 3.14.0 release --- CHANGELOG-3.X.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index b396856bca9..44afe4fc8cb 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,10 @@ # Changelog +## 3.14.0 + +### Added +- Allow php-http/cache-plugin v2 ([GrahamCampbell](https://github.com/GrahamCampbell)) [#1134](https://github.com/KnpLabs/php-github-api/issues/1134) + ## 3.13.0 ### Added From 4fca25fb5d5be992178b99a0ee8e4395030e89e4 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Tue, 19 Mar 2024 15:52:51 +0100 Subject: [PATCH 937/951] Update composer branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 826e15c49b8..f3d598d6940 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.13-dev" + "dev-master": "3.14-dev" } }, "config": { From 4afaaf9936c05f82016fa68e3ebec1e2dff65a47 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 24 Mar 2024 14:10:30 +0000 Subject: [PATCH 938/951] Apply fixes from StyleCI --- lib/Github/Api/Issue/Labels.php | 2 +- lib/Github/Api/Issue/Milestones.php | 6 +- lib/Github/Api/Repo.php | 14 ++--- lib/Github/Api/Repository/Contents.php | 4 +- .../Tests/Api/CurrentUser/MembershipsTest.php | 18 +++--- test/Github/Tests/Api/GistsTest.php | 4 +- test/Github/Tests/Api/GitData/TreesTest.php | 10 ++-- test/Github/Tests/Api/GraphQLTest.php | 4 +- test/Github/Tests/Api/IssueTest.php | 10 ++-- test/Github/Tests/Api/PullRequestTest.php | 28 ++++----- test/Github/Tests/Api/RepoTest.php | 60 +++++++++---------- .../Tests/Api/Repository/ContentsTest.php | 20 +++---- .../Github/Tests/Api/Repository/PagesTest.php | 2 +- test/Github/Tests/Functional/CacheTest.php | 4 +- .../Message/ResponseMediatorTest.php | 8 +-- test/Github/Tests/Mock/PaginatedResponse.php | 2 +- test/Github/Tests/ResultPagerTest.php | 2 +- 17 files changed, 99 insertions(+), 99 deletions(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index d719578d943..3cfad23d5b0 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -108,7 +108,7 @@ public function deleteLabel($username, $repository, $label) public function update($username, $repository, $label, $newName, $color) { $params = [ - 'name' => $newName, + 'name' => $newName, 'color' => $color, ]; diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 4cf2a3d5518..fe9f2296dd6 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -36,9 +36,9 @@ public function all($username, $repository, array $params = []) } return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge([ - 'page' => 1, - 'state' => 'open', - 'sort' => 'due_date', + 'page' => 1, + 'state' => 'open', + 'sort' => 'due_date', 'direction' => 'asc', ], $params)); } diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index d362830c2a7..5653ae4c152 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -204,14 +204,14 @@ public function create( $path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos'; $parameters = [ - 'name' => $name, - 'description' => $description, - 'homepage' => $homepage, - 'private' => ($visibility ?? ($public ? 'public' : 'private')) === 'private', - 'has_issues' => $hasIssues, - 'has_wiki' => $hasWiki, + 'name' => $name, + 'description' => $description, + 'homepage' => $homepage, + 'private' => ($visibility ?? ($public ? 'public' : 'private')) === 'private', + 'has_issues' => $hasIssues, + 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, - 'auto_init' => $autoInit, + 'auto_init' => $autoInit, 'has_projects' => $hasProjects, ]; diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 4f9693dcbe1..b6e170ebce0 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -181,7 +181,7 @@ public function update($username, $repository, $path, $content, $message, $sha, $parameters = [ 'content' => base64_encode($content), 'message' => $message, - 'sha' => $sha, + 'sha' => $sha, ]; if (null !== $branch) { @@ -221,7 +221,7 @@ public function rm($username, $repository, $path, $message, $sha, $branch = null $parameters = [ 'message' => $message, - 'sha' => $sha, + 'sha' => $sha, ]; if (null !== $branch) { diff --git a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php index d3d8e1cbc77..aef9f374c23 100644 --- a/test/Github/Tests/Api/CurrentUser/MembershipsTest.php +++ b/test/Github/Tests/Api/CurrentUser/MembershipsTest.php @@ -15,21 +15,21 @@ public function shouldGetMemberships() [ 'organization' => [ 'login' => 'octocat', - 'id' => 1, + 'id' => 1, ], - 'user' => [ + 'user' => [ 'login' => 'defunkt', - 'id' => 3, + 'id' => 3, ], ], [ 'organization' => [ 'login' => 'invitocat', - 'id' => 2, + 'id' => 2, ], - 'user' => [ + 'user' => [ 'login' => 'defunkt', - 'id' => 3, + 'id' => 3, ], ], ]; @@ -51,11 +51,11 @@ public function shouldGetMembershipsForOrganization() $expectedValue = [ 'organization' => [ 'login' => 'invitocat', - 'id' => 2, + 'id' => 2, ], - 'user' => [ + 'user' => [ 'login' => 'defunkt', - 'id' => 3, + 'id' => 3, ], ]; diff --git a/test/Github/Tests/Api/GistsTest.php b/test/Github/Tests/Api/GistsTest.php index 093af712911..ff4673e4082 100644 --- a/test/Github/Tests/Api/GistsTest.php +++ b/test/Github/Tests/Api/GistsTest.php @@ -227,10 +227,10 @@ public function shouldUpdateGist() 'files' => [ 'filename.txt' => [ 'filename' => 'new_name.txt', - 'content' => 'content', + 'content' => 'content', ], 'filename_new.txt' => [ - 'content' => 'content new', + 'content' => 'content new', ], ], ]; diff --git a/test/Github/Tests/Api/GitData/TreesTest.php b/test/Github/Tests/Api/GitData/TreesTest.php index 901af559e24..0b415f1fb1c 100644 --- a/test/Github/Tests/Api/GitData/TreesTest.php +++ b/test/Github/Tests/Api/GitData/TreesTest.php @@ -35,13 +35,13 @@ public function shouldCreateTreeUsingSha() 'path' => 'path', 'mode' => 'mode', 'type' => 'type', - 'sha' => '1234', + 'sha' => '1234', ], [ 'path' => 'htap', 'mode' => 'edom', 'type' => 'epyt', - 'sha' => '4321', + 'sha' => '4321', ], ], ]; @@ -118,7 +118,7 @@ public function shouldNotCreateTreeWithoutPathParam() 'tree' => [ 'mode' => 'mode', 'type' => 'type', - 'content' => 'content', + 'content' => 'content', ], ]; @@ -139,7 +139,7 @@ public function shouldNotCreateTreeWithoutModeParam() 'tree' => [ 'path' => 'path', 'type' => 'type', - 'content' => 'content', + 'content' => 'content', ], ]; @@ -160,7 +160,7 @@ public function shouldNotCreateTreeWithoutTypeParam() 'tree' => [ 'path' => 'path', 'mode' => 'mode', - 'content' => 'content', + 'content' => 'content', ], ]; diff --git a/test/Github/Tests/Api/GraphQLTest.php b/test/Github/Tests/Api/GraphQLTest.php index 042cb014a50..b241cc5ae90 100644 --- a/test/Github/Tests/Api/GraphQLTest.php +++ b/test/Github/Tests/Api/GraphQLTest.php @@ -13,7 +13,7 @@ public function shouldTestGraphQL() $api->expects($this->once()) ->method('post') - ->with($this->equalTo('/graphql'), $this->equalTo(['query'=>'bar'])) + ->with($this->equalTo('/graphql'), $this->equalTo(['query' => 'bar'])) ->will($this->returnValue('foo')); $result = $api->execute('bar'); @@ -44,7 +44,7 @@ public function shouldJSONEncodeGraphQLVariables() $api->expects($this->once()) ->method('post') ->with('/graphql', $this->equalTo([ - 'query'=>'bar', + 'query' => 'bar', 'variables' => '{"variable":"foo"}', ])); diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index bc8b80fdf5e..a151076ce1f 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -35,10 +35,10 @@ public function shouldGetIssuesUsingAdditionalParameters() $data = [ 'state' => 'open', 'milestone' => '*', - 'assignee' => 'l3l0', + 'assignee' => 'l3l0', 'mentioned' => 'l3l0', - 'labels' => 'bug,@high', - 'sort' => 'created', + 'labels' => 'bug,@high', + 'sort' => 'created', 'direction' => 'asc', ]; $sentData = $data + [ @@ -77,7 +77,7 @@ public function shouldCreateIssue() { $data = [ 'title' => 'some title', - 'body' => 'some body', + 'body' => 'some body', ]; $api = $this->getApiMock(); @@ -95,7 +95,7 @@ public function shouldNotCreateIssueWithoutTitle() { $this->expectException(MissingArgumentException::class); $data = [ - 'body' => 'some body', + 'body' => 'some body', ]; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index fe5b87c9d6d..54cc34f55e0 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -243,10 +243,10 @@ public function shouldMergePullRequestWithMergeMethod() public function shouldCreatePullRequestUsingTitle() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -263,8 +263,8 @@ public function shouldCreatePullRequestUsingTitle() public function shouldCreatePullRequestUsingIssueId() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'issue' => 25, ]; @@ -282,10 +282,10 @@ public function shouldCreatePullRequestUsingIssueId() public function shouldCreateDraftPullRequest() { $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing draft pull-request creation from PHP Github API', - 'body' => 'BODY: Testing draft pull-request creation from PHP Github API', + 'body' => 'BODY: Testing draft pull-request creation from PHP Github API', 'draft' => 'true', ]; @@ -304,9 +304,9 @@ public function shouldNotCreatePullRequestWithoutBase() { $this->expectException(MissingArgumentException::class); $data = [ - 'head' => 'virtualtestbranch', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -323,9 +323,9 @@ public function shouldNotCreatePullRequestWithoutHead() { $this->expectException(MissingArgumentException::class); $data = [ - 'base' => 'master', + 'base' => 'master', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', - 'body' => 'BODY: Testing pull-request creation from PHP Github API', + 'body' => 'BODY: Testing pull-request creation from PHP Github API', ]; $api = $this->getApiMock(); @@ -342,8 +342,8 @@ public function shouldNotCreatePullRequestUsingTitleButWithoutBody() { $this->expectException(MissingArgumentException::class); $data = [ - 'base' => 'master', - 'head' => 'virtualtestbranch', + 'base' => 'master', + 'head' => 'virtualtestbranch', 'title' => 'TITLE: Testing pull-request creation from PHP Github API', ]; diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 7b84a6b52ac..786c27d97b5 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -92,14 +92,14 @@ public function shouldCreateRepositoryUsingNameOnly() $api->expects($this->once()) ->method('post') ->with('/user/repos', [ - 'name' => 'l3l0Repo', - 'description' => '', - 'homepage' => '', - 'private' => false, - 'has_issues' => false, - 'has_wiki' => false, + 'name' => 'l3l0Repo', + 'description' => '', + 'homepage' => '', + 'private' => false, + 'has_issues' => false, + 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false, + 'auto_init' => false, 'has_projects' => true, ]) ->will($this->returnValue($expectedArray)); @@ -118,14 +118,14 @@ public function shouldCreateRepositoryForOrganization() $api->expects($this->once()) ->method('post') ->with('/orgs/KnpLabs/repos', [ - 'name' => 'KnpLabsRepo', - 'description' => '', - 'homepage' => '', - 'private' => false, - 'has_issues' => false, - 'has_wiki' => false, + 'name' => 'KnpLabsRepo', + 'description' => '', + 'homepage' => '', + 'private' => false, + 'has_issues' => false, + 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false, + 'auto_init' => false, 'has_projects' => true, ]) ->will($this->returnValue($expectedArray)); @@ -144,16 +144,16 @@ public function shouldCreateRepositoryWithInternalVisibility() $api->expects($this->once()) ->method('post') ->with('/user/repos', [ - 'name' => 'KnpLabsRepo', - 'description' => '', - 'homepage' => '', - 'has_issues' => false, - 'has_wiki' => false, + 'name' => 'KnpLabsRepo', + 'description' => '', + 'homepage' => '', + 'has_issues' => false, + 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false, - 'has_projects' => true, - 'visibility' => 'internal', - 'private' => false, + 'auto_init' => false, + 'has_projects' => true, + 'visibility' => 'internal', + 'private' => false, ]) ->will($this->returnValue($expectedArray)); @@ -389,14 +389,14 @@ public function shouldCreateUsingAllParams() $api->expects($this->once()) ->method('post') ->with('/user/repos', [ - 'name' => 'l3l0Repo', - 'description' => 'test', - 'homepage' => 'http://l3l0.eu', - 'private' => true, - 'has_issues' => false, - 'has_wiki' => false, + 'name' => 'l3l0Repo', + 'description' => 'test', + 'homepage' => 'http://l3l0.eu', + 'private' => true, + 'has_issues' => false, + 'has_wiki' => false, 'has_downloads' => false, - 'auto_init' => false, + 'auto_init' => false, 'has_projects' => true, ]) ->will($this->returnValue($expectedArray)); diff --git a/test/Github/Tests/Api/Repository/ContentsTest.php b/test/Github/Tests/Api/Repository/ContentsTest.php index ff89ffda8ac..81a79db64fa 100644 --- a/test/Github/Tests/Api/Repository/ContentsTest.php +++ b/test/Github/Tests/Api/Repository/ContentsTest.php @@ -111,10 +111,10 @@ public function shouldCreateNewFile() $branch = 'master'; $committer = ['name' => 'committer name', 'email' => 'email@example.com']; $parameters = [ - 'content' => base64_encode($content), - 'message' => $message, + 'content' => base64_encode($content), + 'message' => $message, 'committer' => $committer, - 'branch' => $branch, + 'branch' => $branch, ]; $api = $this->getApiMock(); @@ -150,11 +150,11 @@ public function shouldUpdateFile() $branch = 'master'; $committer = ['name' => 'committer name', 'email' => 'email@example.com']; $parameters = [ - 'content' => base64_encode($content), - 'message' => $message, + 'content' => base64_encode($content), + 'message' => $message, 'committer' => $committer, - 'branch' => $branch, - 'sha' => $sha, + 'branch' => $branch, + 'sha' => $sha, ]; $api = $this->getApiMock(); @@ -189,10 +189,10 @@ public function shouldDeleteFile() $branch = 'master'; $committer = ['name' => 'committer name', 'email' => 'email@example.com']; $parameters = [ - 'message' => $message, + 'message' => $message, 'committer' => $committer, - 'branch' => $branch, - 'sha' => $sha, + 'branch' => $branch, + 'sha' => $sha, ]; $api = $this->getApiMock(); diff --git a/test/Github/Tests/Api/Repository/PagesTest.php b/test/Github/Tests/Api/Repository/PagesTest.php index c6b34cbc8b3..2fde0df1622 100644 --- a/test/Github/Tests/Api/Repository/PagesTest.php +++ b/test/Github/Tests/Api/Repository/PagesTest.php @@ -37,7 +37,7 @@ public function shouldEnablePages() $params = [ 'source' => [ 'branch' => 'master', - 'path' => '/path', + 'path' => '/path', ], ]; diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index ec9be6b12e0..eef379e61d5 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -24,7 +24,7 @@ public function shouldServeCachedResponse() $mockClient->addResponse($this->getCurrentUserResponse('octocat')); $github = Client::createWithHttpClient($mockClient); - $github->addCache(new ArrayAdapter(), ['default_ttl'=>600]); + $github->addCache(new ArrayAdapter(), ['default_ttl' => 600]); $github->authenticate('fake_token_aaa', AuthMethod::ACCESS_TOKEN); $userA = $github->currentUser()->show(); @@ -44,7 +44,7 @@ public function shouldVaryOnAuthorization() $mockClient->addResponse($this->getCurrentUserResponse('octocat')); $github = Client::createWithHttpClient($mockClient); - $github->addCache(new ArrayAdapter(), ['default_ttl'=>600]); + $github->addCache(new ArrayAdapter(), ['default_ttl' => 600]); $github->authenticate('fake_token_aaa', AuthMethod::ACCESS_TOKEN); $userA = $github->currentUser()->show(); diff --git a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php index 8c1bfd29243..5171ab0bac8 100644 --- a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php +++ b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php @@ -15,7 +15,7 @@ public function testGetContent() $body = ['foo' => 'bar']; $response = new Response( 200, - ['Content-Type'=>'application/json'], + ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($body)) ); @@ -45,7 +45,7 @@ public function testGetContentInvalidJson() $body = 'foobar'; $response = new Response( 200, - ['Content-Type'=>'application/json'], + ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for($body) ); @@ -64,7 +64,7 @@ public function testGetPagination() ]; // response mock - $response = new Response(200, ['link'=>$header]); + $response = new Response(200, ['link' => $header]); $result = ResponseMediator::getPagination($response); $this->assertEquals($pagination, $result); @@ -75,7 +75,7 @@ public function testGetHeader() $header = 'application/json'; $response = new Response( 200, - ['Content-Type'=> $header] + ['Content-Type' => $header] ); $this->assertEquals($header, ResponseMediator::getHeader($response, 'content-type')); diff --git a/test/Github/Tests/Mock/PaginatedResponse.php b/test/Github/Tests/Mock/PaginatedResponse.php index 4586de402ec..9d67b9f42be 100644 --- a/test/Github/Tests/Mock/PaginatedResponse.php +++ b/test/Github/Tests/Mock/PaginatedResponse.php @@ -18,7 +18,7 @@ public function __construct($loopCount, array $content = []) $this->loopCount = $loopCount; $this->content = $content; - parent::__construct(200, ['Content-Type'=>'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($content))); + parent::__construct(200, ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($content))); } public function getHeader($header) diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 2839e16f3df..264fd42ef75 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -152,7 +152,7 @@ public function testFetchAllPreserveKeys() 'sha' => '43068834af7e501778708ed13106de95f782328c', ]; - $response = new Response(200, ['Content-Type'=>'application/json'], Utils::streamFor(json_encode($content))); + $response = new Response(200, ['Content-Type' => 'application/json'], Utils::streamFor(json_encode($content))); // httpClient mock $httpClientMock = $this->getMockBuilder(HttpClient::class) From 61b478ab7246348bba876bf694e3f0e23a665e2d Mon Sep 17 00:00:00 2001 From: Thomas Corbett Date: Sun, 24 Mar 2024 14:20:24 -0400 Subject: [PATCH 939/951] bug #1135 Handle case of GitHub returning 204 No Content in some scenarios (tomcorbett) This PR was squashed before being merged into the 3.14-dev branch. Discussion ---------- ResultPager breaks because no array is returned (it's an empty string) - issue ResultPager::get() can return string #1091 Commits ------- 8a3f154b49c308ad8cc748caf842b7759132ea34 Handle case of GitHub returning 204 No Content in some scenarios which breaks ResultPager because no array is returned (it's an empty string) - issue ResultPager::get() can return string #1091 4fff55583e3c345cb835ecd6ba04db6dd70b7762 fix style issue raised by continuous-integration/styleci/pr eaa7993f2cda2754dbd00f8b6190c0a738eefbb8 Added unit test for case of GitHub API returning 204 empty content in ResultPager #1091 08c3d7a918fb4123b444085f9ae4e6d4ef2639bd Updated based on feedback from continuous-integration/styleci/pr a3d2fb821c49a83a65f27f4b8999e3d44532eed7 Another change requested by continuous-integration/styleci/pr (but not for my changed code) --- lib/Github/ResultPager.php | 4 ++ test/Github/Tests/ResultPagerTest.php | 63 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index cfd1d605e4f..a1d94785ca6 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -86,6 +86,10 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []): $api = $closure($api); $result = $api->$method(...$parameters); + if ($result === '' && $this->client->getLastResponse()->getStatusCode() === 204) { + $result = []; + } + $this->postFetch(true); return $result; diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 264fd42ef75..3df610ee250 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -4,6 +4,7 @@ use Github\Api\Issue; use Github\Api\Organization\Members; +use Github\Api\Repo; use Github\Api\Repository\Statuses; use Github\Api\Search; use Github\Client; @@ -116,6 +117,40 @@ public function shouldGetAllSearchResults() $this->assertCount($amountLoops * count($content['items']), $result); } + /** + * @test + */ + public function shouldHandleEmptyContributorListWith204Header() + { + // Set up a 204 response with an empty body + $response = new Response(204, [], ''); + $username = 'testuser'; + $reponame = 'testrepo'; + + // Mock the HttpClient to return the empty response + $httpClientMock = $this->getMockBuilder(HttpClient::class) + ->onlyMethods(['sendRequest']) + ->getMock(); + $httpClientMock + ->method('sendRequest') + ->willReturn($response); + + $client = Client::createWithHttpClient($httpClientMock); + + $repoApi = new Repo($client); + + $paginator = $this->getMockBuilder(ResultPager::class) + ->setConstructorArgs([$client]) // Pass the Client in the constructor + ->onlyMethods(['fetchAll']) + ->getMock(); + $paginator->expects($this->once()) + ->method('fetchAll') + ->with($repoApi, 'contributors', [$username, $reponame]) + ->willReturn([]); + + $this->assertEquals([], $paginator->fetchAll($repoApi, 'contributors', [$username, $reponame])); + } + public function testFetch() { $result = ['foo']; @@ -201,6 +236,34 @@ public function testFetchAllWithoutKeys() $this->assertCount(9, $result); } + public function testFetchAll() + { + $content = [ + ['title' => 'issue 1'], + ['title' => 'issue 2'], + ['title' => 'issue 3'], + ]; + + $response = new PaginatedResponse(3, $content); + + // httpClient mock + $httpClientMock = $this->getMockBuilder(HttpClient::class) + ->onlyMethods(['sendRequest']) + ->getMock(); + $httpClientMock + ->expects($this->exactly(3)) + ->method('sendRequest') + ->willReturn($response); + + $client = Client::createWithHttpClient($httpClientMock); + + $api = new Issue($client); + $paginator = new ResultPager($client); + $result = $paginator->fetchAll($api, 'all', ['knplabs', 'php-github-api']); + + $this->assertCount(9, $result); + } + /** * @group legacy */ From 71fec50e228737ec23c0b69801b85bf596fbdaca Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 24 Mar 2024 19:21:15 +0100 Subject: [PATCH 940/951] Update changelog for 3.14.1 release --- CHANGELOG-3.X.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index 44afe4fc8cb..d94de7504b2 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,10 @@ # Changelog +## 3.14.1 + +### Fixed +- Handle case of GitHub returning 204 No Content in some scenarios ([tomcorbett](https://github.com/tomcorbett)) [#1135](https://github.com/KnpLabs/php-github-api/issues/1135) + ## 3.14.0 ### Added From 773747a72f4aad5248d05f109f40291bf8543baf Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Mon, 25 Mar 2024 09:25:55 +0000 Subject: [PATCH 941/951] Fix type error in ResultPager::fetch When using etags, the reply from github may be empty and the underlying APIs will return an empty string. We need to flip those to empty arrays. e.g.: ``` $github_builder ->addPlugin(new Http\Client\Common\Plugin\HeaderSetPlugin([ 'If-None-Match' => $etag, ])); $api = $github_client->user('user'); $paginator = new \Github\ResultPager($github_client); $data = $paginator->fetch($api, 'events', [$username]); // $data should be [] if $etag is the latest ``` --- lib/Github/ResultPager.php | 2 +- test/Github/Tests/ResultPagerTest.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index a1d94785ca6..f23b6c6f418 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -86,7 +86,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []): $api = $closure($api); $result = $api->$method(...$parameters); - if ($result === '' && $this->client->getLastResponse()->getStatusCode() === 204) { + if ($result === '') { $result = []; } diff --git a/test/Github/Tests/ResultPagerTest.php b/test/Github/Tests/ResultPagerTest.php index 3df610ee250..b898528483b 100644 --- a/test/Github/Tests/ResultPagerTest.php +++ b/test/Github/Tests/ResultPagerTest.php @@ -7,6 +7,7 @@ use Github\Api\Repo; use Github\Api\Repository\Statuses; use Github\Api\Search; +use Github\Api\User; use Github\Client; use Github\ResultPager; use Github\Tests\Mock\PaginatedResponse; @@ -176,6 +177,29 @@ public function testFetch() $this->assertEquals($result, $paginator->fetch($api, $method, $parameters)); } + public function testEmptyFetch() + { + $parameters = ['username']; + $api = $this->getMockBuilder(User::class) + ->disableOriginalConstructor() + ->onlyMethods(['events']) + ->getMock(); + $api->expects($this->once()) + ->method('events') + ->with(...$parameters) + ->willReturn(''); + + $paginator = $this->getMockBuilder(ResultPager::class) + ->disableOriginalConstructor() + ->onlyMethods(['postFetch']) + ->getMock(); + + $paginator->expects($this->once()) + ->method('postFetch'); + + $this->assertEquals([], $paginator->fetch($api, 'events', $parameters)); + } + public function testFetchAllPreserveKeys() { $content = [ From 1f77a93c3a28e6b0f95c3cb7bbb7cb0b7853fd2b Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 16 Sep 2024 14:23:51 +0100 Subject: [PATCH 942/951] Add API endpoints to interact with organiztion roles --- doc/README.md | 1 + doc/organization/organization-roles.md | 108 ++++++++++ lib/Github/Api/Organization.php | 6 + .../Api/Organization/OrganizationRoles.php | 61 ++++++ .../Organization/OrganizationRolesTest.php | 187 ++++++++++++++++++ 5 files changed, 363 insertions(+) create mode 100644 doc/organization/organization-roles.md create mode 100644 lib/Github/Api/Organization/OrganizationRoles.php create mode 100644 test/Github/Tests/Api/Organization/OrganizationRolesTest.php diff --git a/doc/README.md b/doc/README.md index 35929c2afc3..17c3604dc35 100644 --- a/doc/README.md +++ b/doc/README.md @@ -44,6 +44,7 @@ v3 APIs: * [Secrets](organization/actions/secrets.md) * [Variables](organization/actions/variables.md) * [Secret Scanning Alert](organization/secret-scanning.md) + * [Organization Roles](organization/organization-roles.md) * [Projects](project/projects.md) * [Columns](project/columns.md) * [Cards](project/cards.md) diff --git a/doc/organization/organization-roles.md b/doc/organization/organization-roles.md new file mode 100644 index 00000000000..a320b6eb047 --- /dev/null +++ b/doc/organization/organization-roles.md @@ -0,0 +1,108 @@ +## Organization / Webhooks API +[Back to the navigation](../README.md) + +Listing, showing, assigning, and removing orgniazationroles. +Wraps [GitHub Organization Roles API](https://docs.github.com/en/rest/orgs/organization-roles). + +Additional APIs: +* [Organization](../doc/organization) + +### List all organizaton roles in an organization + +> Requires [authentication](../security.md). + +```php +$roles = $client->organization()->organizationRoles()->all('acme'); +``` + +Returns a counter and a list of organization roles in the organization. + +### Get an organization role in an organization + +> Requires [authentication](../security.md). + +```php +$role = $client->organization()->organizationRoles()->show('acme', 123); +``` + +Returns a single organization role in the organization. + +### List all teams with role assigned in an organization + +> Requires [authentication](../security.md). + +```php +$users = $client->organization()->organizationRoles()->listTeamsWithRole('acme', 1); +``` + +Returns a list of teams with the role assigned to them. + +### Assign a single role to a team in an organization + +> Requires [authentication](../security.md). + +```php +$client->organization()->organizationRoles()->assignRoleToTeam('acme', 1, 'admin-user'); +``` + +No content is returned. + +### Remove a single role from a team in an organization + +> Requires [authentication](../security.md). + +```php +$client->organization()->organizationRoles()->removeRoleFromTeam('acme', 1, 'admin-team'); +``` + +No content is returned. + +### Remove all roles from a team in an organization + +> Requires [authentication](../security.md). + +```php +$client->organization()->organizationRoles()->removeAllRolesFromTeam('acme', 'admin-team'); +``` + +No content is returned. + +### List all users with role assigned in an organization + +> Requires [authentication](../security.md). + +```php +$users = $client->organization()->organizationRoles()->listUsersWithRole('acme', 1); +``` + +Returns a list of users with the role assigned to them. + +### Assign a single role to a user in an organization + +> Requires [authentication](../security.md). + +```php +$client->organization()->organizationRoles()->assignRoleToUser('acme', 1, 'admin-user'); +``` + +No content is returned. + +### Remove a single role from a user in an organization + +> Requires [authentication](../security.md). + +```php +$client->organization()->organizationRoles()->removeRoleFromUser('acme', 1, 'admin-user'); +``` + +No content is returned. + +### Remove all roles from a user in an organization + +> Requires [authentication](../security.md). + +```php +$client->organization()->organizationRoles()->removeAllRolesFromUser('acme', 'admin-user'); +``` + +No content is returned. diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index ada7e66836d..0e1210c95b6 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -7,6 +7,7 @@ use Github\Api\Organization\Actions\Variables; use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; +use Github\Api\Organization\OrganizationRoles; use Github\Api\Organization\OutsideCollaborators; use Github\Api\Organization\SecretScanning; use Github\Api\Organization\Teams; @@ -158,4 +159,9 @@ public function secretScanning(): SecretScanning { return new SecretScanning($this->getClient()); } + + public function organizationRoles(): OrganizationRoles + { + return new OrganizationRoles($this->getClient()); + } } diff --git a/lib/Github/Api/Organization/OrganizationRoles.php b/lib/Github/Api/Organization/OrganizationRoles.php new file mode 100644 index 00000000000..dd44fceceaf --- /dev/null +++ b/lib/Github/Api/Organization/OrganizationRoles.php @@ -0,0 +1,61 @@ +get('/orgs/'.rawurlencode($organization).'/organization-roles'); + } + + public function show(string $organization, int $roleId) + { + return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles/'.$roleId); + } + + public function listTeamsWithRole(string $organization, int $roleId) + { + return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles/'.$roleId.'/teams'); + } + + public function assignRoleToTeam(string $organization, int $roleId, string $teamSlug): void + { + $this->put('/orgs/'.rawurlencode($organization).'/organization-roles/teams/'.rawurlencode($teamSlug).'/'.$roleId); + } + + public function removeRoleFromTeam(string $organization, int $roleId, string $teamSlug): void + { + $this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/teams/'.rawurlencode($teamSlug).'/'.$roleId); + } + + public function removeAllRolesFromTeam(string $organization, string $teamSlug): void + { + $this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/teams/'.rawurlencode($teamSlug)); + } + + public function listUsersWithRole(string $organization, int $roleId): array + { + return $this->get('/orgs/'.rawurlencode($organization).'/organization-roles/'.$roleId.'/users'); + } + + public function assignRoleToUser(string $organization, int $roleId, string $username): void + { + $this->put('/orgs/'.rawurlencode($organization).'/organization-roles/users/'.rawurlencode($username).'/'.$roleId); + } + + public function removeRoleFromUser(string $organization, int $roleId, string $username): void + { + $this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/users/'.rawurlencode($username).'/'.$roleId); + } + + public function removeAllRolesFromUser(string $organization, string $username): void + { + $this->delete('/orgs/'.rawurlencode($organization).'/organization-roles/users/'.rawurlencode($username)); + } +} diff --git a/test/Github/Tests/Api/Organization/OrganizationRolesTest.php b/test/Github/Tests/Api/Organization/OrganizationRolesTest.php new file mode 100644 index 00000000000..f2d801afceb --- /dev/null +++ b/test/Github/Tests/Api/Organization/OrganizationRolesTest.php @@ -0,0 +1,187 @@ + 1, + 'roles' => [[ + 'id' => 1, + 'name' => 'all_repo_admin', + 'description' => 'Grants admin access to all repositories in the organization.', + 'permissions' => [], + 'organization' => null, + 'created_at' => '2023-01-01T00:00:00Z', + 'updated_at' => '2023-01-01T00:00:00Z', + 'source' => 'Predefined', + 'base_role' => 'admin', + ]], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/acme/organization-roles') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('acme')); + } + + /** + * @test + */ + public function shouldShowSingleOrganizationRole() + { + $expectedValue = [ + 'id' => 1, + 'name' => 'all_repo_admin', + 'description' => 'Grants admin access to all repositories in the organization.', + 'permissions' => [], + 'organization' => null, + 'created_at' => '2023-01-01T00:00:00Z', + 'updated_at' => '2023-01-01T00:00:00Z', + 'source' => 'Predefined', + 'base_role' => 'admin', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/acme/organization-roles/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('acme', 1)); + } + + /** + * @test + */ + public function shouldGetAllTeamsWithRole() + { + $expectedValue = [['name' => 'Acme Admins']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/acme/organization-roles/1/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->listTeamsWithRole('acme', 1)); + } + + /** + * @test + */ + public function shouldAssignRoleToTeam() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/orgs/acme/organization-roles/teams/acme-admins/1') + ->will($this->returnValue('')); + + $api->assignRoleToTeam('acme', 1, 'acme-admins'); + } + + /** + * @test + */ + public function shouldRemoveRoleFromTeam() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/orgs/acme/organization-roles/teams/acme-admins/1') + ->will($this->returnValue('')); + + $api->removeRoleFromTeam('acme', 1, 'acme-admins'); + } + + /** + * @test + */ + public function shouldRemoveAllRolesFromTeam() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/orgs/acme/organization-roles/teams/acme-admins') + ->will($this->returnValue('')); + + $api->removeAllRolesFromTeam('acme', 'acme-admins'); + } + + /** + * @test + */ + public function shouldGetAllUsersWithRole() + { + $expectedValue = [['username' => 'Admin']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/acme/organization-roles/1/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->listUsersWithRole('acme', 1)); + } + + /** + * @test + */ + public function shouldAssignRoleToUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/orgs/acme/organization-roles/users/admin/1') + ->will($this->returnValue('')); + + $api->assignRoleToUser('acme', 1, 'admin'); + } + + /** + * @test + */ + public function shouldRemoveRoleFromUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/orgs/acme/organization-roles/users/admin/1') + ->will($this->returnValue('')); + + $api->removeRoleFromUser('acme', 1, 'admin'); + } + + /** + * @test + */ + public function shouldRemoveAllRolesFromUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/orgs/acme/organization-roles/users/admin') + ->will($this->returnValue('')); + + $api->removeAllRolesFromUser('acme', 'admin'); + } + + protected function getApiClass(): string + { + return OrganizationRoles::class; + } +} From 00ab97b4cfce9cc9f07a860ae38f573a40f9d763 Mon Sep 17 00:00:00 2001 From: Eirik Stanghelle Morland Date: Mon, 23 Sep 2024 20:46:31 +0200 Subject: [PATCH 943/951] feature #1144 Fix implicit nullable types to avoid PHP 8.4 warnings (eiriksm, acrobat) This PR was squashed before being merged into the 3.14-dev branch. Discussion ---------- Commits ------- 9bd8e00fe8063bba2aff831c150a2b4b54302f22 Fix implicit nullable types to avoid PHP 8.4 warnings ad84a65147b6c54036a90798b14e23b39461c310 Fix a param that was not supposed to be nullable a35a8295e33d8757ddec2fdcaeca74075cb904ca Update ci.yml 297f04e3c7665fcb1b74cf662fafa2c8d469f631 Fixes with phpcbf 1b635980ac3f1ee264b65196188340a6240be800 Fix implicit nullable case in tests 6d145f54832ea5e7d1c8c488149c9d39c38dd56d Fix upstream deprecation warnings --- .github/workflows/ci.yml | 4 +++- composer.json | 2 +- lib/Github/Api/Notification.php | 4 ++-- lib/Github/Api/Repository/Actions/Workflows.php | 2 +- lib/Github/Api/Repository/Contents.php | 6 +++--- lib/Github/Client.php | 2 +- lib/Github/Exception/ApiLimitExceedException.php | 2 +- lib/Github/Exception/MissingArgumentException.php | 2 +- lib/Github/Exception/SsoRequiredException.php | 2 +- .../Exception/TwoFactorAuthenticationRequiredException.php | 2 +- lib/Github/HttpClient/Builder.php | 6 +++--- lib/Github/ResultPager.php | 2 +- test/Github/Tests/Api/AbstractApiTest.php | 3 ++- test/Github/Tests/Functional/CacheTest.php | 3 ++- .../Tests/HttpClient/Message/ResponseMediatorTest.php | 7 ++++--- .../Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php | 2 +- test/Github/Tests/Mock/PaginatedResponse.php | 7 ++++--- 17 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 923f2ce49c9..9c46d891719 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - uses: actions/checkout@v4 @@ -27,6 +27,8 @@ jobs: - name: Run phpunit run: vendor/bin/phpunit --verbose + env: + SYMFONY_DEPRECATIONS_HELPER: 'max[self]=0' phpstan: name: PHPStan diff --git a/composer.json b/composer.json index f3d598d6940..c1da1aefbca 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "require-dev": { "symfony/cache": "^5.1.8", - "guzzlehttp/psr7": "^1.7", + "guzzlehttp/psr7": "^2.7", "http-interop/http-factory-guzzle": "^1.0", "guzzlehttp/guzzle": "^7.2", "php-http/mock-client": "^1.4.1", diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index e8c9b246a11..f720ad0c88c 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -27,7 +27,7 @@ class Notification extends AbstractApi * * @return array array of notifications */ - public function all($includingRead = false, $participating = false, DateTime $since = null, DateTime $before = null) + public function all($includingRead = false, $participating = false, ?DateTime $since = null, ?DateTime $before = null) { $parameters = [ 'all' => $includingRead, @@ -54,7 +54,7 @@ public function all($includingRead = false, $participating = false, DateTime $si * * @param DateTime|null $since */ - public function markRead(DateTime $since = null) + public function markRead(?DateTime $since = null) { $parameters = []; diff --git a/lib/Github/Api/Repository/Actions/Workflows.php b/lib/Github/Api/Repository/Actions/Workflows.php index e425f9d2651..9a1c9e31c7b 100644 --- a/lib/Github/Api/Repository/Actions/Workflows.php +++ b/lib/Github/Api/Repository/Actions/Workflows.php @@ -70,7 +70,7 @@ public function usage(string $username, string $repository, $workflow) * * @return array|string empty */ - public function dispatches(string $username, string $repository, $workflow, string $ref, array $inputs = null) + public function dispatches(string $username, string $repository, $workflow, string $ref, ?array $inputs = null) { if (is_string($workflow)) { $workflow = rawurlencode($workflow); diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index b6e170ebce0..a3cc1a3ea0e 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -98,7 +98,7 @@ public function show($username, $repository, $path = null, $reference = null, $r * * @return array information about the new file */ - public function create($username, $repository, $path, $content, $message, $branch = null, array $committer = null) + public function create($username, $repository, $path, $content, $message, $branch = null, ?array $committer = null) { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); @@ -174,7 +174,7 @@ public function exists($username, $repository, $path, $reference = null) * * @return array information about the updated file */ - public function update($username, $repository, $path, $content, $message, $sha, $branch = null, array $committer = null) + public function update($username, $repository, $path, $content, $message, $sha, $branch = null, ?array $committer = null) { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); @@ -215,7 +215,7 @@ public function update($username, $repository, $path, $content, $message, $sha, * * @return array information about the updated file */ - public function rm($username, $repository, $path, $message, $sha, $branch = null, array $committer = null) + public function rm($username, $repository, $path, $message, $sha, $branch = null, ?array $committer = null) { $url = '/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/contents/'.rawurlencode($path); diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 56d68d59cec..77fcc7b71a2 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -123,7 +123,7 @@ class Client * @param string|null $apiVersion * @param string|null $enterpriseUrl */ - public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) + public function __construct(?Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); $this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder(); diff --git a/lib/Github/Exception/ApiLimitExceedException.php b/lib/Github/Exception/ApiLimitExceedException.php index 5c1dd4d8a17..c21f5c2729e 100644 --- a/lib/Github/Exception/ApiLimitExceedException.php +++ b/lib/Github/Exception/ApiLimitExceedException.php @@ -20,7 +20,7 @@ class ApiLimitExceedException extends RuntimeException * @param int $code * @param Throwable|null $previous */ - public function __construct(int $limit = 5000, int $reset = 1800, int $code = 0, Throwable $previous = null) + public function __construct(int $limit = 5000, int $reset = 1800, int $code = 0, ?Throwable $previous = null) { $this->limit = (int) $limit; $this->reset = (int) $reset; diff --git a/lib/Github/Exception/MissingArgumentException.php b/lib/Github/Exception/MissingArgumentException.php index 4cd3aeca81d..742cdc5ac7f 100644 --- a/lib/Github/Exception/MissingArgumentException.php +++ b/lib/Github/Exception/MissingArgumentException.php @@ -14,7 +14,7 @@ class MissingArgumentException extends ErrorException * @param int $code * @param Throwable|null $previous */ - public function __construct($required, int $code = 0, Throwable $previous = null) + public function __construct($required, int $code = 0, ?Throwable $previous = null) { if (is_string($required)) { $required = [$required]; diff --git a/lib/Github/Exception/SsoRequiredException.php b/lib/Github/Exception/SsoRequiredException.php index 1725270a036..09b9d63db08 100644 --- a/lib/Github/Exception/SsoRequiredException.php +++ b/lib/Github/Exception/SsoRequiredException.php @@ -14,7 +14,7 @@ class SsoRequiredException extends RuntimeException * @param int $code * @param Throwable|null $previous */ - public function __construct(string $url, int $code = 0, Throwable $previous = null) + public function __construct(string $url, int $code = 0, ?Throwable $previous = null) { $this->url = $url; diff --git a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php index c57e67b8e1d..139033dff5b 100644 --- a/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php +++ b/lib/Github/Exception/TwoFactorAuthenticationRequiredException.php @@ -14,7 +14,7 @@ class TwoFactorAuthenticationRequiredException extends RuntimeException * @param int $code * @param Throwable|null $previous */ - public function __construct(string $type, int $code = 0, Throwable $previous = null) + public function __construct(string $type, int $code = 0, ?Throwable $previous = null) { $this->type = $type; parent::__construct('Two factor authentication is enabled on this account', $code, $previous); diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index a8713de13bc..c77f1ac83d8 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -78,9 +78,9 @@ class Builder * @param StreamFactoryInterface|null $streamFactory */ public function __construct( - ClientInterface $httpClient = null, - RequestFactoryInterface $requestFactory = null, - StreamFactoryInterface $streamFactory = null + ?ClientInterface $httpClient = null, + ?RequestFactoryInterface $requestFactory = null, + ?StreamFactoryInterface $streamFactory = null ) { $this->httpClient = $httpClient ?? Psr18ClientDiscovery::find(); $this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory(); diff --git a/lib/Github/ResultPager.php b/lib/Github/ResultPager.php index a1d94785ca6..4583e5e1268 100644 --- a/lib/Github/ResultPager.php +++ b/lib/Github/ResultPager.php @@ -59,7 +59,7 @@ class ResultPager implements ResultPagerInterface * * @return void */ - public function __construct(Client $client, int $perPage = null) + public function __construct(Client $client, ?int $perPage = null) { if (null !== $perPage && ($perPage < 1 || $perPage > 100)) { throw new ValueError(sprintf('%s::__construct(): Argument #2 ($perPage) must be between 1 and 100, or null', self::class)); diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index 428ece12cf3..53e0eb6970a 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -4,6 +4,7 @@ use Github\Api\AbstractApi; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use Http\Client\Common\HttpMethodsClientInterface; class AbstractApiTest extends TestCase @@ -232,7 +233,7 @@ private function getPSR7Response($expectedArray) return new Response( 200, ['Content-Type' => 'application/json'], - \GuzzleHttp\Psr7\stream_for(json_encode($expectedArray)) + Utils::streamFor(json_encode($expectedArray)) ); } } diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index eef379e61d5..bd217dc5dc2 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -5,6 +5,7 @@ use Github\AuthMethod; use Github\Client; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use Symfony\Component\Cache\Adapter\ArrayAdapter; /** @@ -61,7 +62,7 @@ private function getCurrentUserResponse($username) 'Content-Type' => 'application/json', ]; - $body = \GuzzleHttp\Psr7\stream_for(json_encode([ + $body = Utils::streamFor(json_encode([ 'login' => $username, ])); diff --git a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php index 5171ab0bac8..b6216d57044 100644 --- a/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php +++ b/test/Github/Tests/HttpClient/Message/ResponseMediatorTest.php @@ -4,6 +4,7 @@ use Github\HttpClient\Message\ResponseMediator; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; /** * @author Tobias Nyholm @@ -16,7 +17,7 @@ public function testGetContent() $response = new Response( 200, ['Content-Type' => 'application/json'], - \GuzzleHttp\Psr7\stream_for(json_encode($body)) + Utils::streamFor(json_encode($body)) ); $this->assertEquals($body, ResponseMediator::getContent($response)); @@ -31,7 +32,7 @@ public function testGetContentNotJson() $response = new Response( 200, [], - \GuzzleHttp\Psr7\stream_for($body) + Utils::streamFor($body) ); $this->assertEquals($body, ResponseMediator::getContent($response)); @@ -46,7 +47,7 @@ public function testGetContentInvalidJson() $response = new Response( 200, ['Content-Type' => 'application/json'], - \GuzzleHttp\Psr7\stream_for($body) + Utils::streamFor($body) ); $this->assertEquals($body, ResponseMediator::getContent($response)); diff --git a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php index b2541ec0942..7cb7dfe33a8 100644 --- a/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php +++ b/test/Github/Tests/HttpClient/Plugin/GithubExceptionThrowerTest.php @@ -20,7 +20,7 @@ class GithubExceptionThrowerTest extends TestCase /** * @dataProvider responseProvider */ - public function testHandleRequest(ResponseInterface $response, ExceptionInterface $exception = null): void + public function testHandleRequest(ResponseInterface $response, ?ExceptionInterface $exception = null): void { $request = new Request('GET', 'https://api.github.com/issues'); diff --git a/test/Github/Tests/Mock/PaginatedResponse.php b/test/Github/Tests/Mock/PaginatedResponse.php index 9d67b9f42be..296adf86457 100644 --- a/test/Github/Tests/Mock/PaginatedResponse.php +++ b/test/Github/Tests/Mock/PaginatedResponse.php @@ -3,6 +3,7 @@ namespace Github\Tests\Mock; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; /** * @author Tobias Nyholm @@ -18,10 +19,10 @@ public function __construct($loopCount, array $content = []) $this->loopCount = $loopCount; $this->content = $content; - parent::__construct(200, ['Content-Type' => 'application/json'], \GuzzleHttp\Psr7\stream_for(json_encode($content))); + parent::__construct(200, ['Content-Type' => 'application/json'], Utils::streamFor(json_encode($content))); } - public function getHeader($header) + public function getHeader($header): array { if ($header === 'Link') { if ($this->loopCount > 1) { @@ -38,7 +39,7 @@ public function getHeader($header) return parent::getHeader($header); } - public function hasHeader($header) + public function hasHeader($header): bool { if ($header === 'Link') { return true; From a6f0f4f46be78a047d48ff3f6ae024c065664177 Mon Sep 17 00:00:00 2001 From: anthony-webart <43772613+anthony-webart@users.noreply.github.com> Date: Tue, 24 Sep 2024 02:49:11 +0800 Subject: [PATCH 944/951] feature #1142 Copilot Usage Endpoints (anthony-webart) This PR was squashed before being merged into the 3.14-dev branch. Discussion ---------- Commits ------- f4e822eceede81d302f63cf96e580a816e345824 Add Copilot usage endpoints e16a14c94cc1dbabe4bc4b57e328cef24061d40d Reformat code 3698933a3246ecc363a986151cbed483c84b7999 Fix incorrect team urls 956fe9eb4d7596765710fd5914020fa2cf0068ac Add Copilot Usage API Documentation detailing endpoints for retrieving usage summaries. --- doc/copilot/usage.md | 80 +++++++++++++++++++++ lib/Github/Api/Copilot/Usage.php | 34 +++++++++ lib/Github/Client.php | 5 ++ test/Github/Tests/Api/Copilot/UsageTest.php | 78 ++++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 doc/copilot/usage.md create mode 100644 lib/Github/Api/Copilot/Usage.php create mode 100644 test/Github/Tests/Api/Copilot/UsageTest.php diff --git a/doc/copilot/usage.md b/doc/copilot/usage.md new file mode 100644 index 00000000000..6005adc1600 --- /dev/null +++ b/doc/copilot/usage.md @@ -0,0 +1,80 @@ +# Copilot Usage API Documentation +[Back to the navigation](../README.md) + +## Overview + +The Copilot Usage API provides endpoints to retrieve usage summaries for organizations and enterprises. + +**Note**: This endpoint is in beta and is subject to change. + +## Endpoints + +### Organization Usage Summary + +Retrieve the usage summary for a specific organization. + +**Method:** `GET` + +**Endpoint:** `/orgs/{organization}/copilot/usage` + +**Parameters:** +- `organization` (string): The name of the organization. +- `params` (array, optional): Additional query parameters. + +**Example:** +```php +$usage = $client->api('copilotUsage')->orgUsageSummary('KnpLabs'); +``` + +### Organization Team Usage Summary + +Retrieve the usage summary for a specific team within an organization. + +**Method:** `GET` + +**Endpoint:** `/orgs/{organization}/team/{team}/copilot/usage` + +**Parameters:** +- `organization` (string): The name of the organization. +- `team` (string): The name of the team. +- `params` (array, optional): Additional query parameters. + +**Example:** +```php +$usage = $client->api('copilotUsage')->orgTeamUsageSummary('KnpLabs', 'developers'); +``` + +### Enterprise Usage Summary + +Retrieve the usage summary for a specific enterprise. + +**Method:** `GET` + +**Endpoint:** `/enterprises/{enterprise}/copilot/usage` + +**Parameters:** +- `enterprise` (string): The name of the enterprise. +- `params` (array, optional): Additional query parameters. + +**Example:** +```php +$usage = $client->api('copilotUsage')->enterpriseUsageSummary('KnpLabs'); +``` + +### Enterprise Team Usage Summary + +Retrieve the usage summary for a specific team within an enterprise. + +**Method:** `GET` + +**Endpoint:** `/enterprises/{enterprise}/team/{team}/copilot/usage` + +**Parameters:** +- `enterprise` (string): The name of the enterprise. +- `team` (string): The name of the team. +- `params` (array, optional): Additional query parameters. + +**Example:** +```php +$usage = $client->api('copilotUsage')->enterpriseTeamUsageSummary('KnpLabs', 'developers'); +``` diff --git a/lib/Github/Api/Copilot/Usage.php b/lib/Github/Api/Copilot/Usage.php new file mode 100644 index 00000000000..0110a58bb40 --- /dev/null +++ b/lib/Github/Api/Copilot/Usage.php @@ -0,0 +1,34 @@ +get('/orgs/'.rawurlencode($organization).'/copilot/usage', $params); + } + + public function orgTeamUsageSummary(string $organization, string $teamSlug, array $params = []): array + { + return $this->get( + '/orgs/'.rawurlencode($organization).'/team/'.rawurlencode($teamSlug).'/copilot/usage', + $params + ); + } + + public function enterpriseUsageSummary(string $enterprise, array $params = []): array + { + return $this->get('/enterprises/'.rawurlencode($enterprise).'/copilot/usage', $params); + } + + public function enterpriseTeamUsageSummary(string $enterprise, string $teamSlug, array $params = []): array + { + return $this->get( + '/enterprises/'.rawurlencode($enterprise).'/team/'.rawurlencode($teamSlug).'/copilot/usage', + $params + ); + } +} diff --git a/lib/Github/Client.php b/lib/Github/Client.php index 77fcc7b71a2..49ff9e1a9bc 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -301,6 +301,11 @@ public function api($name): AbstractApi $api = new Api\Organization\OutsideCollaborators($this); break; + case 'copilotUsage': + case 'copilot_usage': + $api = new Api\Copilot\Usage($this); + break; + default: throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); } diff --git a/test/Github/Tests/Api/Copilot/UsageTest.php b/test/Github/Tests/Api/Copilot/UsageTest.php new file mode 100644 index 00000000000..c14c3e3ffa8 --- /dev/null +++ b/test/Github/Tests/Api/Copilot/UsageTest.php @@ -0,0 +1,78 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/copilot/usage', []) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->orgUsageSummary('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetOrgTeamUsageSummary(): void + { + $expectedValue = ['usage1', 'usage2']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/team/php-github-api/copilot/usage', []) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->orgTeamUsageSummary('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetEnterpriseUsageSummary(): void + { + $expectedValue = ['usage1', 'usage2']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/enterprises/KnpLabs/copilot/usage', []) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->enterpriseUsageSummary('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetEnterpriseTeamUsageSummary(): void + { + $expectedValue = ['usage1', 'usage2']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/enterprises/KnpLabs/team/php-github-api/copilot/usage', []) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->enterpriseTeamUsageSummary('KnpLabs', 'php-github-api')); + } + + protected function getApiClass(): string + { + return Usage::class; + } +} From d4b7a1c00e22c1ca32408ecdd4e33c674196b1bc Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 23 Sep 2024 21:00:43 +0200 Subject: [PATCH 945/951] Update changelog for 3.15.0 release --- CHANGELOG-3.X.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index d94de7504b2..f892d41eaac 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,13 @@ # Changelog +## 3.15.0 + +### Added +- Fix implicit nullable types to avoid PHP 8.4 warnings ([eiriksm](https://github.com/eiriksm), [acrobat](https://github.com/acrobat)) [#1144](https://github.com/KnpLabs/php-github-api/issues/1144) +- Add API endpoints to interact with organization roles ([glaubinix](https://github.com/glaubinix)) [#1143](https://github.com/KnpLabs/php-github-api/issues/1143) +- Copilot Usage Endpoints ([anthony-webart](https://github.com/anthony-webart)) [#1142](https://github.com/KnpLabs/php-github-api/issues/1142) +- Fix type error in ResultPager::fetch ([nunoplopes](https://github.com/nunoplopes)) [#1132](https://github.com/KnpLabs/php-github-api/issues/1132) + ## 3.14.1 ### Fixed From 845545b0686e0dbbafe0972a8b5b9f86be856976 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Mon, 23 Sep 2024 21:00:48 +0200 Subject: [PATCH 946/951] Update composer branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c1da1aefbca..a797918fc07 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.14-dev" + "dev-master": "3.15-dev" } }, "config": { From 48e025e19dcd3d7a0a8d1a48d5df077a52454ac0 Mon Sep 17 00:00:00 2001 From: Martin Parsiegla Date: Sat, 17 Aug 2024 19:05:16 +0200 Subject: [PATCH 947/951] Add API to rerequest a check run This change adds a new method to rerequest a check run (see also https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#rerequest-a-check-run). --- doc/repo/check_runs.md | 6 +++++- lib/Github/Api/Repository/Checks/CheckRuns.php | 10 ++++++++++ .../Tests/Api/Repository/Checks/CheckRunsTest.php | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/repo/check_runs.md b/doc/repo/check_runs.md index b0aa4926691..3b7b69b8f86 100644 --- a/doc/repo/check_runs.md +++ b/doc/repo/check_runs.md @@ -62,6 +62,10 @@ $params = [/*...*/]; $checks = $client->api('repo')->checkRuns()->allForReference('KnpLabs', 'php-github-api', $reference, $params); ``` +### Rerequest a check run +https://docs.github.com/en/rest/reference/checks#rerequest-a-check-run - +```php +$checks = $client->api('repo')->checkRuns()->rerequest('KnpLabs', 'php-github-api', $checkRunId); +``` diff --git a/lib/Github/Api/Repository/Checks/CheckRuns.php b/lib/Github/Api/Repository/Checks/CheckRuns.php index 37968a01816..1ddee3770c8 100644 --- a/lib/Github/Api/Repository/Checks/CheckRuns.php +++ b/lib/Github/Api/Repository/Checks/CheckRuns.php @@ -83,4 +83,14 @@ public function allForReference(string $username, string $repository, string $re return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); } + + /** + * @link https://docs.github.com/en/rest/reference/checks#rerequest-a-check-run + * + * @return array + */ + public function rerequest(string $username, string $repository, int $checkRunId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId.'/rerequest'); + } } diff --git a/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php b/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php index 4b7ff086ec5..66bb5277c4b 100644 --- a/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php +++ b/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php @@ -102,6 +102,20 @@ public function shouldGetAllChecksForReference() $api->allForReference('KnpLabs', 'php-github-api', 'cb4abc15424c0015b4468d73df55efb8b60a4a3d', $params); } + /** + * @test + */ + public function shouldRerequestCheckRun() + { + /** @var CheckRuns|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/check-runs/123/rerequest'); + + $api->rerequest('KnpLabs', 'php-github-api', 123); + } + protected function getApiClass(): string { return CheckRuns::class; From d72323c433b3b1ee78cbb29689872c526ec6a36e Mon Sep 17 00:00:00 2001 From: Luke Spencer Date: Thu, 7 Nov 2024 19:34:12 +0000 Subject: [PATCH 948/951] feature #1146 List pull requests associated with a commit (lmjhs) This PR was squashed before being merged into the 3.15-dev branch. Discussion ---------- Added missing `pulls` method to repository commits to allow fetching of pull requests for a commit sha. [List pull requests associated with a commit](https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit) Commits ------- 46c18965fec4ca72d3e78769f760580926cf766c Commit Pulls 5727a4327e30301e448820750d8a98841e1ad866 Update tests c0a48e2196b8e77cc65fa71af69d7d284ecd8123 Added documentation --- doc/commits.md | 8 ++++++++ lib/Github/Api/Repository/Commits.php | 5 +++++ .../Tests/Api/Repository/CommitsTest.php | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/doc/commits.md b/doc/commits.md index 741af0713a2..165d71ecae2 100644 --- a/doc/commits.md +++ b/doc/commits.md @@ -35,3 +35,11 @@ $commit = $client->api('repo')->commits()->compare('KnpLabs', 'php-github-api', ``` Returns an array of commits. + +### List pull requests associated with a commit + +```php +$commit = $client->api('repo')->commits()->pulls('KnpLabs', 'php-github-api', '839e5185da9434753db47959bee16642bb4f2ce4'); +``` + +Returns an array of pull requests. \ No newline at end of file diff --git a/lib/Github/Api/Repository/Commits.php b/lib/Github/Api/Repository/Commits.php index 383905d28f2..0bc5598cbff 100644 --- a/lib/Github/Api/Repository/Commits.php +++ b/lib/Github/Api/Repository/Commits.php @@ -30,4 +30,9 @@ public function show($username, $repository, $sha) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha)); } + + public function pulls($username, $repository, $sha, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($sha).'/pulls', $params); + } } diff --git a/test/Github/Tests/Api/Repository/CommitsTest.php b/test/Github/Tests/Api/Repository/CommitsTest.php index 25ef2536a1c..9d1b3288afe 100644 --- a/test/Github/Tests/Api/Repository/CommitsTest.php +++ b/test/Github/Tests/Api/Repository/CommitsTest.php @@ -55,6 +55,25 @@ public function shouldShowCommitUsingSha() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); } + /** + * @test + */ + public function shouldGetAllPullRequestsUsingSha() + { + $expectedValue = [ + ['number' => '1', 'title' => 'My first PR'], + ['number' => '2', 'title' => 'Another PR'], + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/commits/123/pulls') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->pulls('KnpLabs', 'php-github-api', 123)); + } + /** * @return string */ From 25d7bafd6b0dd088d4850aef7fcc74dc4fba8b28 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 7 Nov 2024 20:35:30 +0100 Subject: [PATCH 949/951] Update changelog for 3.16.0 release --- CHANGELOG-3.X.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG-3.X.md b/CHANGELOG-3.X.md index f892d41eaac..f26bcc96430 100644 --- a/CHANGELOG-3.X.md +++ b/CHANGELOG-3.X.md @@ -1,5 +1,11 @@ # Changelog +## 3.16.0 + +### Added +- Add API to rerequest a check run ([Spea](https://github.com/Spea)) [#1141](https://github.com/KnpLabs/php-github-api/issues/1141) +- List pull requests associated with a commit ([lmjhs](https://github.com/lmjhs)) [#1146](https://github.com/KnpLabs/php-github-api/issues/1146) + ## 3.15.0 ### Added From 663af584732bb385df7bc6b2a9daba8cc1032418 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 7 Nov 2024 20:35:35 +0100 Subject: [PATCH 950/951] Update composer branch-alias --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a797918fc07..da450bc019d 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.15-dev" + "dev-master": "3.16-dev" } }, "config": { From e01e2af5eb761b4498347a9e43ee93df2bdb8646 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 03:26:59 +0000 Subject: [PATCH 951/951] Bump actions/checkout from 4 to 5 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/backwards-compatibility.yml | 2 +- .github/workflows/ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/backwards-compatibility.yml b/.github/workflows/backwards-compatibility.yml index e6418f67a84..93dd8cc62cc 100644 --- a/.github/workflows/backwards-compatibility.yml +++ b/.github/workflows/backwards-compatibility.yml @@ -8,7 +8,7 @@ jobs: name: "Roave BC check" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: fetch-depth: 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c46d891719..c8448f615c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: shivammathur/setup-php@v2 with: