diff --git a/lib/models/arguments.rb b/lib/models/arguments.rb index 12aa66d..f67c7b5 100644 --- a/lib/models/arguments.rb +++ b/lib/models/arguments.rb @@ -7,16 +7,23 @@ class Arguments def initialize(provider, command, issue_content) @args = argument_class(provider, command, issue_content) + @custom_transformers = custom_transformers(command) end def argument_class(provider, command, issue_content) provider.module.const_get(command.classify).new(issue_content, command) end + def custom_transformers(command) + command.options&.dig("custom-transformers")&.split(" ") || Dir.glob("transformers/**/*.rb") + end + def to_output arguments = @args.to_a return if arguments.blank? + arguments.concat(["--custom-transformers", *@custom_transformers]) if @custom_transformers.length.positive? + set_output( "args", arguments.map do |a| diff --git a/spec/models/arguments_spec.rb b/spec/models/arguments_spec.rb index e72deca..243a79d 100644 --- a/spec/models/arguments_spec.rb +++ b/spec/models/arguments_spec.rb @@ -13,6 +13,7 @@ RSpec.describe Arguments do before do expect(provider).to receive(:module).and_return(::Jenkins).at_least(:once) expect(command).to receive(:classify).and_return("Audit").at_least(:once) + expect(command).to receive(:options).and_return({}) end it { is_expected.to be_a(::Jenkins::Audit) } @@ -30,10 +31,13 @@ RSpec.describe Arguments do describe "#to_output" do subject { arguments.to_output } + + let(:options) { {} } before do expect(provider).to receive(:module).and_return(::AzureDevops).at_least(:once) expect(command).to receive(:classify).and_return("Audit").at_least(:once) + expect(command).to receive(:options).and_return(options) expect_any_instance_of(::AzureDevops::Audit).to receive(:to_a).and_return(output) end @@ -63,5 +67,29 @@ RSpec.describe Arguments do subject end end + + context "when there is a custom transformers option" do + let(:output) { ["--option", "value"] } + let(:options) { { "custom-transformers" => "transformers/**/*.rb" } } + + it "writes an output variable" do + expect(arguments).to receive(:set_output).with("args", "--option value --custom-transformers transformers/**/*.rb") + subject + end + end + + context "when there are custom transformers in the repository" do + let(:output) { ["--option", "value"] } + let(:files) { ["transformers/jenkins/transformers.rb", "transformers/all.rb"] } + + before do + expect(Dir).to receive(:glob).with("transformers/**/*.rb").and_return(files) + end + + it "writes an output variable" do + expect(arguments).to receive(:set_output).with("args", "--option value --custom-transformers transformers/jenkins/transformers.rb transformers/all.rb") + subject + end + end end end