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