Skip to content

automated security endpoints (#868) #944

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

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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