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 11, 2017
1 parent f6fbd65 commit f2e7a96
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 52 deletions.
57 changes: 29 additions & 28 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,31 @@
class LabHub(BotPlugin):
"""GitHub and GitLab utilities""" # Ignore QuotesBear

HELLO_WORLD_MSG = ('Welcome @{}! :tada:\n\n'
'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.*\n\n'
'*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.\n\nDon\'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. :)')

INVITE_SUCCESS = {
'newcomers': 'Welcome @{}! :tada:\n\nWe\'ve just sent you an invite'
' via email. Please accept it before proceeding forward.'
'\nTo 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.*\n\n'
'*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.\n\nDon\'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. :)',
'newcomers': '@{} 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',
'developers': ' Wow @{}, you are a part of developers team now! :tada: '
'Welcome to our community! You were a newcomer before, '
'and we\'d like to know what could\'ve been better, '
Expand Down Expand Up @@ -85,7 +94,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 @@ -96,7 +105,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 @@ -106,13 +115,6 @@ def invite_cmd(self, msg, match):
invitee = match.group(1)
inviter = msg.frm.nick

if invitee == 'me':
user = msg.frm.nick
self.send(msg.frm, self.INVITE_SUCCESS['newcomers'].format(user))
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 All @@ -139,12 +141,11 @@ 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):
and user not in self.helloed_users):
# send the invite
self.send(msg.frm,
self.INVITE_SUCCESS['newcomers'].format(user))
self.TEAMS[self.GH_ORG_NAME + ' newcomers'].invite(user)
self.invited_users.add(user)
self.HELLO_WORLD_MSG.format(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
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 f2e7a96

Please sign in to comment.