Skip to content

Commit

Permalink
Wait for github to update PR after a force push
Browse files Browse the repository at this point in the history
Summary:
This is trying to fix the exact same issue as described in D57741395. Except the mentioned diff failed to fully close the race.

This diff fully closes the race by inserting a loop that waits for GH to acknowledge the force push.

I've checked that the SHAs returned by the two libraries are indeed comparable:
```
>>> import github
>>> g = github.Github()
>>> repo = g.get_repo("PyGithub/PyGithub")
>>> pr = repo.get_pull(2987)
>>> pr.head.sha
'294e68a3c605a58695c29e0982a620489956423e'

>>> from git import Repo
>>> r = Repo("~/dev/linux")
>>> r.head.commit.hexsha
'911edc69c832161b62a8ad10a6972290157a7bd3'
```

Reviewed By: anakryiko

Differential Revision: D58542702

fbshipit-source-id: e446828c405aa4edb9b702f00bbd2c9f3671a7ce
  • Loading branch information
Daniel Xu authored and facebook-github-bot committed Jun 14, 2024
1 parent 921d16f commit ad5baf6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kernel_patches_daemon/branch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,21 @@ async def apply_push_comment(
branch_name=branch_name,
can_create=True,
)
assert pr
self.repo_local.git.push("--force", "origin", branch_name)

# Metadata inside `pr` may be stale from the force push; refresh it
if pr:
pr.update()
wanted_sha = self.repo_local.head.commit.hexsha
for _ in range(30):
if pr.head.sha == wanted_sha:
break
logger.info(f"Waiting for {pr} sha={pr.head.sha} to go to {wanted_sha}")
await asyncio.sleep(1)
pr.update()
else:
raise RuntimeError("Github failed to update PR after force push")

return pr
# we don't have a branch, also means no PR, push first then create PR
elif branch_name not in self.branches:
Expand Down

0 comments on commit ad5baf6

Please sign in to comment.