diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-03-03 13:34:40 +0200 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-03-03 13:34:40 +0200 |
commit | e3b2180e57e677ab9e263200645a32d24b5147eb (patch) | |
tree | ec445f15052614e2b29b96926a12bf3b074ddd1f /lib | |
parent | 83835d271fa8fb04fae5c422afeacfba6f061629 (diff) | |
parent | eb24743b70b1ae57002d8c40aadb87c10e7a8993 (diff) | |
download | gitlab-ci-e3b2180e57e677ab9e263200645a32d24b5147eb.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ci
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/projects.rb | 74 | ||||
-rw-r--r-- | lib/upgrader.rb | 7 |
3 files changed, 83 insertions, 2 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: diff --git a/lib/upgrader.rb b/lib/upgrader.rb index 3dff6a8..3969fa2 100644 --- a/lib/upgrader.rb +++ b/lib/upgrader.rb @@ -41,8 +41,6 @@ class Upgrader end def latest_version_raw - git_tags = `git ls-remote --tags origin | grep tags\/v#{current_version.major}` - git_tags = git_tags.lines.to_a.select { |version| version =~ /v\d\.\d\.\d\Z/ } last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s end @@ -91,4 +89,9 @@ class Upgrader end while !choices.include?(answer) answer end + + def git_tags + tags = `git ls-remote --tags origin | grep tags\/v#{current_version.major}` + tags.lines.to_a.select { |version| version =~ /v\d\.\d\.\d\Z/ } + end end |