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
6 changes: 6 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ $milestones = $client->api('repo')->milestones('ornicar', 'php-github-api');

Returns a list of milestones.

### Get the community profile metrics for a repository

```php
$communityProfile = $client->api('repo')->communityProfile('ornicar', 'php-github-api');
```

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

```php
Expand Down
18 changes: 18 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,24 @@ public function events($username, $repository, $page = 1)
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]);
}

/**
* Get the community profile metrics for a repository.
*
* @link https://developer.github.com/v3/repos/community/#retrieve-community-profile-metrics
*
* @param string $username
* @param string $repository
*
* @return array
*/
public function communityProfile($username, $repository)
{
//This api is in preview mode, so set the correct accept-header
$this->acceptHeaderValue = 'application/vnd.github.black-panther-preview+json';

return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/profile');
}

/**
* Get the contents of a repository's code of conduct.
*
Expand Down
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,22 @@ public function shouldGetRepositoryEvents()
$this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3));
}

/**
* @test
*/
public function shouldGetRepositoryCommunityProfile()
{
$expectedArray = ['health_percentage' => 100, 'description' => 'A simple PHP GitHub API client...'];

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

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

/**
* @test
*/
Expand Down