From 295f272d3dc1b5aa6b6d9426c0600410d999de96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20DE=C4=9EER?= Date: Thu, 3 Dec 2020 16:14:49 +0300 Subject: [PATCH] feat(repo): added automated security endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emre DEĞER chore(repo): fixed ci issues Signed-off-by: Emre DEĞER --- doc/repos.md | 16 ++++++++++++ lib/Github/Api/Repo.php | 30 ++++++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 41 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) 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 */