Skip to content

Commit 556d978

Browse files
selatoracrobat
authored andcommitted
Add collaborator permission call (KnpLabs#678)
* Add collaborator permission call * Add docs for permission() call
1 parent 8465bbb commit 556d978

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

doc/repos.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ $repos = $client->api('repo')->find('symfony');
2727
```
2828

2929
Returns a list of repositories.
30-
3130
#### Advanced search
3231

3332
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).
@@ -179,20 +178,29 @@ Returns a list of the collaborators for the 'reponame' repository.
179178
### Add a collaborator to a repository
180179

181180
```php
182-
$client->api('repo')->collaborators()->add('username', 'reponame', 'KnpLabs');
181+
$client->api('repo')->collaborators()->add('username', 'reponame', 'collaborator');
183182
```
184183

185-
Adds the 'username' user as collaborator to the 'reponame' repository.
184+
Adds the 'collaborator' user as collaborator to the 'reponame' repository.
186185

187186
### Remove a collaborator from a repository
188187

189188
> Requires [authentication](security.md).
190189
191190
```php
192-
$client->api('repo')->collaborators()->remove('username', 'reponame', 'KnpLabs');
191+
$client->api('repo')->collaborators()->remove('username', 'reponame', 'collaborator');
193192
```
194193

195-
Remove the 'username' collaborator from the 'reponame' repository.
194+
Remove the 'collaborator' collaborator from the 'reponame' repository.
195+
196+
### Get the permissions of a collaborator for a repository
197+
198+
```php
199+
$permissions = $client->api('repo')->collaborators()->permission('username', 'reponame', 'collaborator');
200+
```
201+
202+
Returns the permissions of 'collaborator' collaborator for the 'reponame' repository.
203+
196204

197205
### Watch and unwatch a repository
198206

lib/Github/Api/Repository/Collaborators.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,16 @@ public function remove($username, $repository, $collaborator)
6767
{
6868
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator));
6969
}
70+
71+
/**
72+
* @link https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
73+
* @param $username
74+
* @param $repository
75+
* @param $collaborator
76+
* @return array|string
77+
*/
78+
public function permission($username, $repository, $collaborator)
79+
{
80+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/collaborators/'.rawurlencode($collaborator).'/permission');
81+
}
7082
}

test/Github/Tests/Api/Repository/CollaboratorsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ public function shouldRemoveRepositoryCollaborator()
7070
$this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', 'l3l0'));
7171
}
7272

73+
/**
74+
* @test
75+
*/
76+
public function shouldGetRepositoryCollaboratorPermission()
77+
{
78+
$expectedValue = array(array('permission' => 'admin', 'user' => 'l3l0'));
79+
80+
$api = $this->getApiMock();
81+
$api->expects($this->once())
82+
->method('get')
83+
->with('/repos/KnpLabs/php-github-api/collaborators/l3l0/permission')
84+
->will($this->returnValue($expectedValue));
85+
86+
$this->assertEquals($expectedValue, $api->permission('KnpLabs', 'php-github-api', 'l3l0'));
87+
}
88+
7389
/**
7490
* @return string
7591
*/

0 commit comments

Comments
 (0)