Skip to content

Commit 784b3e9

Browse files
authored
Merge pull request KnpLabs#846 from sbine/master
Add repo community profile API endpoint
2 parents 8e99737 + 3bce87c commit 784b3e9

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

doc/repos.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ $milestones = $client->api('repo')->milestones('ornicar', 'php-github-api');
312312

313313
Returns a list of milestones.
314314

315+
### Get the community profile metrics for a repository
316+
317+
```php
318+
$communityProfile = $client->api('repo')->communityProfile('ornicar', 'php-github-api');
319+
```
320+
315321
### Get the contents of a repository's code of conduct
316322

317323
```php

lib/Github/Api/Repo.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,24 @@ public function events($username, $repository, $page = 1)
627627
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]);
628628
}
629629

630+
/**
631+
* Get the community profile metrics for a repository.
632+
*
633+
* @link https://developer.github.com/v3/repos/community/#retrieve-community-profile-metrics
634+
*
635+
* @param string $username
636+
* @param string $repository
637+
*
638+
* @return array
639+
*/
640+
public function communityProfile($username, $repository)
641+
{
642+
//This api is in preview mode, so set the correct accept-header
643+
$this->acceptHeaderValue = 'application/vnd.github.black-panther-preview+json';
644+
645+
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/community/profile');
646+
}
647+
630648
/**
631649
* Get the contents of a repository's code of conduct.
632650
*

test/Github/Tests/Api/RepoTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,22 @@ public function shouldGetRepositoryEvents()
538538
$this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3));
539539
}
540540

541+
/**
542+
* @test
543+
*/
544+
public function shouldGetRepositoryCommunityProfile()
545+
{
546+
$expectedArray = ['health_percentage' => 100, 'description' => 'A simple PHP GitHub API client...'];
547+
548+
$api = $this->getApiMock();
549+
$api->expects($this->once())
550+
->method('get')
551+
->with('/repos/KnpLabs/php-github-api/community/profile')
552+
->will($this->returnValue($expectedArray));
553+
554+
$this->assertEquals($expectedArray, $api->communityProfile('KnpLabs', 'php-github-api'));
555+
}
556+
541557
/**
542558
* @test
543559
*/

0 commit comments

Comments
 (0)