4

I am using the Github API via Octokit and have noticed a strange behavior. In one scenario I am programatically syncing master across 2 forks. I need to:

  • Open a pull request from repo1:master to repo2:master
  • Merge that pull request

When I first tried this I kept seeing the error "Head branch was modified. Review and try the merge again." It turns out that simply putting a delay (5 seconds) between creating the pull request and merging it (based on PR number) avoids this error.

So, it seems that github is returning from the 'create' call before it's actually finished or something along those lines. I wonder if there is a more reliable way (not using sleeps) to ensure that the PR is ready to be merged after creation.

Kallin Nagelberg
  • 989
  • 8
  • 17

1 Answers1

1

There will likely be some delay as GitHub creates the pull request. One approach would be to subscribe to a pull request event webhook that will be sent once the pull request has been "officially" opened, and perform the merge then.

kfb
  • 6,252
  • 6
  • 40
  • 51
  • I ended up using a simpler process of maintaining a git checkout on the server, then push/pulling to sync the repos. But, this webhook approach should work well if anyone needs to do something similar to my original approach. – Kallin Nagelberg Sep 15 '16 at 14:06
  • I think it's still necessary to wait and allow Github to reach consistency. The pull_request event is sent before the PR is able to merged successfully, but waiting a couple seconds seems to be enough. – cdignam May 01 '19 at 17:55