Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper for dependabot/alerts api #1130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/organization.md
Expand Up @@ -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/).
Expand Down
11 changes: 11 additions & 0 deletions 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']);
```
9 changes: 9 additions & 0 deletions lib/Github/Api/Organization.php
Expand Up @@ -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;
Expand Down Expand Up @@ -158,4 +159,12 @@ public function secretScanning(): SecretScanning
{
return new SecretScanning($this->getClient());
}

/**
* @return Dependabot
*/
public function dependabot(): Dependabot
{
return new Dependabot($this->getClient());
}
}
21 changes: 21 additions & 0 deletions lib/Github/Api/Organization/Dependabot.php
@@ -0,0 +1,21 @@
<?php

namespace Github\Api\Organization;

use Github\Api\AbstractApi;

class Dependabot extends AbstractApi
{
/**
* @link https://docs.github.com/en/rest/dependabot/alerts?apiVersion=2022-11-28#list-dependabot-alerts-for-an-organization
*
* @param string $organization
* @param array $params
*
* @return array|string
*/
public function alerts(string $organization, array $params = [])
{
return $this->get('/orgs/'.rawurlencode($organization).'/dependabot/alerts', $params);
}
}
38 changes: 38 additions & 0 deletions test/Github/Tests/Api/Organization/DependabotTest.php
@@ -0,0 +1,38 @@
<?php

namespace Github\Tests\Api\Organization;

use Github\Api\Organization\SecretScanning;
use Github\Tests\Api\TestCase;
use PHPUnit\Framework\MockObject\MockObject;

class DependabotTest extends TestCase
{
/**
* @test
*/
public function shouldGetAlerts()
{
$expectedArray = [
['number' => 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;
}
}