Commit 18a6f31b6a3e50e7e3b9ef0e22a2996e7d1803ee
Exists in
master
and in
4 other branches
Merge branch 'feature/api_iids' of /home/git/repositories/gitlab/gitlabhq
Showing
8 changed files
with
40 additions
and
13 deletions
Show diff stats
doc/api/README.md
| ... | ... | @@ -96,13 +96,30 @@ curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --header "SUDO: username" "h |
| 96 | 96 | curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" --header "SUDO: 23" "http://example.com/api/v3/projects" |
| 97 | 97 | ``` |
| 98 | 98 | |
| 99 | -#### Pagination | |
| 99 | +## Pagination | |
| 100 | 100 | |
| 101 | 101 | When listing resources you can pass the following parameters: |
| 102 | 102 | |
| 103 | 103 | + `page` (default: `1`) - page number |
| 104 | 104 | + `per_page` (default: `20`, max: `100`) - number of items to list per page |
| 105 | 105 | |
| 106 | +## id vs iid | |
| 107 | + | |
| 108 | +When you work with API you may notice two similar fields in api entites: id and iid. | |
| 109 | +The main difference between them is scope. Example: | |
| 110 | + | |
| 111 | +Issue | |
| 112 | + id: 46 | |
| 113 | + iid: 5 | |
| 114 | + | |
| 115 | +* id - is uniq across all Issues table. It used for any api calls. | |
| 116 | +* iid - is uniq only in scope of single project. When you browse issues or merge requests with Web UI - you see iid. | |
| 117 | + | |
| 118 | +So if you want to get issue with api you use `http://host/api/v3/.../issues/:id.json` | |
| 119 | +But when you want to create a link to web page - use `http:://host/project/issues/:iid.json` | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 106 | 123 | ## Contents |
| 107 | 124 | |
| 108 | 125 | + [Users](users.md) | ... | ... |
doc/api/issues.md
| ... | ... | @@ -11,6 +11,7 @@ GET /issues |
| 11 | 11 | [ |
| 12 | 12 | { |
| 13 | 13 | "id": 43, |
| 14 | + "iid": 3, | |
| 14 | 15 | "project_id": 8, |
| 15 | 16 | "title": "4xx/5xx pages", |
| 16 | 17 | "description": "", |
| ... | ... | @@ -31,6 +32,7 @@ GET /issues |
| 31 | 32 | }, |
| 32 | 33 | { |
| 33 | 34 | "id": 42, |
| 35 | + "iid": 4, | |
| 34 | 36 | "project_id": 8, |
| 35 | 37 | "title": "Add user settings", |
| 36 | 38 | "description": "", |
| ... | ... | @@ -100,6 +102,7 @@ Parameters: |
| 100 | 102 | ```json |
| 101 | 103 | { |
| 102 | 104 | "id": 42, |
| 105 | + "iid": 3, | |
| 103 | 106 | "project_id": 8, |
| 104 | 107 | "title": "Add user settings", |
| 105 | 108 | "description": "", | ... | ... |
doc/api/merge_requests.md
| ... | ... | @@ -15,6 +15,7 @@ Parameters: |
| 15 | 15 | [ |
| 16 | 16 | { |
| 17 | 17 | "id":1, |
| 18 | + "iid":1, | |
| 18 | 19 | "target_branch":"master", |
| 19 | 20 | "source_branch":"test1", |
| 20 | 21 | "project_id":3, |
| ... | ... | @@ -59,6 +60,7 @@ Parameters: |
| 59 | 60 | ```json |
| 60 | 61 | { |
| 61 | 62 | "id":1, |
| 63 | + "iid":1, | |
| 62 | 64 | "target_branch":"master", |
| 63 | 65 | "source_branch":"test1", |
| 64 | 66 | "project_id":3, | ... | ... |
doc/api/milestones.md
lib/api/entities.rb
| ... | ... | @@ -91,15 +91,16 @@ module API |
| 91 | 91 | expose :expires_at, :updated_at, :created_at |
| 92 | 92 | end |
| 93 | 93 | |
| 94 | - class Milestone < Grape::Entity | |
| 95 | - expose :id | |
| 96 | - expose (:project_id) {|milestone| milestone.project.id} | |
| 94 | + class ProjectEntity < Grape::Entity | |
| 95 | + expose :id, :iid | |
| 96 | + expose (:project_id) { |entity| entity.project.id } | |
| 97 | + end | |
| 98 | + | |
| 99 | + class Milestone < ProjectEntity | |
| 97 | 100 | expose :title, :description, :due_date, :state, :updated_at, :created_at |
| 98 | 101 | end |
| 99 | 102 | |
| 100 | - class Issue < Grape::Entity | |
| 101 | - expose :id | |
| 102 | - expose (:project_id) {|issue| issue.project.id} | |
| 103 | + class Issue < ProjectEntity | |
| 103 | 104 | expose :title, :description |
| 104 | 105 | expose :label_list, as: :labels |
| 105 | 106 | expose :milestone, using: Entities::Milestone |
| ... | ... | @@ -107,14 +108,14 @@ module API |
| 107 | 108 | expose :state, :updated_at, :created_at |
| 108 | 109 | end |
| 109 | 110 | |
| 110 | - class SSHKey < Grape::Entity | |
| 111 | - expose :id, :title, :key, :created_at | |
| 111 | + class MergeRequest < ProjectEntity | |
| 112 | + expose :target_branch, :source_branch, :title, :state, :upvotes, :downvotes | |
| 113 | + expose :author, :assignee, using: Entities::UserBasic | |
| 114 | + expose :source_project_id, :target_project_id | |
| 112 | 115 | end |
| 113 | 116 | |
| 114 | - class MergeRequest < Grape::Entity | |
| 115 | - expose :id, :target_branch, :source_branch, :title, :state, :upvotes, :downvotes | |
| 116 | - expose :target_project_id, as: :project_id | |
| 117 | - expose :author, :assignee, using: Entities::UserBasic | |
| 117 | + class SSHKey < Grape::Entity | |
| 118 | + expose :id, :title, :key, :created_at | |
| 118 | 119 | end |
| 119 | 120 | |
| 120 | 121 | class Note < Grape::Entity | ... | ... |
spec/requests/api/issues_spec.rb
| ... | ... | @@ -42,6 +42,7 @@ describe API::API do |
| 42 | 42 | get api("/projects/#{project.id}/issues/#{issue.id}", user) |
| 43 | 43 | response.status.should == 200 |
| 44 | 44 | json_response['title'].should == issue.title |
| 45 | + json_response['iid'].should == issue.iid | |
| 45 | 46 | end |
| 46 | 47 | |
| 47 | 48 | it "should return 404 if issue id not found" do | ... | ... |
spec/requests/api/merge_requests_spec.rb
| ... | ... | @@ -34,6 +34,7 @@ describe API::API do |
| 34 | 34 | get api("/projects/#{project.id}/merge_request/#{merge_request.id}", user) |
| 35 | 35 | response.status.should == 200 |
| 36 | 36 | json_response['title'].should == merge_request.title |
| 37 | + json_response['iid'].should == merge_request.iid | |
| 37 | 38 | end |
| 38 | 39 | |
| 39 | 40 | it "should return a 404 error if merge_request_id not found" do | ... | ... |
spec/requests/api/milestones_spec.rb
| ... | ... | @@ -30,6 +30,7 @@ describe API::API do |
| 30 | 30 | get api("/projects/#{project.id}/milestones/#{milestone.id}", user) |
| 31 | 31 | response.status.should == 200 |
| 32 | 32 | json_response['title'].should == milestone.title |
| 33 | + json_response['iid'].should == milestone.iid | |
| 33 | 34 | end |
| 34 | 35 | |
| 35 | 36 | it "should return 401 error if user not authenticated" do | ... | ... |