diff --git a/plugins/labhub.py b/plugins/labhub.py index d1ca42e2..a686d710 100644 --- a/plugins/labhub.py +++ b/plugins/labhub.py @@ -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): @@ -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): """ @@ -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)) @@ -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]', diff --git a/plugins/templates/hello_world.jinja2.md b/plugins/templates/hello_world.jinja2.md new file mode 100644 index 00000000..904e00d1 --- /dev/null +++ b/plugins/templates/hello_world.jinja2.md @@ -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. :) diff --git a/plugins/templates/labhub/promotions/newcomers.jinja2.md b/plugins/templates/labhub/promotions/newcomers.jinja2.md index b1fd3484..b4eb2288 100644 --- a/plugins/templates/labhub/promotions/newcomers.jinja2.md +++ b/plugins/templates/labhub/promotions/newcomers.jinja2.md @@ -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 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()