Commit d1fb2254 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '23700-add-filepath-to-release-links-api' into 'master'

Add filepath to release_links API

See merge request gitlab-org/gitlab!25533
parents 5fa50bad 6feab1bf
---
title: Add filepath to release links API
merge_request: 25533
author:
type: added
...@@ -7,7 +7,17 @@ module API ...@@ -7,7 +7,17 @@ module API
expose :id expose :id
expose :name expose :name
expose :url expose :url
expose :direct_asset_url
expose :external?, as: :external expose :external?, as: :external
def direct_asset_url
return object.url unless object.filepath
release = object.release
project = release.project
Gitlab::Routing.url_helpers.project_release_url(project, release) << object.filepath
end
end end
end end
end end
......
...@@ -39,6 +39,7 @@ module API ...@@ -39,6 +39,7 @@ module API
params do params do
requires :name, type: String, desc: 'The name of the link' requires :name, type: String, desc: 'The name of the link'
requires :url, type: String, desc: 'The URL of the link' requires :url, type: String, desc: 'The URL of the link'
optional :filepath, type: String, desc: 'The filepath of the link'
end end
post 'links' do post 'links' do
authorize! :create_release, release authorize! :create_release, release
...@@ -73,6 +74,7 @@ module API ...@@ -73,6 +74,7 @@ module API
params do params do
optional :name, type: String, desc: 'The name of the link' optional :name, type: String, desc: 'The name of the link'
optional :url, type: String, desc: 'The URL of the link' optional :url, type: String, desc: 'The URL of the link'
optional :filepath, type: String, desc: 'The filepath of the link'
at_least_one_of :name, :url at_least_one_of :name, :url
end end
put do put do
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
"properties": { "properties": {
"id": { "type": "integer" }, "id": { "type": "integer" },
"name": { "type": "string" }, "name": { "type": "string" },
"filepath": { "type": "string" },
"url": { "type": "string" }, "url": { "type": "string" },
"direct_asset_url": { "type": "string" },
"external": { "type": "boolean" } "external": { "type": "boolean" }
}, },
"additionalProperties": false "additionalProperties": false
......
...@@ -135,16 +135,44 @@ describe API::Release::Links do ...@@ -135,16 +135,44 @@ describe API::Release::Links do
end end
end end
end end
describe '#direct_asset_url' do
let!(:link) { create(:release_link, release: release, url: url, filepath: filepath) }
let(:url) { 'https://google.com/-/jobs/140463678/artifacts/download' }
context 'when filepath is provided' do
let(:filepath) { '/bin/bigfile.exe' }
specify do
get api("/projects/#{project.id}/releases/v0.1/assets/links/#{link.id}", maintainer)
expect(json_response['direct_asset_url']).to eq("http://localhost/#{project.namespace.path}/#{project.name}/-/releases/#{release.tag}/bin/bigfile.exe")
end
end
context 'when filepath is not provided' do
let(:filepath) { nil }
specify do
get api("/projects/#{project.id}/releases/v0.1/assets/links/#{link.id}", maintainer)
expect(json_response['direct_asset_url']).to eq(url)
end
end
end
end end
describe 'POST /projects/:id/releases/:tag_name/assets/links' do describe 'POST /projects/:id/releases/:tag_name/assets/links' do
let(:params) do let(:params) do
{ {
name: 'awesome-app.dmg', name: 'awesome-app.dmg',
filepath: '/binaries/awesome-app.dmg',
url: 'https://example.com/download/awesome-app.dmg' url: 'https://example.com/download/awesome-app.dmg'
} }
end end
let(:last_release_link) { release.links.last }
it 'accepts the request' do it 'accepts the request' do
post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), params: params post api("/projects/#{project.id}/releases/v0.1/assets/links", maintainer), params: params
...@@ -157,8 +185,9 @@ describe API::Release::Links do ...@@ -157,8 +185,9 @@ describe API::Release::Links do
end.to change { Releases::Link.count }.by(1) end.to change { Releases::Link.count }.by(1)
release.reload release.reload
expect(release.links.last.name).to eq('awesome-app.dmg') expect(last_release_link.name).to eq('awesome-app.dmg')
expect(release.links.last.url).to eq('https://example.com/download/awesome-app.dmg') expect(last_release_link.filepath).to eq('/binaries/awesome-app.dmg')
expect(last_release_link.url).to eq('https://example.com/download/awesome-app.dmg')
end end
it 'matches response schema' do it 'matches response schema' 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