Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions github_backup/github_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions tests/test_temporary_private_forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]