Skip to content

Commit 49d86fd

Browse files
Rkallenkootradutopala
authored andcommitted
Added pipelines API (#172)
* Added pipelines API * Added missing DocBlock types * Added tests and fixes
1 parent f8ea161 commit 49d86fd

File tree

2 files changed

+157
-8
lines changed

2 files changed

+157
-8
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ public function remove($project_id)
127127
{
128128
return $this->delete('projects/'.$this->encodePath($project_id));
129129
}
130-
130+
131131
/**
132132
* @param int $project_id
133133
* @return mixed
134134
*/
135135
public function archive($project_id){
136136
return $this->post("projects/".$this->encodePath($project_id)."/archive");
137137
}
138-
138+
139139
/**
140140
* @param int $project_id
141141
* @return mixed
@@ -157,8 +157,8 @@ public function builds($project_id, $scope = null)
157157
}
158158

159159
/**
160-
* @param $project_id
161-
* @param $build_id
160+
* @param int $project_id
161+
* @param int $build_id
162162
* @return mixed
163163
*/
164164
public function build($project_id, $build_id)
@@ -167,15 +167,65 @@ public function build($project_id, $build_id)
167167
}
168168

169169
/**
170-
* @param $project_id
171-
* @param $build_id
170+
* @param int $project_id
171+
* @param int $build_id
172172
* @return mixed
173173
*/
174174
public function trace($project_id, $build_id)
175175
{
176176
return $this->get($this->getProjectPath($project_id, 'builds/'.$this->encodePath($build_id).'/trace'));
177177
}
178178

179+
/**
180+
* @param int $project_id
181+
* @return mixed
182+
*/
183+
public function pipelines($project_id)
184+
{
185+
return $this->get($this->getProjectPath($project_id, 'pipelines'));
186+
}
187+
188+
/**
189+
* @param int $project_id
190+
* @param int $pipeline_id
191+
* @return mixed
192+
*/
193+
public function pipeline($project_id, $pipeline_id)
194+
{
195+
return $this->get($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id)));
196+
}
197+
198+
/**
199+
* @param int $project_id
200+
* @param string $commit_ref
201+
* @return mixed
202+
*/
203+
public function createPipeline($project_id, $commit_ref)
204+
{
205+
return $this->post($this->getProjectPath($project_id, 'pipelines'), array(
206+
'ref' => $commit_ref));
207+
}
208+
209+
/**
210+
* @param int $project_id
211+
* @param int $pipeline_id
212+
* @return mixed
213+
*/
214+
public function retryPipeline($project_id, $pipeline_id)
215+
{
216+
return $this->post($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id)).'/retry');
217+
}
218+
219+
/**
220+
* @param int $project_id
221+
* @param int $pipeline_id
222+
* @return mixed
223+
*/
224+
public function cancelPipeline($project_id, $pipeline_id)
225+
{
226+
return $this->post($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id)).'/cancel');
227+
}
228+
179229
/**
180230
* @param int $project_id
181231
* @param string $username_query

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function shouldUpdateProject()
142142
'issues_enabled' => true
143143
)));
144144
}
145-
145+
146146
/**
147147
* @test
148148
*/
@@ -159,7 +159,7 @@ public function shouldArchiveProject()
159159

160160
$this->assertEquals($expectedArray, $api->archive(1));
161161
}
162-
162+
163163
/**
164164
* @test
165165
*/
@@ -306,6 +306,105 @@ public function shouldGetTrace()
306306
$this->assertEquals($expectedString, $api->trace(1, 2));
307307
}
308308

309+
/**
310+
* @test
311+
*/
312+
public function shouldGetPipelines()
313+
{
314+
$expectedArray = array(
315+
array('id' => 1, 'status' => 'success','ref' => 'new-pipeline'),
316+
array('id' => 2, 'status' => 'failed', 'ref' => 'new-pipeline'),
317+
array('id' => 3, 'status' => 'pending', 'ref'=> 'test-pipeline')
318+
);
319+
320+
$api = $this->getApiMock();
321+
$api->expects($this->once())
322+
->method('get')
323+
->with('projects/1/pipelines')
324+
->will($this->returnValue($expectedArray))
325+
;
326+
327+
$this->assertEquals($expectedArray, $api->pipelines(1));
328+
}
329+
330+
/**
331+
* @test
332+
*/
333+
public function shouldGetPipeline()
334+
{
335+
$expectedArray = array(
336+
array('id' => 1, 'status' => 'success','ref' => 'new-pipeline'),
337+
array('id' => 2, 'status' => 'failed', 'ref' => 'new-pipeline'),
338+
array('id' => 3, 'status' => 'pending', 'ref'=> 'test-pipeline')
339+
);
340+
341+
$api = $this->getApiMock();
342+
$api->expects($this->once())
343+
->method('get')
344+
->with('projects/1/pipelines/3')
345+
->will($this->returnValue($expectedArray))
346+
;
347+
348+
$this->assertEquals($expectedArray, $api->pipeline(1, 3));
349+
}
350+
351+
/**
352+
* @test
353+
*/
354+
public function shouldCreatePipeline()
355+
{
356+
$expectedArray = array(
357+
array('id' => 4, 'status' => 'created', 'ref'=> 'test-pipeline')
358+
);
359+
360+
$api = $this->getApiMock();
361+
$api->expects($this->once())
362+
->method('post')
363+
->with('projects/1/pipelines', array('ref' => 'test-pipeline'))
364+
->will($this->returnValue($expectedArray))
365+
;
366+
367+
$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline'));
368+
}
369+
370+
/**
371+
* @test
372+
*/
373+
public function shouldRetryPipeline()
374+
{
375+
$expectedArray = array(
376+
array('id' => 5, 'status' => 'pending', 'ref'=> 'test-pipeline')
377+
);
378+
379+
$api = $this->getApiMock();
380+
$api->expects($this->once())
381+
->method('post')
382+
->with('projects/1/pipelines/4/retry')
383+
->will($this->returnValue($expectedArray))
384+
;
385+
386+
$this->assertEquals($expectedArray, $api->retryPipeline(1, 4));
387+
}
388+
389+
/**
390+
* @test
391+
*/
392+
public function shouldCancelPipeline()
393+
{
394+
$expectedArray = array(
395+
array('id' => 6, 'status' => 'cancelled', 'ref'=> 'test-pipeline')
396+
);
397+
398+
$api = $this->getApiMock();
399+
$api->expects($this->once())
400+
->method('post')
401+
->with('projects/1/pipelines/6/cancel')
402+
->will($this->returnValue($expectedArray))
403+
;
404+
405+
$this->assertEquals($expectedArray, $api->cancelPipeline(1, 6));
406+
}
407+
309408
/**
310409
* @test
311410
*/

0 commit comments

Comments
 (0)