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
iv
gitlab-ce
Commits
f441436e
Commit
f441436e
authored
May 26, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add compare branches endpoint to API
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
ef933ae6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
0 deletions
+99
-0
doc/api/repositories.md
doc/api/repositories.md
+66
-0
lib/api/entities.rb
lib/api/entities.rb
+17
-0
lib/api/repositories.rb
lib/api/repositories.rb
+16
-0
No files found.
doc/api/repositories.md
View file @
f441436e
...
@@ -131,3 +131,69 @@ GET /projects/:id/repository/archive
...
@@ -131,3 +131,69 @@ GET /projects/:id/repository/archive
Parameters:
Parameters:
+
`id`
(required) - The ID of a project
+
`id`
(required) - The ID of a project
+
`sha`
(optional) - The commit sha to download defaults to the tip of the default branch
+
`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"
:
"72e10ef47e770a95439255b2c49de722e8782106"
,
"short_id"
:
"72e10ef47e7"
,
"title"
:
"Add NEWFILE"
,
"author_name"
:
"Dmitriy Zaporozhets"
,
"author_email"
:
"dmitriy.zaporozhets@gmail.com"
,
"created_at"
:
"2014-05-26T16:03:54+03:00"
},
"commits"
:
[{
"id"
:
"0b4bc9a49b562e85de7cc9e834518ea6828729b9"
,
"short_id"
:
"0b4bc9a49b5"
,
"title"
:
"Feature added"
,
"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_email"
:
"dmitriy.zaporozhets@gmail.com"
,
"created_at"
:
"2014-05-26T16:03:54+03:00"
}],
"diffs"
:
[{
"old_path"
:
"NEWFILE"
,
"new_path"
:
"NEWFILE"
,
"a_mode"
:
null
,
"b_mode"
:
null
,
"diff"
:
"--- /dev/null
\n
+++ b/NEWFILE
\n
@@ -0,0 +1 @@
\n
+This is NEWFILE content
\n\\
No newline at end of file"
,
"new_file"
:
true
,
"renamed_file"
:
false
,
"deleted_file"
:
false
},
{
"old_path"
:
"files/ruby/feature.rb"
,
"new_path"
:
"files/ruby/feature.rb"
,
"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
}]
}
```
lib/api/entities.rb
View file @
f441436e
...
@@ -194,5 +194,22 @@ module API
...
@@ -194,5 +194,22 @@ module API
class
Label
<
Grape
::
Entity
class
Label
<
Grape
::
Entity
expose
:name
expose
:name
end
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
end
end
lib/api/repositories.rb
View file @
f441436e
...
@@ -15,6 +15,7 @@ module API
...
@@ -15,6 +15,7 @@ module API
not_found!
not_found!
end
end
end
end
# Get a project repository tags
# Get a project repository tags
#
#
# Parameters:
# Parameters:
...
@@ -118,6 +119,21 @@ module API
...
@@ -118,6 +119,21 @@ module API
not_found!
not_found!
end
end
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
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