summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-03-03 11:31:35 +0000
committerValery Sizov <valery@gitlab.com>2015-03-03 11:31:35 +0000
commiteb24743b70b1ae57002d8c40aadb87c10e7a8993 (patch)
tree9c68ec99edbaa2afeab1a0b8afdd9b5e7472e2fc /lib/api
parent6c264f4fc4ab5cdb43855421bea51af98333935f (diff)
parent122befc180769809d5f093a052b118a1d75cdd6a (diff)
downloadgitlab-ci-eb24743b70b1ae57002d8c40aadb87c10e7a8993.tar.gz
Merge branch 'feature_project_jobs_rest_api-1' into 'master'
Implemented api for project jobs with working tests and updated doc The rest API allows you to manipulate a project on gitlab-ci but there is no way to manipulate build jobs through the api. I tested it, implemented truly working tests & updated documentation http://feedback.gitlab.com/forums/176466-general/suggestions/7068630-expose-the-job-api-to-the-rest-api See merge request !39
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb4
-rw-r--r--lib/api/projects.rb74
2 files changed, 78 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index dfd419a..8c4b3c1 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, :project_id, :commands, :active, :name, :build_branches, :build_tags, :tags
+ end
end
end
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index c6da7e5..c60d619 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -28,6 +28,80 @@ 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
+ # active (optional) - The command is active of not
+ # build_branches (optional) - Trigger commit builds
+ # build_tags (optional) - Trigger tag builds
+ # tags (optional) - The tags associated with this 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_params[:active] = params[:active] unless params[:active].nil?
+ job_params[:build_branches] = params[:build_branches] unless params[:build_branches].nil?
+ job_params[:build_tags] = params[:build_tags] unless params[:build_tags].nil?
+ job_params[:tag_list] = params[:tags] unless params[:tags].nil?
+
+ 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: