Skip to content

Commit

Permalink
labhub: Adapt to the modified newcomer process
Browse files Browse the repository at this point in the history
- `invite me` variation of invite command is removed.
- "Hello world"s no longer trigger invites.
- Newcomer invitation message is changed to show the modification in the
  newcomer process.

Closes #476
  • Loading branch information
meetmangukiya committed Dec 17, 2017
1 parent 11ce167 commit a87b74e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 56 deletions.
34 changes: 11 additions & 23 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, bot, name=None):
else:
self.REPOS.update(self.gl_repos)

self.invited_users = set()
self.helloed_users = set()

@property
def TEAMS(self):
Expand All @@ -72,7 +72,7 @@ def TEAMS(self, new):
self._teams = new

# Ignore LineLengthBear, PycodestyleBear
@re_botcmd(pattern=r'^(?:(?:welcome)|(?:inv)|(?:invite))\s+(?:(?:@?([\w-]+)(?:\s*(?:to)\s+(\w+))?)|(me))$',
@re_botcmd(pattern=r'^(?:(?:welcome)|(?:inv)|(?:invite))\s+@?([\w-]+)(?:\s*(?:to)\s+(\w+))?$',
re_cmd_name_help='invite [to team]')
def invite_cmd(self, msg, match):
"""
Expand All @@ -82,18 +82,6 @@ def invite_cmd(self, msg, match):
invitee = match.group(1)
inviter = msg.frm.nick

if invitee == 'me':
user = msg.frm.nick
response = tenv().get_template(
'labhub/promotions/newcomers.jinja2.md'
).render(
username=user,
)
self.send(msg.frm, response)
self.TEAMS[self.GH_ORG_NAME + ' newcomers'].invite(user)
self.invited_users.add(user)
return

team = 'newcomers' if match.group(2) is None else match.group(2)

self.log.info('{} invited {} to {}'.format(inviter, invitee, team))
Expand Down Expand Up @@ -128,16 +116,16 @@ def callback_message(self, msg):
if re.search(r'hello\s*,?\s*world', msg.body, flags=re.IGNORECASE):
user = msg.frm.nick
if (not self.TEAMS[self.GH_ORG_NAME + ' newcomers'].is_member(user)
and user not in self.invited_users):
# send the invite
response = tenv().get_template(
'labhub/promotions/newcomers.jinja2.md'
).render(
target=user,
and user not in self.helloed_users):
self.send(
msg.frm,
tenv().get_template(
'labhub/hello_world.jinja2.md'
).render(
target=user,
)
)
self.send(msg.frm, response)
self.TEAMS[self.GH_ORG_NAME + ' newcomers'].invite(user)
self.invited_users.add(user)
self.helloed_users.add(user)

@re_botcmd(pattern=r'(?:new|file) issue ([\w\-\.]+?)(?: |\n)(.+?)(?:$|\n((?:.|\n)*))', # Ignore LineLengthBear, PyCodeStyleBear
re_cmd_name_help='new issue repo-name title\n[description]',
Expand Down
7 changes: 7 additions & 0 deletions plugins/templates/hello_world.jinja2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Welcome @{{ target }}! :tada:

Please go through https://coala.io/newcomer (skip instructions about using corobo). Find your first issue and ask one of the maintainers to assign you to it and we'll invite you to the org. Most issues will be explained there and in linked pages - it will save you a lot of time, just read it. *Really.*

*Do not take an issue if you don't understand it on your own.* Especially if you are new you have to be aware that getting started with an open source community is not trivial: you will have to work hard and most likely become a better coder than you are now just as we all did.

Don't get us wrong: we are *very* glad to have you with us on this journey into open source! We will also be there for you at all times to help you with actual problems. :)
10 changes: 1 addition & 9 deletions plugins/templates/labhub/promotions/newcomers.jinja2.md
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
Welcome @{{ target }}! :tada:

We've just sent you an invite via email. Please accept it before proceeding forward.

To get started, please follow our [newcomers guide] (https://coala.io/newcomer). Most issues will be explained there and in linked pages - it will save you a lot of time, just read it. *Really.*

*Do not take an issue if you don't understand it on your own.* Especially if you are new you have to be aware that getting started with an open source community is not trivial: you will have to work hard and most likely become a better coder than you are now just as we all did.

Don't get us wrong: we are *very* glad to have you with us on this journey into open source! We will also be there for you at all times to help you with actual problems. :)
@{{ target }} We've just sent you an invite via email. Please accept it before proceeding forward. Please go through [newcomers guide](https://coala.io/newcomer) first, if you have any doubts, they are likely to be solved there. Use relevant channels for help if needed. You have already selected the issue, assign yourself to it using corobo and you can start working on it! :D
25 changes: 1 addition & 24 deletions tests/labhub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ def test_hello_world_callback(self):
labhub = testbot.bot.plugin_manager.get_plugin_obj_by_name('LabHub')
labhub.TEAMS = teams
self.mock_team.is_member.return_value = False
testbot.assertCommand('hello, world', 'newcomer')
testbot.assertCommand('hello, world', 'newcomer', timeout=10000)
# Since the user won't be invited again, it'll timeout waiting for a
# response.
with self.assertRaises(queue.Empty):
testbot.assertCommand('helloworld', 'newcomer')
self.mock_team.invite.assert_called_with(None)

def test_create_issue_cmd(self):
plugins.labhub.GitHub = create_autospec(IGitt.GitHub.GitHub.GitHub)
Expand Down Expand Up @@ -312,25 +311,3 @@ def test_alive(self):
testbot.assertCommand('!pr stats 3hours',
'10 PRs opened in last 3 hours\n'
'The community is on fire')

def test_invite_me(self):
teams = {
'coala maintainers': self.mock_team,
'coala newcomers': self.mock_team,
'coala developers': self.mock_team
}

labhub, testbot = plugin_testbot(plugins.labhub.LabHub, logging.ERROR)
labhub.activate()
labhub._teams = teams

plugins.labhub.os.environ['GH_TOKEN'] = 'patched?'
testbot.assertCommand('!invite me',
'We\'ve just sent you an invite')
with self.assertRaises(queue.Empty):
testbot.pop_message()

testbot.assertCommand('!hey there invite me',
'Command \"hey\" / \"hey there\" not found.')
with self.assertRaises(queue.Empty):
testbot.pop_message()

0 comments on commit a87b74e

Please sign in to comment.