Skip to content

Commit

Permalink
Add --github-approximate-commented argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Apr 4, 2024
1 parent 859735d commit d585e98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 10 additions & 2 deletions did/plugins/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ def fetch(self):
query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format(
user, since, until)
query += "+type:issue"
approx = getattr(
self.options, f"{self.parent.option}_approximate_commented", False)
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)
# Additional filter for the comments by user in the interval
if self.parent.github.has_comments(issue, user, since, until)]
if approx or self.parent.github.has_comments(issue, user, since, until)]


class PullRequestsCreated(Stats):
Expand Down Expand Up @@ -246,10 +248,12 @@ def fetch(self):
query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format(
self.user.login, self.options.since, until)
query += "+type:pr"
approx = getattr(
self.options, f"{self.parent.option}_approximate_commented", False)
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)
# Additional filter for the comments by user in the interval
if self.parent.github.has_comments(issue, user, since, until)]
if approx or self.parent.github.has_comments(issue, user, since, until)]


class PullRequestsClosed(Stats):
Expand Down Expand Up @@ -300,6 +304,10 @@ def __init__(self, option, name=None, parent=None, user=None):
# Check authorization token
self.token = get_token(config)
self.github = GitHub(self.url, self.token)
self.add_argument(
f"--{option}-approximate-commented", action="store_true",
help="If set, the filter to check if the user actually commented issues or "
"pull requests is not applied. It is recommended for long reports")
# Create the list of stats
self.stats = [
IssuesCreated(
Expand Down
11 changes: 11 additions & 0 deletions did/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,24 @@ class StatsGroup(Stats, metaclass=StatsGroupPlugin):
# Default order
order = 500

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.arguments = []

def add_argument(self, *args, **kwargs):
""" A wraper around _ArgumentGroup to add global options for StatsGroup """
self.arguments.append(([*args], {**kwargs}))

def add_group(self, parser):
""" Add option group and all children options. """

group = parser.add_argument_group(self.name)
for stat in self.stats:
stat.add_option(group)

for args, kwargs in self.arguments:
group.add_argument(*args, **kwargs)

group.add_argument(
"--{0}".format(self.option), action="store_true", help="All above")

Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

rlJournalStart
rlPhaseStartTest
rlRun "did --test last week"
rlRun "did --test --github-approximate-commented last quarter"
rlPhaseEnd
rlJournalEnd

0 comments on commit d585e98

Please sign in to comment.