diff --git a/plugins/labhub.py b/plugins/labhub.py index f46d8c33..cee87e6c 100644 --- a/plugins/labhub.py +++ b/plugins/labhub.py @@ -71,6 +71,17 @@ def TEAMS(self): def TEAMS(self, new): self._teams = new + def team_mapping(self): + return { + 'newcomers': self.TEAMS[self.GH_ORG_NAME + ' newcomers'], + 'developers': self.TEAMS[self.GH_ORG_NAME + ' developers'], + 'maintainers': self.TEAMS[self.GH_ORG_NAME + ' maintainers'], + } + + def is_team_member(self, user, team): + teams = self.team_mapping() + return teams[team].is_member(user) + @staticmethod def is_room_member(invitee, msg): return invitee in msg.frm.room.occupants @@ -89,26 +100,18 @@ def invite_cmd(self, msg, match): team = 'newcomers' if match.group(2) is None else match.group(2) team = team.lower() - is_developer = self.TEAMS[self.GH_ORG_NAME + - ' developers'].is_member(inviter) - is_maintainer = self.TEAMS[self.GH_ORG_NAME + - ' maintainers'].is_member(inviter) + is_developer = self.is_team_member(inviter, 'developers') + is_maintainer = self.is_team_member(inviter, 'maintainers') self.log.info('{} invited {} to {}'.format(inviter, invitee, team)) - valid_teams = ['newcomers', 'developers', 'maintainers'] + valid_teams = self.team_mapping() if team not in valid_teams: return 'Please select from one of the valid teams: ' + ', '.join( valid_teams) def invite(invitee, team): - team_mapping = { - 'newcomers': self.GH_ORG_NAME + ' newcomers', - 'developers': self.GH_ORG_NAME + ' developers', - 'maintainers': self.GH_ORG_NAME + ' maintainers' - } - - self.TEAMS[team_mapping[team]].invite(invitee) + self.team_mapping()[team].invite(invitee) if not self.is_room_member(invitee, msg): return '@{} is not a member of this room.'.format(invitee) @@ -149,7 +152,7 @@ def callback_message(self, msg): """Invite the user whose message includes the holy 'hello world'""" 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) + if (not self.is_team_member(user, 'newcomers') and user not in self.hello_world_users): response = tenv().get_template( 'labhub/hello-world.jinja2.md' @@ -312,14 +315,9 @@ def difficulty_level(user, iss): 2. A newcomer asks for assignment to an issue with difficulty higher than low. """ - if (self.TEAMS[self.GH_ORG_NAME + ' newcomers'].is_member(user) - and not (self.TEAMS[self.GH_ORG_NAME + - ' developers'].is_member( - user - ) or - self.TEAMS[self.GH_ORG_NAME + ' maintainers'].is_member( - user - ))): + if (self.is_team_member(user, 'newcomers') and not + (self.is_team_member(user, 'developers') or + self.is_team_member(user, 'maintainers'))): diff_labels = filter( lambda x: 'difficulty' in x, iss.labels) if list(filter(lambda x: ('low' in x) or ('newcomer' in x), @@ -339,8 +337,7 @@ def newcomer_issue_check(user, iss): to the user. """ if (self.is_newcomer_issue(iss) - and self.TEAMS[self.GH_ORG_NAME + - ' newcomers'].is_member(user)): + and self.is_team_member(user, 'newcomers')): search_query = 'user:coala assignee:{} ' \ 'label:difficulty/newcomer'.format(user) result = GitHub.raw_search(GitHubToken( diff --git a/tests/labhub_test.py b/tests/labhub_test.py index 608f1178..d5732f24 100644 --- a/tests/labhub_test.py +++ b/tests/labhub_test.py @@ -111,6 +111,8 @@ def test_is_room_member(self): def test_hello_world_callback(self): teams = { 'coala newcomers': self.mock_team, + 'coala developers': self.mock_team, + 'coala maintainers': self.mock_team, } testbot = TestBot(extra_plugin_dir='plugins', loglevel=logging.ERROR)