Skip to content

Commit efdd795

Browse files
author
Matt Humphrey
committed
Added pagination to project events. Fixes #84
1 parent 1733aa7 commit efdd795

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php namespace Gitlab\Api;
22

3-
use Gitlab\Exception\RuntimeException;
4-
53
class Projects extends AbstractApi
64
{
75
const ORDER_BY = 'created_at';
@@ -10,6 +8,8 @@ class Projects extends AbstractApi
108
/**
119
* @param int $page
1210
* @param int $per_page
11+
* @param string $order_by
12+
* @param string $sort
1313
* @return mixed
1414
*/
1515
public function all($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
@@ -25,6 +25,8 @@ public function all($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORD
2525
/**
2626
* @param int $page
2727
* @param int $per_page
28+
* @param string $order_by
29+
* @param string $sort
2830
* @return mixed
2931
*/
3032
public function accessible($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
@@ -40,6 +42,8 @@ public function accessible($page = 1, $per_page = self::PER_PAGE, $order_by = se
4042
/**
4143
* @param int $page
4244
* @param int $per_page
45+
* @param string $order_by
46+
* @param string $sort
4347
* @return mixed
4448
*/
4549
public function owned($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
@@ -56,6 +60,8 @@ public function owned($page = 1, $per_page = self::PER_PAGE, $order_by = self::O
5660
* @param string $query
5761
* @param int $page
5862
* @param int $per_page
63+
* @param string $order_by
64+
* @param string $sort
5965
* @return mixed
6066
*/
6167
public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
@@ -287,11 +293,16 @@ public function removeKey($project_id, $key_id)
287293

288294
/**
289295
* @param int $project_id
296+
* @param int $page
297+
* @param int $per_page
290298
* @return mixed
291299
*/
292-
public function events($project_id)
300+
public function events($project_id, $page = 1, $per_page = self::PER_PAGE)
293301
{
294-
return $this->get($this->getProjectPath($project_id, 'events'));
302+
return $this->get($this->getProjectPath($project_id, 'events'), array(
303+
'page' => $page,
304+
'per_page' => $per_page
305+
));
295306
}
296307

297308
/**

lib/Gitlab/Model/Project.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,13 @@ public function deleteFile($file_path, $branch_name, $commit_message)
549549
}
550550

551551
/**
552+
* @param int $page
553+
* @param int $per_page
552554
* @return Event[]
553555
*/
554-
public function events()
556+
public function events($page = 1, $per_page = Api::PER_PAGE)
555557
{
556-
$data = $this->api('projects')->events($this->id);
558+
$data = $this->api('projects')->events($this->id, $page, $per_page);
557559

558560
$events = array();
559561
foreach ($data as $event) {

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,39 @@ public function shouldGetEvents()
487487
$api = $this->getApiMock();
488488
$api->expects($this->once())
489489
->method('get')
490-
->with('projects/1/events')
490+
->with('projects/1/events', array(
491+
'page' => 1,
492+
'per_page' => AbstractApi::PER_PAGE
493+
))
491494
->will($this->returnValue($expectedArray))
492495
;
493496

494497
$this->assertEquals($expectedArray, $api->events(1));
495498
}
496499

500+
/**
501+
* @test
502+
*/
503+
public function shouldGetEventsWithPagination()
504+
{
505+
$expectedArray = array(
506+
array('id' => 1, 'title' => 'An event'),
507+
array('id' => 2, 'title' => 'Another event')
508+
);
509+
510+
$api = $this->getApiMock();
511+
$api->expects($this->once())
512+
->method('get')
513+
->with('projects/1/events', array(
514+
'page' => 2,
515+
'per_page' => 15
516+
))
517+
->will($this->returnValue($expectedArray))
518+
;
519+
520+
$this->assertEquals($expectedArray, $api->events(1, 2, 15));
521+
}
522+
497523
/**
498524
* @test
499525
*/

0 commit comments

Comments
 (0)