summaryrefslogtreecommitdiff
path: root/lib/api/projects.rb
diff options
context:
space:
mode:
authorAngelo Lakra <alakra@comverge.com>2013-10-03 12:26:10 -0600
committerAngelo Lakra <angelo.lakra@gmail.com>2013-10-08 00:43:14 -0600
commit519cce2c5149c21cf571ef73c974bffbef1a6398 (patch)
tree99e7b13c85d0ed94faf7225d3d122151d43bba91 /lib/api/projects.rb
parentfc49034fb454a88626e4e705520c2eb686c6594f (diff)
downloadgitlab-ci-519cce2c5149c21cf571ef73c974bffbef1a6398.tar.gz
Adding Project manipulation support via API
* The following actions are now supported: GET /projects/:id - returns information about a project GET /projects - returns list of all projects PUT /projects/:id - updates project information (see docs for more info) DELETE /projects/:id - removes a project POST /projects/:id/runners/:runner_id - links a project to a runner DELETE /projects/:id/runners/:runner_id - removes link between project and runner
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb122
1 files changed, 121 insertions, 1 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index b66e65e..7bd497d 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -4,7 +4,7 @@ module API
before { authenticate! }
resource :projects do
- # Retrieve info for a project
+ # Retrieve info for a Gitlab CI project
#
# Parameters:
# id (required) - The ID of a project
@@ -15,6 +15,26 @@ module API
present project, with: Entities::Project
end
+ # Retrieve info for aall Gitlab CI projects
+ #
+ # Example Request:
+ # GET /projects
+ get do
+ projects = Project.all
+ present projects, with: Entities::Project
+ end
+
+ # Create Gitlab CI project using Gitlab project info
+ #
+ # Parameters:
+ # name (required) - The name of the project
+ # gitlab_id (required) - The gitlab id of the project
+ # gitlab_url (required) - The gitlab web url to the project
+ # ssh_url_to_repo (required) - The gitlab ssh url to the repo
+ # scripts - The shell script provided for a runner to run
+ # default_ref - The branch to run against (defaults to `master`)
+ # Example Request:
+ # POST /projects
post do
required_attributes! [:name, :gitlab_id, :gitlab_url, :ssh_url_to_repo]
@@ -39,6 +59,106 @@ module API
render_api_error!(errors, 400)
end
end
+
+ # Update a Gitlab CI project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # name - The name of the project
+ # gitlab_id - The gitlab id of the project
+ # gitlab_url - The gitlab web url to the project
+ # ssh_url_to_repo - The gitlab ssh url to the repo
+ # scripts - The shell script provided for a runner to run
+ # default_ref - The branch to run against (defaults to `master`)
+ # Example Request:
+ # PUT /projects/:id
+ put ":id" do
+ project = Project.find(params[:id])
+
+ if project.present?
+ attrs = attributes_for_keys [:name, :gitlab_id, :gitlab_url, :scripts, :default_ref, :ssh_url_to_repo]
+
+ if project.update_attributes(attrs)
+ present project, :with => Entities::Project
+ else
+ errors = project.errors.full_messages.join(", ")
+ render_api_error!(errors, 400)
+ end
+ else
+ not_found!
+ end
+ end
+
+ # Remove a Gitlab CI project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # Example Request:
+ # DELETE /projects/:id
+ delete ":id" do
+ project = Project.find(params[:id])
+
+ if project.present?
+ project.destroy
+ else
+ not_found!
+ end
+ end
+
+ # Link a Gitlab CI project to a runner
+ #
+ # Parameters:
+ # id (required) - The ID of a CI project
+ # runner_id (required) - The ID of a runner
+ # Example Request:
+ # POST /projects/:id/runners/:runner_id
+ post ":id/runners/:runner_id" do
+ project_exists = Project.exists?(params[:id])
+ runner_exists = Runner.exists?(params[:runner_id])
+
+ not_found! if project_exists.blank? or runner_exists.blank?
+
+ options = {
+ :project_id => params[:id],
+ :runner_id => params[:runner_id]
+ }
+
+ runner_project = RunnerProject.new(options)
+
+ if runner_project.save
+ present runner_project, :with => Entities::RunnerProject
+ else
+ errors = project.errors.full_messages.join(", ")
+ render_api_error!(errors, 400)
+ end
+ end
+
+ # Remove a Gitlab CI project from a runner
+ #
+ # Parameters:
+ # id (required) - The ID of a CI project
+ # runner_id (required) - The ID of a runner
+ # Example Request:
+ # DELETE /projects/:id/runners/:runner_id
+ delete ":id/runners/:runner_id" do
+ project_exists = Project.exists?(params[:id])
+ runner_exists = Runner.exists?(params[:runner_id])
+
+ not_found! if project_exists.blank? or runner_exists.blank?
+
+ options = {
+ :project_id => params[:id],
+ :runner_id => params[:runner_id]
+ }
+
+ runner_project = RunnerProject.where(options).first
+
+ if runner_project.present?
+ runner_project.destroy
+ else
+ not_found!
+ end
+ end
end
end
end