From 59ba94c11d4786625c44eabb410d476b7ba01840 Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Mon, 12 Jun 2017 09:56:48 -0700 Subject: [PATCH 001/379] 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 002/379] 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 003/379] 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 004/379] 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 005/379] 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 006/379] 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 007/379] 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 008/379] 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 009/379] 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 010/379] 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 011/379] 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 012/379] 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 013/379] 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 014/379] 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 015/379] 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 016/379] 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 017/379] 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 018/379] 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 019/379] 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 020/379] 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 021/379] 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 022/379] 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 023/379] 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 024/379] 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 025/379] 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 026/379] 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 027/379] 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 028/379] 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 029/379] 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 030/379] 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 031/379] 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 032/379] 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 033/379] 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 034/379] 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 035/379] 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 036/379] 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 037/379] 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 038/379] 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 039/379] 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 040/379] 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 041/379] 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 042/379] 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 043/379] 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 044/379] 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 045/379] 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 046/379] 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 047/379] 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 048/379] 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 049/379] 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 050/379] 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 051/379] 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 052/379] 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 053/379] 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 054/379] 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 055/379] 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 056/379] 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 057/379] 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 058/379] 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 059/379] 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 060/379] 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 061/379] 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 062/379] 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 063/379] 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 064/379] 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 065/379] 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 066/379] 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 067/379] 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 068/379] 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 069/379] 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 070/379] 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 071/379] 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 072/379] 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 073/379] 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 074/379] 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 075/379] 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 076/379] 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 077/379] 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 078/379] 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 079/379] 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 080/379] 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 081/379] 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 082/379] 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 083/379] 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 084/379] 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 085/379] 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 086/379] 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 087/379] 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 088/379] 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 089/379] 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 090/379] 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 091/379] 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 092/379] 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 093/379] 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 094/379] 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 095/379] 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 096/379] 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 097/379] 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 098/379] 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 099/379] 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 100/379] 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 101/379] 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 102/379] 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 103/379] 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 104/379] 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 105/379] 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 106/379] 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 107/379] 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 108/379] 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 109/379] 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 110/379] 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 111/379] 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 112/379] 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 113/379] 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 114/379] 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 115/379] 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 116/379] 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 117/379] 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 118/379] 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 119/379] 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 120/379] 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 121/379] 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 122/379] 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 123/379] 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 124/379] 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 125/379] 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 126/379] 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 127/379] 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 128/379] 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 129/379] 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 130/379] 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 131/379] 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 132/379] 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 133/379] 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 134/379] 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 135/379] 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 136/379] 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 137/379] 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 138/379] 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 139/379] 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 140/379] 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 141/379] 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 142/379] 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 143/379] 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 144/379] 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 145/379] 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 146/379] 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 147/379] 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 148/379] 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 149/379] 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 150/379] 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 151/379] 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 152/379] 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 153/379] 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 154/379] 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 155/379] 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 156/379] 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 157/379] 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 158/379] 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 159/379] 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 160/379] 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 161/379] 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 162/379] 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 163/379] 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 164/379] 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 165/379] 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 166/379] 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 167/379] 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 168/379] 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 169/379] 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 170/379] 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 171/379] 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 172/379] 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 173/379] 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 174/379] 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 175/379] 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 176/379] 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 177/379] 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 178/379] 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 179/379] 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 180/379] 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 181/379] 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 182/379] 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 183/379] 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 184/379] 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 185/379] 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 186/379] 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 187/379] 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 188/379] 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 189/379] 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 190/379] 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 191/379] 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 192/379] 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 193/379] 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 194/379] 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 195/379] 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 196/379] 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 197/379] 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 198/379] 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 199/379] 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 200/379] 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 201/379] 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 202/379] 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 203/379] 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 204/379] 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 205/379] 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 206/379] 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 207/379] 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 208/379] 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 209/379] 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 210/379] 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 211/379] 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 212/379] 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 213/379] 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 214/379] 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 215/379] 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 216/379] 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 217/379] 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 218/379] 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 219/379] 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 220/379] 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 221/379] 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 222/379] 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 223/379] 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 224/379] 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 225/379] 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 226/379] 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 227/379] 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 228/379] 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 229/379] 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 230/379] 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 231/379] 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 232/379] 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 233/379] 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 234/379] 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 235/379] 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 236/379] 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 237/379] 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 238/379] 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 239/379] 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 240/379] 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 241/379] 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 242/379] 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 243/379] 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 244/379] 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 245/379] 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 246/379] 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 247/379] 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 248/379] 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 249/379] 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 250/379] 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 251/379] 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 252/379] 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 253/379] 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 254/379] 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 255/379] 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 256/379] 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 257/379] 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 258/379] 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 259/379] 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 260/379] 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 261/379] 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 262/379] 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 263/379] 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 264/379] 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 265/379] 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 266/379] 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 267/379] 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 268/379] 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 269/379] 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 270/379] 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 271/379] 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 272/379] 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 273/379] 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 274/379] 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 275/379] 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 276/379] 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 277/379] 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 278/379] 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 279/379] 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 280/379] 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 281/379] 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 282/379] 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 283/379] 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 284/379] 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 285/379] 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 286/379] 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 287/379] 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 288/379] 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 289/379] 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 290/379] 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 291/379] 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 292/379] 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 293/379] 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 294/379] 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 295/379] 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 296/379] 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 297/379] 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 298/379] 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 299/379] 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 300/379] 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 301/379] 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 302/379] 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 303/379] 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 304/379] 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 305/379] 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 306/379] 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 307/379] 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 308/379] 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 309/379] 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 310/379] 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 311/379] 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 312/379] 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 313/379] 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 314/379] 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 315/379] 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 316/379] 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 317/379] 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 318/379] 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 319/379] 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 320/379] 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 321/379] 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 322/379] 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 323/379] 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 324/379] 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 325/379] 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 326/379] 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 327/379] 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 328/379] 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 329/379] 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 330/379] 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 331/379] 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 332/379] 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 333/379] 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 334/379] 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 335/379] 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 336/379] 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 337/379] 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 338/379] 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 339/379] 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 340/379] 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 341/379] 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 342/379] 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 343/379] 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 344/379] 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 345/379] 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 346/379] 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 347/379] 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 348/379] 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 349/379] 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 350/379] 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 351/379] 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 352/379] 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 353/379] 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 354/379] 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 355/379] 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 356/379] 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 357/379] 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 358/379] 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 359/379] 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 360/379] 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 361/379] 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 362/379] 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 363/379] 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 364/379] 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 365/379] 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 366/379] 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 367/379] 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 368/379] 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 369/379] 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 370/379] 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 371/379] 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 372/379] 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 373/379] 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 374/379] 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 375/379] 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 376/379] 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 377/379] 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 378/379] 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 379/379] 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: