BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c8e3d319
Commit
c8e3d319
authored
Aug 26, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4892 from Aigeruth/feature/api-add-diff
Feature: get the diff of a commit via API.
parents
45c39250
d139cc6b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
0 deletions
+64
-0
repositories.md
doc/api/repositories.md
+28
-0
repositories.rb
lib/api/repositories.rb
+14
-0
repositories_spec.rb
spec/requests/api/repositories_spec.rb
+22
-0
No files found.
doc/api/repositories.md
View file @
c8e3d319
...
...
@@ -239,6 +239,34 @@ Parameters:
]
```
## Get the diff of a commit
Get the diff of a commit in a project.
```
GET /projects/:id/repository/commit/:sha
```
Parameters:
+
`id`
(required) - The ID of a project
+
`sha`
(required) - The name of a repository branch or tag or if not given the default branch
```
json
[
{
"diff"
:
"--- a/doc/update/5.4-to-6.0.md
\n
+++ b/doc/update/5.4-to-6.0.md
\n
@@ -71,6 +71,8 @@
\n
sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production
\n
sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production
\n
\n
+sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
\n
+
\n
```
\n
\n
### 6. Update config files"
,
"new_path"
:
"doc/update/5.4-to-6.0.md"
,
"old_path"
:
"doc/update/5.4-to-6.0.md"
,
"a_mode"
:
null
,
"b_mode"
:
"100644"
,
"new_file"
:
false
,
"renamed_file"
:
false
,
"deleted_file"
:
false
}
]
```
## List repository tree
Get a list of repository files and directories in a project.
...
...
lib/api/repositories.rb
View file @
c8e3d319
...
...
@@ -102,6 +102,20 @@ module API
present
commits
,
with:
Entities
::
RepoCommit
end
# Get a specific commit of a project
#
# Parameters:
# id (required) - The ID of a project
# sha (required) - The commit or branch name
# Example Request:
# GET /projects/:id/repository/commit/:sha
get
":id/repository/commit/:sha"
do
authorize!
:download_code
,
user_project
sha
=
params
[
:sha
]
result
=
CommitLoadContext
.
new
(
user_project
,
current_user
,
{
id:
sha
}).
execute
result
[
:commit
].
diffs
end
# Get a project repository tree
#
# Parameters:
...
...
spec/requests/api/repositories_spec.rb
View file @
c8e3d319
...
...
@@ -112,6 +112,28 @@ describe API::API do
end
end
describe
"GET /projects:id/repository/commit/:sha"
do
context
"authorized user"
do
before
{
project
.
team
<<
[
user2
,
:reporter
]
}
it
"should return the diff of the selected commit"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commit/
#{
project
.
repository
.
commit
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
length
.
should
>=
1
json_response
.
first
.
keys
.
should
include
"diff"
end
end
context
"unauthorized user"
do
it
"should not return the diff of the selected commit"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commit/
#{
project
.
repository
.
commit
.
id
}
"
)
response
.
status
.
should
==
401
end
end
end
describe
"GET /projects/:id/repository/tree"
do
context
"authorized user"
do
before
{
project
.
team
<<
[
user2
,
:reporter
]
}
...
...
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