diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2018-03-29 11:24:08 +0200 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2018-03-29 11:26:37 +0200 |
commit | 51b8993e4c14bc13896d5d764157d213ec6673b8 (patch) | |
tree | 4ab613803c07b0358c65d42961f3bb6b584dfee8 | |
parent | 857f4ef731926bdf705625dd35b2563f72efcba6 (diff) | |
download | gitlab-ce-ac/pages-port.tar.gz |
Add port number to artifacts links to gitlab-pages, if neededac/pages-port
-rw-r--r-- | app/models/ci/artifact_blob.rb | 13 | ||||
-rw-r--r-- | changelogs/unreleased/ac-pages-port.yml | 5 | ||||
-rw-r--r-- | spec/models/ci/artifact_blob_spec.rb | 13 |
3 files changed, 30 insertions, 1 deletions
diff --git a/app/models/ci/artifact_blob.rb b/app/models/ci/artifact_blob.rb index ec56cc53aea..7b9db264a4d 100644 --- a/app/models/ci/artifact_blob.rb +++ b/app/models/ci/artifact_blob.rb @@ -45,7 +45,7 @@ module Ci 'artifacts', path ].join('/') - "#{pages_config.protocol}://#{top_level_group}.#{pages_config.host}/#{artifact_path}" + "#{pages_uri(top_level_group)}/#{artifact_path}" end def external_link?(job) @@ -60,5 +60,16 @@ module Ci def pages_config Gitlab.config.pages end + + def pages_uri(top_level_group) + defaults = { 'https' => 443, 'http' => 80 } + + port = '' + if pages_config.port.present? && defaults[pages_config.protocol] != pages_config.port + port = ":#{pages_config.port}" + end + + "#{pages_config.protocol}://#{top_level_group}.#{pages_config.host}#{port}" + end end end diff --git a/changelogs/unreleased/ac-pages-port.yml b/changelogs/unreleased/ac-pages-port.yml new file mode 100644 index 00000000000..4f7257b4798 --- /dev/null +++ b/changelogs/unreleased/ac-pages-port.yml @@ -0,0 +1,5 @@ +--- +title: Add missing port to artifact links +merge_request: +author: +type: fixed diff --git a/spec/models/ci/artifact_blob_spec.rb b/spec/models/ci/artifact_blob_spec.rb index 4e72d9d748e..94379438b29 100644 --- a/spec/models/ci/artifact_blob_spec.rb +++ b/spec/models/ci/artifact_blob_spec.rb @@ -65,6 +65,19 @@ describe Ci::ArtifactBlob do expect(url).not_to be_nil expect(url).to eq("http://#{project.namespace.path}.#{Gitlab.config.pages.host}/-/#{project.path}/-/jobs/#{build.id}/artifacts/#{path}") end + + context 'when port is configured' do + let(:port) { 1234 } + + it 'returns an URL with port number' do + allow(Gitlab.config.pages).to receive(:port).and_return(port) + + url = subject.external_url(build.project, build) + + expect(url).not_to be_nil + expect(url).to eq("http://#{project.namespace.path}.#{Gitlab.config.pages.host}:#{port}/-/#{project.path}/-/jobs/#{build.id}/artifacts/#{path}") + end + end end end |