diff --git a/plugins/labhub.py b/plugins/labhub.py index 39816db7..ff8c38e2 100644 --- a/plugins/labhub.py +++ b/plugins/labhub.py @@ -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, ' @@ -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): @@ -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): """ @@ -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)) @@ -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]', diff --git a/tests/labhub_test.py b/tests/labhub_test.py index 8bbb7771..c86cd1e8 100644 --- a/tests/labhub_test.py +++ b/tests/labhub_test.py @@ -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) @@ -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()