diff --git a/did/plugins/github.py b/did/plugins/github.py index de35d7d8..07785a30 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -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): @@ -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): @@ -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( diff --git a/did/stats.py b/did/stats.py index 4938db52..8b37cfc6 100644 --- a/did/stats.py +++ b/did/stats.py @@ -142,6 +142,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. """ @@ -149,6 +157,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/smoke/test.sh b/tests/smoke/test.sh index b8170c41..6a843cd1 100755 --- a/tests/smoke/test.sh +++ b/tests/smoke/test.sh @@ -3,6 +3,6 @@ rlJournalStart rlPhaseStartTest - rlRun "did --test last week" + rlRun "did --test --github-approximate-commented last quarter" rlPhaseEnd rlJournalEnd