diff options
author | Michel Courtine <michaK@ivoltage.me> | 2015-02-10 04:22:39 +0100 |
---|---|---|
committer | Michel Courtine <michaK@ivoltage.me> | 2015-02-10 04:22:39 +0100 |
commit | 0d39bfa32967c5f2794bdf30d088b74a78fd54c2 (patch) | |
tree | bae53f9f5ed634c8c719f7447257c864c98479d1 /lib/api | |
parent | e5cfac699a00b343d5368fde753a044d3abd411e (diff) | |
download | gitlab-ci-0d39bfa32967c5f2794bdf30d088b74a78fd54c2.tar.gz |
Implemented api for project jobs
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/projects.rb | 60 |
2 files changed, 64 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index dfd419a..c0bf928 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -27,5 +27,9 @@ module API class WebHook < Grape::Entity expose :id, :project_id, :url end + + class Job < Grape::Entity + expose :name, :commands + end end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index a3cc9f3..cf5dd59 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -28,6 +28,66 @@ module API end end + # Retrieve all jobs for a project + # + # Parameters + # id (required) - The ID of a project + # Example Request + # GET /projects/:id/jobs + get ":id/jobs" do + project = Project.find(params[:id]) + + not_found! if project.blank? + unauthorized! unless current_user.can_access_project?(project.gitlab_id) + + project.jobs + end + + # Add a new job to a project + # + # Parameters + # id (required) - The ID of a project + # name (required) - The job name + # commands (required) - The command line script for the job + # Example Request + # POST /projects/:id/jobs + post ":id/jobs" do + required_attributes! [:name, :commands] + + project = Project.find(params[:id]) + + not_found! if project.blank? + unauthorized! unless current_user.can_access_project?(project.gitlab_id) + + job_params = { name: params[:name], commands: params[:commands] } + job = project.jobs.new(job_params) + if job.save + present job, with: Entities::Job + else + errors = web_hook.errors.full_messages.join(", ") + render_api_error!(errors, 400) + end + end + + # Delete a job for a project + # + # Parameters + # id (required) - The ID of a project + # job_id (required) - The ID of the job to delete + # Example Request + # DELETE /projects/:id/jobs/:job_id + delete ":id/jobs/:job_id" do + required_attributes! [:job_id] + + project = Project.find(params[:id]) + job = project.jobs.find_by_id(params[:job_id]) + + not_found! if project.blank? || job.blank? + unauthorized! unless current_user.can_access_project?(project.gitlab_id) + + job.destroy + end + # Retrieve all Gitlab CI projects that the user has access to # # Example Request: |