Merge pull request #2 from actions/dry-up-custom-transformers

Refactor use of custom transformers
This commit is contained in:
Ethan Dennis
2022-11-23 11:55:37 -08:00
committed by GitHub
3 changed files with 60 additions and 1 deletions
+24
View File
@@ -95,6 +95,30 @@ Optionally, the following environment variables can be set:
Once configured, pipelines can be migrated to GitHub Actions by opening an issue with the relevant issue template and following the instructions. Once configured, pipelines can be migrated to GitHub Actions by opening an issue with the relevant issue template and following the instructions.
### Custom transformers
Custom transformers can be used to customize the behavior of Actions Importer to meet your specific use-case. Custom transformers can be used to:
- Convert items that are not automatically converted.
- Convert items that were automatically converted using different actions.
- Convert environment variable values differently.
- Convert references to runners to use a different runner name in Actions.
Custom transformers must be defined in a file with the `.rb` file extension within a directory named `transformers` in your IssueOps repository. Alternatively, you can provide specific custom transformers to be used by appending the `--custom-transformers` option in the issue comment used to trigger Actions Importer. For example:
```
/migrate ... --custom-transformers my-transformers.rb
```
You can learn more about authoring custom transformers by completing the self-guided learning exercises below:
- Custom transformers for Azure DevOps pipelines [exercise](https://github.com/actions/importer-labs/blob/main/azure_devops/5-custom-transformers.md)
- Custom transformers for CircleCI pipelines [exercise](https://github.com/actions/importer-labs/blob/main/circle_ci/5-custom-transformers.md)
- Custom transformers for GitLab pipelines [exercise](https://github.com/actions/importer-labs/blob/main/gitlab/5-custom-transformers.md)
- Custom transformers for Jenkins pipelines [exercise](https://github.com/actions/importer-labs/blob/main/jenkins/5-custom-transformers.md)
- Custom transformers for Travis CI pipelines [exercise](https://github.com/actions/importer-labs/blob/main/travis/5-custom-transformers.md)
## Privacy statement ## Privacy statement
GitHub Actions Importer will collect anonymous telemetry when running to help us improve the tool. This can be disabled by adding the `--no-telemetry` flag to any command provided to the GitHub Actions Importer CLI. GitHub Actions Importer will collect anonymous telemetry when running to help us improve the tool. This can be disabled by adding the `--no-telemetry` flag to any command provided to the GitHub Actions Importer CLI.
+7
View File
@@ -7,16 +7,23 @@ class Arguments
def initialize(provider, command, issue_content) def initialize(provider, command, issue_content)
@args = argument_class(provider, command, issue_content) @args = argument_class(provider, command, issue_content)
@custom_transformers = custom_transformers(command)
end end
def argument_class(provider, command, issue_content) def argument_class(provider, command, issue_content)
provider.module.const_get(command.classify).new(issue_content, command) provider.module.const_get(command.classify).new(issue_content, command)
end end
def custom_transformers(command)
command.options&.dig("custom-transformers")&.split(" ") || Dir.glob("transformers/**/*.rb")
end
def to_output def to_output
arguments = @args.to_a arguments = @args.to_a
return if arguments.blank? return if arguments.blank?
arguments.concat(["--custom-transformers", *@custom_transformers]) if @custom_transformers.length.positive?
set_output( set_output(
"args", "args",
arguments.map do |a| arguments.map do |a|
+28
View File
@@ -13,6 +13,7 @@ RSpec.describe Arguments do
before do before do
expect(provider).to receive(:module).and_return(::Jenkins).at_least(:once) 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(:classify).and_return("Audit").at_least(:once)
expect(command).to receive(:options).and_return({})
end end
it { is_expected.to be_a(::Jenkins::Audit) } it { is_expected.to be_a(::Jenkins::Audit) }
@@ -31,9 +32,12 @@ RSpec.describe Arguments do
describe "#to_output" do describe "#to_output" do
subject { arguments.to_output } subject { arguments.to_output }
let(:options) { {} }
before do before do
expect(provider).to receive(:module).and_return(::AzureDevops).at_least(:once) 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(: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) expect_any_instance_of(::AzureDevops::Audit).to receive(:to_a).and_return(output)
end end
@@ -63,5 +67,29 @@ RSpec.describe Arguments do
subject subject
end end
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
end end