Skip to content

Commit 0a44bdc

Browse files
authored
feature KnpLabs#1096 Add vulnerability alerts endpoints (andreia)
This PR was merged into the 3.9.x-dev branch. Discussion ---------- Add vulnerability alerts endpoints: - [x] 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). - [x] Enable vulnerability alerts (dependabot alerts) for a repository (https://developer.github.com/v3/repos/#enable-vulnerability-alerts). - [x] Disable vulnerability alerts (dependabot alerts) for a repository (https://developer.github.com/v3/repos/#disable-vulnerability-alerts). Commits ------- 7245b02 Add vulnerability alerts endpoints
2 parents 28029f2 + 7245b02 commit 0a44bdc

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

doc/repos.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,27 @@ $client->api('repo')->createFromTemplate('template-owner', 'template-repo', [
390390
'owner' => 'name-of-new-repo-owner', // can be user or org
391391
]);
392392
```
393+
394+
### Check if vulnerability alerts (dependabot alerts) are enabled for a repository
395+
396+
https://developer.github.com/v3/repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository
397+
398+
```php
399+
$client->api('repo')->isVulnerabilityAlertsEnabled('KnpLabs', 'php-github-api');
400+
```
401+
402+
### Enable vulnerability alerts (dependabot alerts)
403+
404+
https://developer.github.com/v3/repos/#enable-vulnerability-alerts
405+
406+
```php
407+
$client->api('repo')->enableVulnerabilityAlerts('KnpLabs', 'php-github-api');
408+
```
409+
410+
### Disable vulnerability alerts (dependabot alerts)
411+
412+
https://developer.github.com/v3/repos/#disable-vulnerability-alerts
413+
414+
```php
415+
$client->api('repo')->disableVulnerabilityAlerts('KnpLabs', 'php-github-api');
416+
```

lib/Github/Api/Repo.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,4 +843,49 @@ public function createFromTemplate(string $templateOwner, string $templateRepo,
843843

844844
return $this->post('/repos/'.rawurldecode($templateOwner).'/'.rawurldecode($templateRepo).'/generate', $parameters);
845845
}
846+
847+
/**
848+
* Check if vulnerability alerts are enabled for a repository.
849+
*
850+
* @link https://developer.github.com/v3/repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository
851+
*
852+
* @param string $username the username
853+
* @param string $repository the repository
854+
*
855+
* @return array|string
856+
*/
857+
public function isVulnerabilityAlertsEnabled(string $username, string $repository)
858+
{
859+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts');
860+
}
861+
862+
/**
863+
* Enable vulnerability alerts for a repository.
864+
*
865+
* @link https://developer.github.com/v3/repos/#enable-vulnerability-alerts
866+
*
867+
* @param string $username the username
868+
* @param string $repository the repository
869+
*
870+
* @return array|string
871+
*/
872+
public function enableVulnerabilityAlerts(string $username, string $repository)
873+
{
874+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts');
875+
}
876+
877+
/**
878+
* Disable vulnerability alerts for a repository.
879+
*
880+
* @link https://developer.github.com/v3/repos/#disable-vulnerability-alerts
881+
*
882+
* @param string $username the username
883+
* @param string $repository the repository
884+
*
885+
* @return array|string
886+
*/
887+
public function disableVulnerabilityAlerts(string $username, string $repository)
888+
{
889+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/vulnerability-alerts');
890+
}
846891
}

test/Github/Tests/Api/RepoTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,58 @@ protected function getApiClass()
722722
{
723723
return \Github\Api\Repo::class;
724724
}
725+
726+
/**
727+
* @test
728+
*/
729+
public function shouldCheckVulnerabilityAlertsEnabled()
730+
{
731+
$expectedResponse = '';
732+
733+
$api = $this->getApiMock();
734+
735+
$api
736+
->expects($this->once())
737+
->method('get')
738+
->with('/repos/KnpLabs/php-github-api/vulnerability-alerts')
739+
->will($this->returnValue($expectedResponse));
740+
741+
$this->assertEquals($expectedResponse, $api->isVulnerabilityAlertsEnabled('KnpLabs', 'php-github-api'));
742+
}
743+
744+
/**
745+
* @test
746+
*/
747+
public function shouldEnableVulnerabilityAlerts()
748+
{
749+
$expectedResponse = '';
750+
751+
$api = $this->getApiMock();
752+
753+
$api
754+
->expects($this->once())
755+
->method('put')
756+
->with('/repos/KnpLabs/php-github-api/vulnerability-alerts')
757+
->will($this->returnValue($expectedResponse));
758+
759+
$this->assertEquals($expectedResponse, $api->enableVulnerabilityAlerts('KnpLabs', 'php-github-api'));
760+
}
761+
762+
/**
763+
* @test
764+
*/
765+
public function shouldDisableVulnerabilityAlerts()
766+
{
767+
$expectedResponse = '';
768+
769+
$api = $this->getApiMock();
770+
771+
$api
772+
->expects($this->once())
773+
->method('delete')
774+
->with('/repos/KnpLabs/php-github-api/vulnerability-alerts')
775+
->will($this->returnValue($expectedResponse));
776+
777+
$this->assertEquals($expectedResponse, $api->disableVulnerabilityAlerts('KnpLabs', 'php-github-api'));
778+
}
725779
}

0 commit comments

Comments
 (0)