Updating distribution
This commit is contained in:
10
lib/concerns/issue_parser.rb
Normal file
10
lib/concerns/issue_parser.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module IssueParser
|
||||
def parameter_from_issue(name, text)
|
||||
match = text.match(/#{name}: ([^\n]+)/)
|
||||
return if match.nil?
|
||||
|
||||
match[1].strip
|
||||
end
|
||||
end
|
||||
9
lib/concerns/output_writer.rb
Normal file
9
lib/concerns/output_writer.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module OutputWriter
|
||||
def set_output(name, value)
|
||||
return if value.nil?
|
||||
|
||||
puts "::set-output name=#{name}::#{value}"
|
||||
end
|
||||
end
|
||||
29
lib/models/arguments.rb
Normal file
29
lib/models/arguments.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../concerns/output_writer"
|
||||
|
||||
class Arguments
|
||||
include OutputWriter
|
||||
|
||||
def initialize(provider, command, issue_content)
|
||||
@args = argument_class(provider, command, issue_content)
|
||||
end
|
||||
|
||||
def argument_class(provider, command, issue_content)
|
||||
provider.module.const_get(command.classify).new(issue_content, command)
|
||||
end
|
||||
|
||||
def to_output
|
||||
arguments = @args.to_a
|
||||
return if arguments.blank?
|
||||
|
||||
set_output(
|
||||
"args",
|
||||
arguments.map do |a|
|
||||
next a unless a.include?(" ")
|
||||
|
||||
a.inspect
|
||||
end.join(" ")
|
||||
)
|
||||
end
|
||||
end
|
||||
20
lib/models/azure_devops/audit.rb
Normal file
20
lib/models/azure_devops/audit.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module AzureDevops
|
||||
class Audit
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, _)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@project = parameter_from_issue("Project", issue_content)
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--azure-devops-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--azure-devops-project", @project]) unless @project.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
24
lib/models/azure_devops/dry_run.rb
Normal file
24
lib/models/azure_devops/dry_run.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module AzureDevops
|
||||
class DryRun
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@project = parameter_from_issue("Project", issue_content)
|
||||
|
||||
@pipeline_type = command.options.fetch("pipeline-type", "pipeline")
|
||||
@pipeline_id = command.options["pipeline-id"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = [@pipeline_type]
|
||||
args.concat(["--azure-devops-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--azure-devops-project", @project]) unless @project.nil?
|
||||
args.concat(["--pipeline-id", @pipeline_id]) unless @pipeline_id.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
26
lib/models/azure_devops/migrate.rb
Normal file
26
lib/models/azure_devops/migrate.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module AzureDevops
|
||||
class Migrate
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@project = parameter_from_issue("Project", issue_content)
|
||||
|
||||
@pipeline_type = command.options.fetch("pipeline-type", "pipeline")
|
||||
@pipeline_id = command.options["pipeline-id"]
|
||||
@target_url = command.options["target-url"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = [@pipeline_type]
|
||||
args.concat(["--azure-devops-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--azure-devops-project", @project]) unless @project.nil?
|
||||
args.concat(["--pipeline-id", @pipeline_id]) unless @pipeline_id.nil?
|
||||
args.concat(["--target-url", @target_url]) unless @target_url.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/models/circle_ci/audit.rb
Normal file
17
lib/models/circle_ci/audit.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CircleCI
|
||||
class Audit
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, _)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
end
|
||||
|
||||
def to_a
|
||||
return if @organization.nil?
|
||||
|
||||
["--circle-ci-organization", @organization]
|
||||
end
|
||||
end
|
||||
end
|
||||
21
lib/models/circle_ci/dry_run.rb
Normal file
21
lib/models/circle_ci/dry_run.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CircleCI
|
||||
class DryRun
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
# TODO: manually test this
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@project = command.options["project"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--circle-ci-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--circle-ci-project", @project]) unless @project.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
22
lib/models/circle_ci/migrate.rb
Normal file
22
lib/models/circle_ci/migrate.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CircleCI
|
||||
class Migrate
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@project = command.options["project"]
|
||||
@target_url = command.options["target-url"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--circle-ci-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--circle-ci-project", @project]) unless @project.nil?
|
||||
args.concat(["--target-url", @target_url]) unless @target_url.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
50
lib/models/command.rb
Normal file
50
lib/models/command.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "active_support/core_ext/string"
|
||||
require_relative "../concerns/output_writer"
|
||||
|
||||
class Command
|
||||
include OutputWriter
|
||||
|
||||
VALID_COMMANDS = %w[audit migrate dry-run].freeze
|
||||
|
||||
def initialize(comment_body)
|
||||
@comment_body = comment_body
|
||||
end
|
||||
|
||||
def command
|
||||
@command ||= begin
|
||||
command = @comment_body&.match(%r{/([^\s\\]+)})
|
||||
command[1] unless command.nil? || !VALID_COMMANDS.include?(command[1])
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
!command.nil?
|
||||
end
|
||||
|
||||
def classify
|
||||
return unless valid?
|
||||
|
||||
command.tr("-", "_").classify
|
||||
end
|
||||
|
||||
def options
|
||||
return unless valid?
|
||||
|
||||
@options ||= begin
|
||||
command_text = "/#{command}"
|
||||
command_index = @comment_body.index(command_text)
|
||||
|
||||
options_text = @comment_body[command_index + command_text.length..-1]
|
||||
options_text.split(" ")
|
||||
.each_slice(2)
|
||||
.to_h
|
||||
.transform_keys { |key| key.delete_prefix("--") }
|
||||
end
|
||||
end
|
||||
|
||||
def to_output
|
||||
set_output("command", command)
|
||||
end
|
||||
end
|
||||
17
lib/models/gitlab_ci/audit.rb
Normal file
17
lib/models/gitlab_ci/audit.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module GitlabCI
|
||||
class Audit
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, _)
|
||||
@namespace = parameter_from_issue("Namespace", issue_content)
|
||||
end
|
||||
|
||||
def to_a
|
||||
return if @namespace.nil?
|
||||
|
||||
["--namespace", @namespace]
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/models/gitlab_ci/dry_run.rb
Normal file
20
lib/models/gitlab_ci/dry_run.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module GitlabCI
|
||||
class DryRun
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@namespace = parameter_from_issue("Namespace", issue_content)
|
||||
@project = command.options["project"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--namespace", @namespace]) unless @namespace.nil?
|
||||
args.concat(["--project", @project]) unless @project.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
22
lib/models/gitlab_ci/migrate.rb
Normal file
22
lib/models/gitlab_ci/migrate.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module GitlabCI
|
||||
class Migrate
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@namespace = parameter_from_issue("Namespace", issue_content)
|
||||
@project = command.options["project"]
|
||||
@target_url = command.options["target-url"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--namespace", @namespace]) unless @namespace.nil?
|
||||
args.concat(["--project", @project]) unless @project.nil?
|
||||
args.concat(["--target-url", @target_url]) unless @target_url.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/models/jenkins/audit.rb
Normal file
17
lib/models/jenkins/audit.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Jenkins
|
||||
class Audit
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, _)
|
||||
@folders = parameter_from_issue("Folders", issue_content)
|
||||
end
|
||||
|
||||
def to_a
|
||||
return if @folders.nil?
|
||||
|
||||
["--folders", @folders]
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/models/jenkins/dry_run.rb
Normal file
17
lib/models/jenkins/dry_run.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Jenkins
|
||||
class DryRun
|
||||
include IssueParser
|
||||
|
||||
def initialize(_, command)
|
||||
@source_url = command.options["source-url"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
return if @source_url.nil?
|
||||
|
||||
["--source-url", @source_url]
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/models/jenkins/migrate.rb
Normal file
20
lib/models/jenkins/migrate.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Jenkins
|
||||
class Migrate
|
||||
include IssueParser
|
||||
|
||||
def initialize(_, command)
|
||||
@source_url = command.options["source-url"]
|
||||
@target_url = command.options["target-url"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--source-url", @source_url]) unless @source_url.nil?
|
||||
args.concat(["--target-url", @target_url]) unless @target_url.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
41
lib/models/provider.rb
Normal file
41
lib/models/provider.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_rel "./azure_devops/**/*.rb"
|
||||
require_rel "./circle_ci/**/*.rb"
|
||||
require_rel "./gitlab_ci/**/*.rb"
|
||||
require_rel "./jenkins/**/*.rb"
|
||||
require_rel "./travis_ci/**/*.rb"
|
||||
|
||||
class Provider
|
||||
include OutputWriter
|
||||
|
||||
PROVIDER_MAP = {
|
||||
"azure-devops" => ::AzureDevops,
|
||||
"circle-ci" => ::CircleCI,
|
||||
"gitlab" => ::GitlabCI,
|
||||
"jenkins" => ::Jenkins,
|
||||
"travis-ci" => ::TravisCI
|
||||
}.freeze
|
||||
|
||||
def initialize(labels)
|
||||
labels = labels.tr("\n", "").delete_prefix("[").delete_suffix("]").split(",").map(&:strip)
|
||||
providers = labels.select { |label| PROVIDER_MAP.key?(label) }
|
||||
|
||||
raise "One provider must be selected" if providers.empty?
|
||||
raise "Only one provider can be selected" unless providers.one?
|
||||
|
||||
@provider = providers.first
|
||||
end
|
||||
|
||||
def cli_command
|
||||
@provider
|
||||
end
|
||||
|
||||
def module
|
||||
PROVIDER_MAP[@provider]
|
||||
end
|
||||
|
||||
def to_output
|
||||
set_output("provider", cli_command)
|
||||
end
|
||||
end
|
||||
17
lib/models/travis_ci/audit.rb
Normal file
17
lib/models/travis_ci/audit.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module TravisCI
|
||||
class Audit
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, _)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
end
|
||||
|
||||
def to_a
|
||||
return if @organization.nil?
|
||||
|
||||
["--travis-ci-organization", @organization]
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/models/travis_ci/dry_run.rb
Normal file
20
lib/models/travis_ci/dry_run.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module TravisCI
|
||||
class DryRun
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@repository = command.options["repository"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--travis-ci-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--travis-ci-repository", @repository]) unless @repository.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
22
lib/models/travis_ci/migrate.rb
Normal file
22
lib/models/travis_ci/migrate.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module TravisCI
|
||||
class Migrate
|
||||
include IssueParser
|
||||
|
||||
def initialize(issue_content, command)
|
||||
@organization = parameter_from_issue("Organization", issue_content)
|
||||
@repository = command.options["repository"]
|
||||
@target_url = command.options["target-url"]
|
||||
end
|
||||
|
||||
def to_a
|
||||
args = []
|
||||
args.concat(["--travis-ci-organization", @organization]) unless @organization.nil?
|
||||
args.concat(["--travis-ci-repository", @repository]) unless @repository.nil?
|
||||
args.concat(["--target-url", @target_url]) unless @target_url.nil?
|
||||
|
||||
return args unless args.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user