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..2212d01053d 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -5,6 +5,7 @@ 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; @@ -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..7c19f6876ea --- /dev/null +++ b/lib/Github/Api/Organization/Dependabot.php @@ -0,0 +1,21 @@ +get('/orgs/'.rawurlencode($organization).'/dependabot/alerts', $params); + } +} 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) 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; + } +}