Skip to content

Commit

Permalink
Allow special team names.
Browse files Browse the repository at this point in the history
When using the `team:` selector, allow to use some special "team names"
to get stats about groups of users that do not actually correspond to a
GitHub team.

Special team names allowed are:

* `__contributors`: All users who contributed to the repository
* `__committers`: All users who committed to the repository
* `__commenters`: All users who opened a ticket/PR, or who commented on
  one
* `__collaborators`: All users registered as collaborators on the
  repository
  • Loading branch information
gouttegd committed Jul 9, 2023
1 parent c037122 commit de31adb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions incenp/grainyhead/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ def _get_parser(self):
).leaveWhitespace()
team_filter = (
(pp.Literal('team:') + filter_value)
.set_parse_action(
lambda t: TeamFilter(
t[1], [m.login for m in self._repo.get_team(t[1])]
)
)
.set_parse_action(self._team_action)
.leave_whitespace()
)
user_filter = (
Expand Down Expand Up @@ -248,6 +244,20 @@ 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

0 comments on commit de31adb

Please sign in to comment.