Kallin Nagelberg
Kallin Nagelberg

Reputation: 1019

How to avoid delaying github pull request merge using API

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:

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.

Upvotes: 4

Views: 3897

Answers (1)

kfb
kfb

Reputation: 6532

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.

Upvotes: 1

Related Questions