summaryrefslogtreecommitdiff
path: root/lib/api/entities/releases/link.rb
blob: 654df2e2caf213b7e4c0ae577d8c3b27fc5cf390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module API
  module Entities
    module Releases
      class Link < Grape::Entity
        expose :id
        expose :name
        expose :url
        expose :direct_asset_url
        expose :external?, as: :external
        expose :link_type

        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