Skip to content

Commit bed18bf

Browse files
Albin KerouantonNyholm
authored andcommitted
Add a method to fetch repository events (#605)
See [github documentation](https://developer.github.com/v3/activity/events/#list-repository-events).
1 parent 0b5cd52 commit bed18bf

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/Github/Api/Repo.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function show($username, $repository)
150150
{
151151
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository));
152152
}
153-
153+
154154
/**
155155
* Get extended information about a repository by its id.
156156
* Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on.
@@ -580,9 +580,23 @@ public function projects()
580580
{
581581
return new Projects($this->client);
582582
}
583-
583+
584584
public function traffic()
585585
{
586586
return new Traffic($this->client);
587587
}
588+
589+
/**
590+
* @param string $username
591+
* @param string $repository
592+
* @param int $page
593+
*
594+
* @return array|string
595+
*
596+
* @see https://developer.github.com/v3/activity/events/#list-repository-events
597+
*/
598+
public function events($username, $repository, $page = 1)
599+
{
600+
return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]);
601+
}
588602
}

test/Github/Tests/Api/RepoTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function shouldShowRepository()
1919

2020
$this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api'));
2121
}
22-
22+
2323
/**
2424
* @test
2525
*/
@@ -517,6 +517,24 @@ public function shouldGetCommitActivity()
517517
$this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api'));
518518
}
519519

520+
/**
521+
* @test
522+
*/
523+
public function shouldGetRepositoryEvents()
524+
{
525+
$expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent');
526+
527+
$api = $this->getApiMock();
528+
$api->expects($this->once())
529+
->method('get')
530+
->with('/repos/KnpLabs/php-github-api/events', array(
531+
'page' => 3,
532+
))
533+
->will($this->returnValue($expectedArray));
534+
535+
$this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3));
536+
}
537+
520538
/**
521539
* @return string
522540
*/

0 commit comments

Comments
 (0)