Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repo community profile API endpoint #846

Merged
merged 1 commit into from Feb 15, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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