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
Léo-Paul Géneau
gitlab-ce
Commits
378dc55d
Commit
378dc55d
authored
Jun 29, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add project snippets API
parent
1d2c9818
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
0 deletions
+87
-0
lib/api/entities.rb
lib/api/entities.rb
+6
-0
lib/api/projects.rb
lib/api/projects.rb
+53
-0
spec/api/projects_spec.rb
spec/api/projects_spec.rb
+28
-0
No files found.
lib/api/entities.rb
View file @
378dc55d
...
...
@@ -19,5 +19,11 @@ module Gitlab
class
ProjectRepositoryTags
<
Grape
::
Entity
expose
:name
,
:commit
end
class
ProjectSnippet
<
Grape
::
Entity
expose
:id
,
:title
,
:file_name
expose
:author
,
:using
=>
Entities
::
User
expose
:expires_at
,
:updated_at
,
:created_at
end
end
end
lib/api/projects.rb
View file @
378dc55d
...
...
@@ -45,6 +45,59 @@ module Gitlab
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
ProjectRepositoryTags
end
# Get a project snippet
#
# Parameters:
# id (required) - The code of a project
# snippet_id (required) - The ID of a project snippet
# Example Request:
# GET /projects/:id/snippets/:snippet_id
get
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
present
@snippet
,
:with
=>
Entities
::
ProjectSnippet
end
# Create a new project snippet
#
# Parameters:
# id (required) - The code name of a project
# title (required) - The title of a snippet
# file_name (required) - The name of a snippet file
# lifetime (optional) - The expiration date of a snippet
# code (required) - The content of a snippet
# Example Request:
# POST /projects/:id/snippets
post
":id/snippets"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
new
(
:title
=>
params
[
:title
],
:file_name
=>
params
[
:file_name
],
:expires_at
=>
params
[
:lifetime
],
:content
=>
params
[
:code
]
)
@snippet
.
author
=
current_user
if
@snippet
.
save
present
@snippet
,
:with
=>
Entities
::
ProjectSnippet
else
error!
({
'message'
=>
'404 Not found'
},
404
)
end
end
# Delete a project snippet
#
# Parameters:
# id (required) - The code of a project
# snippet_id (required) - The ID of a project snippet
# Example Request:
# DELETE /projects/:id/snippets/:snippet_id
delete
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
.
destroy
end
end
end
end
spec/api/projects_spec.rb
View file @
378dc55d
...
...
@@ -3,6 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
API
do
let
(
:user
)
{
Factory
:user
}
let!
(
:project
)
{
Factory
:project
,
:owner
=>
user
}
let!
(
:snippet
)
{
Factory
:snippet
,
:author
=>
user
,
:project
=>
project
}
before
{
project
.
add_access
(
user
,
:read
)
}
describe
"GET /projects"
do
...
...
@@ -52,4 +53,31 @@ describe Gitlab::API do
json
.
first
[
'name'
].
should
==
project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
.
first
.
name
end
end
describe
"GET /projects/:id/snippets/:snippet_id"
do
it
"should return a project snippet"
do
get
"/api/projects/
#{
project
.
code
}
/snippets/
#{
snippet
.
id
}
?private_token=
#{
user
.
private_token
}
"
response
.
status
.
should
==
200
json
=
JSON
.
parse
(
response
.
body
)
json
[
'title'
].
should
==
snippet
.
title
end
end
describe
"POST /projects/:id/snippets"
do
it
"should create a new project snippet"
do
post
"/api/projects/
#{
project
.
code
}
/snippets?private_token=
#{
user
.
private_token
}
"
,
:title
=>
'api test'
,
:file_name
=>
'sample.rb'
,
:code
=>
'test'
response
.
status
.
should
==
201
json
=
JSON
.
parse
(
response
.
body
)
json
[
'title'
].
should
==
'api test'
end
end
describe
"DELETE /projects/:id/snippets/:snippet_id"
do
it
"should create a new project snippet"
do
expect
{
delete
"/api/projects/
#{
project
.
code
}
/snippets/
#{
snippet
.
id
}
?private_token=
#{
user
.
private_token
}
"
}.
should
change
{
Snippet
.
count
}.
by
(
-
1
)
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