Commit 10ee137e9c13271d49d7046723b1e473d62a578f
1 parent
24229185
Exists in
spb-stable
and in
2 other branches
Expose timeout and same_ref compare fields
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
27 additions
and
31 deletions
Show diff stats
doc/api/repositories.md
... | ... | @@ -152,48 +152,35 @@ GET /projects/:id/repository/compare?from=master&to=feature |
152 | 152 | Response: |
153 | 153 | |
154 | 154 | ```json |
155 | + | |
155 | 156 | { |
156 | 157 | "commit": { |
157 | - "id": "72e10ef47e770a95439255b2c49de722e8782106", | |
158 | - "short_id": "72e10ef47e7", | |
159 | - "title": "Add NEWFILE", | |
158 | + "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1", | |
159 | + "short_id": "12d65c8dd2b", | |
160 | + "title": "JS fix", | |
160 | 161 | "author_name": "Dmitriy Zaporozhets", |
161 | 162 | "author_email": "dmitriy.zaporozhets@gmail.com", |
162 | - "created_at": "2014-05-26T16:03:54+03:00" | |
163 | + "created_at": "2014-02-27T10:27:00+02:00" | |
163 | 164 | }, |
164 | 165 | "commits": [{ |
165 | - "id": "0b4bc9a49b562e85de7cc9e834518ea6828729b9", | |
166 | - "short_id": "0b4bc9a49b5", | |
167 | - "title": "Feature added", | |
168 | - "author_name": "Dmitriy Zaporozhets", | |
169 | - "author_email": "dmitriy.zaporozhets@gmail.com", | |
170 | - "created_at": "2014-02-27T10:26:01+02:00" | |
171 | - }, { | |
172 | - "id": "72e10ef47e770a95439255b2c49de722e8782106", | |
173 | - "short_id": "72e10ef47e7", | |
174 | - "title": "Add NEWFILE", | |
166 | + "id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1", | |
167 | + "short_id": "12d65c8dd2b", | |
168 | + "title": "JS fix", | |
175 | 169 | "author_name": "Dmitriy Zaporozhets", |
176 | 170 | "author_email": "dmitriy.zaporozhets@gmail.com", |
177 | - "created_at": "2014-05-26T16:03:54+03:00" | |
171 | + "created_at": "2014-02-27T10:27:00+02:00" | |
178 | 172 | }], |
179 | 173 | "diffs": [{ |
180 | - "old_path": "NEWFILE", | |
181 | - "new_path": "NEWFILE", | |
174 | + "old_path": "files/js/application.js", | |
175 | + "new_path": "files/js/application.js", | |
182 | 176 | "a_mode": null, |
183 | - "b_mode": null, | |
184 | - "diff": "--- /dev/null\n+++ b/NEWFILE\n@@ -0,0 +1 @@\n+This is NEWFILE content\n\\ No newline at end of file", | |
185 | - "new_file": true, | |
177 | + "b_mode": "100644", | |
178 | + "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+}", | |
179 | + "new_file": false, | |
186 | 180 | "renamed_file": false, |
187 | 181 | "deleted_file": false |
188 | - }, { | |
189 | - "old_path": "files/ruby/feature.rb", | |
190 | - "new_path": "files/ruby/feature.rb", | |
191 | - "a_mode": null, | |
192 | - "b_mode": null, | |
193 | - "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", | |
194 | - "new_file": true, | |
195 | - "renamed_file": false, | |
196 | - "deleted_file": false | |
197 | - }] | |
182 | + }], | |
183 | + "compare_timeout": false, | |
184 | + "compare_same_ref": false | |
198 | 185 | } |
199 | 186 | ``` | ... | ... |
lib/api/entities.rb
... | ... | @@ -210,6 +210,12 @@ module API |
210 | 210 | expose :diffs, using: Entities::RepoDiff do |compare, options| |
211 | 211 | compare.diffs |
212 | 212 | end |
213 | + | |
214 | + expose :compare_timeout do |compare, options| | |
215 | + compare.timeout | |
216 | + end | |
217 | + | |
218 | + expose :same, as: :compare_same_ref | |
213 | 219 | end |
214 | 220 | end |
215 | 221 | end | ... | ... |
lib/api/repositories.rb
... | ... | @@ -130,8 +130,8 @@ module API |
130 | 130 | # GET /projects/:id/repository/compare?from=master&to=feature |
131 | 131 | get ':id/repository/compare' do |
132 | 132 | authorize! :download_code, user_project |
133 | + required_attributes! [:from, :to] | |
133 | 134 | compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE) |
134 | - | |
135 | 135 | present compare, with: Entities::Compare |
136 | 136 | end |
137 | 137 | end | ... | ... |
spec/requests/api/repositories_spec.rb
... | ... | @@ -118,18 +118,21 @@ describe API::API, api: true do |
118 | 118 | get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'simple_merge_request' |
119 | 119 | response.status.should == 200 |
120 | 120 | json_response['commits'].size.should == 3 |
121 | + json_response['diffs'].size.should == 1 | |
121 | 122 | end |
122 | 123 | |
123 | 124 | it "should compare 2 commits" do |
124 | 125 | get api("/projects/#{project.id}/repository/compare", user), from: 'b1e6a9dbf1c85', to: '1e689bfba395' |
125 | 126 | response.status.should == 200 |
126 | 127 | json_response['commits'].size.should == 0 |
128 | + json_response['diffs'].size.should == 0 | |
127 | 129 | end |
128 | 130 | |
129 | 131 | it "should compare 2 commits" do |
130 | 132 | get api("/projects/#{project.id}/repository/compare", user), from: '1e689bfba395', to: 'b1e6a9dbf1c85' |
131 | 133 | response.status.should == 200 |
132 | 134 | json_response['commits'].size.should == 4 |
135 | + json_response['diffs'].size.should == 9 | |
133 | 136 | end |
134 | 137 | end |
135 | 138 | end | ... | ... |