Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/claws/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def normalize_permissions(input) # rubocop:disable Metrics/AbcSize, Metrics/Cycl

def extract_normalized_on(workflow)
if workflow["on"].is_a? String
line_number = workflow.keys.first { |k| k == "on" }.line
line_number = workflow.keys.find { |k| k == "on" }.line
@on = workflow["on"] = [workflow["on"]]
set_attr_line_number(:@on, line_number)
else
Expand Down Expand Up @@ -211,7 +211,7 @@ def set_attr_line_number(key, line)
end

def copy_key_with_line(blob, src, dst)
line = blob.keys.first { |k| k.to_sym == src.to_sym }.line
line = blob.keys.find { |k| k.to_sym == src.to_sym }.line

new_key = String.new(dst).tap { |x| x.instance_eval { |_x| define_singleton_method(:line, -> { line }) } }
# freezing it keeps ruby from making a copy w/o `line`
Expand Down
24 changes: 24 additions & 0 deletions spec/claws/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@
expect(BaseRule.parse_rule("$step.with.type_nil == nil").eval_with(values:)).to eq true
expect(BaseRule.parse_rule("$step.with.type_float == 1.2").eval_with(values:)).to eq true
end

context "key normalization" do
it "preserves line numbers when normalizing hyphenated keys that are not the first key" do
workflow = described_class.load(<<~YAML)
name: test

on: push

jobs:
build:
defaults:
run:
working-directory: ./app
runs-on: ubuntu-latest
steps:
- run: echo hello
YAML

job = workflow.jobs["build"]
runs_on_key = job.keys.find { |k| k == "runs_on" }

expect(runs_on_key.line).to eq(10)
end
end
end

context "built in function - get_key" do
Expand Down