Class: Gitlab::Ci::Config::External::Context
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::External::Context
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/ci/config/external/context.rb
Constant Summary collapse
- TimeoutError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#execution_deadline ⇒ Object
readonly
Returns the value of attribute execution_deadline.
-
#expandset ⇒ Object
readonly
Returns the value of attribute expandset.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#parent_pipeline ⇒ Object
readonly
Returns the value of attribute parent_pipeline.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #all_worktree_paths ⇒ Object
- #check_execution_time! ⇒ Object
- #includes ⇒ Object
-
#initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, logger: nil) {|_self| ... } ⇒ Context
constructor
A new instance of Context.
- #mask_variables_from(string) ⇒ Object
- #mutate(attrs = {}) ⇒ Object
- #sentry_payload ⇒ Object
- #set_deadline(timeout_seconds) ⇒ Object
- #top_level_worktree_paths ⇒ Object
- #variables_hash ⇒ Object
Methods included from Utils::StrongMemoize
#clear_memoization, #strong_memoize, #strong_memoized?
Constructor Details
#initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, logger: nil) {|_self| ... } ⇒ Context
Returns a new instance of Context.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/ci/config/external/context.rb', line 19 def initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, logger: nil) @project = project @sha = sha @user = user @parent_pipeline = parent_pipeline @variables = variables || Ci::Variables::Collection.new @expandset = Set.new @execution_deadline = 0 @logger = logger || Gitlab::Ci::Pipeline::Logger.new(project: project) yield self if block_given? end |
Instance Attribute Details
#execution_deadline ⇒ Object
Returns the value of attribute execution_deadline.
15 16 17 |
# File 'lib/gitlab/ci/config/external/context.rb', line 15 def execution_deadline @execution_deadline end |
#expandset ⇒ Object
Returns the value of attribute expandset.
15 16 17 |
# File 'lib/gitlab/ci/config/external/context.rb', line 15 def @expandset end |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/gitlab/ci/config/external/context.rb', line 15 def logger @logger end |
#parent_pipeline ⇒ Object (readonly)
Returns the value of attribute parent_pipeline.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def parent_pipeline @parent_pipeline end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def project @project end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def sha @sha end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def user @user end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
14 15 16 |
# File 'lib/gitlab/ci/config/external/context.rb', line 14 def variables @variables end |
Instance Method Details
#all_worktree_paths ⇒ Object
38 39 40 41 42 |
# File 'lib/gitlab/ci/config/external/context.rb', line 38 def all_worktree_paths strong_memoize(:all_worktree_paths) do project.repository.ls_files(sha) end end |
#check_execution_time! ⇒ Object
62 63 64 |
# File 'lib/gitlab/ci/config/external/context.rb', line 62 def check_execution_time! raise TimeoutError if execution_expired? end |
#includes ⇒ Object
83 84 85 |
# File 'lib/gitlab/ci/config/external/context.rb', line 83 def includes .map(&:metadata) end |
#mask_variables_from(string) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/gitlab/ci/config/external/context.rb', line 73 def mask_variables_from(string) variables.reduce(string.dup) do |str, variable| if variable[:masked] Gitlab::Ci::MaskSecret.mask!(str, variable[:value]) else str end end end |
#mutate(attrs = {}) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/gitlab/ci/config/external/context.rb', line 50 def mutate(attrs = {}) self.class.new(**attrs) do |ctx| ctx. = ctx.execution_deadline = execution_deadline ctx.logger = logger end end |
#sentry_payload ⇒ Object
66 67 68 69 70 71 |
# File 'lib/gitlab/ci/config/external/context.rb', line 66 def sentry_payload { user: user.inspect, project: project.inspect } end |
#set_deadline(timeout_seconds) ⇒ Object
58 59 60 |
# File 'lib/gitlab/ci/config/external/context.rb', line 58 def set_deadline(timeout_seconds) @execution_deadline = current_monotonic_time + timeout_seconds.to_f end |
#top_level_worktree_paths ⇒ Object
32 33 34 35 36 |
# File 'lib/gitlab/ci/config/external/context.rb', line 32 def top_level_worktree_paths strong_memoize(:top_level_worktree_paths) do project.repository.tree(sha).blobs.map(&:path) end end |
#variables_hash ⇒ Object
44 45 46 47 48 |
# File 'lib/gitlab/ci/config/external/context.rb', line 44 def variables_hash strong_memoize(:variables_hash) do variables.to_hash end end |