Commit 18a6f31b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'feature/api_iids' of /home/git/repositories/gitlab/gitlabhq

parents d20db103 02693b72
...@@ -96,13 +96,30 @@ curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --header "SUDO: username" "h ...@@ -96,13 +96,30 @@ curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --header "SUDO: username" "h
curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --header "SUDO: 23" "http://example.com/api/v3/projects" curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --header "SUDO: 23" "http://example.com/api/v3/projects"
``` ```
#### Pagination ## Pagination
When listing resources you can pass the following parameters: When listing resources you can pass the following parameters:
+ `page` (default: `1`) - page number + `page` (default: `1`) - page number
+ `per_page` (default: `20`, max: `100`) - number of items to list per page + `per_page` (default: `20`, max: `100`) - number of items to list per page
## id vs iid
When you work with API you may notice two similar fields in api entites: id and iid.
The main difference between them is scope. Example:
Issue
id: 46
iid: 5
* id - is uniq across all Issues table. It used for any api calls.
* iid - is uniq only in scope of single project. When you browse issues or merge requests with Web UI - you see iid.
So if you want to get issue with api you use `http://host/api/v3/.../issues/:id.json`
But when you want to create a link to web page - use `http:://host/project/issues/:iid.json`
## Contents ## Contents
+ [Users](users.md) + [Users](users.md)
......
...@@ -11,6 +11,7 @@ GET /issues ...@@ -11,6 +11,7 @@ GET /issues
[ [
{ {
"id": 43, "id": 43,
"iid": 3,
"project_id": 8, "project_id": 8,
"title": "4xx/5xx pages", "title": "4xx/5xx pages",
"description": "", "description": "",
...@@ -31,6 +32,7 @@ GET /issues ...@@ -31,6 +32,7 @@ GET /issues
}, },
{ {
"id": 42, "id": 42,
"iid": 4,
"project_id": 8, "project_id": 8,
"title": "Add user settings", "title": "Add user settings",
"description": "", "description": "",
...@@ -100,6 +102,7 @@ Parameters: ...@@ -100,6 +102,7 @@ Parameters:
```json ```json
{ {
"id": 42, "id": 42,
"iid": 3,
"project_id": 8, "project_id": 8,
"title": "Add user settings", "title": "Add user settings",
"description": "", "description": "",
......
...@@ -15,6 +15,7 @@ Parameters: ...@@ -15,6 +15,7 @@ Parameters:
[ [
{ {
"id":1, "id":1,
"iid":1,
"target_branch":"master", "target_branch":"master",
"source_branch":"test1", "source_branch":"test1",
"project_id":3, "project_id":3,
...@@ -59,6 +60,7 @@ Parameters: ...@@ -59,6 +60,7 @@ Parameters:
```json ```json
{ {
"id":1, "id":1,
"iid":1,
"target_branch":"master", "target_branch":"master",
"source_branch":"test1", "source_branch":"test1",
"project_id":3, "project_id":3,
......
...@@ -10,6 +10,7 @@ GET /projects/:id/milestones ...@@ -10,6 +10,7 @@ GET /projects/:id/milestones
[ [
{ {
"id":12, "id":12,
"iid":3,
"project_id":16, "project_id":16,
"title":"10.0", "title":"10.0",
"description":"Version", "description":"Version",
......
...@@ -91,15 +91,16 @@ module API ...@@ -91,15 +91,16 @@ module API
expose :expires_at, :updated_at, :created_at expose :expires_at, :updated_at, :created_at
end end
class Milestone < Grape::Entity class ProjectEntity < Grape::Entity
expose :id expose :id, :iid
expose (:project_id) {|milestone| milestone.project.id} expose (:project_id) { |entity| entity.project.id }
end
class Milestone < ProjectEntity
expose :title, :description, :due_date, :state, :updated_at, :created_at expose :title, :description, :due_date, :state, :updated_at, :created_at
end end
class Issue < Grape::Entity class Issue < ProjectEntity
expose :id
expose (:project_id) {|issue| issue.project.id}
expose :title, :description expose :title, :description
expose :label_list, as: :labels expose :label_list, as: :labels
expose :milestone, using: Entities::Milestone expose :milestone, using: Entities::Milestone
...@@ -107,14 +108,14 @@ module API ...@@ -107,14 +108,14 @@ module API
expose :state, :updated_at, :created_at expose :state, :updated_at, :created_at
end end
class SSHKey < Grape::Entity class MergeRequest < ProjectEntity
expose :id, :title, :key, :created_at expose :target_branch, :source_branch, :title, :state, :upvotes, :downvotes
expose :author, :assignee, using: Entities::UserBasic
expose :source_project_id, :target_project_id
end end
class MergeRequest < Grape::Entity class SSHKey < Grape::Entity
expose :id, :target_branch, :source_branch, :title, :state, :upvotes, :downvotes expose :id, :title, :key, :created_at
expose :target_project_id, as: :project_id
expose :author, :assignee, using: Entities::UserBasic
end end
class Note < Grape::Entity class Note < Grape::Entity
......
...@@ -42,6 +42,7 @@ describe API::API do ...@@ -42,6 +42,7 @@ describe API::API do
get api("/projects/#{project.id}/issues/#{issue.id}", user) get api("/projects/#{project.id}/issues/#{issue.id}", user)
response.status.should == 200 response.status.should == 200
json_response['title'].should == issue.title json_response['title'].should == issue.title
json_response['iid'].should == issue.iid
end end
it "should return 404 if issue id not found" do it "should return 404 if issue id not found" do
......
...@@ -34,6 +34,7 @@ describe API::API do ...@@ -34,6 +34,7 @@ describe API::API do
get api("/projects/#{project.id}/merge_request/#{merge_request.id}", user) get api("/projects/#{project.id}/merge_request/#{merge_request.id}", user)
response.status.should == 200 response.status.should == 200
json_response['title'].should == merge_request.title json_response['title'].should == merge_request.title
json_response['iid'].should == merge_request.iid
end 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
......
...@@ -30,6 +30,7 @@ describe API::API do ...@@ -30,6 +30,7 @@ describe API::API do
get api("/projects/#{project.id}/milestones/#{milestone.id}", user) get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
response.status.should == 200 response.status.should == 200
json_response['title'].should == milestone.title json_response['title'].should == milestone.title
json_response['iid'].should == milestone.iid
end end
it "should return 401 error if user not authenticated" do it "should return 401 error if user not authenticated" do
......
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