Skip to content

Commit

Permalink
Merge pull request #846 from sbine/master
Browse files Browse the repository at this point in the history
Add repo community profile API endpoint
  • Loading branch information
acrobat committed Feb 15, 2020
2 parents 8e99737 + 3bce87c commit 784b3e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/repos.md
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
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
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

0 comments on commit 784b3e9

Please sign in to comment.