Backend for HTML serving with GitLab Pages

上级 3265ccfc
module ArtifactHelper
include GitlabRoutingHelper
def link_to_artifact(project, job, file)
if external_url?(file.blob)
html_artifact_url(project, job, file.blob)
else
file_project_job_artifacts_path(project, job, path: file.path)
end
end
def external_url?(blob)
blob.name.end_with?(".html") &&
pages_config.enabled &&
pages_config.artifacts_server
end
private
def html_artifact_url(project, job, blob)
http = pages_config.https ? "https://" : "http://"
domain = "#{project.namespace.to_param}.#{pages_config.host}/"
path = "-/jobs/#{job.id}/artifacts/#{blob.path}"
http + domain + path
end
def pages_config
Gitlab.config.pages
end
end
- todo_external_artifacts_path = 'https://google.com'
- is_external_link = !todo_external_artifacts_path.blank?
- path_to_file = todo_external_artifacts_path || file_project_job_artifacts_path(@project, @build, path: file.path)
- blob = file.blob
- is_external_link = external_link?(blob)
- path_to_file = link_to_artifact(@project, @build, file)
%tr.tree-item.js-artifact-tree-row{ data: { link: path_to_file, external_link: "#{is_external_link}" } }
- blob = file.blob
%td.tree-item-file-name
= tree_icon('file', blob.mode, blob.name)
= link_to path_to_file,
......
......@@ -164,6 +164,7 @@ production: &base
host: example.com
port: 80 # Set to 443 if you serve the pages with HTTPS
https: false # Set to true if you serve the pages with HTTPS
artifacts_server: true
# external_http: ["1.1.1.1:80", "[2001::1]:80"] # If defined, enables custom domain support in GitLab Pages
# external_https: ["1.1.1.1:443", "[2001::1]:443"] # If defined, enables custom domain and certificate support in GitLab Pages
......
require 'spec_helper'
describe ArtifactHelper do
set(:job) { create(:ci_build, :artifacts) }
let(:html_entry) { job.artifacts_metadata_entry("other_artifacts_0.1.2/index.html") }
let(:txt_entry) { job.artifacts_metadata_entry("other_artifacts_0.1.2/doc_sample.txt") }
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
end
describe '#link_to_artifact' do
context 'link_to_pages returns true' do
subject { link_to_artifact(job.project, job, entry) }
before do
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
end
context 'when the entry is HTML' do
let(:entry) { html_entry }
it { is_expected.to match Gitlab.config.pages.host }
it { is_expected.to match /-\/jobs\/\d+\/artifacts/ }
end
context 'when the entry is not HTML' do
let(:entry) { txt_entry }
it { is_expected.not_to match Gitlab.config.pages.host }
end
end
end
describe '#external_url?' do
context 'pages enabled' do
before do
allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
end
it 'returns true for HTML files' do
expect(external_url?(txt_entry.blob)).to be(false)
end
it 'returns true for HTML files' do
expect(external_url?(html_entry.blob)).to be(true)
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册