Class: Dependabot::GithubActions::FileUpdater::WorkflowUpdater::SourceUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/github_actions/file_updater/workflow_updater/source_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(workflow_file:, updates:, commenter:, comment_finder:) ⇒ SourceUpdater

Returns a new instance of SourceUpdater.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/source_updater.rb', line 21

def initialize(workflow_file:, updates:, commenter:, comment_finder:)
  @workflow_file = workflow_file
  @updates = updates
  @commenter = commenter
  @metadata_builder = T.let(WorkflowFile::MetadataBuilder.new(workflow_file), WorkflowFile::MetadataBuilder)
  @comment_locator = T.let(
    SourceCommentLocator.new(
      workflow_file: workflow_file,
      comment_finder: comment_finder,
      metadata_builder: @metadata_builder
    ),
    SourceCommentLocator
  )
  @comment_updater = T.let(
    SourceCommentUpdater.new(
      workflow_file: workflow_file,
      commenter: commenter,
      metadata_builder: @metadata_builder,
      comment_locator: @comment_locator
    ),
    SourceCommentUpdater
  )
end

Instance Method Details

#updated_contentObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dependabot/github_actions/file_updater/workflow_updater/source_updater.rb', line 46

def updated_content
  return workflow_file.content if updates.empty?

  sequence_updates = grouped_flow_sequence_updates
  edits = sequence_updates.flat_map do |sequence, grouped_updates|
    expanded_flow_sequence_edits(sequence, grouped_updates)
  end

  updates.each do |update|
    sequence = expanded_sequence_for_update(sequence_updates, update)
    source_node = T.must(update.declaration.source_node)
    source_in_expanded_sequence = sequence_updates.keys.any? do |expanded_sequence|
      node_within?(source_node, expanded_sequence)
    end
    edits << source_value_edit(update) unless source_in_expanded_sequence

    next if sequence

    edits.concat(comment_updater.edits_for(update))
  end

  apply_content_edits(edits)
end