Skip to content

Commit

Permalink
feature #944 automated security endpoints (#868) (lexor)
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat authored Dec 3, 2020
2 parents 0889fc2 + 295f272 commit e561339
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ $languages = $client->api('repo')->languages('ornicar', 'php-github-api');

Returns a list of languages.

### Enable automated security fixes

https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes

```php
$client->api('repo')->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api');
```

### Disable automated security fixes

https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes

```php
$client->api('repo')->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api');
```

### Get the contributors of a repository

```php
Expand Down
30 changes: 30 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,36 @@ public function milestones($username, $repository, array $parameters = [])
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/milestones', $parameters);
}

/**
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#enable-automated-security-fixes
*
* @param string $username
* @param string $repository
*
* @return array|string
*/
public function enableAutomatedSecurityFixes(string $username, string $repository)
{
$this->acceptHeaderValue = 'application/vnd.github.london-preview+json';

return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/automated-security-fixes');
}

/**
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#disable-automated-security-fixes
*
* @param string $username
* @param string $repository
*
* @return array|string
*/
public function disableAutomatedSecurityFixes(string $username, string $repository)
{
$this->acceptHeaderValue = 'application/vnd.github.london-preview+json';

return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/automated-security-fixes');
}

public function projects()
{
return new Projects($this->client);
Expand Down
41 changes: 41 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Github\Tests\Api;

use Github\Api\Repo;
use PHPUnit\Framework\MockObject\MockObject;

class RepoTest extends TestCase
{
/**
Expand Down Expand Up @@ -264,6 +267,44 @@ public function shouldGetRepositoryMilestones()
$this->assertEquals($expectedArray, $api->milestones('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function shouldEnableAutomatedSecurityFixes()
{
$expectedResponse = 'response';

/** @var Repo|MockObject $api */
$api = $this->getApiMock();

$api
->expects($this->once())
->method('put')
->with('/repos/KnpLabs/php-github-api/automated-security-fixes')
->will($this->returnValue($expectedResponse));

$this->assertEquals($expectedResponse, $api->enableAutomatedSecurityFixes('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
public function shouldDisableAutomatedSecurityFixes()
{
$expectedResponse = 'response';

/** @var Repo|MockObject $api */
$api = $this->getApiMock();

$api
->expects($this->once())
->method('delete')
->with('/repos/KnpLabs/php-github-api/automated-security-fixes')
->will($this->returnValue($expectedResponse));

$this->assertEquals($expectedResponse, $api->disableAutomatedSecurityFixes('KnpLabs', 'php-github-api'));
}

/**
* @test
*/
Expand Down

0 comments on commit e561339

Please sign in to comment.