From 635423fcb8557dca375de0545ae850ca21e2a10b Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 00:30:28 +0530 Subject: [PATCH 01/13] chore(composer): enable discovery plugin to find installed `PSR-17` factories, `PSR-18` clients and `HTTPlug` factories Signed-off-by: Hari Darshan Gorana --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ef8d0a84f38..aa183b888d3 100644 --- a/composer.json +++ b/composer.json @@ -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 e12366d8f7efe2c02284c5687a549868d6ece796 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 00:31:04 +0530 Subject: [PATCH 02/13] feat: Improve code completion in PhpStorm Signed-off-by: Hari Darshan Gorana --- .phpstorm.meta.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .phpstorm.meta.php diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 00000000000..bc8691cccca --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,66 @@ + \Github\Api\CurrentUser::class, + "current_user" => \Github\Api\CurrentUser::class, + "currentUser" => \Github\Api\CurrentUser::class, + "codeOfConduct" => \Github\Api\Miscellaneous\CodeOfConduct::class, + "deployment" => \Github\Api\Deployment::class, + "deployments" => \Github\Api\Deployment::class, + "ent" => \Github\Api\Enterprise::class, + "enterprise" => \Github\Api\Enterprise::class, + "emojis" => \Github\Api\Miscellaneous\Emojis::class, + "git" => \Github\Api\GitData::class, + "git_data" => \Github\Api\GitData::class, + "gitData" => \Github\Api\GitData::class, + "gist" => \Github\Api\Gists::class, + "gists" => \Github\Api\Gists::class, + "gitignore" => \Github\Api\Miscellaneous\Gitignore::class, + "apps" => \Github\Api\Apps::class, + "issue" => \Github\Api\Issue::class, + "issues" => \Github\Api\Issue::class, + "markdown" => \Github\Api\Markdown::class, + "licenses" => \Github\Api\Miscellaneous\Licenses::class, + "notification" => \Github\Api\Notification::class, + "notifications" => \Github\Api\Notification::class, + "organization" => \Github\Api\Organization::class, + "organizations" => \Github\Api\Organization::class, + "org_project" => \Github\Api\Organization\Projects::class, + "orgProject" => \Github\Api\Organization\Projects::class, + "org_projects" => \Github\Api\Organization\Projects::class, + "orgProjects" => \Github\Api\Organization\Projects::class, + "organization_project" => \Github\Api\Organization\Projects::class, + "organizationProject" => \Github\Api\Organization\Projects::class, + "organization_projects" => \Github\Api\Organization\Projects::class, + "organizationProjects" => \Github\Api\Organization\Projects::class, + "pr" => \Github\Api\PullRequest::class, + "pulls" => \Github\Api\PullRequest::class, + "pullRequest" => \Github\Api\PullRequest::class, + "pull_request" => \Github\Api\PullRequest::class, + "pullRequests" => \Github\Api\PullRequest::class, + "pull_requests" => \Github\Api\PullRequest::class, + "rateLimit" => \Github\Api\RateLimit::class, + "rate_limit" => \Github\Api\RateLimit::class, + "repo" => \Github\Api\Repo::class, + "repos" => \Github\Api\Repo::class, + "repository" => \Github\Api\Repo::class, + "repositories" => \Github\Api\Repo::class, + "search" => \Github\Api\Search::class, + "team" => \Github\Api\Organization\Teams::class, + "teams" => \Github\Api\Organization\Teams::class, + "member" => \Github\Api\Organization\Members::class, + "members" => \Github\Api\Organization\Members::class, + "user" => \Github\Api\User::class, + "users" => \Github\Api\User::class, + "authorization" => \Github\Api\Authorizations::class, + "authorizations" => \Github\Api\Authorizations::class, + "meta" => \Github\Api\Meta::class, + "graphql" => \Github\Api\GraphQL::class, + "outsideCollaborators" => \Github\Api\Organization\OutsideCollaborators::class, + "outside_collaborators" => \Github\Api\Organization\OutsideCollaborators::class, + ])); +} From 44133c8c85a26016de549b3b35cadfdef1a8bbcf Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 00:52:41 +0530 Subject: [PATCH 03/13] feat: Add Secret Scanning Alerts (Enterprise, Organization & Repository) Signed-off-by: Hari Darshan Gorana --- 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 +++++++++++++++++++ 6 files changed, 131 insertions(+) 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 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..0d38b4da5e7 --- /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..25991d34e59 --- /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..1da6aa85038 --- /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); + } +} From 91f1ed9b67543860cf9bb990354630df56e913e3 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 12:35:11 +0530 Subject: [PATCH 04/13] feat: add new argument `$parameters` to `repositories` method and mark all other arguments as deprecated Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/CurrentUser.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index b5cbc89a376..e6a6d4c2ee9 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -9,6 +9,7 @@ use Github\Api\CurrentUser\PublicKeys; use Github\Api\CurrentUser\Starring; use Github\Api\CurrentUser\Watchers; +use JetBrains\PhpStorm\Deprecated; /** * @link http://developer.github.com/v3/users/ @@ -114,15 +115,28 @@ public function teams() * @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 - * @param string $direction direction of sort, asc or desc - * @param string $visibility visibility of repository - * @param string $affiliation relationship to repository + * @param string $sort sort by (Deprecated) + * @param string $direction direction of sort, asc or desc (Deprecated) + * @param string $visibility visibility of repository (Deprecated) + * @param string $affiliation relationship to repository (Deprecated) + * @param array $parameters e.g. [ + * 'type' => 'owner', + * 'sort' => 'full_name', + * 'direction'=> 'asc', + * 'visibility' => null, + * 'affiliation' => null, + * ] * * @return array */ - public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = null, $affiliation = null) - { + public function repositories( + #[Deprecated(since: '3.12')]$type = 'owner', + #[Deprecated(since: '3.12')]$sort = 'full_name', + #[Deprecated(since: '3.12')]$direction = 'asc', + #[Deprecated(since: '3.12')]$visibility = null, + #[Deprecated(since: '3.12')]$affiliation = null, + array $parameters = [] + ) { $params = [ 'type' => $type, 'sort' => $sort, @@ -139,7 +153,7 @@ public function repositories($type = 'owner', $sort = 'full_name', $direction = $params['affiliation'] = $affiliation; } - return $this->get('/user/repos', $params); + return $this->get('/user/repos', array_merge($params, $parameters)); } /** From 6b1482a8e7b95bb5a84729a6d4a00c50f798c0ad Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 13:25:54 +0530 Subject: [PATCH 05/13] fix: add `$parameters` array to pass additional parameters to `repositories` method and deprecate other arguments. Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/CurrentUser.php | 1 + lib/Github/Api/User.php | 35 +++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index e6a6d4c2ee9..8413e4fd086 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -125,6 +125,7 @@ public function teams() * 'direction'=> 'asc', * 'visibility' => null, * 'affiliation' => null, + * 'per_page' => 50, * ] * * @return array diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index c1ccc89e8c1..06f1e126c44 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -2,6 +2,8 @@ namespace Github\Api; +use JetBrains\PhpStorm\Deprecated; + /** * Searching users, getting user information. * @@ -160,23 +162,38 @@ 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 $visibility visibility of repository - * @param string $affiliation relationship to repository + * @param string $type role in the repository (Deprecated) + * @param string $sort sort by (Deprecated) + * @param string $direction direction of sort, asc or desc (Deprecated) + * @param string $visibility visibility of repository (Deprecated) + * @param string $affiliation relationship to repository (Deprecated) + * @param array $params e.g. e.g. [ + * 'type' => 'owner', + * 'sort' => 'full_name', + * 'direction'=> 'asc', + * 'visibility' => 'all', + * 'affiliation' => 'owner,collaborator,organization_member', + * 'per_page' => 50, + * ] * * @return array list of the user repositories */ - 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', [ + public function repositories( + string $username, + #[Deprecated(since: '3.12')]$type = 'owner', + #[Deprecated(since: '3.12')]$sort = 'full_name', + #[Deprecated(since: '3.12')]$direction = 'asc', + #[Deprecated(since: '3.12')]$visibility = 'all', + #[Deprecated(since: '3.12')]$affiliation = 'owner,collaborator,organization_member', + array $params = [] + ) { + return $this->get('/users/'.rawurlencode($username).'/repos', array_merge([ 'type' => $type, 'sort' => $sort, 'direction' => $direction, 'visibility' => $visibility, 'affiliation' => $affiliation, - ]); + ], $params)); } /** From f4a06bd36b10706f7ae0137ed44a824e02e08633 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 13:26:22 +0530 Subject: [PATCH 06/13] test: add unit test-cases for secret scanning Signed-off-by: Hari Darshan Gorana --- test/Github/Tests/Api/CurrentUserTest.php | 29 ++++ .../Api/Enterprise/SecretScanningTest.php | 41 ++++++ .../Api/Organization/SecretScanningTest.php | 41 ++++++ .../Api/Repository/SecretScanningTest.php | 132 ++++++++++++++++++ test/Github/Tests/Api/UserTest.php | 15 +- 5 files changed, 256 insertions(+), 2 deletions(-) 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/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 5de99f5c911..f3b8f98fb00 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -2,6 +2,9 @@ namespace Github\Tests\Api; +use Github\Api\CurrentUser; +use PHPUnit\Framework\MockObject\MockObject; + class CurrentUserTest extends TestCase { /** @@ -160,6 +163,32 @@ public function shouldGetStarredApiObject() $this->assertInstanceOf(\Github\Api\CurrentUser\Starring::class, $api->starring()); } + /** + * @test + */ + public function shouldGetRepositories() + { + $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'], + ]; + + /** @var CurrentUser|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/user/repos') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->repositories('owner', 'full_name', 'asc', null, null, [ + 'per_page' => 10 + ])); + } + /** * @return string */ diff --git a/test/Github/Tests/Api/Enterprise/SecretScanningTest.php b/test/Github/Tests/Api/Enterprise/SecretScanningTest.php new file mode 100644 index 00000000000..e74fe5a80c2 --- /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..e71993c1dc2 --- /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..4531d8f3962 --- /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; + } +} diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 0be80a28f01..36cedd1a6d4 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -2,6 +2,9 @@ namespace Github\Tests\Api; +use Github\Api\User; +use PHPUnit\Framework\MockObject\MockObject; + class UserTest extends TestCase { /** @@ -188,13 +191,21 @@ public function shouldGetUserRepositories() { $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; + /** @var User|MockObject $api */ $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/users/l3l0/repos', ['type' => 'owner', 'sort' => 'full_name', 'direction' => 'asc', 'visibility' => 'all', 'affiliation' => 'owner,collaborator,organization_member']) + ->with('/users/l3l0/repos') ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->repositories('l3l0')); + $this->assertEquals($expectedArray, $api->repositories('l3l0', 'owner', 'full_name', '', '', '', [ + 'direction' => 'asc', + 'visibility' => 'all', + 'affiliation' => 'owner,collaborator,organization_member', + 'params' => [ + 'per_page' => 1, + ] + ])); } /** From 96442da9216d2c2e7a60c2d5ad2219b85ecd310b Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 13:26:50 +0530 Subject: [PATCH 07/13] chore: ignore .idea folder Signed-off-by: Hari Darshan Gorana --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ebe7b7ea7a3..5120e7abd7b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ phpunit.xml composer.lock composer.phar vendor/* +.idea From 72b5e5b2c51c43e38aeb1c151b76bee19f3ae135 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 13:55:56 +0530 Subject: [PATCH 08/13] docs: update README.md and other documents Signed-off-by: Hari Darshan Gorana --- README.md | 7 +++++- doc/README.md | 4 +++ doc/enterprise/secret-scanning.md | 10 ++++++++ doc/organization/secret-scanning.md | 10 ++++++++ doc/repo/secret-scanning.md | 38 +++++++++++++++++++++++++++++ doc/users.md | 13 ++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 doc/enterprise/secret-scanning.md create mode 100644 doc/organization/secret-scanning.md create mode 100644 doc/repo/secret-scanning.md diff --git a/README.md b/README.md index de79112b4f8..6f4430350a0 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/h ## Advanced install -We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io). +We are decoupled from any HTTP messaging client with help by [HTTPlug](https://httplug.io). ### Using a different http client @@ -53,6 +53,11 @@ $client = Client::createWithHttpClient(new HttplugClient()); Read more about [using different clients in our docs](doc/customize.md). +## Code Completion (JetBrains PhpStorm) +To improve code-completion and ux approach in PhpStorm, advanced metadata is now added. + + + ## Framework integrations ### Laravel diff --git a/doc/README.md b/doc/README.md index ee453269d35..fc8c41898fb 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) @@ -86,3 +89,4 @@ Additional features: * [Request / Response info](request_response_info.md) * [Pagination support](result_pager.md) * [Request any Route](request_any_route.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..f90de728a53 --- /dev/null +++ b/doc/repo/secret-scanning.md @@ -0,0 +1,38 @@ +## 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/doc/users.md b/doc/users.md index 48bb0d7dc15..3cb748c0008 100644 --- a/doc/users.md +++ b/doc/users.md @@ -188,3 +188,16 @@ $emails = $client->api('current_user')->emails()->remove(array('first@provider.o ``` Return an array of the authenticated user emails. + +### List repositories for the user + +> Requires [authentication](security.md) for authenticated user + +```php +$repos = $client->api('current_user')->repositories(); +$repos = $client->api('users')->repositories(); +``` + +> Note: Following arguments `$type`, `$sort`, `$direction`, `$visibility` and `$affiliation` are deprecated and a new array argument is added `$parameters` which can be used to pass all these existing arguments as well as parameters like `per_page` which was not supported earlier. + +Return an array of the authenticated user repos. From acadefcc5f62bc998ac0ef6781b164968727e2bc Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 15:12:29 +0530 Subject: [PATCH 09/13] docs: Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6f4430350a0..9a493a9229b 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ Read more about [using different clients in our docs](doc/customize.md). ## Code Completion (JetBrains PhpStorm) To improve code-completion and ux approach in PhpStorm, advanced metadata is now added. +![Auto-Complete Api Names](https://user-images.githubusercontent.com/1327607/229752632-f1e4a1b3-a9f8-48be-9beb-d41927e96cde.png) + +![Auto-Complete Api Methods](https://user-images.githubusercontent.com/1327607/229752677-3a2f3dc8-51d7-45b7-a7d0-0cde7ac145f7.png) ## Framework integrations From e33f0c51879b0d7595cc54e2a27f61be8666c407 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 17:00:44 +0530 Subject: [PATCH 10/13] feat: Add User Migrations Api Signed-off-by: Hari Darshan Gorana --- doc/README.md | 1 + doc/pull_requests.md | 8 + doc/user/migration.md | 70 +++++++ lib/Github/Api/CurrentUser.php | 10 +- lib/Github/Api/User.php | 19 +- lib/Github/Api/User/Migration.php | 89 ++++++++ test/Github/Tests/Api/User/MigrationTest.php | 203 +++++++++++++++++++ 7 files changed, 390 insertions(+), 10 deletions(-) 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 fc8c41898fb..b20893a01ba 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/pull_requests.md b/doc/pull_requests.md index d87e6180043..af31e4430b0 100644 --- a/doc/pull_requests.md +++ b/doc/pull_requests.md @@ -90,3 +90,11 @@ $pullRequest = $client->api('pull_request')->create('ezsystems', 'ezpublish', ar ``` This returns the details of the pull request. + +### Merge a Pull Request + +> Requires [authentication](security.md) + +```php +$client->api('pull_request')->merge('KnpLabs', 'php-github-api', $pullNumber, $commitMessage, $sha, $mergeMethod, $commitTitle); +``` diff --git a/doc/user/migration.md b/doc/user/migration.md new file mode 100644 index 00000000000..2e8079be56b --- /dev/null +++ b/doc/user/migration.md @@ -0,0 +1,70 @@ +## 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 +$migrations = $client->api('user')->migration()->list([ + 'per_page' => 10 +]); +``` + +# 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/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 8413e4fd086..58bb893c451 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -131,11 +131,11 @@ public function teams() * @return array */ public function repositories( - #[Deprecated(since: '3.12')]$type = 'owner', - #[Deprecated(since: '3.12')]$sort = 'full_name', - #[Deprecated(since: '3.12')]$direction = 'asc', - #[Deprecated(since: '3.12')]$visibility = null, - #[Deprecated(since: '3.12')]$affiliation = null, + $type = 'owner', + $sort = 'full_name', + $direction = 'asc', + $visibility = null, + $affiliation = null, array $parameters = [] ) { $params = [ diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 06f1e126c44..9acf1394967 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\User\Migration; use JetBrains\PhpStorm\Deprecated; /** @@ -180,11 +181,11 @@ public function subscriptions($username) */ public function repositories( string $username, - #[Deprecated(since: '3.12')]$type = 'owner', - #[Deprecated(since: '3.12')]$sort = 'full_name', - #[Deprecated(since: '3.12')]$direction = 'asc', - #[Deprecated(since: '3.12')]$visibility = 'all', - #[Deprecated(since: '3.12')]$affiliation = 'owner,collaborator,organization_member', + $type = 'owner', + $sort = 'full_name', + $direction = 'asc', + $visibility = 'all', + $affiliation = 'owner,collaborator,organization_member', array $params = [] ) { return $this->get('/users/'.rawurlencode($username).'/repos', array_merge([ @@ -263,4 +264,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..4ba41a6ac60 --- /dev/null +++ b/lib/Github/Api/User/Migration.php @@ -0,0 +1,89 @@ +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 + * @throws MissingArgumentException + */ + public function start(array $params) + { + if (!isset($params['repositories'])) { + throw new MissingArgumentException(['repositories']); + } + + 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..d1af096768a --- /dev/null +++ b/test/Github/Tests/Api/User/MigrationTest.php @@ -0,0 +1,203 @@ + 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 shouldNotStartMigration() + { + $this->expectException(MissingArgumentException::class); + + /** @var Migration|MockObject $api */ + $api = $this->getApiMock(); + + $api->expects($this->never()) + ->method('post'); + + $api->start([]); + } + + /** + * @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 64b22deee625f81b03507067615507bff80b3b63 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 17:01:59 +0530 Subject: [PATCH 11/13] fix: styleci Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/CurrentUser.php | 16 +++--- lib/Github/Api/Enterprise/SecretScanning.php | 2 +- .../Api/Organization/SecretScanning.php | 2 +- lib/Github/Api/Repository/SecretScanning.php | 12 ++--- lib/Github/Api/User.php | 16 +++--- test/Github/Tests/Api/CurrentUserTest.php | 2 +- .../Api/Enterprise/SecretScanningTest.php | 2 +- .../Api/Organization/SecretScanningTest.php | 2 +- .../Api/Repository/SecretScanningTest.php | 54 +++++++++---------- test/Github/Tests/Api/UserTest.php | 2 +- 10 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 58bb893c451..34538b9723c 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -119,14 +119,14 @@ public function teams() * @param string $direction direction of sort, asc or desc (Deprecated) * @param string $visibility visibility of repository (Deprecated) * @param string $affiliation relationship to repository (Deprecated) - * @param array $parameters e.g. [ - * 'type' => 'owner', - * 'sort' => 'full_name', - * 'direction'=> 'asc', - * 'visibility' => null, - * 'affiliation' => null, - * 'per_page' => 50, - * ] + * @param array $parameters e.g. [ + * 'type' => 'owner', + * 'sort' => 'full_name', + * 'direction'=> 'asc', + * 'visibility' => null, + * 'affiliation' => null, + * 'per_page' => 50, + * ] * * @return array */ diff --git a/lib/Github/Api/Enterprise/SecretScanning.php b/lib/Github/Api/Enterprise/SecretScanning.php index 0d38b4da5e7..5d92c1d8a47 100644 --- a/lib/Github/Api/Enterprise/SecretScanning.php +++ b/lib/Github/Api/Enterprise/SecretScanning.php @@ -10,7 +10,7 @@ class SecretScanning extends AbstractApi * @link https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-enterprise * * @param string $enterprise - * @param array $params + * @param array $params * * @return array|string */ diff --git a/lib/Github/Api/Organization/SecretScanning.php b/lib/Github/Api/Organization/SecretScanning.php index 25991d34e59..a323fd06fcc 100644 --- a/lib/Github/Api/Organization/SecretScanning.php +++ b/lib/Github/Api/Organization/SecretScanning.php @@ -8,7 +8,7 @@ class SecretScanning extends \Github\Api\AbstractApi * @link https://docs.github.com/en/enterprise-server@3.5/rest/secret-scanning#list-secret-scanning-alerts-for-an-organization * * @param string $organization - * @param array $params + * @param array $params * * @return array|string */ diff --git a/lib/Github/Api/Repository/SecretScanning.php b/lib/Github/Api/Repository/SecretScanning.php index 1da6aa85038..968d352c3ec 100644 --- a/lib/Github/Api/Repository/SecretScanning.php +++ b/lib/Github/Api/Repository/SecretScanning.php @@ -9,7 +9,7 @@ class SecretScanning extends \Github\Api\AbstractApi * * @param string $username * @param string $repository - * @param array $params + * @param array $params * * @return array|string */ @@ -23,7 +23,7 @@ public function alerts(string $username, string $repository, array $params = []) * * @param string $username * @param string $repository - * @param int $alertNumber + * @param int $alertNumber * * @return array|string */ @@ -37,8 +37,8 @@ public function getAlert(string $username, string $repository, int $alertNumber) * * @param string $username * @param string $repository - * @param int $alertNumber - * @param array $params + * @param int $alertNumber + * @param array $params * * @return array|string */ @@ -52,8 +52,8 @@ public function updateAlert(string $username, string $repository, int $alertNumb * * @param string $username * @param string $repository - * @param int $alertNumber - * @param array $params + * @param int $alertNumber + * @param array $params * * @return array|string */ diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index 9acf1394967..e6904cdf772 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -168,14 +168,14 @@ public function subscriptions($username) * @param string $direction direction of sort, asc or desc (Deprecated) * @param string $visibility visibility of repository (Deprecated) * @param string $affiliation relationship to repository (Deprecated) - * @param array $params e.g. e.g. [ - * 'type' => 'owner', - * 'sort' => 'full_name', - * 'direction'=> 'asc', - * 'visibility' => 'all', - * 'affiliation' => 'owner,collaborator,organization_member', - * 'per_page' => 50, - * ] + * @param array $params e.g. e.g. [ + * 'type' => 'owner', + * 'sort' => 'full_name', + * 'direction'=> 'asc', + * 'visibility' => 'all', + * 'affiliation' => 'owner,collaborator,organization_member', + * 'per_page' => 50, + * ] * * @return array list of the user repositories */ diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index f3b8f98fb00..3e072e4ee32 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -185,7 +185,7 @@ public function shouldGetRepositories() ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('owner', 'full_name', 'asc', null, null, [ - 'per_page' => 10 + 'per_page' => 10, ])); } diff --git a/test/Github/Tests/Api/Enterprise/SecretScanningTest.php b/test/Github/Tests/Api/Enterprise/SecretScanningTest.php index e74fe5a80c2..cc5b14b6547 100644 --- a/test/Github/Tests/Api/Enterprise/SecretScanningTest.php +++ b/test/Github/Tests/Api/Enterprise/SecretScanningTest.php @@ -30,7 +30,7 @@ public function shouldGetAlerts() ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->alerts('KnpLabs', [ - 'state' => 'all' + 'state' => 'all', ])); } diff --git a/test/Github/Tests/Api/Organization/SecretScanningTest.php b/test/Github/Tests/Api/Organization/SecretScanningTest.php index e71993c1dc2..01b8f844007 100644 --- a/test/Github/Tests/Api/Organization/SecretScanningTest.php +++ b/test/Github/Tests/Api/Organization/SecretScanningTest.php @@ -30,7 +30,7 @@ public function shouldGetAlerts() ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->alerts('KnpLabs', [ - 'state' => 'all' + 'state' => 'all', ])); } diff --git a/test/Github/Tests/Api/Repository/SecretScanningTest.php b/test/Github/Tests/Api/Repository/SecretScanningTest.php index 4531d8f3962..e2e98dfa879 100644 --- a/test/Github/Tests/Api/Repository/SecretScanningTest.php +++ b/test/Github/Tests/Api/Repository/SecretScanningTest.php @@ -30,7 +30,7 @@ public function shouldGetAllAlerts() ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->alerts('KnpLabs', 'php-github-api', [ - 'state' => 'all' + 'state' => 'all', ])); } @@ -71,7 +71,7 @@ public function shouldUpdateAlert() $this->assertEquals($expectedArray, $api->updateAlert('KnpLabs', 'php-github-api', 2, [ 'state' => 'resolved', - 'resolution' => 'false_positive' + 'resolution' => 'false_positive', ])); } @@ -82,33 +82,33 @@ 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' => 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" - ] - ] + '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 */ diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 36cedd1a6d4..398a466dd43 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -204,7 +204,7 @@ public function shouldGetUserRepositories() 'affiliation' => 'owner,collaborator,organization_member', 'params' => [ 'per_page' => 1, - ] + ], ])); } From 5ed909757f7665a97e3f5c970993cb868df4df1b Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 17:03:28 +0530 Subject: [PATCH 12/13] fix: styleci Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/User/Migration.php | 9 +++-- test/Github/Tests/Api/User/MigrationTest.php | 40 ++++++++++---------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/Github/Api/User/Migration.php b/lib/Github/Api/User/Migration.php index 4ba41a6ac60..133d6436525 100644 --- a/lib/Github/Api/User/Migration.php +++ b/lib/Github/Api/User/Migration.php @@ -24,8 +24,9 @@ public function list(array $params = []) * * @param array $params * - * @return array|string * @throws MissingArgumentException + * + * @return array|string */ public function start(array $params) { @@ -39,7 +40,7 @@ public function start(array $params) /** * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#get-a-user-migration-status * - * @param int $migrationId + * @param int $migrationId * @param array $params * * @return array|string @@ -64,7 +65,7 @@ public function deleteArchive(int $migrationId) /** * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#unlock-a-user-repository * - * @param int $migrationId + * @param int $migrationId * @param string $repository * * @return array|string @@ -77,7 +78,7 @@ public function unlockRepo(int $migrationId, string $repository) /** * @link https://docs.github.com/en/rest/migrations/users?apiVersion=2022-11-28#list-repositories-for-a-user-migration * - * @param int $migrationId + * @param int $migrationId * @param array $params * * @return array|string diff --git a/test/Github/Tests/Api/User/MigrationTest.php b/test/Github/Tests/Api/User/MigrationTest.php index d1af096768a..83cd546b0d3 100644 --- a/test/Github/Tests/Api/User/MigrationTest.php +++ b/test/Github/Tests/Api/User/MigrationTest.php @@ -23,9 +23,9 @@ public function shouldListUserMigrations() [ 'id' => 1296269, 'name' => 'Hello-World', - 'full_name' => 'octocat/Hello-World' - ] - ] + 'full_name' => 'octocat/Hello-World', + ], + ], ], [ 'id' => 2, @@ -35,9 +35,9 @@ public function shouldListUserMigrations() [ 'id' => 123, 'name' => 'php-github-api', - 'full_name' => 'KnpLabs/php-github-api' - ] - ] + 'full_name' => 'KnpLabs/php-github-api', + ], + ], ], ]; @@ -82,9 +82,9 @@ public function shouldStartMigration() [ 'id' => 1296269, 'name' => 'Hello-World', - 'full_name' => 'octocat/Hello-World' - ] - ] + 'full_name' => 'octocat/Hello-World', + ], + ], ]; /** @var Migration|MockObject $api */ @@ -98,8 +98,8 @@ public function shouldStartMigration() $this->assertEquals($expectedArray, $api->start([ 'lock_repositories' => true, 'repositories' => [ - 'KnpLabs/php-github-api' - ] + 'KnpLabs/php-github-api', + ], ])); } @@ -116,9 +116,9 @@ public function shouldGetMigrationStatus() [ 'id' => 1296269, 'name' => 'Hello-World', - 'full_name' => 'octocat/Hello-World' - ] - ] + 'full_name' => 'octocat/Hello-World', + ], + ], ]; /** @var Migration|MockObject $api */ @@ -171,14 +171,14 @@ public function shouldListRepos() { $expectedArray = [ [ - "id" => 1296269, - "name" => "Hello-World", - "full_name" => "test/Hello-World", + 'id' => 1296269, + 'name' => 'Hello-World', + 'full_name' => 'test/Hello-World', ], [ - "id" => 234324, - "name" => "Hello-World2", - "full_name" => "test/Hello-World2", + 'id' => 234324, + 'name' => 'Hello-World2', + 'full_name' => 'test/Hello-World2', ], ]; From 422f4a136cf85f5806b6fea5c6e7ab09bd7a5b53 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Tue, 4 Apr 2023 19:22:09 +0530 Subject: [PATCH 13/13] chore: remove .idea folder from .gitignore Signed-off-by: Hari Darshan Gorana --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5120e7abd7b..ebe7b7ea7a3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ phpunit.xml composer.lock composer.phar vendor/* -.idea