From 21a62d6a20eafb131c868285195323da334cb9fa Mon Sep 17 00:00:00 2001 From: chaseshak Date: Fri, 11 Aug 2023 13:57:27 -0500 Subject: [PATCH] Support project key in audit --- lib/models/bitbucket/audit.rb | 10 +++++++--- spec/models/bitbucket/audit_spec.rb | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/models/bitbucket/audit.rb b/lib/models/bitbucket/audit.rb index 0393eb4..8d02bbb 100644 --- a/lib/models/bitbucket/audit.rb +++ b/lib/models/bitbucket/audit.rb @@ -4,14 +4,18 @@ module Bitbucket class Audit include IssueParser - def initialize(issue_content, _) + def initialize(issue_content, command) @workspace = parameter_from_issue("Workspace", issue_content) + + @project_key = command.options["project-key"] end def to_a - return if @workspace.nil? + args = [] + args.push(["--workspace", @workspace]) unless @workspace.nil? + args.push(["--project-key", @project_key]) unless @project_key.nil? - [["--workspace", @workspace]] + return args unless args.empty? end end end diff --git a/spec/models/bitbucket/audit_spec.rb b/spec/models/bitbucket/audit_spec.rb index 7eaec17..fb3e606 100644 --- a/spec/models/bitbucket/audit_spec.rb +++ b/spec/models/bitbucket/audit_spec.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true RSpec.describe Bitbucket::Audit do - let(:audit) { described_class.new(issue_content, nil) } - describe "#to_a" do + let(:audit) { described_class.new(issue_content, command) } + let(:command) { Command.new(comment_body) } + let(:comment_body) { "/audit" } + subject { audit.to_a } context "when issue_content contains no args" do @@ -16,7 +18,7 @@ RSpec.describe Bitbucket::Audit do it { is_expected.to be_nil } end - context "when issue_content contains a organization" do + context "when issue_content contains a workspace" do let(:issue_content) do <<~ISSUE Workspace: testing @@ -25,5 +27,16 @@ RSpec.describe Bitbucket::Audit do it { is_expected.to eq([["--workspace", "testing"]]) } end + + context "when the comment body contains a project key" do + let(:issue_content) do + <<~ISSUE + Workspace: testing + ISSUE + end + let(:comment_body) { "/audit --project-key SW" } + + it { is_expected.to eq([["--workspace", "testing"], ["--project-key", "SW"]]) } + end end end