Commit 10ee137e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Expose timeout and same_ref compare fields

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 24229185
...@@ -152,48 +152,35 @@ GET /projects/:id/repository/compare?from=master&to=feature ...@@ -152,48 +152,35 @@ GET /projects/:id/repository/compare?from=master&to=feature
Response: Response:
```json ```json
{ {
"commit": { "commit": {
"id": "72e10ef47e770a95439255b2c49de722e8782106", "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",
"short_id": "72e10ef47e7", "short_id": "12d65c8dd2b",
"title": "Add NEWFILE", "title": "JS fix",
"author_name": "Dmitriy Zaporozhets", "author_name": "Dmitriy Zaporozhets",
"author_email": "dmitriy.zaporozhets@gmail.com", "author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2014-05-26T16:03:54+03:00" "created_at": "2014-02-27T10:27:00+02:00"
}, },
"commits": [{ "commits": [{
"id": "0b4bc9a49b562e85de7cc9e834518ea6828729b9", "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",
"short_id": "0b4bc9a49b5", "short_id": "12d65c8dd2b",
"title": "Feature added", "title": "JS fix",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2014-02-27T10:26:01+02:00"
}, {
"id": "72e10ef47e770a95439255b2c49de722e8782106",
"short_id": "72e10ef47e7",
"title": "Add NEWFILE",
"author_name": "Dmitriy Zaporozhets", "author_name": "Dmitriy Zaporozhets",
"author_email": "dmitriy.zaporozhets@gmail.com", "author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2014-05-26T16:03:54+03:00" "created_at": "2014-02-27T10:27:00+02:00"
}], }],
"diffs": [{ "diffs": [{
"old_path": "NEWFILE", "old_path": "files/js/application.js",
"new_path": "NEWFILE", "new_path": "files/js/application.js",
"a_mode": null, "a_mode": null,
"b_mode": null, "b_mode": "100644",
"diff": "--- /dev/null\n+++ b/NEWFILE\n@@ -0,0 +1 @@\n+This is NEWFILE content\n\\ No newline at end of file", "diff": "--- a/files/js/application.js\n+++ b/files/js/application.js\n@@ -24,8 +24,10 @@\n //= require g.raphael-min\n //= require g.bar-min\n //= require branch-graph\n-//= require highlightjs.min\n-//= require ace/ace\n //= require_tree .\n //= require d3\n //= require underscore\n+\n+function fix() { \n+ alert(\"Fixed\")\n+}",
"new_file": true, "new_file": false,
"renamed_file": false, "renamed_file": false,
"deleted_file": false "deleted_file": false
}, { }],
"old_path": "files/ruby/feature.rb", "compare_timeout": false,
"new_path": "files/ruby/feature.rb", "compare_same_ref": false
"a_mode": null,
"b_mode": null,
"diff": "--- /dev/null\n+++ b/files/ruby/feature.rb\n@@ -0,0 +1,5 @@\n+class Feature\n+ def foo\n+ puts 'bar'\n+ end\n+end",
"new_file": true,
"renamed_file": false,
"deleted_file": false
}]
} }
``` ```
...@@ -210,6 +210,12 @@ module API ...@@ -210,6 +210,12 @@ module API
expose :diffs, using: Entities::RepoDiff do |compare, options| expose :diffs, using: Entities::RepoDiff do |compare, options|
compare.diffs compare.diffs
end end
expose :compare_timeout do |compare, options|
compare.timeout
end
expose :same, as: :compare_same_ref
end end
end end
end end
...@@ -130,8 +130,8 @@ module API ...@@ -130,8 +130,8 @@ module API
# GET /projects/:id/repository/compare?from=master&to=feature # GET /projects/:id/repository/compare?from=master&to=feature
get ':id/repository/compare' do get ':id/repository/compare' do
authorize! :download_code, user_project 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) compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE)
present compare, with: Entities::Compare present compare, with: Entities::Compare
end end
end end
......
...@@ -118,18 +118,21 @@ describe API::API, api: true do ...@@ -118,18 +118,21 @@ describe API::API, api: true do
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request' get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request'
response.status.should == 200 response.status.should == 200
json_response['commits'].size.should == 3 json_response['commits'].size.should == 3
json_response['diffs'].size.should == 1
end end
it "should compare 2 commits" do it "should compare 2 commits" do
get api("/projects/#{project.id}/repository/compare", user), from: 'b1e6a9dbf1c85', to: '1e689bfba395' get api("/projects/#{project.id}/repository/compare", user), from: 'b1e6a9dbf1c85', to: '1e689bfba395'
response.status.should == 200 response.status.should == 200
json_response['commits'].size.should == 0 json_response['commits'].size.should == 0
json_response['diffs'].size.should == 0
end end
it "should compare 2 commits" do it "should compare 2 commits" do
get api("/projects/#{project.id}/repository/compare", user), from: '1e689bfba395', to: 'b1e6a9dbf1c85' get api("/projects/#{project.id}/repository/compare", user), from: '1e689bfba395', to: 'b1e6a9dbf1c85'
response.status.should == 200 response.status.should == 200
json_response['commits'].size.should == 4 json_response['commits'].size.should == 4
json_response['diffs'].size.should == 9
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment