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 Oct 18, 2024
1 parent 3c3cea4 commit b0d0bf7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
13 changes: 11 additions & 2 deletions did/plugins/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,13 @@ 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)
]


Expand Down Expand Up @@ -289,11 +291,13 @@ def fetch(self):
query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format(
user, 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)
]


Expand Down Expand Up @@ -359,6 +363,11 @@ def __init__(self, option, name=None, parent=None, user=None):
user=config.get("user"),
repo=config.get("repo"))

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 @@ -140,13 +140,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/basic/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 quarter"
rlRun "did --test --github-approximate-commented last quarter"
rlPhaseEnd
rlJournalEnd

0 comments on commit b0d0bf7

Please sign in to comment.