From 8e7b2472e2d0b1a63898eab0c9afe4db749f6203 Mon Sep 17 00:00:00 2001 From: chaseshak Date: Thu, 10 Aug 2023 09:20:45 -0500 Subject: [PATCH] Add Bamboo support --- lib/models/bamboo/audit.rb | 18 ++++++++++++++++ lib/models/bamboo/dry_run.rb | 20 ++++++++++++++++++ lib/models/bamboo/migrate.rb | 22 ++++++++++++++++++++ spec/models/bamboo/audit_spec.rb | 29 ++++++++++++++++++++++++++ spec/models/bamboo/dry_run_spec.rb | 27 ++++++++++++++++++++++++ spec/models/bamboo/migrate_spec.rb | 33 ++++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 lib/models/bamboo/audit.rb create mode 100644 lib/models/bamboo/dry_run.rb create mode 100644 lib/models/bamboo/migrate.rb create mode 100644 spec/models/bamboo/audit_spec.rb create mode 100644 spec/models/bamboo/dry_run_spec.rb create mode 100644 spec/models/bamboo/migrate_spec.rb diff --git a/lib/models/bamboo/audit.rb b/lib/models/bamboo/audit.rb new file mode 100644 index 0000000..11c8103 --- /dev/null +++ b/lib/models/bamboo/audit.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Bamboo + class Audit + include IssueParser + + def initialize(issue_content, _) + @project = parameter_from_issue("Project", issue_content) + end + + def to_a + args = [] + args.push(["--project", @project]) unless @project.nil? + + return args unless args.empty? + end + end +end diff --git a/lib/models/bamboo/dry_run.rb b/lib/models/bamboo/dry_run.rb new file mode 100644 index 0000000..57e50b2 --- /dev/null +++ b/lib/models/bamboo/dry_run.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Bamboo + class DryRun + include IssueParser + + def initialize(issue_content, command) + @plan_slug = parameter_from_issue("Plan Slug", issue_content) + + @plan_type = command.options.fetch("plan-type", "build") + end + + def to_a + args = [@plan_type] + args.push(["--plan-slug", @plan_slug]) unless @plan_slug.nil? + + return args unless args.empty? + end + end +end diff --git a/lib/models/bamboo/migrate.rb b/lib/models/bamboo/migrate.rb new file mode 100644 index 0000000..25f5698 --- /dev/null +++ b/lib/models/bamboo/migrate.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Bamboo + class Migrate + include IssueParser + + def initialize(issue_content, command) + @plan_slug = parameter_from_issue("Plan Slug", issue_content) + + @plan_type = command.options.fetch("plan-type", "build") + @target_url = command.options["target-url"] + end + + def to_a + args = [@plan_type] + args.push(["--plan-slug", @plan_slug]) unless @plan_slug.nil? + args.push(["--target-url", @target_url]) unless @target_url.nil? + + return args unless args.empty? + end + end +end diff --git a/spec/models/bamboo/audit_spec.rb b/spec/models/bamboo/audit_spec.rb new file mode 100644 index 0000000..a7c5121 --- /dev/null +++ b/spec/models/bamboo/audit_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.describe Bamboo::Audit do + let(:audit) { described_class.new(issue_content, nil) } + + describe "#to_a" do + subject { audit.to_a } + + context "when issue_content contains no args" do + let(:issue_content) do + <<~ISSUE + Project: + ISSUE + end + + it { is_expected.to be_nil } + end + + context "when issue_content contains a project" do + let(:issue_content) do + <<~ISSUE + Project: Demo + ISSUE + end + + it { is_expected.to eq([["--project", "Demo"]]) } + end + end +end diff --git a/spec/models/bamboo/dry_run_spec.rb b/spec/models/bamboo/dry_run_spec.rb new file mode 100644 index 0000000..1061838 --- /dev/null +++ b/spec/models/bamboo/dry_run_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +RSpec.describe Bamboo::DryRun do + let(:dry_run) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + + describe "#to_a" do + subject { dry_run.to_a } + let(:issue_content) do + <<~ISSUE + Plan Slug: PAN-PLAN + ISSUE + end + + context "when the comment body does not contain a plan type" do + let(:comment_body) { "/dry-run" } + + it { is_expected.to eq(["build", ["--plan-slug", "PAN-PLAN"]]) } + end + + context "when the comment body contains a plan type" do + let(:comment_body) { "/dry-run --plan-type deployment" } + + it { is_expected.to eq(["deployment", ["--plan-slug", "PAN-PLAN"]]) } + end + end +end diff --git a/spec/models/bamboo/migrate_spec.rb b/spec/models/bamboo/migrate_spec.rb new file mode 100644 index 0000000..39b5d32 --- /dev/null +++ b/spec/models/bamboo/migrate_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +RSpec.describe Bamboo::Migrate do + let(:dry_run) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + + describe "#to_a" do + subject { dry_run.to_a } + let(:issue_content) do + <<~ISSUE + Plan Slug: PAN-PLAN + ISSUE + end + + context "when the comment body does not contain a pipeline type" do + let(:comment_body) { "/migrate" } + + it { is_expected.to eq(["build", ["--plan-slug", "PAN-PLAN"]]) } + end + + context "when the comment body contains a plan type" do + let(:comment_body) { "/dry-run --plan-type deployment" } + + it { is_expected.to eq(["deployment", ["--plan-slug", "PAN-PLAN"]]) } + end + + context "with a target-url" do + let(:comment_body) { "/migrate --target-url https://github.com/valet" } + + it { is_expected.to eq(["build", ["--plan-slug", "PAN-PLAN"], ["--target-url", "https://github.com/valet"]]) } + end + end +end