Skip to content

Commit

Permalink
feature #860 Replace deprecated Organization\Teams api calls (lolos)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.13.x-dev branch.

Discussion
----------

This Pull Request fixes the API calls for the functions:
- \Github\Api\Organization\Teams::show
- \Github\Api\Organization\Teams::update
- \Github\Api\Organization\Teams::remove
- \Github\Api\Organization\Teams::members
- \Github\Api\Organization\Teams::check
- \Github\Api\Organization\Teams::addMember
- \Github\Api\Organization\Teams::removeMember

based on the official Github's v3 API documentation:
- https://developer.github.com/v3/teams/
- https://developer.github.com/v3/teams/members/

since those functions incorrectly threw `Github\Exception\RuntimeException: Not Found`

Commits
-------

624da98 Ignore PHPStorm's .idea directory
3f332ed Fix various Teams' URIs
7742bd1 Revert "Ignore PHPStorm's .idea directory"
ca63e29 fixes backward compatibility check
9f5071c fix update()
6ecdb0a style fix
6ceeb55 changes based on @acrobat's suggestions
2550444 styling fix
  • Loading branch information
acrobat authored Apr 20, 2020
2 parents 67794ac + 2550444 commit d3d6756
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 31 deletions.
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

0 comments on commit d3d6756

Please sign in to comment.