Skip to content

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 4 commits into from
Jul 9, 2017
Merged

Conversation

moufmouf
Copy link
Contributor

Hey guys,

Here is a PR to add support for the Jobs API (https://docs.gitlab.com/ce/api/jobs.html)

I wrote this PR because I needed a way to download artifacts files. This should replace the PR #164 that is based on old APIs methods that are no more documented.

One important point: since php-gitlab-api uses Buzz (until #191 is closed), I used Buzz to fetch the files. Buzz does not have the notion of streams... so the whole artifacts file is loaded into a PHP string. This is ok for relatively small files, but if you have an artifacts file that is a gigabyte large, this will certainly be a problem.

Should php-gitlab-api migrate to http-client (please do!), I highly recommend adding additional methods in the Jobs class like: artifactsAsStream that returns a stream instead of a string. This way, we can cope with very large artifacts files too.

Note: I've been testing this PR in the washingmachine and it seems to be working.

Do not hesitate if you have any comments.

@fbourigault
Copy link
Contributor

Thanks for this PR David! As HTTPlug support has now landed in master. Could you rebase this branch and use HTTPlug instead of Buzz?

moufmouf added 2 commits July 7, 2017 11:19
Now returning a StreamInterface instead of a string for artifact files.
@moufmouf moufmouf force-pushed the feature/jobs_api branch from 5a6159d to a1174d7 Compare July 7, 2017 09:34
@moufmouf
Copy link
Contributor Author

moufmouf commented Jul 7, 2017

Hey Fabien!

Woot! HTTPlug in master, this is absolutely great news!

I've rebased this PR to include HTTPlug.
Since we have support for PSR-7 responses, I also changed the artifacts download method. Now, they are returning a StreamInterface rather that a string, which is way more robust regarding memory usage if the artifacts files are big.

Let me know if you have any comments!

@fbourigault fbourigault self-assigned this Jul 7, 2017
Copy link
Contributor

@fbourigault fbourigault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank your for your contribution. It works really well unless the Pipeline model. I also added a note on the Jobs::jobs method name.

* @param array $scope
* @return mixed
*/
public function jobs($project_id, array $scope = [])
Copy link
Contributor

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 to all?

{
$pipeline = new static($project, $data['id'], $client);

return $job->hydrate($data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be $pipeline.

* @param array $scopes
* @return Job[]
*/
public function jobs(array $scopes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a default value for the $scopes argument?

@moufmouf
Copy link
Contributor Author

moufmouf commented Jul 8, 2017

Done! Thanks for the thorough code review.

@fbourigault fbourigault merged commit a7bfdc3 into GitLabPHP:master Jul 9, 2017
@fbourigault
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants