diff --git a/doc/repos.md b/doc/repos.md index d6abe19a0fe..c5dbfe89b7a 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -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 diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a626594ade3..151a61b6790 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -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. * diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index e6dfaa619a9..ff1fe4f7e6e 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -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 */