Commit d10d3861 authored by Robert Speicher's avatar Robert Speicher

Add special UrlBuilder Commit handling

Commits will sometimes be wrapped in a `BatchLoader` instance, which
properly delegates `itself` to the wrapped object via `method_missing`
but not the `===` used by the `case` statement.
parent 3a5afd36
...@@ -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"
} }
``` ```
......
...@@ -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
......
...@@ -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