From e214c0782c449760dd87057f7e7912c9efebc4f4 Mon Sep 17 00:00:00 2001 From: Ilia Kondrashov Date: Fri, 5 Jan 2024 15:05:58 +0100 Subject: [PATCH 1/3] support for dependabot/alerts api --- doc/organization.md | 1 + doc/organization/dependabot.md | 11 ++++++ lib/Github/Api/Organization.php | 9 +++++ lib/Github/Api/Organization/Dependabot.php | 21 ++++++++++ .../Tests/Api/Organization/DependabotTest.php | 38 +++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 doc/organization/dependabot.md create mode 100644 lib/Github/Api/Organization/Dependabot.php create mode 100644 test/Github/Tests/Api/Organization/DependabotTest.php diff --git a/doc/organization.md b/doc/organization.md index e44c436dff3..dcd0c6ed3b6 100644 --- a/doc/organization.md +++ b/doc/organization.md @@ -6,6 +6,7 @@ Wraps [GitHub Organization API](http://developer.github.com/v3/orgs/). Additional APIs: * [Members API](organization/members.md) * [Teams API](organization/teams.md) +* [Dependabot API](organization/dependabot.md) ### List issues in an organization [GitHub Issues API](https://developer.github.com/v3/issues/). diff --git a/doc/organization/dependabot.md b/doc/organization/dependabot.md new file mode 100644 index 00000000000..79538549768 --- /dev/null +++ b/doc/organization/dependabot.md @@ -0,0 +1,11 @@ +## Organization / Dependabot API + +[Back to the "Organization API"](../../organization.md) | [Back to the navigation](../../README.md) + +# List Dependabot alerts for an Organization + +https://docs.github.com/en/rest/dependabot/alerts?apiVersion=2022-11-28#list-dependabot-alerts-for-an-organization + +```php +$alerts = $client->api('organization')->dependabot()->alerts('KnpLabs', ['severity' => 'critical']); +``` diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index ada7e66836d..32194cebef4 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -10,6 +10,7 @@ use Github\Api\Organization\OutsideCollaborators; use Github\Api\Organization\SecretScanning; use Github\Api\Organization\Teams; +use Github\Api\Organization\Dependabot; /** * Getting organization information and managing authenticated organization account information. @@ -158,4 +159,12 @@ public function secretScanning(): SecretScanning { return new SecretScanning($this->getClient()); } + + /** + * @return Dependabot + */ + public function dependabot(): Dependabot + { + return new Dependabot($this->getClient()); + } } diff --git a/lib/Github/Api/Organization/Dependabot.php b/lib/Github/Api/Organization/Dependabot.php new file mode 100644 index 00000000000..0184c294174 --- /dev/null +++ b/lib/Github/Api/Organization/Dependabot.php @@ -0,0 +1,21 @@ +get('/orgs/' . rawurlencode($organization) . '/dependabot/alerts', $params); + } +} diff --git a/test/Github/Tests/Api/Organization/DependabotTest.php b/test/Github/Tests/Api/Organization/DependabotTest.php new file mode 100644 index 00000000000..3347bc77fe2 --- /dev/null +++ b/test/Github/Tests/Api/Organization/DependabotTest.php @@ -0,0 +1,38 @@ + 1, 'state' => 'open', 'severity' => 'critical'], + ]; + + /** @var SecretScanning|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/dependabot/alerts') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->alerts('KnpLabs', [ + 'severity' => 'critical', + ])); + } + + protected function getApiClass() + { + return \Github\Api\Organization\Dependabot::class; + } +} From 7e9abbae1cd1f4c7d99a95e6af7bf7ef236fd902 Mon Sep 17 00:00:00 2001 From: Ilia Kondrashov Date: Fri, 5 Jan 2024 16:44:42 +0100 Subject: [PATCH 2/3] styleci.io suggestions --- lib/Github/Api/Organization.php | 2 +- lib/Github/Api/Organization/Dependabot.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 32194cebef4..2212d01053d 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -5,12 +5,12 @@ use Github\Api\Organization\Actions\Secrets; use Github\Api\Organization\Actions\SelfHostedRunners; use Github\Api\Organization\Actions\Variables; +use Github\Api\Organization\Dependabot; 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; -use Github\Api\Organization\Dependabot; /** * Getting organization information and managing authenticated organization account information. diff --git a/lib/Github/Api/Organization/Dependabot.php b/lib/Github/Api/Organization/Dependabot.php index 0184c294174..7c19f6876ea 100644 --- a/lib/Github/Api/Organization/Dependabot.php +++ b/lib/Github/Api/Organization/Dependabot.php @@ -16,6 +16,6 @@ class Dependabot extends AbstractApi */ public function alerts(string $organization, array $params = []) { - return $this->get('/orgs/' . rawurlencode($organization) . '/dependabot/alerts', $params); + return $this->get('/orgs/'.rawurlencode($organization).'/dependabot/alerts', $params); } } From 66a0c69aa57843ebaa8bf92748c915129d264c02 Mon Sep 17 00:00:00 2001 From: Ilia Kondrashov Date: Wed, 19 Jun 2024 21:10:26 +0200 Subject: [PATCH 3/3] add params to teams to use paginator --- lib/Github/Api/Organization/Teams.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 20bb2791a7a..31a86867748 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -12,9 +12,9 @@ */ class Teams extends AbstractApi { - public function all($organization) + public function all($organization, array $params = []) { - return $this->get('/orgs/'.rawurlencode($organization).'/teams'); + return $this->get('/orgs/'.rawurlencode($organization).'/teams', $params); } public function create($organization, array $params)