Class: Ci::FindExposedArtifactsService

Inherits:
BaseService show all
Includes:
Gitlab::Routing
Defined in:
app/services/ci/find_exposed_artifacts_service.rb

Overview

This class loops through all builds with exposed artifacts and returns basic information about exposed artifacts for given jobs for the frontend to display them as custom links in the merge request.

This service must be used with care. Looking for exposed artifacts is very slow and should be done asynchronously.

Constant Summary collapse

MAX_EXPOSED_ARTIFACTS =
10

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Routing

includes_helpers, redirect_legacy_paths, url_helpers

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#for_job(job) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/ci/find_exposed_artifacts_service.rb', line 29

def for_job(job)
  return unless job.has_exposed_artifacts?

   = (job)
  return if .empty?

  {
    text: job.artifacts_expose_as,
    url: path_for_entries(, job),
    job_path: project_job_path(job.project, job),
    job_name: job.name
  }
end

#for_pipeline(pipeline, limit: MAX_EXPOSED_ARTIFACTS) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/ci/find_exposed_artifacts_service.rb', line 15

def for_pipeline(pipeline, limit: MAX_EXPOSED_ARTIFACTS)
  results = []

  pipeline.builds.latest.with_exposed_artifacts.find_each do |job|
    if job_exposed_artifacts = for_job(job)
      results << job_exposed_artifacts
    end

    break if results.size >= limit
  end

  results
end