-
-
Notifications
You must be signed in to change notification settings - Fork 456
Adding the Jobs API #196
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
Adding the Jobs API #196
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php namespace Gitlab\Api; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
|
||
class Jobs extends AbstractApi | ||
{ | ||
const SCOPE_CREATED = 'created'; | ||
const SCOPE_PENDING = 'pending'; | ||
const SCOPE_RUNNING = 'running'; | ||
const SCOPE_FAILED = 'failed'; | ||
const SCOPE_SUCCESS = 'success'; | ||
const SCOPE_CANCELED = 'canceled'; | ||
const SCOPE_SKIPPED = 'skipped'; | ||
const SCOPE_MANUAL = 'manual'; | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param array $scope | ||
* @return mixed | ||
*/ | ||
public function jobs($project_id, array $scope = []) | ||
{ | ||
return $this->get("projects/".$this->encodePath($project_id)."/jobs", array( | ||
'scope' => $scope | ||
)); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $pipeline_id | ||
* @param array $scope | ||
* @return mixed | ||
*/ | ||
public function pipelineJobs($project_id, $pipeline_id, array $scope = []) | ||
{ | ||
return $this->get("projects/".$this->encodePath($project_id)."/pipelines/".$this->encodePath($pipeline_id)."/jobs", array( | ||
'scope' => $scope | ||
)); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return mixed | ||
*/ | ||
public function show($project_id, $job_id) | ||
{ | ||
return $this->get("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return StreamInterface | ||
*/ | ||
public function artifacts($project_id, $job_id) | ||
{ | ||
return $this->getAsResponse("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/artifacts")->getBody(); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param string $ref_name | ||
* @param string $job_name | ||
* @return StreamInterface | ||
*/ | ||
public function artifactsByRefName($project_id, $ref_name, $job_name) | ||
{ | ||
return $this->getAsResponse("projects/".$this->encodePath($project_id)."/jobs/artifacts/".$this->encodePath($ref_name)."/download", array( | ||
'job' => $job_name | ||
))->getBody(); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return string | ||
*/ | ||
public function trace($project_id, $job_id) | ||
{ | ||
return $this->get("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/trace"); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return mixed | ||
*/ | ||
public function cancel($project_id, $job_id) | ||
{ | ||
return $this->post("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/cancel"); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return mixed | ||
*/ | ||
public function retry($project_id, $job_id) | ||
{ | ||
return $this->post("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/retry"); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return mixed | ||
*/ | ||
public function erase($project_id, $job_id) | ||
{ | ||
return $this->post("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/erase"); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return mixed | ||
*/ | ||
public function keepArtifacts($project_id, $job_id) | ||
{ | ||
return $this->post("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/artifacts/keep"); | ||
} | ||
|
||
/** | ||
* @param int|string $project_id | ||
* @param int $job_id | ||
* @return mixed | ||
*/ | ||
public function play($project_id, $job_id) | ||
{ | ||
return $this->post("projects/".$this->encodePath($project_id)."/jobs/".$this->encodePath($job_id)."/play"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php namespace Gitlab\Model; | ||
|
||
use Gitlab\Client; | ||
|
||
/** | ||
* Class Commit | ||
* | ||
* @property-read Commit $commit | ||
* @property-read int $id | ||
* @property-read string $coverage | ||
* @property-read string $created_at | ||
* @property-read string $artifacts_file | ||
* @property-read string $finished_at | ||
* @property-read string $name | ||
* @property-read Pipeline $pipeline | ||
* @property-read string $ref | ||
* @property-read string $runner | ||
* @property-read string $stage | ||
* @property-read string $started_at | ||
* @property-read string $status | ||
* @property-read string|bool $tag | ||
* @property-read User $user | ||
*/ | ||
class Job extends AbstractModel | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static $properties = array( | ||
'id', | ||
'commit', | ||
'coverage', | ||
'created_at', | ||
'artifacts_file', | ||
'finished_at', | ||
'name', | ||
'pipeline', | ||
'ref', | ||
'runner', | ||
'stage', | ||
'started_at', | ||
'status', | ||
'tag', | ||
'user' | ||
); | ||
|
||
/** | ||
* @param Client $client | ||
* @param Project $project | ||
* @param array $data | ||
* @return Job | ||
*/ | ||
public static function fromArray(Client $client, Project $project, array $data) | ||
{ | ||
$job = new static($project, $data['id'], $client); | ||
|
||
if (isset($data['user'])) { | ||
$data['user'] = User::fromArray($client, $data['user']); | ||
} | ||
|
||
if (isset($data['commit'])) { | ||
$data['commit'] = Commit::fromArray($client, $project, $data['commit']); | ||
} | ||
|
||
if (isset($data['pipeline'])) { | ||
$data['pipeline'] = Pipeline::fromArray($client, $project, $data['pipeline']); | ||
} | ||
|
||
return $job->hydrate($data); | ||
} | ||
|
||
/** | ||
* @param Project $project | ||
* @param int $id | ||
* @param Client $client | ||
*/ | ||
public function __construct(Project $project, $id = null, Client $client = null) | ||
{ | ||
$this->setClient($client); | ||
$this->setData('project', $project); | ||
$this->setData('id', $id); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php namespace Gitlab\Model; | ||
|
||
use Gitlab\Client; | ||
|
||
/** | ||
* Class Commit | ||
* | ||
* @property-read int $id | ||
* @property-read string $ref | ||
* @property-read string $sha | ||
* @property-read string $status | ||
*/ | ||
class Pipeline extends AbstractModel | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected static $properties = array( | ||
'id', | ||
'ref', | ||
'sha', | ||
'status' | ||
); | ||
|
||
/** | ||
* @param Client $client | ||
* @param Project $project | ||
* @param array $data | ||
* @return Commit | ||
*/ | ||
public static function fromArray(Client $client, Project $project, array $data) | ||
{ | ||
$pipeline = new static($project, $data['id'], $client); | ||
|
||
return $job->hydrate($data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
} | ||
|
||
/** | ||
* @param Project $project | ||
* @param int $id | ||
* @param Client $client | ||
*/ | ||
public function __construct(Project $project, $id = null, Client $client = null) | ||
{ | ||
$this->setClient($client); | ||
$this->setData('project', $project); | ||
$this->setData('id', $id); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1092,4 +1092,49 @@ public function contributors() | |
|
||
return $contributors; | ||
} | ||
|
||
/** | ||
* @param array $scopes | ||
* @return Job[] | ||
*/ | ||
public function jobs(array $scopes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a default value for the |
||
{ | ||
$data = $this->api('jobs')->jobs($this->id, $scopes); | ||
|
||
$jobs = array(); | ||
foreach ($data as $job) { | ||
$jobs[] = Job::fromArray($this->getClient(), $this, $job); | ||
} | ||
|
||
return $jobs; | ||
} | ||
|
||
/** | ||
* @param int $pipeline_id | ||
* @param array $scopes | ||
* @return Job[] | ||
*/ | ||
public function pipelineJobs($pipeline_id, array $scopes = []) | ||
{ | ||
$data = $this->api('jobs')->pipelineJobs($this->id, $pipeline_id, $scopes); | ||
|
||
$jobs = array(); | ||
foreach ($data as $job) { | ||
$jobs[] = Job::fromArray($this->getClient(), $this, $job); | ||
} | ||
|
||
return $jobs; | ||
} | ||
|
||
/** | ||
* @param int $job_id | ||
* @return Job | ||
*/ | ||
public function job($job_id) | ||
{ | ||
$data = $this->api('jobs')->show($this->id, $job_id); | ||
|
||
return Job::fromArray($this->getClient(), $this, $data); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name
all
seems to be more used than the plural noun form. Could you change the method name toall
?