Skip to content
代码片段 群组 项目
提交 be4174d6 编辑于 作者: David Fernandez's avatar David Fernandez
浏览文件

Merge branch '246811-dry-up-direct_asset_url-method-between-graphql-and-rest-api' into 'master'

Resolve "DRY up direct_asset_url method between GraphQL and REST API"

See merge request gitlab-org/gitlab!89432
No related branches found
No related tags found
无相关合并请求
...@@ -7,6 +7,8 @@ class ReleaseAssetLinkType < BaseObject ...@@ -7,6 +7,8 @@ class ReleaseAssetLinkType < BaseObject
authorize :read_release authorize :read_release
present_using Releases::LinkPresenter
field :external, GraphQL::Types::Boolean, null: true, method: :external?, field :external, GraphQL::Types::Boolean, null: true, method: :external?,
description: 'Indicates the link points to an external resource.' description: 'Indicates the link points to an external resource.'
field :id, GraphQL::Types::ID, null: false, field :id, GraphQL::Types::ID, null: false,
...@@ -22,12 +24,5 @@ class ReleaseAssetLinkType < BaseObject ...@@ -22,12 +24,5 @@ class ReleaseAssetLinkType < BaseObject
description: 'Relative path for the direct asset link.' description: 'Relative path for the direct asset link.'
field :direct_asset_url, GraphQL::Types::String, null: true, field :direct_asset_url, GraphQL::Types::String, null: true,
description: 'Direct asset URL of the link.' description: 'Direct asset URL of the link.'
def direct_asset_url
return object.url unless object.filepath
release = object.release.present
release.download_url(object.filepath)
end
end end
end end
# frozen_string_literal: true
module Releases
class LinkPresenter < Gitlab::View::Presenter::Delegated
def direct_asset_url
return @subject.url unless @subject.filepath
release = @subject.release.present
release.download_url(@subject.filepath)
end
end
end
...@@ -7,16 +7,11 @@ class Link < Grape::Entity ...@@ -7,16 +7,11 @@ class Link < Grape::Entity
expose :id expose :id
expose :name expose :name
expose :url expose :url
expose :direct_asset_url expose :direct_asset_url do |link|
::Releases::LinkPresenter.new(link).direct_asset_url
end
expose :external?, as: :external expose :external?, as: :external
expose :link_type expose :link_type
def direct_asset_url
return object.url unless object.filepath
release = object.release.present
release.download_url(object.filepath)
end
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::LinkPresenter do
describe '#direct_asset_url' do
let_it_be(:release) { create(:release) }
let(:link) { build(:release_link, release: release, url: url, filepath: filepath) }
let(:url) { 'https://google.com/-/jobs/140463678/artifacts/download' }
let(:presenter) { described_class.new(link) }
subject { presenter.direct_asset_url }
context 'when filepath is provided' do
let(:filepath) { '/bin/bigfile.exe' }
let(:expected_url) do
"http://localhost/#{release.project.namespace.path}/#{release.project.name}" \
"/-/releases/#{release.tag}/downloads/bin/bigfile.exe"
end
it { is_expected.to eq(expected_url) }
end
context 'when filepath is not provided' do
let(:filepath) { nil }
it { is_expected.to eq(url) }
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册