diff --git a/CHANGELOG.md b/CHANGELOG.md index 40b2dff1928..fc9bad6dc3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Change Log -The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. ## 2.6.0 (unreleased) ### Added - Support for graphql api [variables](https://developer.github.com/v4/guides/forming-calls/#working-with-variables) (#612) +- Added missing branch protection methods (#616) ## 2.5.0 @@ -25,7 +26,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- `Integrations::configure` to allow accessing early access program endpoints. +- `Integrations::configure` to allow accessing early access program endpoints. - Add support for pagination and parameters in the pull request comments - Add the ability to fetch user installations (`CurrentUser::installations`) - Allow getting repo info by id (`Repo::showById`) @@ -33,7 +34,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed -- `PullRequest\Review` and `PullRequest\ReviewRequest` is now part of the official API. No need to call `configure`. +- `PullRequest\Review` and `PullRequest\ReviewRequest` is now part of the official API. No need to call `configure`. ## 2.3.0 @@ -49,7 +50,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed -- First argument to `Integrations::listRepositories()` is now optional. +- First argument to `Integrations::listRepositories()` is now optional. - Moved tests from "functional" to "integration" ## 2.2.0 @@ -57,10 +58,10 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added - API support for Pull Request Review Requests. -- API support for Traffic. -- API support for issue Assignees. -- API support for Miscellaneous Gitignore and Emojis. -- Added endpoints for issue lock, unlock and issue label show. +- API support for Traffic. +- API support for issue Assignees. +- API support for Miscellaneous Gitignore and Emojis. +- Added endpoints for issue lock, unlock and issue label show. - Added more parameters to `User::starred`. - Fluid interface by allowing `configure()` to return `$this`. - `configure()` support for issues API. @@ -74,21 +75,21 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- Add support for retrieving a single notification info using his ID +- Add support for retrieving a single notification info using his ID - Add a function to get user organizations - Added GraphQL support - Add page variable to organization repo list (Organization::repositories()) -- Add support for pull request review. +- Add support for pull request review. - Add support for adding branch protection. ### Fixed -- Bug with double slashes when using enterprise URL. +- Bug with double slashes when using enterprise URL. - Bug when headers not being passed to request (#529) ## 2.0.0 -### Added +### Added - Support for JWT authentication - API for Organization\Members @@ -101,26 +102,26 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Changed -- `ApiLimitExceedException::__construct` has a new second parameter for the remaining API calls. -- First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to -`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: - +- `ApiLimitExceedException::__construct` has a new second parameter for the remaining API calls. +- First parameter of `Github\Client` has changed type from `\Http\Client\HttpClient` to +`Github\HttpClient\Builder`. A factory class was also added. To upgrade you need to change: + ```php // Old way does not work: -$github = new Github\Client($httpClient); +$github = new Github\Client($httpClient); // New way will work: -$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); -$github = Github\Client::createWithHttpClient($httpClient); +$github = new Github\Client(new Github\HttpClient\Builder($httpClient)); +$github = Github\Client::createWithHttpClient($httpClient); ``` -- Renamed the currentuser `DeployKeys` api class to `PublicKeys` to reflect to github api name. +- Renamed the currentuser `DeployKeys` api class to `PublicKeys` to reflect to github api name. ## 2.0.0-rc4 -### Added +### Added - HTTPlug to decouple from Guzzle -- `Github\Client::getLastResponse` was added +- `Github\Client::getLastResponse` was added - Support for PSR-6 cache - `Github\Client::addPlugin` and `Github\Client::removePlugin` - `Github\Client::getApiVersion` @@ -143,6 +144,6 @@ $github = Github\Client::createWithHttpClient($httpClient); - `Github/HttpClient/CachedHttpClient` was removed - All classes in `Github/HttpClient/Cache/*` were removed -## 1.7.1 +## 1.7.1 No change log before this version diff --git a/doc/repo/protection.md b/doc/repo/protection.md index 28ff7c2cb9f..6fed148096b 100644 --- a/doc/repo/protection.md +++ b/doc/repo/protection.md @@ -41,3 +41,233 @@ $protection = $client->api('repo')->protection()->show('twbs', 'bootstrap', 'mas ```php $protection = $client->api('repo')->protection()->remove('twbs', 'bootstrap', 'master'); ``` + +### Get required status checks of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showStatusChecks('twbs', 'bootstrap', 'master'); +``` + +### Update required status checks of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'strict' => true, + 'contexts' => [ + 'continuous-integration/travis-ci', + ], +]; +$protection = $client->api('repo')->protection()->updateStatusChecks('twbs', 'bootstrap', 'master', $params); +``` + +### Remove required status checks of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->removeStatusChecks('twbs', 'bootstrap', 'master'); +``` + +### List required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showStatusChecksContexts('twbs', 'bootstrap', 'master'); +``` + +### Replace required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'continuous-integration/travis-ci', +]; +$protection = $client->api('repo')->protection()->replaceStatusChecksContexts('twbs', 'bootstrap', 'master', $params); +``` + +### Add required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'continuous-integration/jenkins', +]; +$protection = $client->api('repo')->protection()->addStatusChecksContexts('twbs', 'bootstrap', 'master', $params); +``` + +### Remove required status checks contexts of protected branch + +> Requires [authentication](../security.md). + +```php +$params = [ + 'continuous-integration/jenkins', +]; +$protection = $client->api('repo')->protection()->removeStatusChecksContexts('twbs', 'bootstrap', 'master', $params); +``` + +### Get pull request review enforcement of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showPullRequestReviewEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Update pull request review enforcement of protected branch + +> Requires [authentication](../security.md) with admin access and branch protection to be enabled. + +```php +$params = [ + 'dismissal_restrictions' => [ + 'users' => [ + 'octocat', + ], + 'teams' => [ + 'justice-league', + ], + ], + 'dismiss_stale_reviews' => true, + 'require_code_owner_reviews' => true, +]; +$protection = $client->api('repo')->protection()->updatePullRequestReviewEnforcement('twbs', 'bootstrap', 'master', $params); +``` + +### Remove pull request review enforcement of protected branch + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->removePullRequestReviewEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Get admin enforcement of protected branch + + +> Requires [authentication](../security.md). + +```php +$protection = $client->api('repo')->protection()->showAdminEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Add admin enforcement of protected branch + +> Requires [authentication](../security.md) with admin access and branch protection to be enabled. + +```php +$protection = $client->api('repo')->protection()->addAdminEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Remove admin enforcement of protected branch + +> Requires [authentication](../security.md) with admin access and branch protection to be enabled. + +```php +$protection = $client->api('repo')->protection()->removeAdminEnforcement('twbs', 'bootstrap', 'master'); +``` + +### Get restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->showRestrictions('twbs', 'bootstrap', 'master'); +``` + +### Remove restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->removeRestrictions('twbs', 'bootstrap', 'master'); +``` + +### List team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->showTeamRestrictions('twbs', 'bootstrap', 'master'); +``` + +### Replace team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'justice-league', +]; +$protection = $client->api('repo')->protection()->replaceTeamRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Add team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'justice-league', +]; +$protection = $client->api('repo')->protection()->addTeamRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Remove team restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'octocats', +]; +$protection = $client->api('repo')->protection()->removeTeamRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### List user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$protection = $client->api('repo')->protection()->showUserRestrictions('twbs', 'bootstrap', 'master'); +``` + +### Replace user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'octocat', +]; +$protection = $client->api('repo')->protection()->replaceUserRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Add user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'octocat', +]; +$protection = $client->api('repo')->protection()->addUserRestrictions('twbs', 'bootstrap', 'master', $params); +``` + +### Remove user restrictions of protected branch + +> Requires [authentication](../security.md) and is only available for organization-owned repositories. + +```php +$params = [ + 'defunkt', +]; +$protection = $client->api('repo')->protection()->removeUserRestrictions('twbs', 'bootstrap', 'master', $params); +``` diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 33c68bf7960..3c96e668933 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -66,4 +66,375 @@ public function remove($username, $repository, $branch) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection'); } + + /** + * Get required status checks of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The required status checks information + */ + public function showStatusChecks($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks'); + } + + /** + * Update required status checks of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks information + * + * @return array The updated branch status checks information + */ + public function updateStatusChecks($username, $repository, $branch, array $params = array()) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks', $params); + } + + /** + * Remove required status checks of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removeStatusChecks($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks'); + } + + /** + * List required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The required status checks contexts information + */ + public function showStatusChecksContexts($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts'); + } + + /** + * Replace required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information + * + * @return array The new branch status checks contexts information + */ + public function replaceStatusChecksContexts($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); + } + + /** + * Add required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information + * + * @return array The updated branch status checks contexts information + */ + public function addStatusChecksContexts($username, $repository, $branch, array $params = array()) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); + } + + /** + * Remove required status checks contexts of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks contexts information + * + * @return array The updated branch status checks contexts information + */ + public function removeStatusChecksContexts($username, $repository, $branch, array $params = array()) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_status_checks/contexts', $params); + } + + /** + * Get pull request review enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The pull request review enforcement information + */ + public function showPullRequestReviewEnforcement($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews'); + } + + /** + * Update pull request review enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The branch status checks information + * + * @return array The updated branch status checks information + */ + public function updatePullRequestReviewEnforcement($username, $repository, $branch, array $params = array()) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews', $params); + } + + /** + * Remove pull request review enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removePullRequestReviewEnforcement($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/required_pull_request_reviews'); + } + + /** + * Get admin enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The admin enforcement information + */ + public function showAdminEnforcement($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins'); + } + + /** + * Add admin enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The updated admin enforcement information + */ + public function addAdminEnforcement($username, $repository, $branch) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins'); + } + + /** + * Remove admin enforcement of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removeAdminEnforcement($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/enforce_admins'); + } + + /** + * Get restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch restrictions information + */ + public function showRestrictions($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions'); + } + + /** + * Remove restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + */ + public function removeRestrictions($username, $repository, $branch) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions'); + } + + /** + * List team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch team restrictions information + */ + public function showTeamRestrictions($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams'); + } + + /** + * Replace team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access + * + * @return array The new branch team restrictions information + */ + public function replaceTeamRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); + } + + /** + * Add team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access + * + * @return array The branch team restrictions information + */ + public function addTeamRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); + } + + /** + * Remove team restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of team slugs with push access + * + * @return array The updated branch team restrictions information + */ + public function removeTeamRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/teams', $params); + } + + /** + * List user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * + * @return array The branch user restrictions information + */ + public function showUserRestrictions($username, $repository, $branch) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users'); + } + + /** + * Replace user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access + * + * @return array The new branch user restrictions information + */ + public function replaceUserRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); + } + + /** + * Add user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access + * + * @return array The branch user restrictions information + */ + public function addUserRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); + } + + /** + * Remove user restrictions of protected branch + * + * @link https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch + * + * @param string $username The user who owns the repository + * @param string $repository The name of the repo + * @param string $branch The name of the branch + * @param array $params The list of user logins with push access + * + * @return array The updated branch user restrictions information + */ + public function removeUserRestrictions($username, $repository, $branch, array $params = array()) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/branches/'.rawurlencode($branch).'/protection/restrictions/users', $params); + } } diff --git a/test/Github/Tests/Api/Repository/ProtectionTest.php b/test/Github/Tests/Api/Repository/ProtectionTest.php index 5b1fb62f17b..53f4e7ade69 100644 --- a/test/Github/Tests/Api/Repository/ProtectionTest.php +++ b/test/Github/Tests/Api/Repository/ProtectionTest.php @@ -55,6 +55,385 @@ public function shouldRemoveProtection() $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'master')); } + /** + * @test + */ + public function shouldShowStatusChecks() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showStatusChecks('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldUpdateStatusChecks() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->updateStatusChecks('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveStatusChecks() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeStatusChecks('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowStatusChecksContexts() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showStatusChecksContexts('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldReplaceStatusChecksContexts() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->replaceStatusChecksContexts('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldAddStatusChecksContexts() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addStatusChecksContexts('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveStatusChecksContexts() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_status_checks/contexts') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeStatusChecksContexts('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldShowPullRequestReviewEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_pull_request_reviews') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showPullRequestReviewEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldUpdatePullRequestReviewEnforcement() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_pull_request_reviews') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->updatePullRequestReviewEnforcement('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemovePullRequestReviewEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/required_pull_request_reviews') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removePullRequestReviewEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowAdminEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/enforce_admins') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showAdminEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldAddAdminEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/enforce_admins') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addAdminEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldRemoveAdminEnforcement() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/enforce_admins') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeAdminEnforcement('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldRemoveRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldShowTeamRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showTeamRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldReplaceTeamRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->replaceTeamRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldAddTeamRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addTeamRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveTeamRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/teams') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeTeamRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldShowUserRestrictions() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->showUserRestrictions('KnpLabs', 'php-github-api', 'master')); + } + + /** + * @test + */ + public function shouldReplaceUserRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->replaceUserRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldAddUserRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->addUserRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + + /** + * @test + */ + public function shouldRemoveUserRestrictions() + { + $expectedValue = array('someOutput'); + $data = array('someInput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/branches/master/protection/restrictions/users') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->removeUserRestrictions('KnpLabs', 'php-github-api', 'master', $data)); + } + /** * @return string */