From 0bba472ce9b047110b77eab3a7095bf252c20509 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Thu, 2 Apr 2026 11:42:13 +0200 Subject: [PATCH 1/2] Refactor commented_in_range, no functional change Factor out code that checks whether an issue given as an URL has comments by a user in a given date range. --- did/plugins/github.py | 55 +++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/did/plugins/github.py b/did/plugins/github.py index 754dea63..7ce008fb 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -128,6 +128,36 @@ def condition(key: str, names: str) -> list[str]: condition("+-org", exclude_org) ) + def issue_pr_commented_in_range(self, + issue_pr_url: str, + since: datetime, + until: datetime, + login: str) -> bool: + issue_checked = False + url = issue_pr_url + while not issue_checked: + response = self.request(url) + comments = response.json() + log.debug("%s comments fetched for %s", len(comments), url) + log.data(pretty(comments)) + for comment in comments: + created_at = datetime.strptime( + comment["created_at"], + r"%Y-%m-%dT%H:%M:%SZ" + ) + if created_at > until: + # Comments are sorted by created_at asc + issue_checked = True + break + if comment["user"]["login"] == login and since <= created_at: + issue_checked = True + return True + if 'next' in response.links: + url = response.links['next']['url'] + else: + issue_checked = True + return False + def commented_in_range(self, commented_issues: list, since: datetime, @@ -136,33 +166,12 @@ def commented_in_range(self, valid_issues = [] for issue in commented_issues: issue_since = since - issue_checked = False url = ( f"{issue['comments_url']}" f"?per_page={PER_PAGE}&since={issue_since.isoformat()}" ) - while not issue_checked: - response = self.request(url) - comments = response.json() - log.debug("%s comments fetched for %s", len(comments), url) - log.data(pretty(comments)) - for comment in comments: - created_at = datetime.strptime( - comment["created_at"], - r"%Y-%m-%dT%H:%M:%SZ" - ) - if created_at > until: - # Comments are sorted by created_at asc - issue_checked = True - break - if comment["user"]["login"] == login and since <= created_at: - valid_issues.append(issue) - issue_checked = True - break - if 'next' in response.links: - url = response.links['next']['url'] - else: - issue_checked = True + if self.issue_pr_commented_in_range(url, since, until, login): + valid_issues.append(issue) return valid_issues @staticmethod From 9cf41eda3cff7ec0db531aba93e19d4583de9ca6 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Thu, 2 Apr 2026 11:47:41 +0200 Subject: [PATCH 2/2] Consider GitHub PR review comments Review comments on GitHub PR diffs are different from ordinary comments in the discussion. The latter can be fetched for PRs just as for issues, as every PR is also an issue. But review comments on diffs need to be fetched in a different way - by requesting them from the PR endpoint like https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments not from the issue endpoint like https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/comments . The current code has been doing only the latter and not the former, missing review comments on diffs in the GitHub activity report. Fix that. --- did/plugins/github.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/did/plugins/github.py b/did/plugins/github.py index 7ce008fb..4e0ca58d 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -170,8 +170,28 @@ def commented_in_range(self, f"{issue['comments_url']}" f"?per_page={PER_PAGE}&since={issue_since.isoformat()}" ) - if self.issue_pr_commented_in_range(url, since, until, login): + if self.issue_pr_commented_in_range(url, since, + until, login): valid_issues.append(issue) + continue + # If the issue is a PR, retry with review comments, these + # are different from issue comments: + # https://docs.github.com/en/rest/pulls/comments?apiVersion=2026-03-10 + pr_dict = issue.get('pull_request') + if pr_dict: + # pr_dict is a small dict that contains the actual + # pull request URL. + response = self.request(pr_dict['url']) + # the full PR dict, contains different fields + # than the issue dict even if the issue is actually a PR + pr = response.json() + url = ( + f"{pr['review_comments_url']}" + f"?per_page={PER_PAGE}&since={issue_since.isoformat()}" + ) + if self.issue_pr_commented_in_range(url, since, + until, login): + valid_issues.append(issue) return valid_issues @staticmethod