Class: Dependabot::GithubActions::WorkflowFile
- Inherits:
-
Object
- Object
- Dependabot::GithubActions::WorkflowFile
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/github_actions/workflow_file.rb,
lib/dependabot/github_actions/workflow_file/node_context.rb,
lib/dependabot/github_actions/workflow_file/uses_collector.rb,
lib/dependabot/github_actions/workflow_file/metadata_builder.rb,
lib/dependabot/github_actions/workflow_file/uses_declaration.rb
Defined Under Namespace
Classes: MetadataBuilder, NodeContext, UsesCollector, UsesDeclaration
Constant Summary collapse
- Path =
T.type_alias { T::Array[T.any(String, Integer)] }
- Metadata =
T.type_alias { T::Hash[Symbol, Object] }
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#sequences ⇒ Object
readonly
Returns the value of attribute sequences.
-
#uses_declarations ⇒ Object
readonly
Returns the value of attribute uses_declarations.
Instance Method Summary collapse
- #byte_column(line, column) ⇒ Object
- #declaration_at(path) ⇒ Object
- #declarations_in_sequence(sequence) ⇒ Object
-
#initialize(content) ⇒ WorkflowFile
constructor
A new instance of WorkflowFile.
- #line_body(line) ⇒ Object
- #line_end_offset(line) ⇒ Object
- #mapping_node_style(node) ⇒ Object
- #newline ⇒ Object
- #node_children(node) ⇒ Object
- #node_end_column(node) ⇒ Object
- #node_end_line(node) ⇒ Object
- #node_source(node) ⇒ Object
- #node_start_column(node) ⇒ Object
- #node_start_line(node) ⇒ Object
- #offset(line, column) ⇒ Object
- #scalar_node_style(node) ⇒ Object
- #sequence_node_style(node) ⇒ Object
- #source_metadata(declaration) ⇒ Object
- #source_metadata_required?(declaration) ⇒ Boolean
- #steps_key_node_for(sequence) ⇒ Object
- #steps_sequences ⇒ Object
Constructor Details
#initialize(content) ⇒ WorkflowFile
Returns a new instance of WorkflowFile.
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/workflow_file.rb', line 24 def initialize(content) @content = content @data = T.let( T.cast( YAML.safe_load(content, aliases: true, permitted_classes: [Date, Time, Symbol]), T.nilable(Object) ), T.nilable(Object) ) @contexts = T.let({}, T::Hash[Path, NodeContext]) @anchors = T.let({}, T::Hash[String, Psych::Nodes::Node]) @alias_targets = T.let({}, T::Hash[Path, Psych::Nodes::Node]) @sequences = T.let([], T::Array[Psych::Nodes::Sequence]) @steps_key_nodes = T.let({}, T::Hash[Psych::Nodes::Sequence, Psych::Nodes::Scalar]) @lines = T.let(content.lines, T::Array[String]) @line_offsets = T.let(line_offsets(content), T::Array[Integer]) index_stream(YAML.parse_stream(content)) @uses_declarations = T.let(build_uses_declarations, T::Array[UsesDeclaration]) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
52 53 54 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 52 def content @content end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
46 47 48 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 46 def data @data end |
#sequences ⇒ Object (readonly)
Returns the value of attribute sequences.
55 56 57 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 55 def sequences @sequences end |
#uses_declarations ⇒ Object (readonly)
Returns the value of attribute uses_declarations.
49 50 51 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 49 def uses_declarations @uses_declarations end |
Instance Method Details
#byte_column(line, column) ⇒ Object
147 148 149 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 147 def byte_column(line, column) offset(line, column) - T.must(@line_offsets[line]) end |
#declaration_at(path) ⇒ Object
64 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 64 def declaration_at(path) = uses_declarations.find { |declaration| declaration.path == path } |
#declarations_in_sequence(sequence) ⇒ Object
67 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 67 def declarations_in_sequence(sequence) = uses_declarations.select { |item| item.steps_sequence.equal?(sequence) } |
#line_body(line) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 152 def line_body(line) start_offset = T.must(@line_offsets[line]) end_offset = @line_offsets[line + 1] || content.bytesize value = T.must(content.byteslice(start_offset...end_offset)) value = value.delete_suffix("\n") value.delete_suffix("\r") end |
#line_end_offset(line) ⇒ Object
161 162 163 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 161 def line_end_offset(line) T.must(@line_offsets[line]) + line_body(line).bytesize end |
#mapping_node_style(node) ⇒ Object
121 122 123 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 121 def mapping_node_style(node) T.cast(node.style, Integer) end |
#newline ⇒ Object
166 167 168 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 166 def newline content.include?("\r\n") ? "\r\n" : "\n" end |
#node_children(node) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 131 def node_children(node) children = node.children return [] unless children.is_a?(Array) children end |
#node_end_column(node) ⇒ Object
111 112 113 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 111 def node_end_column(node) T.cast(node.end_column, Integer) end |
#node_end_line(node) ⇒ Object
106 107 108 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 106 def node_end_line(node) T.cast(node.end_line, Integer) end |
#node_source(node) ⇒ Object
89 90 91 92 93 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 89 def node_source(node) start_offset = offset(node_start_line(node), node_start_column(node)) end_offset = offset(node_end_line(node), node_end_column(node)) T.must(content.byteslice(start_offset...end_offset)) end |
#node_start_column(node) ⇒ Object
101 102 103 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 101 def node_start_column(node) T.cast(node.start_column, Integer) end |
#node_start_line(node) ⇒ Object
96 97 98 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 96 def node_start_line(node) T.cast(node.start_line, Integer) end |
#offset(line, column) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 139 def offset(line, column) line_start = T.must(@line_offsets[line]) line_content = @lines[line] || "" prefix = line_content[0, column] || "" line_start + prefix.bytesize end |
#scalar_node_style(node) ⇒ Object
126 127 128 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 126 def scalar_node_style(node) T.cast(node.style, Integer) end |
#sequence_node_style(node) ⇒ Object
116 117 118 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 116 def sequence_node_style(node) T.cast(node.style, Integer) end |
#source_metadata(declaration) ⇒ Object
86 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 86 def (declaration) = MetadataBuilder.new(self).build(declaration) |
#source_metadata_required?(declaration) ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 70 def (declaration) return true if declaration.value_node.is_a?(Psych::Nodes::Alias) source_node = declaration.source_node if source_node.is_a?(Psych::Nodes::Scalar) return true if block_scalar_style?(scalar_node_style(source_node)) return true unless node_source(source_node).include?(declaration.value.strip) end sequence = declaration.steps_sequence return true if sequence && sequence_node_style(sequence) == Psych::Nodes::Sequence::FLOW MetadataBuilder.new(self).comment_line_collision?(declaration) end |
#steps_key_node_for(sequence) ⇒ Object
61 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 61 def steps_key_node_for(sequence) = @steps_key_nodes[sequence] |
#steps_sequences ⇒ Object
58 |
# File 'lib/dependabot/github_actions/workflow_file.rb', line 58 def steps_sequences = @steps_key_nodes.keys |