spacedentist / spr

Submit pull requests for individual, amendable, rebaseable commits to GitHub
https://getcord.github.io/spr/
MIT License
376 stars 33 forks source link

Add retries to GitHub land API call #168

Open jozef-mokry opened 1 year ago

jozef-mokry commented 1 year ago

In Cord we notice that when working on a stack of diffs, then sometimes spr land fails with the following error:

  ❌  GitHub Pull Request merge failed
  πŸ›‘  GitHub: At least 1 approving review is required by reviewers with write access.
      Documentation URL: https://docs.github.com/articles/about-protected-branches

This problem goes away if we go to the PR and manually change the PR's base branch to master. Then spr land works fine. This is surprising because in the PR history I can see that spr changed the base branch to master too when we tried to spr land the first time.

I initially added a 5s sleep call, and the problem went away. Hence, I suspect this is an issue on GitHub's end. Hence, I added a retry mechanism around the API call.

I added a utility function do_with_retry() to do this. Not as much for code re-use, but because it makes the code easier to read IMO. There is code above my changes that also uses retries, but I did not refactor it to use do_with_retry() because that code looked more complex πŸ™ƒ

Test Plan: I will be using spr with this change for the next few days