Skip to content

Commit 8de302c

Browse files
authored
feature #925 Add OutsideCollaborators api (Matth--)
This PR was merged into the 2.x branch. Discussion ---------- https://developer.github.com/v3/orgs/outside_collaborators/ Commits ------- da5124c Add OutsideCollaborators api
2 parents 4bc9fb9 + da5124c commit 8de302c

File tree

5 files changed

+179
-43
lines changed

5 files changed

+179
-43
lines changed

lib/Github/Api/Organization.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Api\Organization\Hooks;
66
use Github\Api\Organization\Members;
7+
use Github\Api\Organization\OutsideCollaborators;
78
use Github\Api\Organization\Teams;
89

910
/**
@@ -100,6 +101,14 @@ public function teams()
100101
return new Teams($this->client);
101102
}
102103

104+
/**
105+
* @return OutsideCollaborators
106+
*/
107+
public function outsideCollaborators()
108+
{
109+
return new OutsideCollaborators($this->client);
110+
}
111+
103112
/**
104113
* @link http://developer.github.com/v3/issues/#list-issues
105114
*
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Github\Api\Organization;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://developer.github.com/v3/orgs/outside_collaborators/
9+
*
10+
* @author Matthieu Calie <matthieu@calie.be>
11+
*/
12+
class OutsideCollaborators extends AbstractApi
13+
{
14+
/**
15+
* @link https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators-for-an-organization
16+
*
17+
* @param string $organization the organization
18+
* @param array $params
19+
*
20+
* @return array the organizations
21+
*/
22+
public function all($organization, array $params = [])
23+
{
24+
return $this->get('/orgs/'.rawurlencode($organization).'/outside_collaborators', $params);
25+
}
26+
27+
/**
28+
* @link https://developer.github.com/v3/orgs/outside_collaborators/#convert-an-organization-member-to-outside-collaborator
29+
*
30+
* @param string $organization the organization
31+
* @param string $username the github username
32+
*
33+
* @return array
34+
*/
35+
public function convert($organization, $username)
36+
{
37+
return $this->put('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username));
38+
}
39+
40+
/**
41+
* @link https://developer.github.com/v3/orgs/outside_collaborators/#remove-outside-collaborator-from-an-organization
42+
*
43+
* @param string $organization the organization
44+
* @param string $username the username
45+
*
46+
* @return array
47+
*/
48+
public function remove($organization, $username)
49+
{
50+
return $this->delete('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username));
51+
}
52+
}

lib/Github/Client.php

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,50 @@
1919
/**
2020
* Simple yet very cool PHP GitHub client.
2121
*
22-
* @method Api\CurrentUser currentUser()
23-
* @method Api\CurrentUser me()
24-
* @method Api\Enterprise ent()
25-
* @method Api\Enterprise enterprise()
26-
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
27-
* @method Api\Miscellaneous\Emojis emojis()
28-
* @method Api\Miscellaneous\Licenses licenses()
29-
* @method Api\GitData git()
30-
* @method Api\GitData gitData()
31-
* @method Api\Gists gist()
32-
* @method Api\Gists gists()
33-
* @method Api\Miscellaneous\Gitignore gitignore()
34-
* @method Api\Integrations integration() (deprecated)
35-
* @method Api\Integrations integrations() (deprecated)
36-
* @method Api\Apps apps()
37-
* @method Api\Issue issue()
38-
* @method Api\Issue issues()
39-
* @method Api\Markdown markdown()
40-
* @method Api\Notification notification()
41-
* @method Api\Notification notifications()
42-
* @method Api\Organization organization()
43-
* @method Api\Organization organizations()
44-
* @method Api\Organization\Projects orgProject()
45-
* @method Api\Organization\Projects orgProjects()
46-
* @method Api\Organization\Projects organizationProject()
47-
* @method Api\Organization\Projects organizationProjects()
48-
* @method Api\PullRequest pr()
49-
* @method Api\PullRequest pullRequest()
50-
* @method Api\PullRequest pullRequests()
51-
* @method Api\RateLimit rateLimit()
52-
* @method Api\Repo repo()
53-
* @method Api\Repo repos()
54-
* @method Api\Repo repository()
55-
* @method Api\Repo repositories()
56-
* @method Api\Search search()
57-
* @method Api\Organization\Teams team()
58-
* @method Api\Organization\Teams teams()
59-
* @method Api\User user()
60-
* @method Api\User users()
61-
* @method Api\Authorizations authorization()
62-
* @method Api\Authorizations authorizations()
63-
* @method Api\Meta meta()
64-
* @method Api\GraphQL graphql()
22+
* @method Api\CurrentUser currentUser()
23+
* @method Api\CurrentUser me()
24+
* @method Api\Enterprise ent()
25+
* @method Api\Enterprise enterprise()
26+
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
27+
* @method Api\Miscellaneous\Emojis emojis()
28+
* @method Api\Miscellaneous\Licenses licenses()
29+
* @method Api\GitData git()
30+
* @method Api\GitData gitData()
31+
* @method Api\Gists gist()
32+
* @method Api\Gists gists()
33+
* @method Api\Miscellaneous\Gitignore gitignore()
34+
* @method Api\Integrations integration() (deprecated)
35+
* @method Api\Integrations integrations() (deprecated)
36+
* @method Api\Apps apps()
37+
* @method Api\Issue issue()
38+
* @method Api\Issue issues()
39+
* @method Api\Markdown markdown()
40+
* @method Api\Notification notification()
41+
* @method Api\Notification notifications()
42+
* @method Api\Organization organization()
43+
* @method Api\Organization organizations()
44+
* @method Api\Organization\Projects orgProject()
45+
* @method Api\Organization\Projects orgProjects()
46+
* @method Api\Organization\Projects organizationProject()
47+
* @method Api\Organization\Projects organizationProjects()
48+
* @method Api\Organization\OutsideCollaborators outsideCollaborators()
49+
* @method Api\PullRequest pr()
50+
* @method Api\PullRequest pullRequest()
51+
* @method Api\PullRequest pullRequests()
52+
* @method Api\RateLimit rateLimit()
53+
* @method Api\Repo repo()
54+
* @method Api\Repo repos()
55+
* @method Api\Repo repository()
56+
* @method Api\Repo repositories()
57+
* @method Api\Search search()
58+
* @method Api\Organization\Teams team()
59+
* @method Api\Organization\Teams teams()
60+
* @method Api\User user()
61+
* @method Api\User users()
62+
* @method Api\Authorizations authorization()
63+
* @method Api\Authorizations authorizations()
64+
* @method Api\Meta meta()
65+
* @method Api\GraphQL graphql()
6566
*
6667
* @author Joseph Bielawski <stloyd@gmail.com>
6768
*
@@ -318,6 +319,11 @@ public function api($name)
318319
$api = new Api\GraphQL($this);
319320
break;
320321

322+
case 'outsideCollaborators':
323+
case 'outside_collaborators':
324+
$api = new Api\Organization\OutsideCollaborators($this);
325+
break;
326+
321327
default:
322328
throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name));
323329
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Github\Tests\Api\Organization;
6+
7+
use Github\Tests\Api\TestCase;
8+
9+
class OutsideCollaboratorsTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
*/
14+
public function shouldGetAllRepositoryProjects()
15+
{
16+
$expectedValue = [['login' => 'KnpLabs']];
17+
18+
$api = $this->getApiMock();
19+
$api->expects($this->once())
20+
->method('get')
21+
->with('/orgs/KnpLabs/outside_collaborators')
22+
->will($this->returnValue($expectedValue));
23+
24+
$this->assertEquals($expectedValue, $api->all('KnpLabs'));
25+
}
26+
27+
/**
28+
* @test
29+
*/
30+
public function shouldConvertAnOrganizationMemberToOutsideCollaborator()
31+
{
32+
$expectedValue = 'expectedResponse';
33+
34+
$api = $this->getApiMock();
35+
$api->expects($this->once())
36+
->method('put')
37+
->with('/orgs/KnpLabs/outside_collaborators/username')
38+
->will($this->returnValue($expectedValue));
39+
40+
$this->assertEquals($expectedValue, $api->convert('KnpLabs', 'username'));
41+
}
42+
43+
/**
44+
* @test
45+
*/
46+
public function shouldRemoveAnOutsideCollaboratorFromAnOrganization()
47+
{
48+
$expectedValue = 'expectedResponse';
49+
50+
$api = $this->getApiMock();
51+
$api->expects($this->once())
52+
->method('delete')
53+
->with('/orgs/KnpLabs/outside_collaborators/username')
54+
->will($this->returnValue($expectedValue));
55+
56+
$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'username'));
57+
}
58+
59+
/**
60+
* @return string
61+
*/
62+
protected function getApiClass()
63+
{
64+
return \Github\Api\Organization\OutsideCollaborators::class;
65+
}
66+
}

test/Github/Tests/ClientTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public function getApiClassesProvider()
209209
['authorizations', Api\Authorizations::class],
210210

211211
['meta', Api\Meta::class],
212+
213+
['outsideCollaborators', Api\Organization\OutsideCollaborators::class],
214+
['outside_collaborators', Api\Organization\OutsideCollaborators::class],
212215
];
213216
}
214217

0 commit comments

Comments
 (0)