Skip to content

Added pipelines API #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 56 additions & 6 deletions lib/Gitlab/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ public function remove($project_id)
{
return $this->delete('projects/'.$this->encodePath($project_id));
}

/**
* @param int $project_id
* @return mixed
*/
public function archive($project_id){
return $this->post("projects/".$this->encodePath($project_id)."/archive");
}

/**
* @param int $project_id
* @return mixed
Expand All @@ -156,8 +156,8 @@ public function builds($project_id, $scope = null)
}

/**
* @param $project_id
* @param $build_id
* @param int $project_id
* @param int $build_id
* @return mixed
*/
public function build($project_id, $build_id)
Expand All @@ -166,15 +166,65 @@ public function build($project_id, $build_id)
}

/**
* @param $project_id
* @param $build_id
* @param int $project_id
* @param int $build_id
* @return mixed
*/
public function trace($project_id, $build_id)
{
return $this->get($this->getProjectPath($project_id, 'builds/'.$this->encodePath($build_id).'/trace'));
}

/**
* @param int $project_id
* @return mixed
*/
public function pipelines($project_id)
{
return $this->get($this->getProjectPath($project_id, 'pipelines'));
}

/**
* @param int $project_id
* @param int $pipeline_id
* @return mixed
*/
public function pipeline($project_id, $pipeline_id)
{
return $this->get($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id)));
}

/**
* @param int $project_id
* @param string $commit_ref
* @return mixed
*/
public function createPipeline($project_id, $commit_ref)
{
return $this->post($this->getProjectPath($project_id, 'pipelines'), array(
'ref' => $commit_ref));
}

/**
* @param int $project_id
* @param int $pipeline_id
* @return mixed
*/
public function retryPipeline($project_id, $pipeline_id)
{
return $this->post($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id)).'/retry');
}

/**
* @param int $project_id
* @param int $pipeline_id
* @return mixed
*/
public function cancelPipeline($project_id, $pipeline_id)
{
return $this->post($this->getProjectPath($project_id, 'pipelines/'.$this->encodePath($pipeline_id)).'/cancel');
}

/**
* @param int $project_id
* @param string $username_query
Expand Down
103 changes: 101 additions & 2 deletions test/Gitlab/Tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function shouldUpdateProject()
'issues_enabled' => true
)));
}

/**
* @test
*/
Expand All @@ -159,7 +159,7 @@ public function shouldArchiveProject()

$this->assertEquals($expectedArray, $api->archive(1));
}

/**
* @test
*/
Expand Down Expand Up @@ -306,6 +306,105 @@ public function shouldGetTrace()
$this->assertEquals($expectedString, $api->trace(1, 2));
}

/**
* @test
*/
public function shouldGetPipelines()
{
$expectedArray = array(
array('id' => 1, 'status' => 'success','ref' => 'new-pipeline'),
array('id' => 2, 'status' => 'failed', 'ref' => 'new-pipeline'),
array('id' => 3, 'status' => 'pending', 'ref'=> 'test-pipeline')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/pipelines')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->pipelines(1));
}

/**
* @test
*/
public function shouldGetPipeline()
{
$expectedArray = array(
array('id' => 1, 'status' => 'success','ref' => 'new-pipeline'),
array('id' => 2, 'status' => 'failed', 'ref' => 'new-pipeline'),
array('id' => 3, 'status' => 'pending', 'ref'=> 'test-pipeline')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/pipelines/3')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->pipeline(1, 3));
}

/**
* @test
*/
public function shouldCreatePipeline()
{
$expectedArray = array(
array('id' => 4, 'status' => 'created', 'ref'=> 'test-pipeline')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/pipelines', array('ref' => 'test-pipeline'))
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->createPipeline(1, 'test-pipeline'));
}

/**
* @test
*/
public function shouldRetryPipeline()
{
$expectedArray = array(
array('id' => 5, 'status' => 'pending', 'ref'=> 'test-pipeline')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/pipelines/4/retry')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->retryPipeline(1, 4));
}

/**
* @test
*/
public function shouldCancelPipeline()
{
$expectedArray = array(
array('id' => 6, 'status' => 'cancelled', 'ref'=> 'test-pipeline')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/pipelines/6/cancel')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->cancelPipeline(1, 6));
}

/**
* @test
*/
Expand Down