git - libgit2sharp what is correct sha to supply to GitHub API merge pull-request? -
github api requires merge pull-request submitted
put /repos/:owner/:repo/pulls/:number/merge
with request body json
{ "commit_message": "blah", "sha": "{sha pull request head must match allow merge}", }
following commit, push, create pr, libgit2sharp property supplies correct sha ?
for current branch, appears branch.tip.sha
correct value, i'm receiving response error :
{ "message": "head branch modified. review , try merge again.", "documentation_url": "https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button" }
two different commits , shas come play when comes pull request.
the tip of branch (the last commit you've pushed on branch)
- syntax:
get /repos/:owner/:repo/git/refs/:ref
(where:ref
should ofpull/{number}/head
format) - example: https://api.github.com/repos/libgit2/libgit2sharp/git/refs/pull/1123/head
- syntax:
the virtual merge commit github dynamically creates behind scene determine mergeability , allow ci servers run build/tests if branch merged (and thus, detect in advance potential issue)
- syntax:
get /repos/:owner/:repo/git/refs/:ref
(where:ref
should ofpull/{number}/merge
format) - example: https://api.github.com/repos/libgit2/libgit2sharp/git/refs/pull/1123/merge
- syntax:
when leveraging github api merge opened pull request, optional sha property json payload expected match sha of branch tip as known github.
provided local repository in sync github knows repository, should matching repo.branches["your_topic_branch"].tip.sha
returns.
note: in order ensure github known head of pr matches local branch tip, using libgit2sharp, can retrieve github pr merge/head pointed @ commits, directly fetching special reference namespace. following code demonstrates this
var remotename = "origin"; // or whatever remote named var remote = repo.network.remotes[remotename]; var prnumber = "1123"; // or whatever pr number // build refspec string refspec = string.format("+refs/pull/{1}/*:refs/remotes/{0}/pull/{1}/*", remotename, prnumber); // perform actual fetch repo.network.fetch(remote, new[] { refspec }); console.writeline(repo.branches[string.format("pull/{0}/merge", prnumber)].tip.sha);
Comments
Post a Comment