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
Jérome Perrin
gitlab-ce
Commits
10d3a30b
Commit
10d3a30b
authored
Sep 21, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
APi for commits. Better api docs
parent
4cc169d3
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
199 additions
and
79 deletions
+199
-79
Guardfile
Guardfile
+1
-0
app/views/help/api.html.haml
app/views/help/api.html.haml
+77
-70
doc/api/commits.md
doc/api/commits.md
+38
-0
lib/api.rb
lib/api.rb
+1
-0
lib/api/commits.rb
lib/api/commits.rb
+29
-0
lib/api/entities.rb
lib/api/entities.rb
+5
-0
lib/api/helpers.rb
lib/api/helpers.rb
+1
-1
lib/api/milestones.rb
lib/api/milestones.rb
+6
-0
lib/api/projects.rb
lib/api/projects.rb
+12
-8
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+29
-0
No files found.
Guardfile
View file @
10d3a30b
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
guard
'rspec'
,
:version
=>
2
,
:all_on_start
=>
false
,
:all_after_pass
=>
false
do
guard
'rspec'
,
:version
=>
2
,
:all_on_start
=>
false
,
:all_after_pass
=>
false
do
watch
(
%r{^spec/.+_spec
\.
rb$}
)
watch
(
%r{^spec/.+_spec
\.
rb$}
)
watch
(
%r{^lib/(.+)
\.
rb$}
)
{
|
m
|
"spec/lib/
#{
m
[
1
]
}
_spec.rb"
}
watch
(
%r{^lib/(.+)
\.
rb$}
)
{
|
m
|
"spec/lib/
#{
m
[
1
]
}
_spec.rb"
}
watch
(
%r{^lib/api/(.+)
\.
rb$}
)
{
|
m
|
"spec/requests/api/
#{
m
[
1
]
}
_spec.rb"
}
watch
(
'spec/spec_helper.rb'
)
{
"spec"
}
watch
(
'spec/spec_helper.rb'
)
{
"spec"
}
# Rails example
# Rails example
...
...
app/views/help/api.html.haml
View file @
10d3a30b
%h3
API
%h3
.page_title
API
.back_link
.back_link
=
link_to
help_path
do
=
link_to
help_path
do
←
to index
←
to index
%
h
r
%
b
r
%ol
%ul
.nav.nav-tabs.log-tabs
%li
.active
=
link_to
"README"
,
"#README"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#README"
}
README
=
link_to
"Projects"
,
"#projects"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#projects"
}
Projects
=
link_to
"Snippets"
,
"#snippets"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#snippets"
}
Snippets
=
link_to
"Users"
,
"#users"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#users"
}
Users
=
link_to
"Session"
,
"#session"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#session"
}
Session
=
link_to
"Issues"
,
"#issues"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#issues"
}
Issues
=
link_to
"Milestones"
,
"#milestones"
,
'data-toggle'
=>
'tab'
%li
%li
%a
{
href:
"#milestones"
}
Milestones
=
link_to
"Commits"
,
"#commits"
,
'data-toggle'
=>
'tab'
.file_holder
#README
.tab-content
.tab-pane.active
#README
.file_holder
.file_title
.file_title
%i
.icon-file
%i
.icon-file
README
README
...
@@ -28,9 +32,8 @@
...
@@ -28,9 +32,8 @@
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"README.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"README.md"
))
%br
.tab-pane
#projects
.file_holder
.file_holder
#projects
.file_title
.file_title
%i
.icon-file
%i
.icon-file
Projects
Projects
...
@@ -38,9 +41,8 @@
...
@@ -38,9 +41,8 @@
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"projects.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"projects.md"
))
%br
.tab-pane
#snippets
.file_holder
.file_holder
#snippets
.file_title
.file_title
%i
.icon-file
%i
.icon-file
Projects Snippets
Projects Snippets
...
@@ -48,9 +50,8 @@
...
@@ -48,9 +50,8 @@
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"snippets.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"snippets.md"
))
%br
.tab-pane
#users
.file_holder
.file_holder
#users
.file_title
.file_title
%i
.icon-file
%i
.icon-file
Users
Users
...
@@ -58,9 +59,8 @@
...
@@ -58,9 +59,8 @@
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"users.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"users.md"
))
%br
.tab-pane
#session
.file_holder
.file_holder
#session
.file_title
.file_title
%i
.icon-file
%i
.icon-file
Session
Session
...
@@ -68,9 +68,8 @@
...
@@ -68,9 +68,8 @@
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"session.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"session.md"
))
%br
.tab-pane
#issues
.file_holder
.file_holder
#issues
.file_title
.file_title
%i
.icon-file
%i
.icon-file
Issues
Issues
...
@@ -78,12 +77,20 @@
...
@@ -78,12 +77,20 @@
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"issues.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"issues.md"
))
%br
.tab-pane
#milestones
.file_holder
.file_holder
#milestones
.file_title
.file_title
%i
.icon-file
%i
.icon-file
Milestones
Milestones
.file_content.wiki
.file_content.wiki
=
preserve
do
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"milestones.md"
))
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"milestones.md"
))
.tab-pane
#commits
.file_holder
.file_title
%i
.icon-file
Commits
.file_content.wiki
=
preserve
do
=
markdown
File
.
read
(
Rails
.
root
.
join
(
"doc"
,
"api"
,
"commits.md"
))
doc/api/commits.md
0 → 100644
View file @
10d3a30b
## List Commits
Get a list of project commits.
```
GET /projects/:id/commits
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`ref_name`
(optional) - branch/tag name
+
`page`
(optional)
+
`per_page`
(optional)
```
json
[
{
"id"
:
"ed899a2f4b50b4370feeea94676502b42383c746"
,
"short_id"
:
"ed899a2f4b5"
,
"title"
:
"Replace sanitize with escape once"
,
"author_name"
:
"Dmitriy Zaporozhets"
,
"author_email"
:
"dzaporozhets@sphereconsultinginc.com"
,
"created_at"
:
"2012-09-20T11:50:22+03:00"
},
{
"id"
:
"6104942438c14ec7bd21c6cd5bd995272b3faff6"
,
"short_id"
:
"6104942438c"
,
"title"
:
"Sanitize for network graph"
,
"author_name"
:
"randx"
,
"author_email"
:
"dmitriy.zaporozhets@gmail.com"
,
"created_at"
:
"2012-09-20T09:06:12+03:00"
}
]
```
lib/api.rb
View file @
10d3a30b
...
@@ -19,5 +19,6 @@ module Gitlab
...
@@ -19,5 +19,6 @@ module Gitlab
mount
Milestones
mount
Milestones
mount
Keys
mount
Keys
mount
Session
mount
Session
mount
Commits
end
end
end
end
lib/api/commits.rb
0 → 100644
View file @
10d3a30b
module
Gitlab
# Commits API
class
Commits
<
Grape
::
API
before
{
authenticate!
}
resource
:projects
do
# Get a list of project commits
#
# Parameters:
# id (required) - The ID or code name of a project
# ref_name (optional) - Name of branch or tag
# page (optional) - default is 0
# per_page (optional) - default is 20
# Example Request:
# GET /projects/:id/commits
get
":id/commits"
do
authorize!
:download_code
,
user_project
page
=
params
[
:page
]
||
0
per_page
=
params
[
:per_page
]
||
20
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
commits
=
user_project
.
commits
(
ref
,
nil
,
per_page
,
page
*
per_page
)
present
CommitDecorator
.
decorate
(
commits
),
with:
Entities
::
Commit
end
end
end
end
lib/api/entities.rb
View file @
10d3a30b
...
@@ -17,6 +17,11 @@ module Gitlab
...
@@ -17,6 +17,11 @@ module Gitlab
expose
:id
,
:url
expose
:id
,
:url
end
end
class
Commit
<
Grape
::
Entity
expose
:id
,
:short_id
,
:title
,
:author_name
,
:author_email
,
:created_at
end
class
Project
<
Grape
::
Entity
class
Project
<
Grape
::
Entity
expose
:id
,
:code
,
:name
,
:description
,
:path
,
:default_branch
expose
:id
,
:code
,
:name
,
:description
,
:path
,
:default_branch
expose
:owner
,
using:
Entities
::
UserBasic
expose
:owner
,
using:
Entities
::
UserBasic
...
...
lib/api/helpers.rb
View file @
10d3a30b
lib/api/milestones.rb
View file @
10d3a30b
...
@@ -11,6 +11,8 @@ module Gitlab
...
@@ -11,6 +11,8 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/milestones
# GET /projects/:id/milestones
get
":id/milestones"
do
get
":id/milestones"
do
authorize!
:read_milestone
,
user_project
present
paginate
(
user_project
.
milestones
),
with:
Entities
::
Milestone
present
paginate
(
user_project
.
milestones
),
with:
Entities
::
Milestone
end
end
...
@@ -22,6 +24,8 @@ module Gitlab
...
@@ -22,6 +24,8 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/milestones/:milestone_id
# GET /projects/:id/milestones/:milestone_id
get
":id/milestones/:milestone_id"
do
get
":id/milestones/:milestone_id"
do
authorize!
:read_milestone
,
user_project
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
present
@milestone
,
with:
Entities
::
Milestone
present
@milestone
,
with:
Entities
::
Milestone
end
end
...
@@ -36,6 +40,8 @@ module Gitlab
...
@@ -36,6 +40,8 @@ module Gitlab
# Example Request:
# Example Request:
# POST /projects/:id/milestones
# POST /projects/:id/milestones
post
":id/milestones"
do
post
":id/milestones"
do
authorize!
:admin_milestone
,
user_project
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
@milestone
=
user_project
.
milestones
.
new
attrs
@milestone
=
user_project
.
milestones
.
new
attrs
if
@milestone
.
save
if
@milestone
.
save
...
...
lib/api/projects.rb
View file @
10d3a30b
...
@@ -207,6 +207,8 @@ module Gitlab
...
@@ -207,6 +207,8 @@ module Gitlab
# Example Request:
# Example Request:
# POST /projects/:id/snippets
# POST /projects/:id/snippets
post
":id/snippets"
do
post
":id/snippets"
do
authorize!
:write_snippet
,
user_project
attrs
=
attributes_for_keys
[
:title
,
:file_name
]
attrs
=
attributes_for_keys
[
:title
,
:file_name
]
attrs
[
:expires_at
]
=
params
[
:lifetime
]
if
params
[
:lifetime
].
present?
attrs
[
:expires_at
]
=
params
[
:lifetime
]
if
params
[
:lifetime
].
present?
attrs
[
:content
]
=
params
[
:code
]
if
params
[
:code
].
present?
attrs
[
:content
]
=
params
[
:code
]
if
params
[
:code
].
present?
...
@@ -282,6 +284,8 @@ module Gitlab
...
@@ -282,6 +284,8 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/repository/commits/:sha/blob
# GET /projects/:id/repository/commits/:sha/blob
get
":id/repository/commits/:sha/blob"
do
get
":id/repository/commits/:sha/blob"
do
authorize!
:download_code
,
user_project
ref
=
params
[
:sha
]
ref
=
params
[
:sha
]
commit
=
user_project
.
commit
ref
commit
=
user_project
.
commit
ref
...
...
spec/requests/api/commits_spec.rb
0 → 100644
View file @
10d3a30b
require
'spec_helper'
describe
Gitlab
::
API
do
include
ApiHelpers
let
(
:user
)
{
Factory
:user
}
let!
(
:project
)
{
Factory
:project
,
owner:
user
}
describe
"GET /projects/:id/commits"
do
context
"authorized user"
do
before
{
project
.
add_access
(
user
,
:read
)
}
it
"should return project commits"
do
get
api
(
"/projects/
#{
project
.
code
}
/commits"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'id'
].
should
==
project
.
commit
.
id
end
end
context
"unauthorized user"
do
it
"should return project commits"
do
get
api
(
"/projects/
#{
project
.
code
}
/commits"
)
response
.
status
.
should
==
401
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