Skip to content

Missing code of conduct api endpoints #656

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
Dec 12, 2017
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
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ v3 APIs:
* [Timeline](issue/timeline.md)
* [Meta](meta.md)
* Miscellaneous
* [Code of conduct](miscellaneous/codeofconduct.md)
* [Emojis](miscellaneous/emojis.md)
* [Gitignore](miscellaneous/gitignore.md)
* [Markdown](miscellaneous/markdown.md)
Expand Down
14 changes: 14 additions & 0 deletions doc/miscellaneous/codeofconduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## CodeOfConduct API
[Back to the navigation](../README.md)

### Lists all code of conducts.

```php
$codeOfConducts = $client->api('codeOfConduct')->all();
```

### Get a code of conduct.

```php
$codeOfConducts = $client->api('codeOfConduct')->show('contributor_covenant');
```
6 changes: 6 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,9 @@ $milestones = $client->api('repo')->milestones('ornicar', 'php-github-api');
```

Returns a list of milestones.

### Get the contents of a repository's code of conduct

```php
$codeOfConduct = $client->api('repo')->codeOfConduct('ornicar', 'php-github-api');
```
44 changes: 44 additions & 0 deletions lib/Github/Api/Miscellaneous/CodeOfConduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Github\Api\Miscellaneous;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;

class CodeOfConduct extends AbstractApi
{
use AcceptHeaderTrait;

public function configure()
{
$this->acceptHeaderValue = 'application/vnd.github.scarlet-witch-preview+json';

return $this;
}

/**
* List all codes of conduct.
*
* @link https://developer.github.com/v3/codes_of_conduct/#list-all-codes-of-conduct
*
* @return array
*/
public function all()
{
return $this->get('/codes_of_conduct');
}

/**
* Get an individual code of conduct
*
* @link https://developer.github.com/v3/codes_of_conduct/#get-an-individual-code-of-conduct
*
* @param string $key
*
* @return array
*/
public function show($key)
{
return $this->get('/codes_of_conduct/' . rawurlencode($key));
}
}
20 changes: 20 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
class Repo extends AbstractApi
{
use AcceptHeaderTrait;

/**
* Search repositories by keyword.
*
Expand Down Expand Up @@ -599,4 +601,22 @@ public function events($username, $repository, $page = 1)
{
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]);
}

/**
* Get the contents of a repository's code of conduct
*
* @link https://developer.github.com/v3/codes_of_conduct/#get-the-contents-of-a-repositorys-code-of-conduct
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function codeOfConduct($username, $repository)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.scarlet-witch-preview+json';

return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/code_of_conduct');
}
}
4 changes: 4 additions & 0 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @method Api\CurrentUser me()
* @method Api\Enterprise ent()
* @method Api\Enterprise enterprise()
* @method Api\Miscellaneous\CodeOfConduct codeOfConduct()
* @method Api\Miscellaneous\Emojis emojis()
* @method Api\GitData git()
* @method Api\GitData gitData()
Expand Down Expand Up @@ -169,6 +170,9 @@ public function api($name)
case 'currentUser':
$api = new Api\CurrentUser($this);
break;
case 'codeOfConduct':
$api = new Api\Miscellaneous\CodeOfConduct($this);
break;

case 'deployment':
case 'deployments':
Expand Down
54 changes: 54 additions & 0 deletions test/Github/Tests/Api/Miscellaneous/CodeOfConductTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Github\Tests\Api\Miscellaneous;

use Github\Api\Miscellaneous\CodeOfConduct;
use Github\Tests\Api\TestCase;

class CodeOfConductTest extends TestCase
{
/**
* @test
*/
public function shouldGetAllCodeOfConducts()
{
$expectedArray = [
['name' => 'CoC1'],
['name' => 'CoC2'],
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/codes_of_conduct')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->all());
}

/**
* @test
*/
public function shouldGetSingleCodeOfConducts()
{
$expectedArray = [
'name' => 'CoC',
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/codes_of_conduct/contributor_covenant')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->show('contributor_covenant'));
}

/**
* @return string
*/
protected function getApiClass()
{
return CodeOfConduct::class;
}
}
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,22 @@ public function shouldGetRepositoryEvents()
$this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3));
}

/**
* @test
*/
public function shouldGetRepositoryCodeOfConduct()
{
$expectedArray = array('name' => 'Contributor Covenant', 'url' => 'http://...');

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/community/code_of_conduct')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->codeOfConduct('KnpLabs', 'php-github-api'));
}

/**
* @return string
*/
Expand Down