diff options
author | Michel Courtine <michaK@ivoltage.me> | 2015-02-10 04:22:39 +0100 |
---|---|---|
committer | Michel Courtine <michaK@ivoltage.me> | 2015-02-11 15:06:13 +0100 |
commit | 02a1d95fb2503106443feaea82a20ac472c40ecf (patch) | |
tree | 8c7abf3f8889d33a95ca56bea65652def38e8c50 /lib | |
parent | b98b7e904b84d58d7f945569f51047149d1d4dda (diff) | |
download | gitlab-ci-02a1d95fb2503106443feaea82a20ac472c40ecf.tar.gz |
Implemented api for project jobs with working tests and updated doc
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/projects.rb | 63 |
2 files changed, 66 insertions, 1 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index dfd419a..bc21e22 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 :id, :name, :commands + end end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index a3cc9f3..7d94c89 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -20,7 +20,7 @@ module API web_hook = project.web_hooks.new({url: params[:web_hook]}) if web_hook.save - present web_hook, :with => Entities::WebHook + present web_hook, with: Entities::WebHook else errors = web_hook.errors.full_messages.join(", ") render_api_error!(errors, 400) @@ -28,6 +28,67 @@ 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) + + # present job, with: Entities::Job + 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 = job.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(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: |