问题描述
我试图使用github API(通过githubot merge_commit_sha
属性,因为它很混乱。正如他们描述:
merge_commit_sha属性保存了测试合并提交的SHA
这意味着GitHub创建了一个特殊的分支,它们将主分支和您的pull请求分支合并,并且 merge_commit_sha
指向该代理合并提交,但是您没有当地回购。您必须获取特殊的 pr /< pull_request_id> / merge
分支来查看该提交。
好的是,您可以在 之前完成合并请求。像这样的工具这项技术的优势。同时 commit_sha
是实际的合并提交,这就是为什么你能够恢复它。
所以,如果还不清楚, merge_commit_sha
确实会给你正确的commit ,但要使用它,您必须首先获取 pr /< pull_request_id> / merge
分支。为了避免将来的弃用问题,您可以使用前面提到的合并分支的头部提交,而不是使用 merge_commit_sha
。
顺便说一下,如果你正在用Hubot创建一些东西,你可能想看看(无耻的插件)。它包含一个关于GitHub集成的章节。
I'm trying to use the github api (via githubot https://github.com/iangreenleaf/githubot) to GET a pull request merge commit sha from the pull request number.
I'm able to get the proper response (example here under "get a single pull request": https://developer.github.com/v3/pulls/) but the merge_commit_sha gives me this error:
fatal: bad object 304fc816f33f808080c9c87895eea2d66081d373
When I compare the 2 pages on github I'm seeing both the merge_commit_sha from the commit page but I'm seeing a different commit sha from the pull request merge page. Both parent are the same but the merge commit is different. The one returned from the api call doesn't work, but the other one let's me revert the pull request commit via
git revert -m 1 commit_sha
Here are some example screen shots
So this leads me to 2 questions:- What is the difference between those 2 commit sha's and why does only one work to revert the pull request?
- How do I obtain the merge pull request commit sha using the github api?
Thanks.
GitHub has deprecated the merge_commit_sha
attribute because it was confusing. As they describe here:
The merge_commit_sha attribute holds the SHA of the test merge commit
Which means that GitHub creates a special branch where they merge master and your pull request branch, and merge_commit_sha
points to that surrogate merge commit, however you don't have it in your local repo. You would have to fetch the special pr/<pull_request_id>/merge
branch to see that commit.
Good thing is that you can do that before merging the pull request. And tools like Jenkins GitHub pull request builder take advantage of this technique. Meanwhile commit_sha
is the actual merge commit, that's why you are able to revert it.
So, if it's still unclear, merge_commit_sha
does give you the correct commit sha, but to use it you have to fetch pr/<pull_request_id>/merge
branch first. To avoid problems of future deprecation, you could fetch the head commit of the aforementioned merge branch instead of using merge_commit_sha
.
By the way, if you're building something with Hubot, you may want to check out this book (shameless plug). It includes a chapter about GitHub integration.
这篇关于使用github api从拉请求号码中获取拉请求合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!