forked from ropensci-org/buffy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ropensci-org#55 from openjournals/list-team-members
New List Team Members responder
- Loading branch information
Showing
9 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? -%> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters