Skip to content

Commit

Permalink
Merge pull request #310 from grosser/zdrve/group-update-details
Browse files Browse the repository at this point in the history
Wrap update details in a collapsible group
  • Loading branch information
grosser committed Mar 3, 2024
2 parents dabba20 + cf60373 commit 373e321
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/kennel/syncer/plan_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ def print(plan)

def print_changes(step, list, color)
return if list.empty?

use_groups = ENV.key?("GITHUB_STEP_SUMMARY")

list.each do |item|
# No trailing newline
Kennel.out.print "::group::" if item.class::TYPE == :update && use_groups

Kennel.out.puts Console.color(color, "#{step} #{item.api_resource} #{item.tracking_id}")
if item.class::TYPE == :update
item.diff.each { |args| Kennel.out.puts @attribute_differ.format(*args) } # only for update
end

Kennel.out.puts "::endgroup::" if item.class::TYPE == :update && use_groups
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/kennel/syncer/plan_printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
require_relative "../../test_helper"

# Covered by syncer_test.rb
SingleCov.covered! uncovered: 12
SingleCov.covered! uncovered: 15
14 changes: 14 additions & 0 deletions test/kennel/syncer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

describe Kennel::Syncer do
define_test_classes
with_env("GITHUB_STEP_SUMMARY" => nil)

def project(pid)
project = TestProject.new
Expand Down Expand Up @@ -239,6 +240,19 @@ def change(*args)
TEXT
end

it "wraps in a group, if running under GitHub" do
with_env("GITHUB_STEP_SUMMARY" => "true") do
expected << monitor("a", "b", tags: ["foo", "bar"])
monitors << monitor_api_response("a", "b", tags: ["foo", "baz"])
output.must_equal <<~TEXT
Plan:
::group::Update monitor a:b
~tags[1] \"baz\" -> \"bar\"
::endgroup::
TEXT
end
end

it "deletes when removed from code" do
monitors << monitor_api_response("a", "b", id: 1)
plan.changes.must_equal [change(:delete, "monitor", "a:b", 1)]
Expand Down

0 comments on commit 373e321

Please sign in to comment.