Commit e43c4060 authored by Ben Boeckel's avatar Ben Boeckel

api: expose web_url for project entities

This allows web hooks to have a URL back to entities without having to
generate it themselves.
parent 9b470aeb
...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.12.0 (unreleased) v 8.12.0 (unreleased)
- Change merge_error column from string to text type - Change merge_error column from string to text type
- Add `web_url` field to issue, merge request, and snippet API objects (Ben Boeckel)
- Optimistic locking for Issues and Merge Requests (title and description overriding prevention) - Optimistic locking for Issues and Merge Requests (title and description overriding prevention)
- Added tests for diff notes - Added tests for diff notes
......
...@@ -79,7 +79,8 @@ Example response: ...@@ -79,7 +79,8 @@ Example response:
"labels" : [], "labels" : [],
"subscribed" : false, "subscribed" : false,
"user_notes_count": 1, "user_notes_count": 1,
"due_date": "2016-07-22" "due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/6"
} }
] ]
``` ```
...@@ -156,7 +157,8 @@ Example response: ...@@ -156,7 +157,8 @@ Example response:
"created_at" : "2016-01-04T15:31:46.176Z", "created_at" : "2016-01-04T15:31:46.176Z",
"subscribed" : false, "subscribed" : false,
"user_notes_count": 1, "user_notes_count": 1,
"due_date": null "due_date": null,
"web_url": "http://example.com/example/example/issues/1"
} }
] ]
``` ```
...@@ -235,7 +237,8 @@ Example response: ...@@ -235,7 +237,8 @@ Example response:
"created_at" : "2016-01-04T15:31:46.176Z", "created_at" : "2016-01-04T15:31:46.176Z",
"subscribed" : false, "subscribed" : false,
"user_notes_count": 1, "user_notes_count": 1,
"due_date": "2016-07-22" "due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/1"
} }
] ]
``` ```
...@@ -299,7 +302,8 @@ Example response: ...@@ -299,7 +302,8 @@ Example response:
"created_at" : "2016-01-04T15:31:46.176Z", "created_at" : "2016-01-04T15:31:46.176Z",
"subscribed": false, "subscribed": false,
"user_notes_count": 1, "user_notes_count": 1,
"due_date": null "due_date": null,
"web_url": "http://example.com/example/example/issues/1"
} }
``` ```
...@@ -357,7 +361,8 @@ Example response: ...@@ -357,7 +361,8 @@ Example response:
"milestone" : null, "milestone" : null,
"subscribed" : true, "subscribed" : true,
"user_notes_count": 0, "user_notes_count": 0,
"due_date": null "due_date": null,
"web_url": "http://example.com/example/example/issues/14"
} }
``` ```
...@@ -418,7 +423,8 @@ Example response: ...@@ -418,7 +423,8 @@ Example response:
"milestone" : null, "milestone" : null,
"subscribed" : true, "subscribed" : true,
"user_notes_count": 0, "user_notes_count": 0,
"due_date": "2016-07-22" "due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/15"
} }
``` ```
...@@ -496,7 +502,8 @@ Example response: ...@@ -496,7 +502,8 @@ Example response:
"avatar_url": "http://www.gravatar.com/avatar/7a190fecbaa68212a4b68aeb6e3acd10?s=80&d=identicon", "avatar_url": "http://www.gravatar.com/avatar/7a190fecbaa68212a4b68aeb6e3acd10?s=80&d=identicon",
"web_url": "https://gitlab.example.com/u/solon.cremin" "web_url": "https://gitlab.example.com/u/solon.cremin"
}, },
"due_date": null "due_date": null,
"web_url": "http://example.com/example/example/issues/11"
} }
``` ```
...@@ -551,7 +558,8 @@ Example response: ...@@ -551,7 +558,8 @@ Example response:
"avatar_url": "http://www.gravatar.com/avatar/7a190fecbaa68212a4b68aeb6e3acd10?s=80&d=identicon", "avatar_url": "http://www.gravatar.com/avatar/7a190fecbaa68212a4b68aeb6e3acd10?s=80&d=identicon",
"web_url": "https://gitlab.example.com/u/solon.cremin" "web_url": "https://gitlab.example.com/u/solon.cremin"
}, },
"due_date": null "due_date": null,
"web_url": "http://example.com/example/example/issues/11"
} }
``` ```
...@@ -607,7 +615,8 @@ Example response: ...@@ -607,7 +615,8 @@ Example response:
"web_url": "https://gitlab.example.com/u/orville" "web_url": "https://gitlab.example.com/u/orville"
}, },
"subscribed": false, "subscribed": false,
"due_date": null "due_date": null,
"web_url": "http://example.com/example/example/issues/12"
} }
``` ```
...@@ -693,7 +702,9 @@ Example response: ...@@ -693,7 +702,9 @@ Example response:
"subscribed": true, "subscribed": true,
"user_notes_count": 7, "user_notes_count": 7,
"upvotes": 0, "upvotes": 0,
"downvotes": 0 "downvotes": 0,
"due_date": null,
"web_url": "http://example.com/example/example/issues/110"
}, },
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/issues/10", "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/issues/10",
"body": "Vel voluptas atque dicta mollitia adipisci qui at.", "body": "Vel voluptas atque dicta mollitia adipisci qui at.",
......
...@@ -70,7 +70,8 @@ Parameters: ...@@ -70,7 +70,8 @@ Parameters:
"subscribed" : false, "subscribed" : false,
"user_notes_count": 1, "user_notes_count": 1,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
} }
] ]
``` ```
...@@ -136,7 +137,8 @@ Parameters: ...@@ -136,7 +137,8 @@ Parameters:
"subscribed" : true, "subscribed" : true,
"user_notes_count": 1, "user_notes_count": 1,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
} }
``` ```
...@@ -239,6 +241,7 @@ Parameters: ...@@ -239,6 +241,7 @@ Parameters:
"user_notes_count": 1, "user_notes_count": 1,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false, "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1",
"changes": [ "changes": [
{ {
"old_path": "VERSION", "old_path": "VERSION",
...@@ -321,7 +324,8 @@ Parameters: ...@@ -321,7 +324,8 @@ Parameters:
"subscribed" : true, "subscribed" : true,
"user_notes_count": 0, "user_notes_count": 0,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
} }
``` ```
...@@ -395,7 +399,8 @@ Parameters: ...@@ -395,7 +399,8 @@ Parameters:
"subscribed" : true, "subscribed" : true,
"user_notes_count": 1, "user_notes_count": 1,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
} }
``` ```
...@@ -496,7 +501,8 @@ Parameters: ...@@ -496,7 +501,8 @@ Parameters:
"subscribed" : true, "subscribed" : true,
"user_notes_count": 1, "user_notes_count": 1,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
} }
``` ```
...@@ -565,7 +571,8 @@ Parameters: ...@@ -565,7 +571,8 @@ Parameters:
"subscribed" : true, "subscribed" : true,
"user_notes_count": 1, "user_notes_count": 1,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
} }
``` ```
...@@ -886,7 +893,8 @@ Example response: ...@@ -886,7 +893,8 @@ Example response:
"subscribed": true, "subscribed": true,
"user_notes_count": 7, "user_notes_count": 7,
"should_remove_source_branch": true, "should_remove_source_branch": true,
"force_remove_source_branch": false "force_remove_source_branch": false,
"web_url": "http://example.com/example/example/merge_requests/1"
}, },
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/merge_requests/7", "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/merge_requests/7",
"body": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.", "body": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.",
......
...@@ -53,7 +53,8 @@ Parameters: ...@@ -53,7 +53,8 @@ Parameters:
}, },
"expires_at": null, "expires_at": null,
"updated_at": "2012-06-28T10:52:04Z", "updated_at": "2012-06-28T10:52:04Z",
"created_at": "2012-06-28T10:52:04Z" "created_at": "2012-06-28T10:52:04Z",
"web_url": "http://example.com/example/example/snippets/1"
} }
``` ```
......
...@@ -177,6 +177,10 @@ module API ...@@ -177,6 +177,10 @@ module API
# TODO (rspeicher): Deprecated; remove in 9.0 # TODO (rspeicher): Deprecated; remove in 9.0
expose(:expires_at) { |snippet| nil } expose(:expires_at) { |snippet| nil }
expose :web_url do |snippet, options|
Gitlab::UrlBuilder.build(snippet)
end
end end
class ProjectEntity < Grape::Entity class ProjectEntity < Grape::Entity
...@@ -206,6 +210,10 @@ module API ...@@ -206,6 +210,10 @@ module API
expose :user_notes_count expose :user_notes_count
expose :upvotes, :downvotes expose :upvotes, :downvotes
expose :due_date expose :due_date
expose :web_url do |issue, options|
Gitlab::UrlBuilder.build(issue)
end
end end
class ExternalIssue < Grape::Entity class ExternalIssue < Grape::Entity
...@@ -229,6 +237,10 @@ module API ...@@ -229,6 +237,10 @@ module API
expose :user_notes_count expose :user_notes_count
expose :should_remove_source_branch?, as: :should_remove_source_branch expose :should_remove_source_branch?, as: :should_remove_source_branch
expose :force_remove_source_branch?, as: :force_remove_source_branch expose :force_remove_source_branch?, as: :force_remove_source_branch
expose :web_url do |merge_request, options|
Gitlab::UrlBuilder.build(merge_request)
end
end end
class MergeRequestChanges < MergeRequest class MergeRequestChanges < MergeRequest
......
...@@ -61,6 +61,7 @@ describe API::API, api: true do ...@@ -61,6 +61,7 @@ describe API::API, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(issue.title) expect(json_response.first['title']).to eq(issue.title)
expect(json_response.last).to have_key('web_url')
end end
it "adds pagination headers and keep query params" do it "adds pagination headers and keep query params" do
......
...@@ -33,6 +33,7 @@ describe API::API, api: true do ...@@ -33,6 +33,7 @@ describe API::API, api: true do
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.length).to eq(3) expect(json_response.length).to eq(3)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
expect(json_response.last).to have_key('web_url')
end end
it "returns an array of all merge_requests" do it "returns an array of all merge_requests" do
......
...@@ -30,6 +30,7 @@ describe API::API, api: true do ...@@ -30,6 +30,7 @@ describe API::API, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id) expect(json_response.map{ |snippet| snippet['id']} ).to include(public_snippet.id, internal_snippet.id, private_snippet.id)
expect(json_response.last).to have_key('web_url')
end end
it 'hides private snippets from regular user' do it 'hides private snippets from regular user' 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