libgit2sharp提供给GitHub API合并拉取请求的正确答案是什么? [英] libgit2sharp what is correct sha to supply to GitHub API merge pull-request?

查看:245
本文介绍了libgit2sharp提供给GitHub API合并拉取请求的正确答案是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  PUT / repos /:owner /:repo / pulls / :数字/合并

与请求正文json

  {
commit_message:blah,
sha:{SHA拉请求头必须匹配以允许合并},
}

在提交,推送,创建PR之后,libgit2sharp属性提供正确的sha? p>

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


{message:Head branch was modified。Review and try the merge
again。,documentation_url :
https://开发者。


解决方案



当利用GitHub API要合并已打开的Pull请求,json有效载荷中的可选sha属性应与当前GitHub 所知的分支提示相同。



如果你的本地仓库与GitHub知道你的仓库相同步,这肯定应该匹配 repo.Branches [your_topic_branch]。Tip.Sha 返回注意:为了确保PR的GitHub已知头部与本地分支头端相匹配,使用LibGit2Sharp,您可以检索GitHub PR合并/头指向提交,通过直接获取一个特殊的引用命名空间。以下代码演示了这个

  var remoteName =origin; //或者任何你的远程命名为
var remote = repo.Network.Remotes [remoteName];
var prNumber =1123; //或者任何你的pr数是

//构建refspec
字符串refSpec = string.Format(+ refs / pull / {1} / *:refs / remotes / {0 } / pull / {1} / *,
remoteName,prNumber);

//执行实际的读取
repo.Network.Fetch(remote,new [] {refSpec});

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


GitHub API requires merge pull-request to be submitted as

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

with request body json

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

Following a commit, push, create PR, what libgit2sharp property supplies the correct sha ?

For the current branch, it appears Branch.Tip.Sha is the correct value, but I'm receiving response error :

{ "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" }

解决方案

Two different commits and shas come into play when it comes to Pull Request.

When leveraging the GitHub API to merge an opened Pull Request, the optional sha property from the json payload is expected to match the sha of the branch tip as currently known by GitHub.

Provided your local repository is in sync with what GitHub knows about your repository, this should definitely be matching what repo.Branches["your_topic_branch"].Tip.Sha returns.

Note: In order to ensure that the GitHub known head of the PR matches your local branch tip, using LibGit2Sharp, you can retrieve GitHub PR merge/head pointed at commits, by directly fetching a special reference namespace. The following code demonstrates this

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);

这篇关于libgit2sharp提供给GitHub API合并拉取请求的正确答案是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆