Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
3bdf0e29
Commit
3bdf0e29
authored
May 27, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'compare-api' into 'master'
Compare api Fixes #1165
parents
3553e36d
c7e00aca
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
0 deletions
+133
-0
doc/api/repositories.md
doc/api/repositories.md
+53
-0
lib/api/entities.rb
lib/api/entities.rb
+25
-0
lib/api/repositories.rb
lib/api/repositories.rb
+16
-0
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+39
-0
No files found.
doc/api/repositories.md
View file @
3bdf0e29
...
...
@@ -131,3 +131,56 @@ GET /projects/:id/repository/archive
Parameters:
+
`id`
(required) - The ID of a project
+
`sha`
(optional) - The commit sha to download defaults to the tip of the default branch
## Compare branches, tags or commits
```
GET /projects/:id/repository/compare
```
Parameters:
+
`id`
(required) - The ID of a project
+
`from`
(required) - the commit sha or branch name
+
`to`
(required) - the commit sha or branch name
```
GET /projects/:id/repository/compare?from=master&to=feature
```
Response:
```
json
{
"commit"
:
{
"id"
:
"12d65c8dd2b2676fa3ac47d955accc085a37a9c1"
,
"short_id"
:
"12d65c8dd2b"
,
"title"
:
"JS fix"
,
"author_name"
:
"Dmitriy Zaporozhets"
,
"author_email"
:
"dmitriy.zaporozhets@gmail.com"
,
"created_at"
:
"2014-02-27T10:27:00+02:00"
},
"commits"
:
[{
"id"
:
"12d65c8dd2b2676fa3ac47d955accc085a37a9c1"
,
"short_id"
:
"12d65c8dd2b"
,
"title"
:
"JS fix"
,
"author_name"
:
"Dmitriy Zaporozhets"
,
"author_email"
:
"dmitriy.zaporozhets@gmail.com"
,
"created_at"
:
"2014-02-27T10:27:00+02:00"
}],
"diffs"
:
[{
"old_path"
:
"files/js/application.js"
,
"new_path"
:
"files/js/application.js"
,
"a_mode"
:
null
,
"b_mode"
:
"100644"
,
"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"
:
false
,
"renamed_file"
:
false
,
"deleted_file"
:
false
}],
"compare_timeout"
:
false
,
"compare_same_ref"
:
false
}
```
lib/api/entities.rb
View file @
3bdf0e29
...
...
@@ -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
lib/api/repositories.rb
View file @
3bdf0e29
...
...
@@ -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
spec/requests/api/repositories_spec.rb
View file @
3bdf0e29
...
...
@@ -112,4 +112,43 @@ describe API::API, api: true do
response
.
status
.
should
==
404
end
end
describe
'GET /GET /projects/:id/repository/compare'
do
it
"should compare branches"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'master'
,
to:
'simple_merge_request'
response
.
status
.
should
==
200
json_response
[
'commits'
].
should
be_present
json_response
[
'diffs'
].
should
be_present
end
it
"should compare tags"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'v1.0.1'
,
to:
'v1.0.2'
response
.
status
.
should
==
200
json_response
[
'commits'
].
should
be_present
json_response
[
'diffs'
].
should
be_present
end
it
"should compare commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'b1e6a9dbf1c85'
,
to:
'1e689bfba395'
response
.
status
.
should
==
200
json_response
[
'commits'
].
should
be_empty
json_response
[
'diffs'
].
should
be_empty
json_response
[
'compare_same_ref'
].
should
be_false
end
it
"should compare commits in reverse order"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'1e689bfba395'
,
to:
'b1e6a9dbf1c85'
response
.
status
.
should
==
200
json_response
[
'commits'
].
should
be_present
json_response
[
'diffs'
].
should
be_present
end
it
"should compare same refs"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'master'
,
to:
'master'
response
.
status
.
should
==
200
json_response
[
'commits'
].
should
be_empty
json_response
[
'diffs'
].
should
be_empty
json_response
[
'compare_same_ref'
].
should
be_true
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment