From 1cbbebbc807b14976cb7627a3e17172e4c33fce9 Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Thu, 26 Nov 2026 21:12:53 +0100 Subject: [PATCH 1/2] Fix duplicated code that resulted in data getting overridden --- github_backup/github_backup.py | 42 ---------------------------------- 1 file changed, 42 deletions(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 4b760fa..0717896 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -3273,48 +3273,6 @@ def pull_is_due_for_repository_checkpoint(pull): pulls[number]["comment_regular_data"] = get_pull_comments_with_graphql( args, repository, number ) - after = None - comments_page = 1 - comments = [] - comment_total_count = 0 - owner, name = _repository_owner_name(repository) - while True: - data = retrieve_graphql_data( - args, - PULL_COMMENTS_QUERY, - { - "owner": owner, - "name": name, - "number": number, - "after": after, - "pageSize": PULL_PAGE_SIZE, - }, - log_context="pull request {0}#{1} comments page {2}".format( - repository["full_name"], number, comments_page - ), - ) - repository_data = data.get("repository") or {} - pr_data = repository_data.get("pullRequest") - if pr_data is None: - raise Exception( - "Pull request #{0} not found in {1}".format( - number, repository["full_name"] - ) - ) - - comments_connection = pr_data.get("comments") or {} - comment_total_count = comments_connection.get( - "totalCount", comment_total_count - ) - comments.extend(_connection_nodes(comments_connection)) - - page_info = comments_connection.get("pageInfo") or {} - if not page_info.get("hasNextPage"): - break - - after = page_info.get("endCursor") - comments_page += 1 - pulls[number]["comment_regular_data"] = comments template = comments_template.format(number) pulls[number]["comment_data"] = retrieve_data(args, template) From cf68b9f2bc8b36ef6ab1120d4d895f1bd9810211 Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Thu, 26 Nov 2026 21:29:59 +0100 Subject: [PATCH 2/2] Add regression test --- tests/test_temporary_private_forks.py | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_temporary_private_forks.py b/tests/test_temporary_private_forks.py index 8c857af..241003d 100644 --- a/tests/test_temporary_private_forks.py +++ b/tests/test_temporary_private_forks.py @@ -134,3 +134,43 @@ def test_get_pull_comments_with_graphql_paginates(create_args): "pull request owner/repo#42 comments page 1", "pull request owner/repo#42 comments page 2", ] + + +def test_backup_pulls_uses_rest_api_for_comments_when_possible( + create_args, tmp_path, monkeypatch +): + args = create_args(include_pulls=True, include_pull_comments=True) + repository = {"full_name": "owner/repo"} + pull_file = tmp_path / "pulls" / "1.json" + inline_comment = {"id": 10, "body": "inline comment"} + regular_comment = {"id": 11, "body": "regular comment"} + + def fake_retrieve_data( + passed_args, template, query_args=None, paginated=True, **kwargs + ): + if template == "https://api.github.com/repos/owner/repo/pulls": + if query_args["state"] == "open": + return [ + { + "number": 1, + "updated_at": "2026-02-01T00:00:00Z", + "title": "PR with comments", + } + ] + return [] + if template == "https://api.github.com/repos/owner/repo/pulls/1/comments": + return [inline_comment] + if template == "https://api.github.com/repos/owner/repo/issues/1/comments": + return [regular_comment] + raise AssertionError("Unexpected template: {0}".format(template)) + + monkeypatch.setattr(github_backup, "retrieve_data", fake_retrieve_data) + + github_backup.backup_pulls( + args, tmp_path, repository, "https://api.github.com/repos" + ) + + pr_data = json.loads(pull_file.read_text()) + + assert pr_data["comment_data"] == [inline_comment] + assert pr_data["comment_regular_data"] == [regular_comment]