From c821c6fad55b4889eb72068e02022765378a710a Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Fri, 23 Jun 2017 10:30:59 +0200 Subject: [PATCH] Add a method to fetch repository events See [github documentation](https://developer.github.com/v3/activity/events/#list-repository-events). --- lib/Github/Api/Repo.php | 18 ++++++++++++++++-- test/Github/Tests/Api/RepoTest.php | 20 +++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 5dbe7b9444c..912a9c520bb 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -150,7 +150,7 @@ public function show($username, $repository) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } - + /** * Get extended information about a repository by its id. * 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() { return new Projects($this->client); } - + public function traffic() { return new Traffic($this->client); } + + /** + * @param string $username + * @param string $repository + * @param int $page + * + * @return array|string + * + * @see https://developer.github.com/v3/activity/events/#list-repository-events + */ + public function events($username, $repository, $page = 1) + { + return $this->get('/repos/'.rawurldecode($username).'/'.rawurldecode($repository).'/events', ['page' => $page]); + } } diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index beb68c415d3..d84f841009a 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -19,7 +19,7 @@ public function shouldShowRepository() $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api')); } - + /** * @test */ @@ -517,6 +517,24 @@ public function shouldGetCommitActivity() $this->assertEquals($expectedArray, $api->activity('KnpLabs', 'php-github-api')); } + /** + * @test + */ + public function shouldGetRepositoryEvents() + { + $expectedArray = array('id' => 6122723754, 'type' => 'ForkEvent'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/events', array( + 'page' => 3, + )) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->events('KnpLabs', 'php-github-api', 3)); + } + /** * @return string */