-
-
Couldn't load subscription status.
- 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
Adding the Jobs API #196
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"); | ||
| } | ||
| } | ||
| 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); | ||
| } | ||
| } |
| 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); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * @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); | ||
| } | ||
| } | ||
| 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) | ||
|
||
| { | ||
| $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); | ||
| } | ||
|
|
||
| } | ||
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
allseems to be more used than the plural noun form. Could you change the method name toall?