summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-26 16:08:22 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-26 16:08:22 +0300
commitf441436e53377f207657ac0e0e518e5ee2b33a6c (patch)
tree0397efd7d9fa5ebe7727d314c247b5f220fd767b /lib
parentef933ae69bb48fd186c650927bff7d52a3956174 (diff)
downloadgitlab-ce-f441436e53377f207657ac0e0e518e5ee2b33a6c.tar.gz
Add compare branches endpoint to API
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb17
-rw-r--r--lib/api/repositories.rb16
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 457af52fe9d..eead8b18ebd 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -194,5 +194,22 @@ module API
class Label < Grape::Entity
expose :name
end
+
+ class RepoDiff < Grape::Entity
+ expose :old_path, :new_path, :a_mode, :b_mode, :diff
+ expose :new_file, :renamed_file, :deleted_file
+ end
+
+ class Compare < Grape::Entity
+ expose :commit, using: Entities::RepoCommit do |compare, options|
+ Commit.new compare.commit
+ end
+ expose :commits, using: Entities::RepoCommit do |compare, options|
+ Commit.decorate compare.commits
+ end
+ expose :diffs, using: Entities::RepoDiff do |compare, options|
+ compare.diffs
+ end
+ end
end
end
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 076a9ceeb74..d59c25cf316 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -15,6 +15,7 @@ module API
not_found!
end
end
+
# Get a project repository tags
#
# Parameters:
@@ -118,6 +119,21 @@ module API
not_found!
end
end
+
+ # Compare two branches, tags or commits
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # from (required) - the commit sha or branch name
+ # to (required) - the commit sha or branch name
+ # Example Request:
+ # GET /projects/:id/repository/compare?from=master&to=feature
+ get ':id/repository/compare' do
+ authorize! :download_code, user_project
+ compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE)
+
+ present compare, with: Entities::Compare
+ end
end
end
end