diff options
-rw-r--r-- | doc/api/projects.md | 4 | ||||
-rw-r--r-- | lib/api/entities.rb | 2 | ||||
-rw-r--r-- | lib/api/projects.rb | 17 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 11 |
4 files changed, 30 insertions, 4 deletions
diff --git a/doc/api/projects.md b/doc/api/projects.md index 14e84ee..436dcda 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -173,6 +173,10 @@ Parameters: * `id` (required) - The ID of the Gitlab CI project * `name` (required) - The name of the Job to add * `commands` (required) - The script commands of 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 ### Remove a Job from a Project diff --git a/lib/api/entities.rb b/lib/api/entities.rb index bc21e22..8c4b3c1 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -29,7 +29,7 @@ module API end class Job < Grape::Entity - expose :id, :name, :commands + 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 7d94c89..1226a02 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -40,7 +40,6 @@ module API not_found! if project.blank? unauthorized! unless current_user.can_access_project?(project.gitlab_id) - # present job, with: Entities::Job project.jobs end @@ -50,6 +49,10 @@ module API # 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 @@ -60,7 +63,17 @@ module API 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 = + { + 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 diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 7256dfe..669784e 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -59,6 +59,10 @@ describe API::API do { name: "A Job Name", commands: "ls -lad", + active: false, + build_branches: false, + build_tags: true, + tags: "release, deployment", } } let(:invalid_job_info) { {} } @@ -84,6 +88,11 @@ describe API::API do response.status.should == 201 json_response["name"].should == job_info[:name] json_response["commands"].should == job_info[:commands] + json_response["active"].should == job_info[:active] + json_response["build_branches"].should == job_info[:build_branches] + json_response["build_tags"].should == job_info[:build_tags] + json_response["tags"].first["name"].should == "deployment" + json_response["tags"].last["name"].should == "release" end it "fails to create job for non existsing project" do @@ -135,8 +144,8 @@ describe API::API do let(:job_info) { { - name: "A Job Name", commands: "ls -lad", + name: "A Job Name", } } |