diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 401dbe4f116..8b84028db24 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -32,12 +32,24 @@ public function create($organization, array $params) return $this->post('/orgs/'.rawurlencode($organization).'/teams', $params); } - public function show($team) + /** + * @link https://developer.github.com/v3/teams/#list-teams + */ + public function show($team, $organization = null) { - return $this->get('/teams/'.rawurlencode($team)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->get('/teams/'.rawurlencode($team)); + } + + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } - public function update($team, array $params) + /** + * @link https://developer.github.com/v3/teams/#edit-team + */ + public function update($team, array $params, $organization = null) { if (!isset($params['name'])) { throw new MissingArgumentException('name'); @@ -46,32 +58,83 @@ public function update($team, array $params) $params['permission'] = 'pull'; } - return $this->patch('/teams/'.rawurlencode($team), $params); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->patch('/teams/'.rawurlencode($team), $params); + } + + return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); } - public function remove($team) + /** + * @link https://developer.github.com/v3/teams/#delete-team + */ + public function remove($team, $organization = null) { - return $this->delete('/teams/'.rawurlencode($team)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->delete('/teams/'.rawurlencode($team)); + } + + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } - public function members($team) + /** + * @link https://developer.github.com/v3/teams/members/#list-team-members + */ + public function members($team, $organization = null) { - return $this->get('/teams/'.rawurlencode($team).'/members'); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->get('/teams/'.rawurlencode($team).'/members'); + } + + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); } - public function check($team, $username) + /** + * @link https://developer.github.com/v3/teams/members/#get-team-membership + */ + public function check($team, $username, $organization = null) { - return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + } + + return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - public function addMember($team, $username) + /** + * @link https://developer.github.com/v3/teams/members/#add-or-update-team-membership + */ + public function addMember($team, $username, $organization = null) { - return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + } + + return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } - public function removeMember($team, $username) + /** + * @link https://developer.github.com/v3/teams/members/#remove-team-membership + */ + public function removeMember($team, $username, $organization = null) { - return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + if (null === $organization) { + @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); + + return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); + } + + return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } public function repositories($team) diff --git a/test/Github/Tests/Api/Organization/TeamsTest.php b/test/Github/Tests/Api/Organization/TeamsTest.php index 3c5474181e7..3538113ad61 100644 --- a/test/Github/Tests/Api/Organization/TeamsTest.php +++ b/test/Github/Tests/Api/Organization/TeamsTest.php @@ -33,10 +33,10 @@ public function shouldCheckIfMemberIsInOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/teams/KnpWorld/memberships/l3l0') + ->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0')); + $this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0', 'KnpLabs')); } /** @@ -49,10 +49,10 @@ public function shouldRemoveOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/teams/KnpWorld') + ->with('/orgs/KnpLabs/teams/KnpWorld') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->remove('KnpWorld')); + $this->assertEquals($expectedValue, $api->remove('KnpWorld', 'KnpLabs')); } /** @@ -65,10 +65,10 @@ public function shouldShowOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/teams/KnpWorld') + ->with('/orgs/KnpLabs/teams/KnpWorld') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->show('KnpWorld')); + $this->assertEquals($expectedValue, $api->show('KnpWorld', 'KnpLabs')); } /** @@ -81,10 +81,10 @@ public function shouldGetTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/teams/KnpWorld/members') + ->with('/orgs/KnpLabs/teams/KnpWorld/members') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->members('KnpWorld')); + $this->assertEquals($expectedValue, $api->members('KnpWorld', 'KnpLabs')); } /** @@ -97,10 +97,10 @@ public function shouldAddTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('/teams/KnpWorld/memberships/l3l0') + ->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0')); + $this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0', 'KnpLabs')); } /** @@ -113,10 +113,10 @@ public function shouldRemoveTeamMembers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/teams/KnpWorld/memberships/l3l0') + ->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0')); + $this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0', 'KnpLabs')); } /** @@ -261,7 +261,7 @@ public function shouldNotUpdateTeamWithoutName() $api->expects($this->never()) ->method('patch'); - $api->update('KnpWorld', $data); + $api->update('KnpWorld', $data, 'KnpLabs'); } /** @@ -275,10 +275,10 @@ public function shouldUpdateOrganizationTeam() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/teams/KnpWorld', $data) + ->with('/orgs/KnpLabs/teams/KnpWorld', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); + $this->assertEquals($expectedValue, $api->update('KnpWorld', $data, 'KnpLabs')); } /** @@ -292,10 +292,10 @@ public function shouldUpdateWithPullPermissionWhenPermissionParamNotRecognized() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull']) + ->with('/orgs/KnpLabs/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull']) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpWorld', $data)); + $this->assertEquals($expectedValue, $api->update('KnpWorld', $data, 'KnpLabs')); } /**