diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-27 15:16:07 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-05-27 15:16:07 +0400 |
commit | 3bdf0e2921c4cac46084834899302b25858e6bde (patch) | |
tree | f1272e4a21f232aaad5ac1e0a5254b13ce1df040 /lib | |
parent | 3553e36d169e18025a2409b7055fff082d89f630 (diff) | |
parent | c7e00aca2d68a15c901506f1af4242df92670b6a (diff) |
Merge branch 'compare-api' into 'master'
Compare api
Fixes #1165
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 25 | ||||
-rw-r--r-- | lib/api/repositories.rb | 16 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 457af52fe9d..6bad6c74bca 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -194,5 +194,30 @@ 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| + if compare.commit + Commit.new compare.commit + end + 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 + + expose :compare_timeout do |compare, options| + compare.timeout + end + + expose :same, as: :compare_same_ref + end end end diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 076a9ceeb74..a587d4a7bdf 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 + required_attributes! [:from, :to] + 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 |