Skip to content

Commit d3d6756

Browse files
authored
feature #860 Replace deprecated Organization\Teams api calls (lolos)
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
2 parents 67794ac + 2550444 commit d3d6756

File tree

2 files changed

+94
-31
lines changed

2 files changed

+94
-31
lines changed

lib/Github/Api/Organization/Teams.php

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,24 @@ public function create($organization, array $params)
3232
return $this->post('/orgs/'.rawurlencode($organization).'/teams', $params);
3333
}
3434

35-
public function show($team)
35+
/**
36+
* @link https://developer.github.com/v3/teams/#list-teams
37+
*/
38+
public function show($team, $organization = null)
3639
{
37-
return $this->get('/teams/'.rawurlencode($team));
40+
if (null === $organization) {
41+
@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);
42+
43+
return $this->get('/teams/'.rawurlencode($team));
44+
}
45+
46+
return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team));
3847
}
3948

40-
public function update($team, array $params)
49+
/**
50+
* @link https://developer.github.com/v3/teams/#edit-team
51+
*/
52+
public function update($team, array $params, $organization = null)
4153
{
4254
if (!isset($params['name'])) {
4355
throw new MissingArgumentException('name');
@@ -46,32 +58,83 @@ public function update($team, array $params)
4658
$params['permission'] = 'pull';
4759
}
4860

49-
return $this->patch('/teams/'.rawurlencode($team), $params);
61+
if (null === $organization) {
62+
@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);
63+
64+
return $this->patch('/teams/'.rawurlencode($team), $params);
65+
}
66+
67+
return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params);
5068
}
5169

52-
public function remove($team)
70+
/**
71+
* @link https://developer.github.com/v3/teams/#delete-team
72+
*/
73+
public function remove($team, $organization = null)
5374
{
54-
return $this->delete('/teams/'.rawurlencode($team));
75+
if (null === $organization) {
76+
@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);
77+
78+
return $this->delete('/teams/'.rawurlencode($team));
79+
}
80+
81+
return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team));
5582
}
5683

57-
public function members($team)
84+
/**
85+
* @link https://developer.github.com/v3/teams/members/#list-team-members
86+
*/
87+
public function members($team, $organization = null)
5888
{
59-
return $this->get('/teams/'.rawurlencode($team).'/members');
89+
if (null === $organization) {
90+
@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);
91+
92+
return $this->get('/teams/'.rawurlencode($team).'/members');
93+
}
94+
95+
return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members');
6096
}
6197

62-
public function check($team, $username)
98+
/**
99+
* @link https://developer.github.com/v3/teams/members/#get-team-membership
100+
*/
101+
public function check($team, $username, $organization = null)
63102
{
64-
return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
103+
if (null === $organization) {
104+
@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);
105+
106+
return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
107+
}
108+
109+
return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
65110
}
66111

67-
public function addMember($team, $username)
112+
/**
113+
* @link https://developer.github.com/v3/teams/members/#add-or-update-team-membership
114+
*/
115+
public function addMember($team, $username, $organization = null)
68116
{
69-
return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
117+
if (null === $organization) {
118+
@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);
119+
120+
return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
121+
}
122+
123+
return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
70124
}
71125

72-
public function removeMember($team, $username)
126+
/**
127+
* @link https://developer.github.com/v3/teams/members/#remove-team-membership
128+
*/
129+
public function removeMember($team, $username, $organization = null)
73130
{
74-
return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
131+
if (null === $organization) {
132+
@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);
133+
134+
return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
135+
}
136+
137+
return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username));
75138
}
76139

77140
public function repositories($team)

test/Github/Tests/Api/Organization/TeamsTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function shouldCheckIfMemberIsInOrganizationTeam()
3333
$api = $this->getApiMock();
3434
$api->expects($this->once())
3535
->method('get')
36-
->with('/teams/KnpWorld/memberships/l3l0')
36+
->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0')
3737
->will($this->returnValue($expectedValue));
3838

39-
$this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0'));
39+
$this->assertEquals($expectedValue, $api->check('KnpWorld', 'l3l0', 'KnpLabs'));
4040
}
4141

4242
/**
@@ -49,10 +49,10 @@ public function shouldRemoveOrganizationTeam()
4949
$api = $this->getApiMock();
5050
$api->expects($this->once())
5151
->method('delete')
52-
->with('/teams/KnpWorld')
52+
->with('/orgs/KnpLabs/teams/KnpWorld')
5353
->will($this->returnValue($expectedValue));
5454

55-
$this->assertEquals($expectedValue, $api->remove('KnpWorld'));
55+
$this->assertEquals($expectedValue, $api->remove('KnpWorld', 'KnpLabs'));
5656
}
5757

5858
/**
@@ -65,10 +65,10 @@ public function shouldShowOrganizationTeam()
6565
$api = $this->getApiMock();
6666
$api->expects($this->once())
6767
->method('get')
68-
->with('/teams/KnpWorld')
68+
->with('/orgs/KnpLabs/teams/KnpWorld')
6969
->will($this->returnValue($expectedValue));
7070

71-
$this->assertEquals($expectedValue, $api->show('KnpWorld'));
71+
$this->assertEquals($expectedValue, $api->show('KnpWorld', 'KnpLabs'));
7272
}
7373

7474
/**
@@ -81,10 +81,10 @@ public function shouldGetTeamMembers()
8181
$api = $this->getApiMock();
8282
$api->expects($this->once())
8383
->method('get')
84-
->with('/teams/KnpWorld/members')
84+
->with('/orgs/KnpLabs/teams/KnpWorld/members')
8585
->will($this->returnValue($expectedValue));
8686

87-
$this->assertEquals($expectedValue, $api->members('KnpWorld'));
87+
$this->assertEquals($expectedValue, $api->members('KnpWorld', 'KnpLabs'));
8888
}
8989

9090
/**
@@ -97,10 +97,10 @@ public function shouldAddTeamMembers()
9797
$api = $this->getApiMock();
9898
$api->expects($this->once())
9999
->method('put')
100-
->with('/teams/KnpWorld/memberships/l3l0')
100+
->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0')
101101
->will($this->returnValue($expectedValue));
102102

103-
$this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0'));
103+
$this->assertEquals($expectedValue, $api->addMember('KnpWorld', 'l3l0', 'KnpLabs'));
104104
}
105105

106106
/**
@@ -113,10 +113,10 @@ public function shouldRemoveTeamMembers()
113113
$api = $this->getApiMock();
114114
$api->expects($this->once())
115115
->method('delete')
116-
->with('/teams/KnpWorld/memberships/l3l0')
116+
->with('/orgs/KnpLabs/teams/KnpWorld/memberships/l3l0')
117117
->will($this->returnValue($expectedValue));
118118

119-
$this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0'));
119+
$this->assertEquals($expectedValue, $api->removeMember('KnpWorld', 'l3l0', 'KnpLabs'));
120120
}
121121

122122
/**
@@ -261,7 +261,7 @@ public function shouldNotUpdateTeamWithoutName()
261261
$api->expects($this->never())
262262
->method('patch');
263263

264-
$api->update('KnpWorld', $data);
264+
$api->update('KnpWorld', $data, 'KnpLabs');
265265
}
266266

267267
/**
@@ -275,10 +275,10 @@ public function shouldUpdateOrganizationTeam()
275275
$api = $this->getApiMock();
276276
$api->expects($this->once())
277277
->method('patch')
278-
->with('/teams/KnpWorld', $data)
278+
->with('/orgs/KnpLabs/teams/KnpWorld', $data)
279279
->will($this->returnValue($expectedValue));
280280

281-
$this->assertEquals($expectedValue, $api->update('KnpWorld', $data));
281+
$this->assertEquals($expectedValue, $api->update('KnpWorld', $data, 'KnpLabs'));
282282
}
283283

284284
/**
@@ -292,10 +292,10 @@ public function shouldUpdateWithPullPermissionWhenPermissionParamNotRecognized()
292292
$api = $this->getApiMock();
293293
$api->expects($this->once())
294294
->method('patch')
295-
->with('/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull'])
295+
->with('/orgs/KnpLabs/teams/KnpWorld', ['name' => 'KnpWorld', 'permission' => 'pull'])
296296
->will($this->returnValue($expectedValue));
297297

298-
$this->assertEquals($expectedValue, $api->update('KnpWorld', $data));
298+
$this->assertEquals($expectedValue, $api->update('KnpWorld', $data, 'KnpLabs'));
299299
}
300300

301301
/**

0 commit comments

Comments
 (0)