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
7b33d8cb
Commit
7b33d8cb
authored
Jul 24, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add issues API
parent
0f604e62
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
0 deletions
+195
-0
lib/api.rb
lib/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+12
-0
lib/api/issues.rb
lib/api/issues.rb
+111
-0
spec/api/issues_spec.rb
spec/api/issues_spec.rb
+71
-0
No files found.
lib/api.rb
View file @
7b33d8cb
...
...
@@ -15,5 +15,6 @@ module Gitlab
mount
Users
mount
Projects
mount
Issues
end
end
lib/api/entities.rb
View file @
7b33d8cb
...
...
@@ -25,5 +25,17 @@ module Gitlab
expose
:author
,
:using
=>
Entities
::
UserBasic
expose
:expires_at
,
:updated_at
,
:created_at
end
class
Milestone
<
Grape
::
Entity
expose
:id
,
:title
,
:description
,
:due_date
,
:closed
,
:updated_at
,
:created_at
end
class
Issue
<
Grape
::
Entity
expose
:id
,
:title
,
:description
expose
:label_list
,
:as
=>
:labels
expose
:milestone
,
:using
=>
Entities
::
Milestone
expose
:assignee
,
:author
,
:using
=>
Entities
::
UserBasic
expose
:closed
,
:updated_at
,
:created_at
end
end
end
lib/api/issues.rb
0 → 100644
View file @
7b33d8cb
module
Gitlab
# Issues API
class
Issues
<
Grape
::
API
before
{
authenticate!
}
resource
:issues
do
# Get currently authenticated user's issues
#
# Example Request:
# GET /issues
get
do
present
current_user
.
issues
,
:with
=>
Entities
::
Issue
end
end
resource
:projects
do
# Get a list of project issues
#
# Parameters:
# id (required) - The code name of a project
# Example Request:
# GET /projects/:id/issues
get
":id/issues"
do
present
user_project
.
issues
,
:with
=>
Entities
::
Issue
end
# Get a single project issue
#
# Parameters:
# id (required) - The code name of a project
# issue_id (required) - The ID of a project issue
# Example Request:
# GET /projects/:id/issues/:issue_id
get
":id/issues/:issue_id"
do
@issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
present
@issue
,
:with
=>
Entities
::
Issue
end
# Create a new project issue
#
# Parameters:
# id (required) - The code name of a project
# title (required) - The title of an issue
# description (optional) - The description of an issue
# assignee_id (optional) - The ID of a user to assign issue
# milestone_id (optional) - The ID of a milestone to assign issue
# labels (optional) - The labels of an issue
# Example Request:
# POST /projects/:id/issues
post
":id/issues"
do
@issue
=
user_project
.
issues
.
new
(
:title
=>
params
[
:title
],
:description
=>
params
[
:description
],
:assignee_id
=>
params
[
:assignee_id
],
:milestone_id
=>
params
[
:milestone_id
],
:label_list
=>
params
[
:labels
]
)
@issue
.
author
=
current_user
if
@issue
.
save
present
@issue
,
:with
=>
Entities
::
Issue
else
error!
({
'message'
=>
'404 Not found'
},
404
)
end
end
# Update an existing issue
#
# Parameters:
# id (required) - The code name of a project
# issue_id (required) - The ID of a project issue
# title (optional) - The title of an issue
# description (optional) - The description of an issue
# assignee_id (optional) - The ID of a user to assign issue
# milestone_id (optional) - The ID of a milestone to assign issue
# labels (optional) - The labels of an issue
# closed (optional) - The state of an issue (0 = false, 1 = true)
# Example Request:
# PUT /projects/:id/issues/:issue_id
put
":id/issues/:issue_id"
do
@issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
parameters
=
{
:title
=>
(
params
[
:title
]
||
@issue
.
title
),
:description
=>
(
params
[
:description
]
||
@issue
.
description
),
:assignee_id
=>
(
params
[
:assignee_id
]
||
@issue
.
assignee_id
),
:milestone_id
=>
(
params
[
:milestone_id
]
||
@issue
.
milestone_id
),
:label_list
=>
(
params
[
:labels
]
||
@issue
.
label_list
),
:closed
=>
(
params
[
:closed
]
||
@issue
.
closed
)
}
if
@issue
.
update_attributes
(
parameters
)
present
@issue
,
:with
=>
Entities
::
Issue
else
error!
({
'message'
=>
'404 Not found'
},
404
)
end
end
# Delete a project issue
#
# Parameters:
# id (required) - The code name of a project
# issue_id (required) - The ID of a project issue
# Example Request:
# DELETE /projects/:id/issues/:issue_id
delete
":id/issues/:issue_id"
do
@issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
@issue
.
destroy
end
end
end
end
spec/api/issues_spec.rb
0 → 100644
View file @
7b33d8cb
require
'spec_helper'
describe
Gitlab
::
API
do
let
(
:user
)
{
Factory
:user
}
let!
(
:project
)
{
Factory
:project
,
:owner
=>
user
}
let!
(
:issue
)
{
Factory
:issue
,
:author
=>
user
,
:assignee
=>
user
,
:project
=>
project
}
before
{
project
.
add_access
(
user
,
:read
)
}
describe
"GET /issues"
do
it
"should return authentication error"
do
get
"
#{
api_prefix
}
/issues"
response
.
status
.
should
==
401
end
describe
"authenticated GET /issues"
do
it
"should return an array of issues"
do
get
"
#{
api_prefix
}
/issues?private_token=
#{
user
.
private_token
}
"
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
issue
.
title
end
end
end
describe
"GET /projects/:id/issues"
do
it
"should return project issues"
do
get
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/issues?private_token=
#{
user
.
private_token
}
"
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
issue
.
title
end
end
describe
"GET /projects/:id/issues/:issue_id"
do
it
"should return a project issue by id"
do
get
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/issues/
#{
issue
.
id
}
?private_token=
#{
user
.
private_token
}
"
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
issue
.
title
end
end
describe
"POST /projects/:id/issues"
do
it
"should create a new project issue"
do
post
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/issues?private_token=
#{
user
.
private_token
}
"
,
:title
=>
'new issue'
,
:labels
=>
'label, label2'
response
.
status
.
should
==
201
json_response
[
'title'
].
should
==
'new issue'
json_response
[
'description'
].
should
be_nil
json_response
[
'labels'
].
should
==
[
'label'
,
'label2'
]
end
end
describe
"PUT /projects/:id/issues/:issue_id"
do
it
"should update a project issue"
do
put
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/issues/
#{
issue
.
id
}
?private_token=
#{
user
.
private_token
}
"
,
:title
=>
'updated title'
,
:labels
=>
'label2'
,
:closed
=>
1
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
'updated title'
json_response
[
'labels'
].
should
==
[
'label2'
]
json_response
[
'closed'
].
should
be_true
end
end
describe
"DELETE /projects/:id/issues/:issue_id"
do
it
"should delete a project issue"
do
expect
{
delete
"
#{
api_prefix
}
/projects/
#{
project
.
code
}
/issues/
#{
issue
.
id
}
?private_token=
#{
user
.
private_token
}
"
}.
to
change
{
Issue
.
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