Skip to content

Commit 01f28c7

Browse files
authored
Merge pull request ropensci-org#55 from openjournals/list-team-members
New List Team Members responder
2 parents 05f5b0b + 5fbb93b commit 01f28c7

File tree

9 files changed

+148
-6
lines changed

9 files changed

+148
-6
lines changed

app/lib/responder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def required_params(*param_names)
143143
if empty_param?(param_name)
144144
raise "Configuration Error in #{self.class.name}: No value for #{param_name}."
145145
else
146-
self.class.define_method(param_name.to_s) { params[param_name].strip }
146+
self.class.define_method(param_name.to_s) { params[param_name] }
147147
end
148148
end
149149
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require_relative '../lib/responder'
2+
3+
class ListTeamMembersResponder < Responder
4+
5+
keyname :list_team_members
6+
7+
def define_listening
8+
required_params :command, :team_id
9+
10+
@event_action = "issue_comment.created"
11+
@event_regex = /\A@#{bot_name} #{command}\.?\s*\z/i
12+
end
13+
14+
def process_message(message)
15+
team_members = team_members(params[:team_id])
16+
heading = params[:heading].to_s
17+
respond_template :list_team_members, { heading: heading, team_members: team_members }
18+
end
19+
20+
def description
21+
params[:description] || "Replies to '#{command}'"
22+
end
23+
24+
def example_invocation
25+
"@#{bot_name} #{command}"
26+
end
27+
end

app/responses/list_team_members.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= heading %>
2+
3+
```
4+
<% team_members.each do |team_member| -%>
5+
@<%= team_member %>
6+
<% end -%>
7+
<%= "The list is empty" if team_members.empty? -%>
8+
```

config/settings-production.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ buffy:
1919
- "Our CoC: https://github.com/openjournals/joss/blob/master/CODE_OF_CONDUCT.md"
2020
- "It's adapted from the Contributor Covenant: http://contributor-covenant.org"
2121
- "Reports of abusive or harassing behavior may be reported to [email protected]"
22-
- editor_list:
23-
command: list editors
24-
description: List all current topic editors
25-
template_file: editors.md
2622
assign_reviewer_n:
2723
only: editors
2824
if:
@@ -45,6 +41,10 @@ buffy:
4541
only: editors
4642
add_remove_assignee:
4743
only: editors
44+
list_team_members:
45+
command: list editors
46+
team_id: 3824115
47+
heading: Current journal editors
4848
check_references:
4949
repo_checks:
5050
set_value:

docs/available_responders.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Buffy includes a list of Responders that can be used by configuring them in the
2222
responders/invite
2323
responders/set_value
2424
responders/list_of_values
25+
responders/list_team_members
2526
responders/add_remove_assignee
2627
responders/reviewer_checklist_comment
2728
responders/add_remove_checklist
35.4 KB
Loading

docs/responders/list_team_members.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
List team members
2+
=================
3+
4+
This responder replies with a list of members from a GitHub team
5+
6+
## Listens to
7+
8+
```
9+
@botname <command>
10+
```
11+
12+
For example, if you configure the command to be _list editors_, it would respond to:
13+
```
14+
@botname list editors
15+
```
16+
17+
## Settings key
18+
19+
`list_team_members`
20+
21+
## Params
22+
```eval_rst
23+
:command: The command this responder will listen to.
24+
25+
:team_id: The id of the GitHub team to be listed.
26+
27+
:heading: *Optional* Heading for the replied list.
28+
29+
:description: *Optional* String to show when the help command is invoked.
30+
```
31+
32+
## Examples
33+
34+
**List editors team members with custom heading**
35+
```yaml
36+
...
37+
responders:
38+
list_team_members:
39+
command: list editors
40+
team_id: 3824115
41+
heading: Current journal editors
42+
...
43+
```
44+
45+
46+
## In action
47+
48+
![](../images/responders/list_team_members.png "List team members responder in action")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require_relative "../spec_helper.rb"
2+
3+
describe ListTeamMembersResponder do
4+
5+
subject do
6+
described_class
7+
end
8+
9+
describe "listening" do
10+
before { @responder = subject.new({env: { bot_github_user: "botsci" }}, { command: "list editors", team_id: 12345 }) }
11+
12+
it "should listen to new comments" do
13+
expect(@responder.event_action).to eq("issue_comment.created")
14+
end
15+
16+
it "should define regex" do
17+
expect(@responder.event_regex).to match("@botsci list editors")
18+
expect(@responder.event_regex).to match("@botsci list editors.")
19+
expect(@responder.event_regex).to match("@botsci list editors \r\n")
20+
expect(@responder.event_regex).to_not match("```@botsci list editors")
21+
expect(@responder.event_regex).to_not match("@botsci list editors \r\n more")
22+
end
23+
end
24+
25+
describe "#process_message" do
26+
before do
27+
@responder = subject.new({env: {bot_github_user: "botsci"}}, { command: "list editors", team_id: 12345 })
28+
@team_members = ["user1", "user2"]
29+
disable_github_calls_for(@responder)
30+
end
31+
32+
it "should respond with a erb template to github" do
33+
team_members = ["user1", "user2"]
34+
expect(@responder).to receive(:team_members).once.with(12345).and_return(@team_members)
35+
36+
expected_locals = { heading: "", team_members: @team_members }
37+
expect(@responder).to receive(:respond_template).once.with(:list_team_members, expected_locals)
38+
@responder.process_message("@botsci list editors")
39+
end
40+
41+
it "should allow to customize heading" do
42+
@responder.params[:heading] = "Current editors"
43+
expect(@responder).to receive(:team_members).once.with(12345).and_return(@team_members)
44+
45+
expected_locals = { heading: "Current editors", team_members: @team_members }
46+
expect(@responder).to receive(:respond_template).once.with(:list_team_members, expected_locals)
47+
@responder.process_message("@botsci list editors")
48+
end
49+
50+
it "should allow to customize description" do
51+
expect(@responder.description).to eq("Replies to 'list editors'")
52+
53+
@responder.params[:description] = "List current editors"
54+
expect(@responder.description).to eq("List current editors")
55+
end
56+
end
57+
end

spec/support/responder_params.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def sample_params(responder_class)
1111
AddAndRemoveUserChecklistResponder => { template_file: "checklist.md" },
1212
ReviewerChecklistCommentResponder => { template_file: "checklist.md" },
1313
GithubActionResponder => { workflow_repo: "openjournals/joss-reviews", workflow_name: "compiler", command: "generate pdf" },
14-
InitialValuesResponder => { values: ["version", "target-repository"]}
14+
InitialValuesResponder => { values: ["version", "target-repository"]},
15+
ListTeamMembersResponder => { command: "list editors", team_id: 3824115 },
1516
}
1617

1718
params_by_responder[responder_class] || {}

0 commit comments

Comments
 (0)