diff --git a/did/plugins/github.py b/did/plugins/github.py index aaa73d73..10212b1d 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -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) ] @@ -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) ] @@ -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( diff --git a/did/stats.py b/did/stats.py index 2d302443..5a35dfca 100644 --- a/did/stats.py +++ b/did/stats.py @@ -140,6 +140,14 @@ 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. """ @@ -147,6 +155,9 @@ def add_group(self, parser): 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") diff --git a/tests/basic/smoke/test.sh b/tests/basic/smoke/test.sh index c1377077..6a843cd1 100755 --- a/tests/basic/smoke/test.sh +++ b/tests/basic/smoke/test.sh @@ -3,6 +3,6 @@ rlJournalStart rlPhaseStartTest - rlRun "did --test last quarter" + rlRun "did --test --github-approximate-commented last quarter" rlPhaseEnd rlJournalEnd