Skip to content
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
18 changes: 13 additions & 5 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ $repos = $client->api('repo')->find('symfony');
```

Returns a list of repositories.

#### Advanced search

You can filter the results by language. It takes the same values as the language drop down on [http://github.com/search](http://github.com/search).
Expand Down Expand Up @@ -179,20 +178,29 @@ Returns a list of the collaborators for the 'reponame' repository.
### Add a collaborator to a repository

```php
$client->api('repo')->collaborators()->add('username', 'reponame', 'KnpLabs');
$client->api('repo')->collaborators()->add('username', 'reponame', 'collaborator');
```

Adds the 'username' user as collaborator to the 'reponame' repository.
Adds the 'collaborator' user as collaborator to the 'reponame' repository.

### Remove a collaborator from a repository

> Requires [authentication](security.md).

```php
$client->api('repo')->collaborators()->remove('username', 'reponame', 'KnpLabs');
$client->api('repo')->collaborators()->remove('username', 'reponame', 'collaborator');
```

Remove the 'username' collaborator from the 'reponame' repository.
Remove the 'collaborator' collaborator from the 'reponame' repository.

### Get the permissions of a collaborator for a repository

```php
$permissions = $client->api('repo')->collaborators()->permission('username', 'reponame', 'collaborator');
```

Returns the permissions of 'collaborator' collaborator for the 'reponame' repository.


### Watch and unwatch a repository

Expand Down
12 changes: 12 additions & 0 deletions lib/Github/Api/Repository/Collaborators.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@ public function remove($username, $repository, $collaborator)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator));
}

/**
* @link https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
* @param $username
* @param $repository
* @param $collaborator
* @return array|string
*/
public function permission($username, $repository, $collaborator)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator).'/permission');
}
}
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/Repository/CollaboratorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public function shouldRemoveRepositoryCollaborator()
$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0'));
}

/**
* @test
*/
public function shouldGetRepositoryCollaboratorPermission()
{
$expectedValue = array(array('permission' => 'admin', 'user' => 'l3l0'));

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/collaborators/l3l0/permission')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->permission('KnpLabs', 'php-github-api', 'l3l0'));
}

/**
* @return string
*/
Expand Down