debian-mirror-gitlab/app/models/ci/artifact_blob.rb

66 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Ci
class ArtifactBlob
include BlobLike
2019-12-04 20:38:33 +05:30
EXTENSIONS_SERVED_BY_PAGES = %w[.html .htm .txt .json .xml .log].freeze
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
attr_reader :entry
def initialize(entry)
@entry = entry
end
delegate :name, :path, to: :entry
def id
Digest::SHA1.hexdigest(path)
end
def size
entry.metadata[:size]
end
2018-03-17 18:26:18 +05:30
alias_method :external_size, :size
2017-08-17 22:00:37 +05:30
def data
"Build artifact #{path}"
end
def mode
entry.metadata[:mode]
end
def external_storage
:build_artifact
end
2018-03-17 18:26:18 +05:30
def external_url(project, job)
return unless external_link?(job)
2018-05-09 12:01:36 +05:30
url_project_path = project.full_path.partition('/').last
2018-03-17 18:26:18 +05:30
artifact_path = [
2018-05-09 12:01:36 +05:30
'-', url_project_path, '-',
2018-03-17 18:26:18 +05:30
'jobs', job.id,
'artifacts', path
].join('/')
2018-05-09 12:01:36 +05:30
"#{project.pages_group_url}/#{artifact_path}"
2018-03-17 18:26:18 +05:30
end
def external_link?(job)
pages_config.enabled &&
pages_config.artifacts_server &&
EXTENSIONS_SERVED_BY_PAGES.include?(File.extname(name)) &&
job.project.public?
end
private
def pages_config
Gitlab.config.pages
end
2017-08-17 22:00:37 +05:30
end
end