Skip to content

Commit

Permalink
Custom reviewer responder (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu authored and maelle committed Feb 24, 2021
1 parent cb763ff commit 67a1c55
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 15 deletions.
111 changes: 111 additions & 0 deletions app/responders/ropensci/reviewers_due_date_responder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
require_relative '../../lib/responder'

module Ropensci
class ReviewersDueDateResponder < Responder

keyname :ropensci_reviewers

def define_listening
@event_action = "issue_comment.created"
@event_regex = /\A@#{@bot_name} (add|remove) (\S+) (as reviewer|to reviewers|from reviewers)\s*\z/i
end

def process_message(message)
add_or_remove = @match_data[1].downcase
reviewer = @match_data[2]
to_or_from = @match_data[3].downcase

if !issue_body_has?("reviewers-list")
respond("I can't find the reviewers list")
return
end

add_to_or_remove_from = [add_or_remove, to_or_from].join(" ")

if ["add to reviewers", "add as reviewer"].include?(add_to_or_remove_from)
add reviewer
elsif add_to_or_remove_from == "remove from reviewers"
remove reviewer
else
respond("That command is confusing. Did you mean to ADD TO reviewers or to REMOVE FROM reviewers?")
end
end

def add(reviewer)
if list_of_reviewers.include?(reviewer)
respond("#{reviewer} is already included in the reviewers list")
else
new_list = (list_of_reviewers + [reviewer]).uniq
update_list("reviewers", new_list.join(", "))
update_list("due-dates", add_reviewer_due_date(reviewer).join("\n"))
respond("#{reviewer} added to the reviewers list. Review due date is #{due_date}")
add_collaborator(reviewer) if add_as_collaborator?(reviewer)
add_assignee(reviewer) if add_as_assignee?(reviewer)
process_labeling if new_list.size == 2
end
end

def remove(reviewer)
if list_of_reviewers.include?(reviewer)
new_list = (list_of_reviewers - [reviewer]).uniq
updated_list = new_list.empty? ? no_reviewer_text : new_list.join(", ")
update_list("due-dates", remove_reviewer_due_date(reviewer).join("\n"))
update_list("reviewers", updated_list)
respond("#{reviewer} removed from the reviewers list!")
remove_assignee(reviewer) if add_as_assignee?(reviewer)
process_reverse_labeling if new_list.size == 1
else
respond("#{reviewer} is not in the reviewers list")
end
end

def list_of_reviewers
@list_of_reviewers ||= read_value_from_body("reviewers-list").split(",").map(&:strip)-[no_reviewer_text]
end

def list_of_due_dates
@list_of_due_dates ||= read_value_from_body("due-dates-list").strip.split("\n").map(&:strip)
end

def add_reviewer_due_date(reviewer)
list = list_of_due_dates
list << "Due date for #{reviewer}: #{due_date}"
end

def remove_reviewer_due_date(reviewer)
list = list_of_due_dates
list.delete_if {|due_date| due_date.match?(/^Due date for #{reviewer}:/)}
end

def due_date
# Today + 21 days
(Time.now + due_date_in_days_from_now * 86400).strftime("%Y-%m-%d")
end

def due_date_in_days_from_now
params[:due_date_days] || 21
end

def add_as_collaborator?(value)
username?(value) && params[:add_as_collaborator] == true
end

def add_as_assignee?(value)
username?(value) && params[:add_as_assignee] == true
end

def no_reviewer_text
params[:no_reviewer_text] || 'TBD'
end

def description
["Add a user to this issue's reviewers list",
"Remove a user from the reviewers list"]
end

def example_invocation
["@#{@bot_name} add #{params[:sample_value] || 'xxxxx'} to reviewers",
"@#{@bot_name} remove #{params[:sample_value] || 'xxxxx'} from reviewers"]
end
end
end
30 changes: 15 additions & 15 deletions config/settings-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ buffy:
- 1/editor-checks
add_labels:
- 2/seeking-reviewer(s)
only:
only:
- editors
- maelle
- approved:
Expand All @@ -38,48 +38,48 @@ buffy:
- reviewer-1
- reviewer-2
remove_labels:
- 5/awaiting-reviewer(s)-response
- 5/awaiting-reviewer(s)-response
add_labels:
- 6/approved
only:
- 6/approved
only:
- editors
- maelle
assign_reviewer_n:
only:
ropensci_reviewers:
only:
- editors
- maelle
if:
role_assigned: editor
remove_reviewer_n:
only:
- editors
- maelle
no_reviewer_text: "TBD"
add_labels:
- 3/reviewer(s)-assigned
remove_labels:
- 2/seeking-reviewer(s)
assign_editor:
message: "The editor guide can be found at https://devguide.ropensci.org/editorguide.html#editorchecklist"
only:
only:
- editors
- maelle
add_labels:
- 1/editor-checks
remove_editor:
only:
only:
- editors
- maelle
no_editor_text: "TBD"
close_issue_command:
- when_approving:
only:
only:
- editors
- maelle
command: approve
- out_of_scope:
only:
only:
- editors
- maelle
command: out of scope
add_labels:
- out-of-scope
remove_labels:
- 1/editor-checks

Loading

0 comments on commit 67a1c55

Please sign in to comment.