Skip to content

Commit

Permalink
Merge pull request ropensci-org#55 from openjournals/list-team-members
Browse files Browse the repository at this point in the history
New List Team Members responder
  • Loading branch information
xuanxu authored Dec 10, 2021
2 parents 05f5b0b + 5fbb93b commit 01f28c7
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/lib/responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def required_params(*param_names)
if empty_param?(param_name)
raise "Configuration Error in #{self.class.name}: No value for #{param_name}."
else
self.class.define_method(param_name.to_s) { params[param_name].strip }
self.class.define_method(param_name.to_s) { params[param_name] }
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions app/responders/list_team_members_responder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative '../lib/responder'

class ListTeamMembersResponder < Responder

keyname :list_team_members

def define_listening
required_params :command, :team_id

@event_action = "issue_comment.created"
@event_regex = /\A@#{bot_name} #{command}\.?\s*\z/i
end

def process_message(message)
team_members = team_members(params[:team_id])
heading = params[:heading].to_s
respond_template :list_team_members, { heading: heading, team_members: team_members }
end

def description
params[:description] || "Replies to '#{command}'"
end

def example_invocation
"@#{bot_name} #{command}"
end
end
8 changes: 8 additions & 0 deletions app/responses/list_team_members.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= heading %>

```
<% team_members.each do |team_member| -%>
@<%= team_member %>
<% end -%>
<%= "The list is empty" if team_members.empty? -%>
```
8 changes: 4 additions & 4 deletions config/settings-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ buffy:
- "Our CoC: https://github.com/openjournals/joss/blob/master/CODE_OF_CONDUCT.md"
- "It's adapted from the Contributor Covenant: http://contributor-covenant.org"
- "Reports of abusive or harassing behavior may be reported to [email protected]"
- editor_list:
command: list editors
description: List all current topic editors
template_file: editors.md
assign_reviewer_n:
only: editors
if:
Expand All @@ -45,6 +41,10 @@ buffy:
only: editors
add_remove_assignee:
only: editors
list_team_members:
command: list editors
team_id: 3824115
heading: Current journal editors
check_references:
repo_checks:
set_value:
Expand Down
1 change: 1 addition & 0 deletions docs/available_responders.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Buffy includes a list of Responders that can be used by configuring them in the
responders/invite
responders/set_value
responders/list_of_values
responders/list_team_members
responders/add_remove_assignee
responders/reviewer_checklist_comment
responders/add_remove_checklist
Expand Down
Binary file added docs/images/responders/list_team_members.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions docs/responders/list_team_members.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
List team members
=================

This responder replies with a list of members from a GitHub team

## Listens to

```
@botname <command>
```

For example, if you configure the command to be _list editors_, it would respond to:
```
@botname list editors
```

## Settings key

`list_team_members`

## Params
```eval_rst
:command: The command this responder will listen to.
:team_id: The id of the GitHub team to be listed.
:heading: *Optional* Heading for the replied list.
:description: *Optional* String to show when the help command is invoked.
```

## Examples

**List editors team members with custom heading**
```yaml
...
responders:
list_team_members:
command: list editors
team_id: 3824115
heading: Current journal editors
...
```


## In action

![](../images/responders/list_team_members.png "List team members responder in action")
57 changes: 57 additions & 0 deletions spec/responders/list_team_members_responder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require_relative "../spec_helper.rb"

describe ListTeamMembersResponder do

subject do
described_class
end

describe "listening" do
before { @responder = subject.new({env: { bot_github_user: "botsci" }}, { command: "list editors", team_id: 12345 }) }

it "should listen to new comments" do
expect(@responder.event_action).to eq("issue_comment.created")
end

it "should define regex" do
expect(@responder.event_regex).to match("@botsci list editors")
expect(@responder.event_regex).to match("@botsci list editors.")
expect(@responder.event_regex).to match("@botsci list editors \r\n")
expect(@responder.event_regex).to_not match("```@botsci list editors")
expect(@responder.event_regex).to_not match("@botsci list editors \r\n more")
end
end

describe "#process_message" do
before do
@responder = subject.new({env: {bot_github_user: "botsci"}}, { command: "list editors", team_id: 12345 })
@team_members = ["user1", "user2"]
disable_github_calls_for(@responder)
end

it "should respond with a erb template to github" do
team_members = ["user1", "user2"]
expect(@responder).to receive(:team_members).once.with(12345).and_return(@team_members)

expected_locals = { heading: "", team_members: @team_members }
expect(@responder).to receive(:respond_template).once.with(:list_team_members, expected_locals)
@responder.process_message("@botsci list editors")
end

it "should allow to customize heading" do
@responder.params[:heading] = "Current editors"
expect(@responder).to receive(:team_members).once.with(12345).and_return(@team_members)

expected_locals = { heading: "Current editors", team_members: @team_members }
expect(@responder).to receive(:respond_template).once.with(:list_team_members, expected_locals)
@responder.process_message("@botsci list editors")
end

it "should allow to customize description" do
expect(@responder.description).to eq("Replies to 'list editors'")

@responder.params[:description] = "List current editors"
expect(@responder.description).to eq("List current editors")
end
end
end
3 changes: 2 additions & 1 deletion spec/support/responder_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def sample_params(responder_class)
AddAndRemoveUserChecklistResponder => { template_file: "checklist.md" },
ReviewerChecklistCommentResponder => { template_file: "checklist.md" },
GithubActionResponder => { workflow_repo: "openjournals/joss-reviews", workflow_name: "compiler", command: "generate pdf" },
InitialValuesResponder => { values: ["version", "target-repository"]}
InitialValuesResponder => { values: ["version", "target-repository"]},
ListTeamMembersResponder => { command: "list editors", team_id: 3824115 },
}

params_by_responder[responder_class] || {}
Expand Down

0 comments on commit 01f28c7

Please sign in to comment.