summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-05 13:50:07 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-05 13:50:07 +0200
commit056df41ed16f6eddf3271caad93a118f97e8b58c (patch)
tree956f8d0b1dabb1fa9b921b0e153b41c4e575b1e3 /lib/api
parent3559e3906a005a71183032bc06cf7538fc9d7d05 (diff)
downloadgitlab-ci-056df41ed16f6eddf3271caad93a118f97e8b58c.tar.gz
Add Commits API
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/builds.rb8
-rw-r--r--lib/api/commits.rb65
-rw-r--r--lib/api/entities.rb10
4 files changed, 82 insertions, 2 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index f41a881..ac23f81 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -26,6 +26,7 @@ module API
helpers Helpers
mount Builds
+ mount Commits
mount Runners
mount Projects
end
diff --git a/lib/api/builds.rb b/lib/api/builds.rb
index 5d2c352..1103dad 100644
--- a/lib/api/builds.rb
+++ b/lib/api/builds.rb
@@ -51,6 +51,12 @@ module API
end
end
+ # TODO: Remove it after 5.2 release
+ #
+ # THIS API IS DEPRECATED.
+ # Now builds are created by commit. In order to test specific commit you
+ # need to create Commit entity via Commit API
+ #
# Create a build
#
# Parameters:
@@ -85,7 +91,7 @@ module API
authenticate_project_token!(project)
builds = CreateBuildsService.new.execute(project, params[:data])
- # to keep api compatibility for now
+ # Temporary solution to keep api compatibility
build = builds.first
if build.persisted?
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
new file mode 100644
index 0000000..032233e
--- /dev/null
+++ b/lib/api/commits.rb
@@ -0,0 +1,65 @@
+module API
+ class Commits < Grape::API
+ resource :commits do
+ # Get list of commits per project
+ #
+ # Parameters:
+ # project_id (required) - The ID of a project
+ # project_token (requires) - Project token
+ # page (optional)
+ # per_page (optional) - items per request (default is 20)
+ #
+ get do
+ required_attributes! [:project_id, :project_token]
+ project = Project.find(params[:project_id])
+ authenticate_project_token!(project)
+
+ commits = project.commits.page(params[:page]).per(params[:per_page] || 20)
+ present commits, with: Entities::Commit
+ end
+
+ # Create a commit
+ #
+ # Parameters:
+ # project_id (required) - The ID of a project
+ # project_token (requires) - Project token
+ # data (required) - GitLab push data
+ #
+ # Sample GitLab push data:
+ # {
+ # "before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
+ # "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
+ # "ref": "refs/heads/master",
+ # "commits": [
+ # {
+ # "id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
+ # "message": "Update Catalan translation to e38cb41.",
+ # "timestamp": "2011-12-12T14:27:31+02:00",
+ # "url": "http://localhost/diaspora/commits/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
+ # "author": {
+ # "name": "Jordi Mallach",
+ # "email": "jordi@softcatala.org",
+ # }
+ # }, .... more commits
+ # ]
+ # }
+ #
+ # Example Request:
+ # POST /commits
+ post do
+ required_attributes! [:project_id, :data, :project_token]
+ project = Project.find(params[:project_id])
+ authenticate_project_token!(project)
+ commit = CreateCommitService.new.execute(project, params[:data])
+
+ if commit.persisted?
+ present commit, with: Entities::Commit
+ else
+ errors = commit.errors.full_messages.join(", ")
+ render_api_error!(errors, 400)
+ end
+ end
+ end
+ end
+end
+
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index b6394e9..9f4ea7f 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1,7 +1,15 @@
module API
module Entities
+ class Commit < Grape::Entity
+ expose :id, :ref, :sha, :project_id, :before_sha, :created_at
+ expose :status, :finished_at, :duration
+ expose :git_commit_message, :git_author_name, :git_author_email
+ expose :builds
+ end
+
class Build < Grape::Entity
- expose :id, :commands, :path, :ref, :sha, :project_id, :repo_url, :before_sha, :timeout, :allow_git_fetch, :project_name
+ expose :id, :commands, :path, :ref, :sha, :project_id, :repo_url,
+ :before_sha, :timeout, :allow_git_fetch, :project_name
end
class Runner < Grape::Entity