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
Tatuya Kamada
gitlab-ce
Commits
fa300909
Commit
fa300909
authored
Apr 12, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make subscription API more RESTful
parent
f875189b
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
72 deletions
+68
-72
doc/api/issues.md
doc/api/issues.md
+14
-13
doc/api/merge_requests.md
doc/api/merge_requests.md
+14
-14
lib/api/helpers.rb
lib/api/helpers.rb
+1
-1
lib/api/issues.rb
lib/api/issues.rb
+6
-23
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+7
-7
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+19
-7
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+7
-7
No files found.
doc/api/issues.md
View file @
fa300909
...
@@ -408,13 +408,14 @@ Example response:
...
@@ -408,13 +408,14 @@ Example response:
## Subscribe to an issue
## Subscribe to an issue
Subscribes to an issue to receive notifications. If the operation is successful,
Subscribes the authenticated user to an issue to receive notifications. If the
status code
`201`
together with the updated issue is returned. If the user is
operation is successful, status code
`201`
together with the updated issue is
already subscribed to the issue, the status code
`304`
is returned. If the
returned. If the user is already subscribed to the issue, the status code
`304`
project or issue is not found, status code
`404`
is returned.
is returned. If the project or issue is not found, status code
`404`
is
returned.
```
```
POST /projects/:id/issues/:issue_id/subscri
be
POST /projects/:id/issues/:issue_id/subscri
ption
```
```
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
...
@@ -423,7 +424,7 @@ POST /projects/:id/issues/:issue_id/subscribe
...
@@ -423,7 +424,7 @@ POST /projects/:id/issues/:issue_id/subscribe
|
`issue_id`
| integer | yes | The ID of a project's issue |
|
`issue_id`
| integer | yes | The ID of a project's issue |
```
bash
```
bash
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/issues/93/subscri
be
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/issues/93/subscri
ption
```
```
Example response:
Example response:
...
@@ -461,14 +462,14 @@ Example response:
...
@@ -461,14 +462,14 @@ Example response:
## Unsubscribe from an issue
## Unsubscribe from an issue
Unsubscribes
from an issue to not receive notifications from that issue. If the
Unsubscribes
the authenticated user from the issue to not receive notifications
operation is successful, status code
`201`
together with the updated issue is
from it. If the operation is successful, status code
`200`
together with the
returned. If the user is not subscribed to the issue, the status code
`304`
updated issue is returned. If the user is not subscribed to the issue, the
is returned. If the project or issue is not found, status code
`404`
is
status code
`304`
is returned. If the project or issue is not found, status code
returned.
`404`
is
returned.
```
```
POST /projects/:id/issues/:issue_id/unsubscribe
DELETE /projects/:id/issues/:issue_id/subscription
```
```
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
...
@@ -477,7 +478,7 @@ POST /projects/:id/issues/:issue_id/unsubscribe
...
@@ -477,7 +478,7 @@ POST /projects/:id/issues/:issue_id/unsubscribe
|
`issue_id`
| integer | yes | The ID of a project's issue |
|
`issue_id`
| integer | yes | The ID of a project's issue |
```
bash
```
bash
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/issues/93/unsubscribe
curl
-X
DELETE
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/issues/93/subscription
```
```
Example response:
Example response:
...
...
doc/api/merge_requests.md
View file @
fa300909
...
@@ -609,14 +609,14 @@ Example response:
...
@@ -609,14 +609,14 @@ Example response:
## Subscribe to a merge request
## Subscribe to a merge request
Subscribes t
o a merge request to receive notification. If the operation is
Subscribes t
he authenticated user to a merge request to receive notification. If
successful, status code
`201`
together with the updated merge request is
the operation is successful, status code
`201`
together with the updated merge
re
turned. If the user is already subscribed to the merge request, the status
re
quest is returned. If the user is already subscribed to the merge request, the
code
`304`
is returned. If the project or merge request is not found, status
status code
`304`
is returned. If the project or merge request is not found,
code
`404`
is returned.
status
code
`404`
is returned.
```
```
POST /projects/:id/merge_requests/:merge_request_id/subscri
be
POST /projects/:id/merge_requests/:merge_request_id/subscri
ption
```
```
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
...
@@ -625,7 +625,7 @@ POST /projects/:id/merge_requests/:merge_request_id/subscribe
...
@@ -625,7 +625,7 @@ POST /projects/:id/merge_requests/:merge_request_id/subscribe
|
`merge_request_id`
| integer | yes | The ID of the merge request |
|
`merge_request_id`
| integer | yes | The ID of the merge request |
```
bash
```
bash
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/merge_requests/17/subscri
be
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/merge_requests/17/subscri
ption
```
```
Example response:
Example response:
...
@@ -682,14 +682,14 @@ Example response:
...
@@ -682,14 +682,14 @@ Example response:
```
```
## Unsubscribe from a merge request
## Unsubscribe from a merge request
Unsubscribes
from a merge request to not receive notifications from that merg
e
Unsubscribes
the authenticated user from a merge request to not receiv
e
request. If the operation is successful, status code
`201`
together with the
notifications from that merge request. If the operation is successful, status
updated merge request is returned. If the user is not subscribed to the merge
code
`200`
together with the updated merge request is returned. If the user is
request, the status code
`304`
is returned. If the project or merge request is
not subscribed to the merge request, the status code
`304`
is returned. If the
not found, status code
`404`
is returned.
project or merge request is
not found, status code
`404`
is returned.
```
```
POST /projects/:id/merge_requests/:merge_request_id/unsubscribe
DELETE /projects/:id/merge_requests/:merge_request_id/subscription
```
```
| Attribute | Type | Required | Description |
| Attribute | Type | Required | Description |
...
@@ -698,7 +698,7 @@ POST /projects/:id/merge_requests/:merge_request_id/unsubscribe
...
@@ -698,7 +698,7 @@ POST /projects/:id/merge_requests/:merge_request_id/unsubscribe
|
`merge_request_id`
| integer | yes | The ID of the merge request |
|
`merge_request_id`
| integer | yes | The ID of the merge request |
```
bash
```
bash
curl
-X
POST
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/merge_requests/17/subscribe
curl
-X
DELETE
-H
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v3/projects/5/merge_requests/17/subscription
```
```
Example response:
Example response:
...
...
lib/api/helpers.rb
View file @
fa300909
...
@@ -242,7 +242,7 @@ module API
...
@@ -242,7 +242,7 @@ module API
end
end
def
not_modified!
def
not_modified!
render_api_error!
(
'304 Not
m
odified'
,
304
)
render_api_error!
(
'304 Not
M
odified'
,
304
)
end
end
def
render_validation_error!
(
model
)
def
render_validation_error!
(
model
)
...
...
lib/api/issues.rb
View file @
fa300909
...
@@ -238,32 +238,15 @@ module API
...
@@ -238,32 +238,15 @@ module API
# id (required) - The ID of a project
# id (required) - The ID of a project
# issue_id (required) - The ID of a project issue
# issue_id (required) - The ID of a project issue
# Example Request:
# Example Request:
# POST /projects/:id/issues/:issue_id
# POST /projects/:id/issues/:issue_id
/subscription
post
":id/issues/:issue_id
subscribe
"
do
post
":id/issues/:issue_id
/subscription
"
do
issue
=
user_project
.
issues
.
find_by
(
id:
params
[
:issue_id
])
issue
=
user_project
.
issues
.
find_by
(
id:
params
[
:issue_id
])
if
!
issue
.
subscribed?
(
current_user
)
if
issue
.
subscribed?
(
current_user
)
present
issue
,
with:
Entities
::
Issue
,
current_user:
current_user
else
not_modified!
not_modified!
end
else
end
# Subscribes to a project issue
#
# Parameters:
# id (required) - The ID of a project
# issue_id (required) - The ID of a project issue
# Example Request:
# POST /projects/:id/issues/:issue_id/subscribe
post
":id/issues/:issue_id/subscribe"
do
issue
=
user_project
.
issues
.
find_by
(
id:
params
[
:issue_id
])
if
!
issue
.
subscribed?
(
current_user
)
issue
.
toggle_subscription
(
current_user
)
issue
.
toggle_subscription
(
current_user
)
present
issue
,
with:
Entities
::
Issue
,
current_user:
current_user
present
issue
,
with:
Entities
::
Issue
,
current_user:
current_user
else
not_modified!
end
end
end
end
...
@@ -273,8 +256,8 @@ module API
...
@@ -273,8 +256,8 @@ module API
# id (required) - The ID of a project
# id (required) - The ID of a project
# issue_id (required) - The ID of a project issue
# issue_id (required) - The ID of a project issue
# Example Request:
# Example Request:
#
POST /projects/:id/issues/:issue_id/unsubscribe
#
DELETE /projects/:id/issues/:issue_id/subscription
post
":id/issues/:issue_id/unsubscribe
"
do
delete
":id/issues/:issue_id/subscription
"
do
issue
=
user_project
.
issues
.
find_by
(
id:
params
[
:issue_id
])
issue
=
user_project
.
issues
.
find_by
(
id:
params
[
:issue_id
])
if
issue
.
subscribed?
(
current_user
)
if
issue
.
subscribed?
(
current_user
)
...
...
lib/api/merge_requests.rb
View file @
fa300909
...
@@ -334,15 +334,15 @@ module API
...
@@ -334,15 +334,15 @@ module API
# id (required) - The ID of a project
# id (required) - The ID of a project
# merge_request_id (required) - The ID of a merge request
# merge_request_id (required) - The ID of a merge request
# Example Request:
# Example Request:
# POST /projects/:id/issues/:merge_request_id/subscri
be
# POST /projects/:id/issues/:merge_request_id/subscri
ption
post
"
#{
path
}
/subscri
be
"
do
post
"
#{
path
}
/subscri
ption
"
do
merge_request
=
user_project
.
merge_requests
.
find
(
params
[
:merge_request_id
])
merge_request
=
user_project
.
merge_requests
.
find
(
params
[
:merge_request_id
])
if
!
merge_request
.
subscribed?
(
current_user
)
if
merge_request
.
subscribed?
(
current_user
)
not_modified!
else
merge_request
.
toggle_subscription
(
current_user
)
merge_request
.
toggle_subscription
(
current_user
)
present
merge_request
,
with:
Entities
::
MergeRequest
,
current_user:
current_user
present
merge_request
,
with:
Entities
::
MergeRequest
,
current_user:
current_user
else
not_modified!
end
end
end
end
...
@@ -352,8 +352,8 @@ module API
...
@@ -352,8 +352,8 @@ module API
# id (required) - The ID of a project
# id (required) - The ID of a project
# merge_request_id (required) - The ID of a merge request
# merge_request_id (required) - The ID of a merge request
# Example Request:
# Example Request:
#
POST /projects/:id/merge_requests/:merge_request_id/unsubscribe
#
DELETE /projects/:id/merge_requests/:merge_request_id/subscription
post
"
#{
path
}
/unsubscribe
"
do
delete
"
#{
path
}
/subscription
"
do
merge_request
=
user_project
.
merge_requests
.
find
(
params
[
:merge_request_id
])
merge_request
=
user_project
.
merge_requests
.
find
(
params
[
:merge_request_id
])
if
merge_request
.
subscribed?
(
current_user
)
if
merge_request
.
subscribed?
(
current_user
)
...
...
spec/requests/api/issues_spec.rb
View file @
fa300909
...
@@ -571,33 +571,45 @@ describe API::API, api: true do
...
@@ -571,33 +571,45 @@ describe API::API, api: true do
end
end
end
end
describe
'POST :id/issues/:issue_id/subscri
be
'
do
describe
'POST :id/issues/:issue_id/subscri
ption
'
do
it
'subscribes to an issue'
do
it
'subscribes to an issue'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscri
be
"
,
user2
)
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscri
ption
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
true
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
true
)
end
end
it
'returns 304 if already subscribed'
do
it
'returns 304 if already subscribed'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscri
be
"
,
user
)
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscri
ption
"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
.
status
).
to
eq
(
304
)
end
end
it
'returns 404 if the issue is not found'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/123/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
describe
'
POST :id/issues/:issue_id/unsubscribe
'
do
describe
'
DELETE :id/issues/:issue_id/subscription
'
do
it
'unsubscribes from an issue'
do
it
'unsubscribes from an issue'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/
unsubscribe
"
,
user
)
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/
subscription
"
,
user
)
expect
(
response
.
status
).
to
eq
(
20
1
)
expect
(
response
.
status
).
to
eq
(
20
0
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
false
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
false
)
end
end
it
'returns 304 if not subscribed'
do
it
'returns 304 if not subscribed'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/
unsubscribe
"
,
user2
)
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/
subscription
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
.
status
).
to
eq
(
304
)
end
end
it
'returns 404 if the issue is not found'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/123/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
end
spec/requests/api/merge_requests_spec.rb
View file @
fa300909
...
@@ -516,31 +516,31 @@ describe API::API, api: true do
...
@@ -516,31 +516,31 @@ describe API::API, api: true do
end
end
end
end
describe
'POST :id/merge_requests/:merge_request_id/subscri
be
'
do
describe
'POST :id/merge_requests/:merge_request_id/subscri
ption
'
do
it
'subscribes to a merge request'
do
it
'subscribes to a merge request'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscri
be
"
,
admin
)
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscri
ption
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
true
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
true
)
end
end
it
'returns 304 if already subscribed'
do
it
'returns 304 if already subscribed'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscri
be
"
,
user
)
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscri
ption
"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
.
status
).
to
eq
(
304
)
end
end
end
end
describe
'
POST :id/merge_requests/:merge_request_id/unsubscribe
'
do
describe
'
DELETE :id/merge_requests/:merge_request_id/subscription
'
do
it
'unsubscribes from a merge request'
do
it
'unsubscribes from a merge request'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/unsubscribe
"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscription
"
,
user
)
expect
(
response
.
status
).
to
eq
(
20
1
)
expect
(
response
.
status
).
to
eq
(
20
0
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
false
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
false
)
end
end
it
'returns 304 if not subscribed'
do
it
'returns 304 if not subscribed'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/unsubscribe
"
,
admin
)
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscription
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
.
status
).
to
eq
(
304
)
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