Skip to content

Commit

Permalink
LabHub: Remove redundant teams list
Browse files Browse the repository at this point in the history
Redefine excessive usage for the list
of teams.

Closes coala#575
  • Loading branch information
nvzard committed Jun 27, 2018
1 parent 2feedd6 commit de4fbaf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
43 changes: 20 additions & 23 deletions plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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),
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions tests/labhub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit de4fbaf

Please sign in to comment.