Skip to content

Commit bad4c44

Browse files
committed
Merge pull request #117 from guillermoandrae/master
Added ability to pull a year's worth of commit activity for a repository
2 parents dfc9ea0 + 7192587 commit bad4c44

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

doc/repos.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,11 @@ To include non GitHub users, add a third parameter to true:
230230
```php
231231
$contributors = $client->api('repo')->contributors('ornicar', 'php-github-api', true);
232232
```
233+
234+
### Get the commit activity of a repository
235+
236+
```php
237+
$activity = $client->api('repo')->activity('ornicar', 'php-github-api');
238+
```
239+
240+
Returns an array of commit activity group by week.

lib/Github/Api/Repo.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,33 @@ public function find($keyword, array $params = array())
3939
}
4040

4141
/**
42-
* Get contributor commit statistics for a repository
43-
* @link http://developer.github.com/v3/repos/statistics/#contributors
42+
* Get the last year of commit activity for a repository grouped by week
43+
* @link http://developer.github.com/v3/repos/statistics/#commit-activity
4444
*
4545
* @param string $username the user who owns the repository
4646
* @param string $repository the name of the repository
4747
*
48-
* @return array list of contributors and their commit statistics
48+
* @return array commit activity grouped by week
4949
*/
50-
public function statistics($username, $repository)
50+
public function activity($username, $repository)
5151
{
52-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors');
52+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/commit_activity');
5353
}
5454

55+
/**
56+
* Get contributor commit statistics for a repository
57+
* @link http://developer.github.com/v3/repos/statistics/#contributors
58+
*
59+
* @param string $username the user who owns the repository
60+
* @param string $repository the name of the repository
61+
*
62+
* @return array list of contributors and their commit statistics
63+
*/
64+
public function statistics($username, $repository)
65+
{
66+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/stats/contributors');
67+
}
68+
5569
/**
5670
* List all repositories for an organization
5771
* @link http://developer.github.com/v3/repos/#list-organization-repositories

test/Github/Tests/Api/RepoTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,22 @@ public function shouldGetReleasesApiObject()
417417
$this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases());
418418
}
419419

420+
/**
421+
* @test
422+
*/
423+
public function shouldGetCommitActivity()
424+
{
425+
$expectedArray = array(array('days' => array(0, 3, 26, 20, 39, 1, 0), 'total' => 89, 'week' => 1336280400));
426+
427+
$api = $this->getApiMock();
428+
$api->expects($this->once())
429+
->method('get')
430+
->with('repos/KnpLabs/php-github-api/stats/commit_activity')
431+
->will($this->returnValue($expectedArray));
432+
433+
$this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api'));
434+
}
435+
420436
protected function getApiClass()
421437
{
422438
return 'Github\Api\Repo';

0 commit comments

Comments
 (0)