libgit2sharp 提供给 GitHub API 合并拉取请求的正确 sha 是什么?

libgit2sharp what is correct sha to supply to GitHub API merge pull-request?

GitHub API 需要将合并拉取请求提交为

PUT /repos/:owner/:repo/pulls/:number/merge

带有请求正文json

{
  "commit_message": "blah",
  "sha": "{SHA that pull request head must match to allow merge}",
}

在提交、推送、创建 PR 之后,什么 libgit2sharp 属性 提供了正确的 sha?

对于当前分支,似乎 Branch.Tip.Sha 是正确的值,但我收到响应错误:

{ "message": "Head branch was modified. Review and try the merge again.", "documentation_url": "https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button" }

当涉及到 Pull Request 时,有两种不同的提交和 shas 发挥作用。

当利用 GitHub API 合并打开的 Pull Request 时,来自 json 有效负载的可选 sha 属性 应该与分支的 sha 相匹配提示 目前已知的 GitHub.

假设您的本地存储库与 GitHub 对您的存储库的了解同步,这绝对应该与 repo.Branches["your_topic_branch"].Tip.Sha returns.

相匹配

注意:为了确保PR的GitHub已知head与你本地的分支提示匹配,使用LibGit2Sharp,你可以检索GitHub PR merge/head 通过直接获取一个特殊的引用命名空间来指向提交。下面的代码演示了这个

var remoteName = "origin"; // or whatever your remote is named
var remote = repo.Network.Remotes[remoteName];
var prNumber = "1123"; // or whatever your pr number is

// Build the refspec
string refSpec = string.Format("+refs/pull/{1}/*:refs/remotes/{0}/pull/{1}/*", 
                        remoteName, prNumber);

// Perform the actual fetch
repo.Network.Fetch(remote, new[] { refSpec });

Console.WriteLine(repo.Branches[string.Format("pull/{0}/merge", prNumber)].Tip.Sha);