I am trying to split Dangerfile
into multiple files and call them from the main Dangerfile
.
I tried this way,
In the parent Dangerfile
puts "Branch #{github.branch_for_base} #{git.lines_of_code}"
require_relative "scripts/large_diff.rb"
warn 'Some warning'
And in the scripts/large_diff.rb
puts '---->>>>'
puts github.pr_json.inspect
puts '<<<<---->>>>'
puts github.inspect
puts '<<<<----'
But this gives this error
You used `puts` in your Dangerfile. To print out text to GitHub use `message` instead
Branch release/abc/xyz 304
---->>>>
bundler: failed to load command: danger (/Users/runner/work/my-proj/my-proj/vendor/bundle/ruby/3.0.0/bin/danger)
/Users/runner/work/my-proj/my-proj/scripts/large_diff.rb:2:in `<top (required)>': \e[31m (Danger::DSLError)
[!] Invalid `Dangerfile` file: undefined local variable or method `github' for main:Object. Updating the Danger gem might fix the issue. Your Danger version: 8.5.0, latest Danger version: 8.6.1
\e[0m
# from Dangerfile:3
# -------------------------------------------
# puts "Branch #{github.branch_for_base} #{git.lines_of_code}"
> require_relative "scripts/large_diff.rb"
# warn 'Big PR, split it into smaller ones'
# -------------------------------------------
from Dangerfile:3:in `require_relative'
from Dangerfile:3:in `eval_file'
from /Users/runner/work/bitrise-comment/bitrise-comment/vendor/bundle/ruby/3.0.0/gems/danger-8.5.0/lib/danger/danger_core/dangerfile.rb:311:in `eval'
from /Users/runner/work/bitrise-comment/bitrise-comment/vendor/bundle/ruby/3.0.0/gems/danger-8.5.0/lib/danger/danger_core/dangerfile.rb:311:in `eval_file'
...
...
...
I know this is because the github
object is not avaialble in the child danger file. How can I use variables and functions (the object github
functions warn
, fail
etc) available in Parent Dangerfile
also in the child danger file?
PS: I am new to ruby :)