summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-04-22 09:55:50 +0000
committerValery Sizov <valery@gitlab.com>2015-04-22 09:55:50 +0000
commit313c9b3caba4224f07074b929d45cc0fabcc7f54 (patch)
tree9c199e0edac46b3a9a21e84d1ddb32f5bbd76325 /lib
parentb3e2939aa2904c92aba0399d511cb05228bfc9be (diff)
parent9cb877ca13078121ec6438c07d08a779c0cfdef1 (diff)
downloadgitlab-ci-313c9b3caba4224f07074b929d45cc0fabcc7f54.tar.gz
Merge branch 'deploy_job_api' into 'master'
API for deploy jobs https://dev.gitlab.org/gitlab/gitlab-ci/issues/192 See merge request !69
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb11
-rw-r--r--lib/api/projects.rb39
2 files changed, 48 insertions, 2 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8c4b3c1..3d98866 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -17,7 +17,8 @@ module API
end
class Project < Grape::Entity
- expose :id, :name, :timeout, :token, :default_ref, :gitlab_url, :always_build, :polling_interval, :public, :ssh_url_to_repo, :gitlab_id
+ expose :id, :name, :timeout, :token, :default_ref, :gitlab_url,
+ :always_build, :polling_interval, :public, :ssh_url_to_repo, :gitlab_id
end
class RunnerProject < Grape::Entity
@@ -29,7 +30,13 @@ module API
end
class Job < Grape::Entity
- expose :id, :project_id, :commands, :active, :name, :build_branches, :build_tags, :tags
+ expose :id, :project_id, :commands, :active, :name, :build_branches,
+ :build_tags, :tags, :job_type, :tag_list
+ end
+
+ class DeployJob < Grape::Entity
+ expose :id, :project_id, :commands, :active, :name,
+ :refs, :tags, :job_type, :refs, :tag_list
end
end
end
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index ea10a82..38c8c1b 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -83,6 +83,45 @@ module API
end
end
+ # Add a new deploy 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
+ # refs (optional) - The list of refs
+ # tags (optional) - The tags associated with this job
+ # Example Request
+ # POST /projects/:id/deploy_jobs
+ post ":id/deploy_jobs" do
+ required_attributes! [:name, :commands]
+
+ project = Project.find(params[:id])
+
+ not_found! if project.blank?
+ unauthorized! unless current_user.can_manage_project?(project.gitlab_id)
+
+ job_params =
+ {
+ name: params[:name],
+ commands: params[:commands],
+ job_type: "deploy"
+ }
+
+ job_params[:active] = params[:active] unless params[:active].nil?
+ job_params[:refs] = params[:refs] unless params[:refs].nil?
+ job_params[:tag_list] = params[:tags] unless params[:tags].nil?
+
+ job = project.jobs.new(job_params)
+ if job.save
+ present job, with: Entities::DeployJob
+ else
+ errors = job.errors.full_messages.join(", ")
+ render_api_error!(errors, 400)
+ end
+ end
+
# Delete a job for a project
#
# Parameters