From db1995bc025f1cfd24d8a09d11c011cb157e68c8 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 14:39:09 -0500 Subject: [PATCH 1/5] Add the activity() method to return a year's worth of commit activity, grouped by week. --- lib/Github/Api/Repo.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a7fd586e16d..a05d5d1559c 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 From f082186958c5717d333887fa47a5ad6ab4c2b3f7 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 14:46:39 -0500 Subject: [PATCH 2/5] Added documentation for the activity() method. --- doc/repos.md | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From 8e207cbb135f712ff52b84bdf0305249367f5c18 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 15:01:21 -0500 Subject: [PATCH 3/5] Added test for the new activity() method. --- test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 84fba69f843..082ce2fdde0 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'; From d9120252b13ae22769ec47679ebe6cb127476300 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 15:07:59 -0500 Subject: [PATCH 4/5] Fixed spacing. --- lib/Github/Api/Repo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index a05d5d1559c..892e807d538 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -40,7 +40,7 @@ public function find($keyword, array $params = array()) /** * Get the last year of commit activity for a repository grouped by week - * @link http://developer.github.com/v3/repos/statistics/#commit-activity + * @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 From 719258739930276602af7b86ff3be2f466b7e524 Mon Sep 17 00:00:00 2001 From: "Guillermo A. Fisher" Date: Fri, 14 Feb 2014 15:16:54 -0500 Subject: [PATCH 5/5] Fixed spacing. --- test/Github/Tests/Api/RepoTest.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 082ce2fdde0..90366110110 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -417,21 +417,21 @@ 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')); - } + /** + * @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() {