diff --git a/lib/fastlane/plugin/ddg_apple_automation/helper/git_helper.rb b/lib/fastlane/plugin/ddg_apple_automation/helper/git_helper.rb index fd1df0c..a2fa77d 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/helper/git_helper.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/helper/git_helper.rb @@ -45,7 +45,7 @@ def self.delete_branch(repo_name, branch, github_token) client.delete_branch(repo_name, branch) UI.success("Deleted #{branch}") rescue StandardError => e - UI.important("Failed to delete #{branch}: #{e}") + UI.important("Failed to delete #{branch} branch: #{e}") raise e end end diff --git a/lib/fastlane/plugin/ddg_apple_automation/version.rb b/lib/fastlane/plugin/ddg_apple_automation/version.rb index 45af7df..80ed082 100644 --- a/lib/fastlane/plugin/ddg_apple_automation/version.rb +++ b/lib/fastlane/plugin/ddg_apple_automation/version.rb @@ -1,5 +1,5 @@ module Fastlane module DdgAppleAutomation - VERSION = "0.11.0" + VERSION = "0.11.1" end end diff --git a/spec/git_helper_spec.rb b/spec/git_helper_spec.rb new file mode 100644 index 0000000..ee8a7e1 --- /dev/null +++ b/spec/git_helper_spec.rb @@ -0,0 +1,79 @@ +describe Fastlane::Helper::GitHelper do + let(:repo_name) { "repo_name" } + let(:branch) { "branch" } + let(:base_branch) { "base_branch" } + let(:github_token) { "github_token" } + let(:client) { double("client") } + + shared_context "common setup" do + before do + allow(Octokit::Client).to receive(:new).and_return(client) + allow(Fastlane::UI).to receive(:success) + allow(Fastlane::UI).to receive(:important) + end + end + + describe "#merge_branch" do + subject { Fastlane::Helper::GitHelper.merge_branch(repo_name, branch, base_branch, github_token) } + + include_context "common setup" + + context "when merge is successful" do + before do + allow(client).to receive(:merge) + end + + it "reports success" do + expect { subject }.not_to raise_error + + expect(client).to have_received(:merge).with(repo_name, base_branch, branch) + expect(Fastlane::UI).to have_received(:success).with("Merged #{branch} branch to #{base_branch}") + end + end + + context "when merge fails" do + before do + allow(client).to receive(:merge).and_raise(StandardError) + end + + it "shows error" do + expect { subject }.to raise_error(StandardError) + + expect(client).to have_received(:merge).with(repo_name, base_branch, branch) + expect(Fastlane::UI).to have_received(:important).with("Failed to merge #{branch} branch to #{base_branch}: StandardError") + end + end + end + + describe "#delete_branch" do + subject { Fastlane::Helper::GitHelper.delete_branch(repo_name, branch, github_token) } + + include_context "common setup" + + context "when delete is successful" do + before do + allow(client).to receive(:delete_branch) + end + + it "reports success" do + expect { subject }.not_to raise_error + + expect(client).to have_received(:delete_branch).with(repo_name, branch) + expect(Fastlane::UI).to have_received(:success).with("Deleted #{branch}") + end + end + + context "when delete fails" do + before do + allow(client).to receive(:delete_branch).and_raise(StandardError) + end + + it "shows error" do + expect { subject }.to raise_error(StandardError) + + expect(client).to have_received(:delete_branch).with(repo_name, branch) + expect(Fastlane::UI).to have_received(:important).with("Failed to delete #{branch} branch: StandardError") + end + end + end +end