Class: Gitlab::Pages::UrlBuilder
- Inherits:
-
Object
- Object
- Gitlab::Pages::UrlBuilder
- Defined in:
- lib/gitlab/pages/url_builder.rb
Constant Summary collapse
- ALLOWED_ARTIFACT_EXTENSIONS =
%w[.html .htm .txt .json .xml .log].freeze
- ARTIFACT_URL =
"%{host}/-/%{project_path}/-/jobs/%{job_id}/artifacts/%{artifact_path}"
Instance Attribute Summary collapse
-
#project_namespace ⇒ Object
readonly
Returns the value of attribute project_namespace.
Instance Method Summary collapse
- #artifact_url(artifact, job) ⇒ Object
- #artifact_url_available?(artifact, job) ⇒ Boolean
-
#initialize(project) ⇒ UrlBuilder
constructor
A new instance of UrlBuilder.
- #namespace_pages? ⇒ Boolean
- #pages_url(with_unique_domain: false) ⇒ Object
- #unique_host ⇒ Object
Constructor Details
#initialize(project) ⇒ UrlBuilder
Returns a new instance of UrlBuilder.
11 12 13 14 |
# File 'lib/gitlab/pages/url_builder.rb', line 11 def initialize(project) @project = project @project_namespace, _, @project_path = project.full_path.partition('/') end |
Instance Attribute Details
#project_namespace ⇒ Object (readonly)
Returns the value of attribute project_namespace.
6 7 8 |
# File 'lib/gitlab/pages/url_builder.rb', line 6 def project_namespace @project_namespace end |
Instance Method Details
#artifact_url(artifact, job) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gitlab/pages/url_builder.rb', line 40 def artifact_url(artifact, job) return unless artifact_url_available?(artifact, job) format( ARTIFACT_URL, host: namespace_url, project_path: project_path, job_id: job.id, artifact_path: artifact.path) end |
#artifact_url_available?(artifact, job) ⇒ Boolean
51 52 53 54 55 56 |
# File 'lib/gitlab/pages/url_builder.rb', line 51 def artifact_url_available?(artifact, job) config.enabled && config.artifacts_server && ALLOWED_ARTIFACT_EXTENSIONS.include?(File.extname(artifact.name)) && (config.access_control || job.project.public?) end |
#namespace_pages? ⇒ Boolean
36 37 38 |
# File 'lib/gitlab/pages/url_builder.rb', line 36 def namespace_pages? namespace_url == pages_url end |
#pages_url(with_unique_domain: false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab/pages/url_builder.rb', line 16 def pages_url(with_unique_domain: false) return unique_url if with_unique_domain && unique_domain_enabled? project_path_url = "#{config.protocol}://#{project_path}".downcase # If the project path is the same as host, we serve it as group page # On development we ignore the URL port to make it work on GDK return namespace_url if Rails.env.development? && portless(namespace_url) == project_path_url # If the project path is the same as host, we serve it as group page return namespace_url if namespace_url == project_path_url "#{namespace_url}/#{project_path}" end |
#unique_host ⇒ Object
30 31 32 33 34 |
# File 'lib/gitlab/pages/url_builder.rb', line 30 def unique_host return unless unique_domain_enabled? URI(unique_url).host end |