Commit 747232ee authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'api-iid' of https://github.com/jubianchi/gitlabhq into jubianchi-api-iid

parents a7ddff87 2c544d43
...@@ -26,6 +26,7 @@ v 7.11.0 (unreleased) ...@@ -26,6 +26,7 @@ v 7.11.0 (unreleased)
- Include commit comments in MR from a forked project. - Include commit comments in MR from a forked project.
- Fix adding new group members from admin area - Fix adding new group members from admin area
- Group milestones by title in the dashboard and all other issue views. - Group milestones by title in the dashboard and all other issue views.
- Query issues, merge requests and milestones with their IID through API (Julien Bianchi)
- Add default project and snippet visibility settings to the admin web UI. - Add default project and snippet visibility settings to the admin web UI.
- Show incompatible projects in Google Code import status (Stan Hu) - Show incompatible projects in Google Code import status (Stan Hu)
- Fix bug where commit data would not appear in some subdirectories (Stan Hu) - Fix bug where commit data would not appear in some subdirectories (Stan Hu)
......
...@@ -99,11 +99,13 @@ GET /projects/:id/issues?labels=foo,bar ...@@ -99,11 +99,13 @@ GET /projects/:id/issues?labels=foo,bar
GET /projects/:id/issues?labels=foo,bar&state=opened GET /projects/:id/issues?labels=foo,bar&state=opened
GET /projects/:id/issues?milestone=1.0.0 GET /projects/:id/issues?milestone=1.0.0
GET /projects/:id/issues?milestone=1.0.0&state=opened GET /projects/:id/issues?milestone=1.0.0&state=opened
GET /projects/:id/issues?iid=42
``` ```
Parameters: Parameters:
- `id` (required) - The ID of a project - `id` (required) - The ID of a project
- `iid` (optional) - Return the issue having the given `iid`
- `state` (optional) - Return `all` issues or just those that are `opened` or `closed` - `state` (optional) - Return `all` issues or just those that are `opened` or `closed`
- `labels` (optional) - Comma-separated list of label names - `labels` (optional) - Comma-separated list of label names
- `milestone` (optional) - Milestone title - `milestone` (optional) - Milestone title
......
...@@ -10,11 +10,13 @@ The pagination parameters `page` and `per_page` can be used to restrict the list ...@@ -10,11 +10,13 @@ The pagination parameters `page` and `per_page` can be used to restrict the list
GET /projects/:id/merge_requests GET /projects/:id/merge_requests
GET /projects/:id/merge_requests?state=opened GET /projects/:id/merge_requests?state=opened
GET /projects/:id/merge_requests?state=all GET /projects/:id/merge_requests?state=all
GET /projects/:id/merge_requests?iid=42
``` ```
Parameters: Parameters:
- `id` (required) - The ID of a project - `id` (required) - The ID of a project
- `iid` (optional) - Return the request having the given `iid`
- `state` (optional) - Return `all` requests or just those that are `merged`, `opened` or `closed` - `state` (optional) - Return `all` requests or just those that are `merged`, `opened` or `closed`
- `order_by` (optional) - Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` - `order_by` (optional) - Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at`
- `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` - `sort` (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc`
...@@ -388,6 +390,6 @@ Parameters: ...@@ -388,6 +390,6 @@ Parameters:
] ]
``` ```
## Comments on issues ## Comments on merge requets
Comments are done via the notes resource. Comments are done via the notes resource.
...@@ -6,6 +6,7 @@ Returns a list of project milestones. ...@@ -6,6 +6,7 @@ Returns a list of project milestones.
``` ```
GET /projects/:id/milestones GET /projects/:id/milestones
GET /projects/:id/milestones?iid=42
``` ```
```json ```json
...@@ -27,6 +28,7 @@ GET /projects/:id/milestones ...@@ -27,6 +28,7 @@ GET /projects/:id/milestones
Parameters: Parameters:
- `id` (required) - The ID of a project - `id` (required) - The ID of a project
- `iid` (optional) - Return the milestone having the given `iid`
## Get single milestone ## Get single milestone
......
...@@ -173,6 +173,10 @@ module API ...@@ -173,6 +173,10 @@ module API
end end
end end
def filter_by_iid(items, iid)
items.where(iid: iid)
end
# error helpers # error helpers
def forbidden!(reason = nil) def forbidden!(reason = nil)
......
...@@ -51,6 +51,7 @@ module API ...@@ -51,6 +51,7 @@ module API
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# iid (optional) - Return the project issue having the given `iid`
# state (optional) - Return "opened" or "closed" issues # state (optional) - Return "opened" or "closed" issues
# labels (optional) - Comma-separated list of label names # labels (optional) - Comma-separated list of label names
# milestone (optional) - Milestone title # milestone (optional) - Milestone title
...@@ -66,10 +67,12 @@ module API ...@@ -66,10 +67,12 @@ module API
# GET /projects/:id/issues?labels=foo,bar&state=opened # GET /projects/:id/issues?labels=foo,bar&state=opened
# GET /projects/:id/issues?milestone=1.0.0 # GET /projects/:id/issues?milestone=1.0.0
# GET /projects/:id/issues?milestone=1.0.0&state=closed # GET /projects/:id/issues?milestone=1.0.0&state=closed
# GET /issues?iid=42
get ":id/issues" do get ":id/issues" do
issues = user_project.issues issues = user_project.issues
issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? issues = filter_issues_state(issues, params[:state]) unless params[:state].nil?
issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil?
issues = filter_by_iid(issues, params[:iid]) unless params[:iid].nil?
unless params[:milestone].nil? unless params[:milestone].nil?
issues = filter_issues_milestone(issues, params[:milestone]) issues = filter_issues_milestone(issues, params[:milestone])
......
...@@ -24,6 +24,7 @@ module API ...@@ -24,6 +24,7 @@ module API
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# iid (optional) - Return the project MR having the given `iid`
# state (optional) - Return requests "merged", "opened" or "closed" # state (optional) - Return requests "merged", "opened" or "closed"
# order_by (optional) - Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at` # order_by (optional) - Return requests ordered by `created_at` or `updated_at` fields. Default is `created_at`
# sort (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc` # sort (optional) - Return requests sorted in `asc` or `desc` order. Default is `desc`
...@@ -36,11 +37,16 @@ module API ...@@ -36,11 +37,16 @@ module API
# GET /projects/:id/merge_requests?order_by=updated_at # GET /projects/:id/merge_requests?order_by=updated_at
# GET /projects/:id/merge_requests?sort=desc # GET /projects/:id/merge_requests?sort=desc
# GET /projects/:id/merge_requests?sort=asc # GET /projects/:id/merge_requests?sort=asc
# GET /projects/:id/merge_requests?iid=42
# #
get ":id/merge_requests" do get ":id/merge_requests" do
authorize! :read_merge_request, user_project authorize! :read_merge_request, user_project
merge_requests = user_project.merge_requests merge_requests = user_project.merge_requests
unless params[:iid].nil?
merge_requests = filter_by_iid(merge_requests, params[:iid])
end
merge_requests = merge_requests =
case params["state"] case params["state"]
when "opened" then merge_requests.opened when "opened" then merge_requests.opened
...@@ -169,8 +175,8 @@ module API ...@@ -169,8 +175,8 @@ module API
# Merge MR # Merge MR
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# merge_request_id (required) - ID of MR # merge_request_id (required) - ID of MR
# merge_commit_message (optional) - Custom merge commit message # merge_commit_message (optional) - Custom merge commit message
# Example: # Example:
# PUT /projects/:id/merge_request/:merge_request_id/merge # PUT /projects/:id/merge_request/:merge_request_id/merge
...@@ -209,7 +215,7 @@ module API ...@@ -209,7 +215,7 @@ module API
# Get a merge request's comments # Get a merge request's comments
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# merge_request_id (required) - ID of MR # merge_request_id (required) - ID of MR
# Examples: # Examples:
# GET /projects/:id/merge_request/:merge_request_id/comments # GET /projects/:id/merge_request/:merge_request_id/comments
...@@ -225,9 +231,9 @@ module API ...@@ -225,9 +231,9 @@ module API
# Post comment to merge request # Post comment to merge request
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# merge_request_id (required) - ID of MR # merge_request_id (required) - ID of MR
# note (required) - Text of comment # note (required) - Text of comment
# Examples: # Examples:
# POST /projects/:id/merge_request/:merge_request_id/comments # POST /projects/:id/merge_request/:merge_request_id/comments
# #
......
...@@ -194,6 +194,14 @@ describe API::API, api: true do ...@@ -194,6 +194,14 @@ describe API::API, api: true do
expect(json_response['iid']).to eq(issue.iid) expect(json_response['iid']).to eq(issue.iid)
end end
it 'should return a project issue by iid' do
get api("/projects/#{project.id}/issues?iid=#{issue.iid}", user)
response.status.should == 200
json_response.first['title'].should == issue.title
json_response.first['id'].should == issue.id
json_response.first['iid'].should == issue.iid
end
it "should return 404 if issue id not found" do it "should return 404 if issue id not found" do
get api("/projects/#{project.id}/issues/54321", user) get api("/projects/#{project.id}/issues/54321", user)
expect(response.status).to eq(404) expect(response.status).to eq(404)
......
...@@ -115,6 +115,14 @@ describe API::API, api: true do ...@@ -115,6 +115,14 @@ describe API::API, api: true do
expect(json_response['iid']).to eq(merge_request.iid) expect(json_response['iid']).to eq(merge_request.iid)
end end
it 'should return merge_request by iid' do
url = "/projects/#{project.id}/merge_requests?iid=#{merge_request.iid}"
get api(url, user)
response.status.should == 200
json_response.first['title'].should == merge_request.title
json_response.first['id'].should == merge_request.id
end
it "should return a 404 error if merge_request_id not found" do it "should return a 404 error if merge_request_id not found" do
get api("/projects/#{project.id}/merge_request/999", user) get api("/projects/#{project.id}/merge_request/999", user)
expect(response.status).to eq(404) expect(response.status).to eq(404)
......
...@@ -30,6 +30,13 @@ describe API::API, api: true do ...@@ -30,6 +30,13 @@ describe API::API, api: true do
expect(json_response['iid']).to eq(milestone.iid) expect(json_response['iid']).to eq(milestone.iid)
end end
it 'should return a project milestone by iid' do
get api("/projects/#{project.id}/milestones?iid=#{milestone.iid}", user)
response.status.should == 200
json_response.first['title'].should == milestone.title
json_response.first['id'].should == milestone.id
end
it 'should return 401 error if user not authenticated' do it 'should return 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}") get api("/projects/#{project.id}/milestones/#{milestone.id}")
expect(response.status).to eq(401) expect(response.status).to eq(401)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment