Skip to content

Fix checking target branch and label name. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
source 'https://rubygems.org'
gem 'octokit'
gem 'octokit'
gem 'rspec'
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -3,12 +3,26 @@ GEM
specs:
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
diff-lcs (1.4.4)
faraday (0.17.0)
multipart-post (>= 1.2, < 3)
multipart-post (2.1.1)
octokit (4.14.0)
sawyer (~> 0.8.0, >= 0.5.3)
public_suffix (4.0.6)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
@@ -18,6 +32,7 @@ PLATFORMS

DEPENDENCIES
octokit
rspec

BUNDLED WITH
1.17.2
4 changes: 2 additions & 2 deletions lib/services/merge_branch_service.rb
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ class MergeBrachService

def self.validate_inputs!(target_branch:, type:, label_name:)
raise "Invalid type" unless [TYPE_LABELED, TYPE_NOW].include?(type)
raise "Empty target branch" unless target_branch
raise "Empty target branch" if target_branch.nil? || target_branch.empty?
if type == TYPE_LABELED
raise "Empty target label name" unless label_name
raise "Empty target label name" if label_name.nil? || label_name.empty?
end
end

24 changes: 24 additions & 0 deletions spec/merge_brach_service_spec.rb
Original file line number Diff line number Diff line change
@@ -33,6 +33,30 @@
end
end

context "with empty label name" do
let(:label_name) { '' }

it ".validate_inputs!" do
expect { MergeBrachService.validate_inputs!(inputs) }.to raise_error()
end
end

context "with invalid target branch" do
let(:target_branch) { nil }

it ".validate_inputs!" do
expect { MergeBrachService.validate_inputs!(inputs) }.to raise_error()
end
end

context "with empty target branch" do
let(:target_branch) { '' }

it ".validate_inputs!" do
expect { MergeBrachService.validate_inputs!(inputs) }.to raise_error()
end
end

context "not match label" do
let(:event) { { 'action' => 'labeled', 'label' => { 'name' => 'other label' } } }