Commit 51d962d2 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rs-commit-web_url' into 'master'

Add web_url attribute to API response for Commits

See merge request gitlab-org/gitlab!26173
parents e723ac82 d10d3861
---
title: Add web_url attribute to API response for Commits
merge_request: 26173
author:
type: added
...@@ -42,7 +42,8 @@ Example response: ...@@ -42,7 +42,8 @@ Example response:
"message": "Replace sanitize with escape once", "message": "Replace sanitize with escape once",
"parent_ids": [ "parent_ids": [
"6104942438c14ec7bd21c6cd5bd995272b3faff6" "6104942438c14ec7bd21c6cd5bd995272b3faff6"
] ],
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
}, },
{ {
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
...@@ -56,7 +57,8 @@ Example response: ...@@ -56,7 +57,8 @@ Example response:
"message": "Sanitize for network graph", "message": "Sanitize for network graph",
"parent_ids": [ "parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
] ],
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
} }
] ]
``` ```
...@@ -156,7 +158,8 @@ Example response: ...@@ -156,7 +158,8 @@ Example response:
"deletions": 2, "deletions": 2,
"total": 4 "total": 4
}, },
"status": null "status": null,
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
} }
``` ```
...@@ -235,7 +238,8 @@ Example response: ...@@ -235,7 +238,8 @@ Example response:
"deletions": 10, "deletions": 10,
"total": 25 "total": 25
}, },
"status": "running" "status": "running",
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/6104942438c14ec7bd21c6cd5bd995272b3faff6"
} }
``` ```
...@@ -314,7 +318,8 @@ Example response: ...@@ -314,7 +318,8 @@ Example response:
"message": "Feature added\n\nSigned-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>\n", "message": "Feature added\n\nSigned-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>\n",
"parent_ids": [ "parent_ids": [
"a738f717824ff53aebad8b090c1b79a14f2bd9e8" "a738f717824ff53aebad8b090c1b79a14f2bd9e8"
] ],
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad"
} }
``` ```
...@@ -370,7 +375,8 @@ Example response: ...@@ -370,7 +375,8 @@ Example response:
"authored_date":"2018-11-08T15:55:26.000Z", "authored_date":"2018-11-08T15:55:26.000Z",
"committer_name":"Administrator", "committer_name":"Administrator",
"committer_email":"admin@example.com", "committer_email":"admin@example.com",
"committed_date":"2018-11-08T15:55:26.000Z" "committed_date":"2018-11-08T15:55:26.000Z",
"web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad"
} }
``` ```
......
...@@ -9,6 +9,10 @@ module API ...@@ -9,6 +9,10 @@ module API
expose :safe_message, as: :message expose :safe_message, as: :message
expose :author_name, :author_email, :authored_date expose :author_name, :author_email, :authored_date
expose :committer_name, :committer_email, :committed_date expose :committer_name, :committer_email, :committed_date
expose :web_url do |commit, _options|
Gitlab::UrlBuilder.build(commit)
end
end end
end end
end end
...@@ -13,7 +13,8 @@ module Gitlab ...@@ -13,7 +13,8 @@ module Gitlab
end end
def url def url
case object # Objects are sometimes wrapped in a BatchLoader instance
case object.itself
when Commit when Commit
commit_url commit_url
when Issue when Issue
...@@ -33,7 +34,7 @@ module Gitlab ...@@ -33,7 +34,7 @@ module Gitlab
when User when User
user_url(object) user_url(object)
else else
raise NotImplementedError.new("No URL builder defined for #{object.class}") raise NotImplementedError.new("No URL builder defined for #{object.inspect}")
end end
end end
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
"authored_date", "authored_date",
"committer_name", "committer_name",
"committer_email", "committer_email",
"committed_date" "committed_date",
"web_url"
], ],
"properties" : { "properties" : {
"id": { "type": ["string", "null"] }, "id": { "type": ["string", "null"] },
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
"authored_date": { "type": "date" }, "authored_date": { "type": "date" },
"committer_name": { "type": "string" }, "committer_name": { "type": "string" },
"committer_email": { "type": "string" }, "committer_email": { "type": "string" },
"committed_date": { "type": "date" } "committed_date": { "type": "date" },
"web_url": { "type": "string" }
} }
} }
...@@ -14,6 +14,18 @@ describe Gitlab::UrlBuilder do ...@@ -14,6 +14,18 @@ describe Gitlab::UrlBuilder do
end end
end end
context 'when passing a batch loaded Commit' do
it 'returns a proper URL' do
commit = BatchLoader.for(:commit).batch do |batch, loader|
batch.each { |commit| loader.call(:commit, build_stubbed(:commit)) }
end
url = described_class.build(commit)
expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.full_path}/-/commit/#{commit.id}"
end
end
context 'when passing an Issue' do context 'when passing an Issue' do
it 'returns a proper URL' do it 'returns a proper URL' do
issue = build_stubbed(:issue, iid: 42) issue = build_stubbed(:issue, iid: 42)
...@@ -160,7 +172,7 @@ describe Gitlab::UrlBuilder do ...@@ -160,7 +172,7 @@ describe Gitlab::UrlBuilder do
project = build_stubbed(:project) project = build_stubbed(:project)
expect { described_class.build(project) } expect { described_class.build(project) }
.to raise_error(NotImplementedError, 'No URL builder defined for Project') .to raise_error(NotImplementedError, "No URL builder defined for #{project.inspect}")
end end
end end
end end
......
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