Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,11 @@ To include non GitHub users, add a third parameter to true:
```php
$contributors = $client->api('repo')->contributors('ornicar', 'php-github-api', true);
```

### Get the commit activity of a repository

```php
$activity = $client->api('repo')->activity('ornicar', 'php-github-api');
```

Returns an array of commit activity group by week.
24 changes: 19 additions & 5 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,33 @@ public function find($keyword, array $params = array())
}

/**
* Get contributor commit statistics for a repository
* @link http://developer.github.com/v3/repos/statistics/#contributors
* Get the last year of commit activity for a repository grouped by week
* @link http://developer.github.com/v3/repos/statistics/#commit-activity
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of contributors and their commit statistics
* @return array commit activity grouped by week
*/
public function statistics($username, $repository)
public function activity($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors');
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity');
}

/**
* Get contributor commit statistics for a repository
* @link http://developer.github.com/v3/repos/statistics/#contributors
*
* @param string $username the user who owns the repository
* @param string $repository the name of the repository
*
* @return array list of contributors and their commit statistics
*/
public function statistics($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors');
}

/**
* List all repositories for an organization
* @link http://developer.github.com/v3/repos/#list-organization-repositories
Expand Down
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@ public function shouldGetReleasesApiObject()
$this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases());
}

/**
* @test
*/
public function shouldGetCommitActivity()
{
$expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400));

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('repos/KnpLabs/php-github-api/stats/commit_activity')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api'));
}

protected function getApiClass()
{
return 'Github\Api\Repo';
Expand Down