diff --git a/doc/repos.md b/doc/repos.md index 0c7068987d5..7b361aba9b2 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -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 diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b9b02ea0b30..47a3aa1795e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -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); diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 88434750883..35033e7da20 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -2,6 +2,9 @@ namespace Github\Tests\Api; +use Github\Api\Repo; +use PHPUnit\Framework\MockObject\MockObject; + class RepoTest extends TestCase { /** @@ -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 */