Skip to content

Commit

Permalink
Use same "special names" for user: and team: selectors.
Browse files Browse the repository at this point in the history
Use `user:*__contributors` (instead of `user:*CONTRIBUTORS`) to get
individual stats for contributors. This is for consistency with the
syntax expected by the team selector (which uses `team:__contributors`
to get grouped stats for all contributors).

Ditto for commenters, committers, and collaborators.

This uniformises the code to deal with those special groups, which may
now be all assimilated to special team names, as was already the case
for `__collaborators`.
  • Loading branch information
gouttegd committed Jul 10, 2023
1 parent de31adb commit 9e758d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
37 changes: 10 additions & 27 deletions incenp/grainyhead/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,15 @@ def _expand_wildcard_selectors(self, selectors):
expanded_selectors = []
for selector in selectors:
if 'user:*' in selector:
user_group = selector[5:]
if user_group == '*':
users = self._repo.contributors
elif user_group == '*COMMITTERS':
users = self._repo.committers
elif user_group == '*COMMENTERS':
users = self._repo.commenters
elif user_group == '*COLLABORATORS':
users = self._repo.collaborators
else:
users = [u.login for u in self._repo.get_team(user_group[1:])]
group = selector[6:].split(' ', 2)[0]
real_group = group if len(group) > 0 else '__contributors'
expanded_selectors.extend(
[selector.replace('user:' + user_group, f'user:{u}') for u in users]
[
selector.replace('user:*' + group, f'user:{u}')
for u in self._repo.get_usernames(real_group)
]
)

elif 'label:*' in selector:
expanded_selectors.extend(
[
Expand All @@ -182,7 +177,9 @@ def _get_parser(self):
).leaveWhitespace()
team_filter = (
(pp.Literal('team:') + filter_value)
.set_parse_action(self._team_action)
.set_parse_action(
lambda t: TeamFilter(t[1], self._repo.get_usernames(t[1]))
)
.leave_whitespace()
)
user_filter = (
Expand Down Expand Up @@ -244,20 +241,6 @@ def _expression_action(self, tokens):
else:
return tokens[0]

def _team_action(self, tokens):
team_name = tokens[1]
if team_name == '__contributors':
users = self._repo.contributors
elif team_name == '__committers':
users = self._repo.committers
elif team_name == '__commenters':
users = self._repo.commenters
elif team_name == '__collaborators':
users = self._repo.collaborators
else:
users = [u.login for u in self._repo.get_team(team_name)]
return TeamFilter(team_name, users)


class MetricsFormatter(object):
"""Write a MetricsReportSet object."""
Expand Down
10 changes: 10 additions & 0 deletions incenp/grainyhead/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def get_team(self, name='__collaborators'):
self._teams[team.slug] = team
return self._teams[name].members

def get_usernames(self, group='__collaborators'):
if group == '__contributors':
return self.contributors
elif group == '__committers':
return self.committers
elif group == '__commenters':
return self.commenters
else:
return [u.login for u in self.get_team(group)]

def create_label(self, name, color, description):
if not name in self.labels:
self._api.issues.create_label(name, color, description)
Expand Down

0 comments on commit 9e758d3

Please sign in to comment.