Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

Commit 5c00f2b

Browse files
committed
Simplify at_exit hook - try direct status_report access
1 parent e89d519 commit 5c00f2b

1 file changed

Lines changed: 8 additions & 38 deletions

File tree

Dangerfile

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,14 @@ at_exit do
1414
# Only skip if there's an actual exception (not SystemExit from danger calling exit)
1515
next if $ERROR_INFO && !$ERROR_INFO.is_a?(SystemExit)
1616

17-
# Try to export the danger report
18-
begin
19-
puts "DEBUG at_exit: Trying to find status_report"
20-
puts "DEBUG at_exit: defined?(Danger) = #{defined?(Danger)}"
21-
puts "DEBUG at_exit: Danger.class = #{Danger.class}" if defined?(Danger)
22-
23-
# Try multiple ways to access the status report
24-
danger_report = nil
25-
26-
# Method 1: Try Danger.current_dangerfile
27-
if defined?(Danger) && Danger.respond_to?(:current_dangerfile)
28-
puts "DEBUG at_exit: Danger.current_dangerfile exists"
29-
danger_report = Danger.current_dangerfile.status_report
30-
end
31-
32-
# Method 2: Try via ObjectSpace to find active dangerfile
33-
unless danger_report
34-
puts "DEBUG at_exit: Looking for Danger::Dangerfile via ObjectSpace"
35-
ObjectSpace.each_object(Danger::Dangerfile) do |df|
36-
danger_report = df.status_report
37-
break
38-
end
39-
end
40-
41-
if danger_report
42-
puts "DEBUG at_exit: Found danger_report, exporting"
43-
reporter = RubyGrapeDanger::Reporter.new(danger_report)
44-
reporter.export_json(
45-
ENV.fetch('DANGER_REPORT_PATH', nil),
46-
ENV.fetch('GITHUB_EVENT_PATH', nil)
47-
)
48-
else
49-
puts "DEBUG at_exit: Could not find danger_report"
50-
end
51-
rescue => e
52-
# Log any errors but don't fail the entire exit
53-
puts "ERROR at_exit: #{e.class} - #{e.message}"
54-
puts e.backtrace.join("\n")
17+
# Export the danger report
18+
# The status_report method is available from the Dangerfile DSL
19+
if defined?(Danger) && defined?(status_report)
20+
reporter = RubyGrapeDanger::Reporter.new(status_report)
21+
reporter.export_json(
22+
ENV.fetch('DANGER_REPORT_PATH', nil),
23+
ENV.fetch('GITHUB_EVENT_PATH', nil)
24+
)
5525
end
5626
end
5727

0 commit comments

Comments
 (0)