Skip to content

Commit 7e218a9

Browse files
authored
Merge pull request GitLabPHP#165 from thomasvargiu/feature/deployments
Added project deployments API
2 parents 9803a8b + 665fa37 commit 7e218a9

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,28 @@ public function uploadFile($project_id, $file)
537537
{
538538
return $this->post($this->getProjectPath($project_id, 'uploads'), array(), array(), array('file' => $file));
539539
}
540+
541+
/**
542+
* @param int $project_id
543+
* @param int $page
544+
* @param int $per_page
545+
* @return mixed
546+
*/
547+
public function deployments($project_id, $page = 1, $per_page = self::PER_PAGE)
548+
{
549+
return $this->get($this->getProjectPath($project_id, 'deployments'), array(
550+
'page' => $page,
551+
'per_page' => $per_page
552+
));
553+
}
554+
555+
/**
556+
* @param int $project_id
557+
* @param int $deployment_id
558+
* @return mixed
559+
*/
560+
public function deployment($project_id, $deployment_id)
561+
{
562+
return $this->get($this->getProjectPath($project_id, 'deployments/'.$this->encodePath($deployment_id)));
563+
}
540564
}

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,52 @@ protected function getMultipleProjectsRequestMock($path, $expectedArray = array(
937937
return $api;
938938
}
939939

940+
/**
941+
* @test
942+
*/
943+
public function shouldGetDeployments()
944+
{
945+
$expectedArray = array(
946+
array('id' => 1, 'sha' => '0000001'),
947+
array('id' => 2, 'sha' => '0000002'),
948+
);
949+
950+
$api = $this->getApiMock();
951+
$api->expects($this->once())
952+
->method('get')
953+
->with('projects/1/deployments', array(
954+
'page' => 1,
955+
'per_page' => AbstractApi::PER_PAGE
956+
))
957+
->will($this->returnValue($expectedArray))
958+
;
959+
960+
$this->assertEquals($expectedArray, $api->deployments(1));
961+
}
962+
963+
/**
964+
* @test
965+
*/
966+
public function shouldGetDeploymentsWithPagination()
967+
{
968+
$expectedArray = array(
969+
array('id' => 1, 'sha' => '0000001'),
970+
array('id' => 2, 'sha' => '0000002'),
971+
);
972+
973+
$api = $this->getApiMock();
974+
$api->expects($this->once())
975+
->method('get')
976+
->with('projects/1/deployments', array(
977+
'page' => 2,
978+
'per_page' => 15
979+
))
980+
->will($this->returnValue($expectedArray))
981+
;
982+
983+
$this->assertEquals($expectedArray, $api->deployments(1, 2, 15));
984+
}
985+
940986
protected function getMultipleProjectsData()
941987
{
942988
return array(

0 commit comments

Comments
 (0)