diff --git a/plugins/labhub.py b/plugins/labhub.py index 1d702b71..ca0b3502 100644 --- a/plugins/labhub.py +++ b/plugins/labhub.py @@ -122,6 +122,9 @@ def invite_cmd(self, msg, match): """ invitee = match.group(1) inviter = msg.frm.nick + if not inviter: + yield 'ERROR: The above command cannot be operated without nick.' + return team = 'newcomers' if match.group(2) is None else match.group(2) team = team.lower() @@ -196,6 +199,9 @@ def callback_message(self, msg): def create_issue_cmd(self, msg, match): """Create issues on GitHub and GitLab repositories.""" # Ignore QuotesBear, LineLengthBear, PyCodeStyleBear user = msg.frm.nick + if not user: + yield 'ERROR: The above command cannot be operated without nick.' + return repo_name = match.group(1) iss_title = match.group(2) iss_description = match.group(3) if match.group(3) is not None else '' @@ -234,6 +240,9 @@ def unassign_cmd(self, msg, match): issue_number = match.group(4) user = msg.frm.nick + if not user: + yield 'ERROR: The above command cannot be operated without nick.' + return try: assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME @@ -317,6 +326,9 @@ def assign_cmd(self, msg, match): iss_number = match.group(4) user = msg.frm.nick + if not user: + yield 'ERROR: The above command cannot be operated without nick.' + return try: assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME diff --git a/tests/labhub_test.py b/tests/labhub_test.py index 80492ce4..cac4130e 100644 --- a/tests/labhub_test.py +++ b/tests/labhub_test.py @@ -33,6 +33,7 @@ def setUp(self): 'GH_ORG_NAME': 'coala', 'GL_ORG_NAME': 'coala', } + self.bot.sender._nick = 'batman' self.labhub = self.load_plugin('LabHub', self.global_mocks, configs) def test_invite_cmd(self): @@ -102,6 +103,11 @@ def test_invite_cmd(self): testbot.assertCommand('!invite meetto newcomers', 'Command "invite" / "invite meetto" not found.') + self.bot.sender._nick = None + testbot.assertCommand( + '!invite meet to newcomers', + 'ERROR: The above command cannot be operated without nick.') + # not a member of org mock_team_newcomers.is_member.return_value = False mock_team_developers.is_member.return_value = False @@ -156,7 +162,7 @@ def test_create_issue_cmd(self): textwrap.dedent('''\ first line of body second line of body - Opened by @None at [text]()''') + Opened by @batman at [text]()''') ) testbot_public.assertCommand( @@ -171,13 +177,18 @@ def test_create_issue_cmd(self): 'another title', textwrap.dedent('''\ body - Opened by @None at [text]()''') + Opened by @batman at [text]()''') ) testbot_public.assertCommand( '!new issue coala title', 'repository that does not exist') + self.bot.sender._nick = None + testbot_public.assertCommand( + '!new issue coala title', + 'ERROR: The above command cannot be operated without nick.') + # not a member of org self.mock_team.is_member.return_value = False testbot_public.assertCommand( @@ -201,7 +212,7 @@ def test_unassign_cmd(self): mock_iss = create_autospec(IGitt.GitHub.GitHubIssue) self.mock_repo.get_issue.return_value = mock_iss mock_iss.assignees = PropertyMock() - mock_iss.assignees = (None, ) + mock_iss.assignees = ('batman', ) mock_iss.unassign = MagicMock() self.mock_team.is_member.return_value = True testbot = self @@ -211,7 +222,7 @@ def test_unassign_cmd(self): 'you are unassigned now', timeout=10000) self.mock_repo.get_issue.assert_called_with(999) - mock_iss.unassign.assert_called_once_with(None) + mock_iss.unassign.assert_called_once_with('batman') mock_iss.assignees = ('meetmangukiya', ) testbot.assertCommand( @@ -226,6 +237,11 @@ def test_unassign_cmd(self): '!unassign https://gitlab.com/example/test/issues/999', 'Repository not owned by our org.') + self.bot.sender._nick = None + testbot.assertCommand( + '!unassign https://gitlab.com/example/test/issues/999', + 'ERROR: The above command cannot be operated without nick.') + # not a member of org self.mock_team.is_member.return_value = False testbot.assertCommand( @@ -253,6 +269,13 @@ def test_assign_cmd(self): testbot = self cmd = '!assign https://github.com/{}/{}/issues/{}' + + self.bot.sender._nick = None + testbot.assertCommand( + cmd.format('coa', 'a', '23'), + 'ERROR: The above command cannot be operated without nick.') + self.bot.sender._nick = 'batman' + # no assignee, not newcomer mock_issue.assignees = tuple() self.mock_team.is_member.return_value = False @@ -335,7 +358,7 @@ def test_assign_cmd(self): 'already assigned to someone') # has assignee same as user - mock_issue.assignees = (None, ) + mock_issue.assignees = ('batman', ) testbot.assertCommand(cmd.format('coala', 'a', '23'), 'already assigned to you')