Skip to content

Replace deprecated Organization\Teams api calls #860

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 8 commits into from
Apr 20, 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
91 changes: 77 additions & 14 deletions lib/Github/Api/Organization/Teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions test/Github/Tests/Api/Organization/TeamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -261,7 +261,7 @@ public function shouldNotUpdateTeamWithoutName()
$api->expects($this->never())
->method('patch');

$api->update('KnpWorld', $data);
$api->update('KnpWorld', $data, 'KnpLabs');
}

/**
Expand All @@ -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'));
}

/**
Expand All @@ -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'));
}

/**
Expand Down