Skip to content

Commit 295f272

Browse files
committed
feat(repo): added automated security endpoints
Signed-off-by: Emre DEĞER <ben@emre.dev> chore(repo): fixed ci issues Signed-off-by: Emre DEĞER <ben@emre.dev>
1 parent 0889fc2 commit 295f272

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

doc/repos.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ $languages = $client->api('repo')->languages('ornicar', 'php-github-api');
271271

272272
Returns a list of languages.
273273

274+
### Enable automated security fixes
275+
276+
https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes
277+
278+
```php
279+
$client->api('repo')->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api');
280+
```
281+
282+
### Disable automated security fixes
283+
284+
https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes
285+
286+
```php
287+
$client->api('repo')->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api');
288+
```
289+
274290
### Get the contributors of a repository
275291

276292
```php

lib/Github/Api/Repo.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,36 @@ public function milestones($username, $repository, array $parameters = [])
693693
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones', $parameters);
694694
}
695695

696+
/**
697+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes
698+
*
699+
* @param string $username
700+
* @param string $repository
701+
*
702+
* @return array|string
703+
*/
704+
public function enableAutomatedSecurityFixes(string $username, string $repository)
705+
{
706+
$this->acceptHeaderValue = 'application/vnd.github.london-preview+json';
707+
708+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/automated-security-fixes');
709+
}
710+
711+
/**
712+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes
713+
*
714+
* @param string $username
715+
* @param string $repository
716+
*
717+
* @return array|string
718+
*/
719+
public function disableAutomatedSecurityFixes(string $username, string $repository)
720+
{
721+
$this->acceptHeaderValue = 'application/vnd.github.london-preview+json';
722+
723+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/automated-security-fixes');
724+
}
725+
696726
public function projects()
697727
{
698728
return new Projects($this->client);

test/Github/Tests/Api/RepoTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Github\Tests\Api;
44

5+
use Github\Api\Repo;
6+
use PHPUnit\Framework\MockObject\MockObject;
7+
58
class RepoTest extends TestCase
69
{
710
/**
@@ -264,6 +267,44 @@ public function shouldGetRepositoryMilestones()
264267
$this->assertEquals($expectedArray, $api->milestones('KnpLabs', 'php-github-api'));
265268
}
266269

270+
/**
271+
* @test
272+
*/
273+
public function shouldEnableAutomatedSecurityFixes()
274+
{
275+
$expectedResponse = 'response';
276+
277+
/** @var Repo|MockObject $api */
278+
$api = $this->getApiMock();
279+
280+
$api
281+
->expects($this->once())
282+
->method('put')
283+
->with('/repos/KnpLabs/php-github-api/automated-security-fixes')
284+
->will($this->returnValue($expectedResponse));
285+
286+
$this->assertEquals($expectedResponse, $api->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api'));
287+
}
288+
289+
/**
290+
* @test
291+
*/
292+
public function shouldDisableAutomatedSecurityFixes()
293+
{
294+
$expectedResponse = 'response';
295+
296+
/** @var Repo|MockObject $api */
297+
$api = $this->getApiMock();
298+
299+
$api
300+
->expects($this->once())
301+
->method('delete')
302+
->with('/repos/KnpLabs/php-github-api/automated-security-fixes')
303+
->will($this->returnValue($expectedResponse));
304+
305+
$this->assertEquals($expectedResponse, $api->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api'));
306+
}
307+
267308
/**
268309
* @test
269310
*/

0 commit comments

Comments
 (0)