Skip to content

Commit

Permalink
add wait_lock?
Browse files Browse the repository at this point in the history
  • Loading branch information
davidx committed Dec 5, 2016
1 parent be633c6 commit 8ced92c
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 22 deletions.
17 changes: 17 additions & 0 deletions lib/thumbs/pull_request_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ def valid_for_merge?
return false
end

if wait_lock?
debug_message "wait_lock? thumbot wait set. delete comment to release lock"
return false
end

unless thumb_config['merge'] == true
debug_message "thumb_config['merge'] != 'true' || thumbs config says: merge: #{thumb_config['merge'].inspect}"
return false
Expand Down Expand Up @@ -584,6 +589,14 @@ def merge
return status
end
if wait_lock?
debug_message "wait_lock? thumbot wait enabled."
status[:result]=:error
status[:message]="wait_lock? thumbot wait enabled."
status[:ended_at]=DateTime.now
return status
end
begin
debug_message("Starting github API merge request")
commit_message = 'Thumbs Git Robot Merge. '
Expand Down Expand Up @@ -960,6 +973,10 @@ def forked_repo_branch_pr?
pr.base.repo.full_name != pr.head.repo.full_name ? true : false
end
def wait_lock?
all_comments.any? {|comment| comment[:body] =~ /^thumbot wait/ }
end
private
def render_template(template)
Expand Down
62 changes: 47 additions & 15 deletions test/test_build_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,24 @@
cassette(:get_events_unmergable) do

UNMERGABLEPRW.build_steps = ["make", "make test", "make UNKNOWN_OPTION"]
cassette(:get_state, :record => :new_episodes) do

cassette(:get_open) do
assert_equal true, UNMERGABLEPRW.open?
UNMERGABLEPRW.reset_build_status
UNMERGABLEPRW.unpersist_build_status
UNMERGABLEPRW.try_merge
UNMERGABLEPRW.run_build_steps
assert_equal :error, UNMERGABLEPRW.aggregate_build_status_result, UNMERGABLEPRW.build_status
step, status = UNMERGABLEPRW.build_status[:steps].collect { |step_name, status| [step_name, status] if status[:result] != :ok }.compact.shift
assert_equal :merge, step

assert status[:result]==:error
assert status[:exit_code]!=0

cassette(:get_new_comments, :record => :new_episodes) do
assert_equal false, UNMERGABLEPRW.valid_for_merge?
cassette(:get_open) do
assert_equal true, UNMERGABLEPRW.open?
UNMERGABLEPRW.reset_build_status
UNMERGABLEPRW.unpersist_build_status
UNMERGABLEPRW.try_merge
UNMERGABLEPRW.run_build_steps
assert_equal :error, UNMERGABLEPRW.aggregate_build_status_result, UNMERGABLEPRW.build_status
step, status = UNMERGABLEPRW.build_status[:steps].collect { |step_name, status| [step_name, status] if status[:result] != :ok }.compact.shift
assert_equal :merge, step

assert status[:result]==:error
assert status[:exit_code]!=0

cassette(:get_new_comments, :record => :new_episodes) do
assert_equal false, UNMERGABLEPRW.valid_for_merge?
end
end
end

Expand Down Expand Up @@ -257,6 +259,36 @@
end


test "should not merge if wait_lock?" do
cassette(:get_wait_lock_pr, :record => :new_episodes) do
prw = Thumbs::PullRequestWorker.new(repo: 'davidx/prtester', pr: 323)
prw.validate
prw.thumb_config['merge'] = true
prw.thumb_config['minimum_reviewers'] = 0
client2 = Octokit::Client.new(:netrc => true,
:netrc_file => ".netrc.davidpuddy1")
# client2.add_comment(prw.repo, prw.pr.number, "+1", options = {})
wait_lock_comments=prw.all_comments.collect { |comment| comment if comment[:body] =~ /^thumbot wait/ }.compact
wait_lock_comments.each do |comment|
client2.delete_comment(prw.repo, comment[:id])
end
cassette(:get_updated_comments, :record => :new_episodes) do
assert_equal true, prw.valid_for_merge?
cassette(:get_valid_for_merge_update, :record => :all) do
comment=client2.add_comment(prw.repo, prw.pr.number, "thumbot wait", options = {})
sleep 1
cassette(:get_valid_for_merge_update_refresh, :record => :all) do
assert_equal false, prw.valid_for_merge?
cassette(:get_valid_for_merge_update_clean, :record => :all) do
client2.delete_comment(prw.repo, comment[:id])
end
end
end
end
end
end


test "should identify org comments" do
default_vcr_state do
assert ORGPRW.respond_to?(:org_member_comments)
Expand Down
42 changes: 35 additions & 7 deletions test/test_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@
end
end

test "can determine org_member" do
default_vcr_state do
ORGPRW.respond_to?(:org_member?)
assert_false ORGPRW.org_member?('bob')
assert_true ORGPRW.org_member?('thumbot')
end
end
test "can determine org_member" do
default_vcr_state do
ORGPRW.respond_to?(:org_member?)
assert_false ORGPRW.org_member?('bob')
assert_true ORGPRW.org_member?('thumbot')
end
end

test "can detect forked repo branch pr" do
default_vcr_state do
Expand All @@ -116,6 +116,34 @@
assert_false PRW.forked_repo_branch_pr?
end
end

test "should be able to detect wait lock" do
cassette(:prmain, :record => :new_episodes) do
prw = Thumbs::PullRequestWorker.new(repo: 'davidx/prtester', pr: 323)
assert prw.respond_to?(:wait_lock?)

client2 = Octokit::Client.new(:netrc => true,
:netrc_file => ".netrc.davidpuddy1")
cassette(:pr, :record => :new_episodes, :record => :all) do

comment=client2.add_comment(prw.repo, prw.pr.number, "thumbot wait", options = {})
sleep 2
cassette(:refresh, :record => :all) do

cassette(:get_new_comments, :record => :all) do
comments=client2.issue_comments(prw.repo, prw.pr.number, per_page: 100)
assert_true comments.any? { |comment| comment[:body] =~ /^thumbot wait/ }
assert_true prw.wait_lock?
assert_equal prw.all_comments.any? { |comment| comment[:body] =~ /^thumbot wait/ }, prw.wait_lock?
assert_false PRW.wait_lock?
client2.delete_comment(prw.repo, comment[:id])
end
end
end
end

end
end



0 comments on commit 8ced92c

Please sign in to comment.