Skip to content

Add OutsideCollaborators api #925

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 1 commit into from
Oct 5, 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
9 changes: 9 additions & 0 deletions lib/Github/Api/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\Organization\Hooks;
use Github\Api\Organization\Members;
use Github\Api\Organization\OutsideCollaborators;
use Github\Api\Organization\Teams;

/**
Expand Down Expand Up @@ -100,6 +101,14 @@ public function teams()
return new Teams($this->client);
}

/**
* @return OutsideCollaborators
*/
public function outsideCollaborators()
{
return new OutsideCollaborators($this->client);
}

/**
* @link http://developer.github.com/v3/issues/#list-issues
*
Expand Down
52 changes: 52 additions & 0 deletions lib/Github/Api/Organization/OutsideCollaborators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Github\Api\Organization;

use Github\Api\AbstractApi;

/**
* @link https://developer.github.com/v3/orgs/outside_collaborators/
*
* @author Matthieu Calie <matthieu@calie.be>
*/
class OutsideCollaborators extends AbstractApi
{
/**
* @link https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators-for-an-organization
*
* @param string $organization the organization
* @param array $params
*
* @return array the organizations
*/
public function all($organization, array $params = [])
{
return $this->get('/orgs/'.rawurlencode($organization).'/outside_collaborators', $params);
}

/**
* @link https://developer.github.com/v3/orgs/outside_collaborators/#convert-an-organization-member-to-outside-collaborator
*
* @param string $organization the organization
* @param string $username the github username
*
* @return array
*/
public function convert($organization, $username)
{
return $this->put('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username));
}

/**
* @link https://developer.github.com/v3/orgs/outside_collaborators/#remove-outside-collaborator-from-an-organization
*
* @param string $organization the organization
* @param string $username the username
*
* @return array
*/
public function remove($organization, $username)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/outside_collaborators/'.rawurldecode($username));
}
}
92 changes: 49 additions & 43 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,50 @@
/**
* Simple yet very cool PHP GitHub client.
*
* @method Api\CurrentUser currentUser()
* @method Api\CurrentUser me()
* @method Api\Enterprise ent()
* @method Api\Enterprise enterprise()
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
* @method Api\Miscellaneous\Emojis emojis()
* @method Api\Miscellaneous\Licenses licenses()
* @method Api\GitData git()
* @method Api\GitData gitData()
* @method Api\Gists gist()
* @method Api\Gists gists()
* @method Api\Miscellaneous\Gitignore gitignore()
* @method Api\Integrations integration() (deprecated)
* @method Api\Integrations integrations() (deprecated)
* @method Api\Apps apps()
* @method Api\Issue issue()
* @method Api\Issue issues()
* @method Api\Markdown markdown()
* @method Api\Notification notification()
* @method Api\Notification notifications()
* @method Api\Organization organization()
* @method Api\Organization organizations()
* @method Api\Organization\Projects orgProject()
* @method Api\Organization\Projects orgProjects()
* @method Api\Organization\Projects organizationProject()
* @method Api\Organization\Projects organizationProjects()
* @method Api\PullRequest pr()
* @method Api\PullRequest pullRequest()
* @method Api\PullRequest pullRequests()
* @method Api\RateLimit rateLimit()
* @method Api\Repo repo()
* @method Api\Repo repos()
* @method Api\Repo repository()
* @method Api\Repo repositories()
* @method Api\Search search()
* @method Api\Organization\Teams team()
* @method Api\Organization\Teams teams()
* @method Api\User user()
* @method Api\User users()
* @method Api\Authorizations authorization()
* @method Api\Authorizations authorizations()
* @method Api\Meta meta()
* @method Api\GraphQL graphql()
* @method Api\CurrentUser currentUser()
* @method Api\CurrentUser me()
* @method Api\Enterprise ent()
* @method Api\Enterprise enterprise()
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
* @method Api\Miscellaneous\Emojis emojis()
* @method Api\Miscellaneous\Licenses licenses()
* @method Api\GitData git()
* @method Api\GitData gitData()
* @method Api\Gists gist()
* @method Api\Gists gists()
* @method Api\Miscellaneous\Gitignore gitignore()
* @method Api\Integrations integration() (deprecated)
* @method Api\Integrations integrations() (deprecated)
* @method Api\Apps apps()
* @method Api\Issue issue()
* @method Api\Issue issues()
* @method Api\Markdown markdown()
* @method Api\Notification notification()
* @method Api\Notification notifications()
* @method Api\Organization organization()
* @method Api\Organization organizations()
* @method Api\Organization\Projects orgProject()
* @method Api\Organization\Projects orgProjects()
* @method Api\Organization\Projects organizationProject()
* @method Api\Organization\Projects organizationProjects()
* @method Api\Organization\OutsideCollaborators outsideCollaborators()
* @method Api\PullRequest pr()
* @method Api\PullRequest pullRequest()
* @method Api\PullRequest pullRequests()
* @method Api\RateLimit rateLimit()
* @method Api\Repo repo()
* @method Api\Repo repos()
* @method Api\Repo repository()
* @method Api\Repo repositories()
* @method Api\Search search()
* @method Api\Organization\Teams team()
* @method Api\Organization\Teams teams()
* @method Api\User user()
* @method Api\User users()
* @method Api\Authorizations authorization()
* @method Api\Authorizations authorizations()
* @method Api\Meta meta()
* @method Api\GraphQL graphql()
*
* @author Joseph Bielawski <stloyd@gmail.com>
*
Expand Down Expand Up @@ -318,6 +319,11 @@ public function api($name)
$api = new Api\GraphQL($this);
break;

case 'outsideCollaborators':
case 'outside_collaborators':
$api = new Api\Organization\OutsideCollaborators($this);
break;

default:
throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name));
}
Expand Down
66 changes: 66 additions & 0 deletions test/Github/Tests/Api/Organization/OutsideCollaboratorsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace Github\Tests\Api\Organization;

use Github\Tests\Api\TestCase;

class OutsideCollaboratorsTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllRepositoryProjects()
{
$expectedValue = [['login' => 'KnpLabs']];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/orgs/KnpLabs/outside_collaborators')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->all('KnpLabs'));
}

/**
* @test
*/
public function shouldConvertAnOrganizationMemberToOutsideCollaborator()
{
$expectedValue = 'expectedResponse';

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('/orgs/KnpLabs/outside_collaborators/username')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->convert('KnpLabs', 'username'));
}

/**
* @test
*/
public function shouldRemoveAnOutsideCollaboratorFromAnOrganization()
{
$expectedValue = 'expectedResponse';

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('/orgs/KnpLabs/outside_collaborators/username')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'username'));
}

/**
* @return string
*/
protected function getApiClass()
{
return \Github\Api\Organization\OutsideCollaborators::class;
}
}
3 changes: 3 additions & 0 deletions test/Github/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public function getApiClassesProvider()
['authorizations', Api\Authorizations::class],

['meta', Api\Meta::class],

['outsideCollaborators', Api\Organization\OutsideCollaborators::class],
['outside_collaborators', Api\Organization\OutsideCollaborators::class],
];
}

Expand Down