diff --git a/doc/repos.md b/doc/repos.md index fd8601a3b9e..d3c62ed203c 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -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. \ No newline at end of file diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a7fd586e16d..892e807d538 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -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 diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 84fba69f843..90366110110 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -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';