lib/tutter/action/sppuppet.rb in tutter-sppuppet-1.2.6 vs lib/tutter/action/sppuppet.rb in tutter-sppuppet-1.2.7
- old
+ new
@@ -10,10 +10,12 @@
INCIDENT = /jira.*INCIDENT/
def initialize(settings, client, project, data, event)
@settings = settings
@settings['plus_ones_required'] ||= 1
+ @settings['owner_plus_ones_required'] ||= 0
+ @settings['owners'] ||= []
@client = client
@project = project
@data = data
@event = event
end
@@ -47,21 +49,27 @@
when 'pull_request'
# If a new pull request is opened, comment with instructions
if @data['action'] == 'opened' && @settings['post_instructions']
issue = @data['number']
- comment = @settings['instructions'] || "To merge at least #{@settings['plus_ones_required']} person other than the submitter needs to write a comment containing only _+1_ or :+1:. Then write _!merge_ or :shipit: to trigger merging."
+ if @settings['owner_plus_ones_required'] > 0
+ owners_required_text = " and at least #{@settings['owner_plus_ones_required']} of the owners "
+ else
+ owners_required_text = ""
+ end
+ comment = @settings['instructions'] || "To merge at least #{@settings['plus_ones_required']} person other than the submitter #{owners_required_text}needs to write a comment containing only _+1_ or :+1:. Then write _!merge_ or :shipit: to trigger merging."
return post_comment(issue, comment)
else
return 200, 'Not posting instructions'
end
else
return 200, "Unhandled event type #{@event}"
end
end
def maybe_merge(pull_request_id, merge_command, merger = nil)
+ owner_votes = {}
votes = {}
incident_merge_override = false
pr = @client.pull_request @project, pull_request_id
# We fetch the latest commit and it's date.
@@ -74,27 +82,37 @@
comments.each do |i|
# Comment is older than last commit.
# We only want to check newer comments
next if last_commit_date > i.created_at
+ commenter = i.attrs[:user].attrs[:login]
# Skip comments from tutter itself
- next if i.attrs[:user].attrs[:login] == @client.user.login
+ next if commenter == @client.user.login
if MERGE_COMMENT.match(i.body)
- merger ||= i.attrs[:user].attrs[:login]
+ merger ||= commenter
# Count as a +1 if it is not the author
- unless pr.user.login == i.attrs[:user].attrs[:login]
- votes[i.attrs[:user].attrs[:login]] = 1
+ unless pr.user.login == commenter
+ votes[commenter] = 1
+ if @settings['owners'].include?(commenter)
+ owner_votes[commenter] = 1
+ end
end
end
- if PLUS_VOTE.match(i.body) && pr.user.login != i.attrs[:user].attrs[:login]
- votes[i.attrs[:user].attrs[:login]] = 1
+ if PLUS_VOTE.match(i.body) && pr.user.login != commenter
+ votes[commenter] = 1
+ if @settings['owners'].include?(commenter)
+ owner_votes[commenter] = 1
+ end
end
- if MINUS_VOTE.match(i.body) && pr.user.login != i.attrs[:user].attrs[:login]
- votes[i.attrs[:user].attrs[:login]] = -1
+ if MINUS_VOTE.match(i.body) && pr.user.login != commenter
+ votes[commenter] = -1
+ if @settings['owners'].include?(commenter)
+ owner_votes[commenter] = -1
+ end
end
if BLOCK_VOTE.match(i.body)
msg = 'Commit cannot be merged so long as a -2 comment appears in the PR.'
return post_comment(pull_request_id, msg)
@@ -120,9 +138,15 @@
return 200, 'No merge comment found' unless merger
num_votes = votes.values.reduce(0) { |a, e| a + e }
if num_votes < @settings['plus_ones_required'] && !incident_merge_override
msg = "Not enough plus ones. #{@settings['plus_ones_required']} required, and only have #{num_votes}"
+ return post_comment(pull_request_id, msg)
+ end
+
+ num_owner_votes = owner_votes.values.reduce(0) { |a, e| a + e }
+ if num_owner_votes < @settings['owner_plus_ones_required'] && !incident_merge_override
+ msg = "Not enough plus ones from owners. #{@settings['owner_plus_ones_required']} required, and only have #{num_owner_votes}"
return post_comment(pull_request_id, msg)
end
# TODO: Word wrap description
merge_msg = <<MERGE_MSG