blob: 1020e98f4637b1bf95807a4b62960161ade0bf11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# frozen_string_literal: true
module Ci
class ListConfigVariablesService < ::BaseService
include ReactiveCaching
self.reactive_cache_key = ->(service) { [service.class.name, service.id] }
self.reactive_cache_work_type = :external_dependency
self.reactive_cache_worker_finder = ->(id, *_args) { from_cache(id) }
def self.from_cache(id)
project_id, user_id = id.split('-')
project = Project.find(project_id)
user = User.find(user_id)
new(project, user)
end
def execute(ref)
sha = project.commit(ref).try(:sha)
with_reactive_cache(sha) { |result| result }
end
def calculate_reactive_cache(sha)
config = ::Gitlab::Ci::ProjectConfig.new(project: project, sha: sha)
return {} unless config.exists?
result = Gitlab::Ci::YamlProcessor.new(
config.content,
project: project,
user: current_user,
sha: sha
).execute
result.valid? ? result.root_variables_with_prefill_data : {}
end
# Required for ReactiveCaching, it is also used in `reactive_cache_worker_finder`
def id
"#{project.id}-#{current_user.id}"
end
end
end
|