Skip to content
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

Fix merging into deployable #120

Merged
merged 6 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ rvm:
- 2.2
script: bundle exec rspec
before_install:
- gem uninstall bundler && gem install bundler
- gem install bundler
19 changes: 6 additions & 13 deletions lib/octopolo/scripts/deployable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,21 @@ def execute
CLI.say 'Pull request status checks have not passed. Cannot be marked deployable.'
exit!
end
if config.deployable_label
with_labelling do
merge
end
else
merge
end

merge_result = merge
add_deployable_label if config.deployable_label && merge_result
end
end

def merge
PullRequestMerger.perform Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications
PullRequestMerger.new(Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications).perform
end
private :merge

def with_labelling(&block)
def add_deployable_label
pull_request.add_labels(Deployable.deployable_label)
unless yield
pull_request.remove_labels(Deployable.deployable_label)
end
end
private :with_labelling
private :add_deployable_label

def deployable?
pull_request.mergeable? && pull_request.status_checks_passed?
Expand Down
1 change: 1 addition & 0 deletions octopolo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'semantic', '~> 1.3'

gem.add_development_dependency 'rake', '~> 10.1'
gem.add_development_dependency 'bundler', '~> 1.16'
gem.add_development_dependency 'rspec', '~> 2.99'
gem.add_development_dependency 'guard', '~> 2.6'
gem.add_development_dependency 'guard-rspec', '~> 4.3'
Expand Down
15 changes: 7 additions & 8 deletions spec/octopolo/scripts/deployable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Scripts
allow(subject).to receive(:cli) { cli }
allow(subject).to receive(:config) { config }
allow(Octopolo::GitHub::PullRequest).to receive(:new) { pull_request }
allow(PullRequestMerger).to receive(:perform) { true }
allow_any_instance_of(PullRequestMerger).to receive(:perform) { true }
allow(Octopolo::GitHub).to receive(:check_connection) { true }
end

Expand All @@ -43,7 +43,7 @@ module Scripts
end

it "takes the pull requests ID from the current branch" do
PullRequestMerger.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, pull_request.number, :user_notifications => config.user_notifications)
expect_any_instance_of(PullRequestMerger).to receive(:perform)
end
end

Expand All @@ -67,17 +67,17 @@ module Scripts

context "when merge to deployable fails" do
before do
allow(PullRequestMerger).to receive(:perform) { false }
allow_any_instance_of(PullRequestMerger).to receive(:perform) { false }
end

it "removes the deployable label" do
pull_request.should_receive(:remove_labels)
it "does not add any labels" do
pull_request.should_not_receive(:add_labels)
end
end

context "when the merge to deployable succeeds" do
it "doesn't remove the deployable label" do
pull_request.should_not_receive(:remove_labels)
it "adds a label" do
pull_request.should_receive(:add_labels)
end
end

Expand Down Expand Up @@ -134,7 +134,6 @@ module Scripts
pull_request.should_receive(:add_labels)
end
end

end
end
end
Expand Down