From 3bce87ce3c6f348a46fd704c3d10fb2c4205efa4 Mon Sep 17 00:00:00 2001 From: Sara Bine Date: Wed, 29 Jan 2020 17:16:48 -0800 Subject: [PATCH] Add repo community profile API endpoint --- doc/repos.md | 6 ++++++ lib/Github/Api/Repo.php | 18 ++++++++++++++++++ test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 3 files changed, 40 insertions(+) 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 e9eaf44c781..682fcfb856e 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 */