[英]How do I get the PR information from a branch that's been merged to master using the Github API?
Say I have branches like patch-1
, patch-2
, patch-3
that were merged to master
by raising PRs on it (the branches have not been merged).假设我有诸如patch-1
、 patch-2
、 patch-3
之类的分支,它们通过在其上提高 PR 合并到master
(分支尚未合并)。 I would like to obtain information like the PR number, the reviews on the PR, of the PR that was used to merge patch-1
to master
.我想获取 PR 编号、PR 上的评论、用于将patch-1
合并到master
的 PR 等信息。 How can I do this using the Github API?如何使用 Github API 做到这一点? I've gone through the documentation but I can't seem to find any API that can help me do that.我浏览了文档,但似乎找不到任何可以帮助我做到这一点的 API。
NB : I don't know how to do this via the API!注意:我不知道如何通过 API 做到这一点!
...but I noticed that GitHub has started providing this information as part of the information it displays about a particular commit. ...但我注意到 GitHub 已开始提供此信息,作为它显示的有关特定提交的信息的一部分。 Eg, take a look at https://github.com/ansible/ansible/commit/a01376a493a755923895893e21ac3ce7e4b12ed2 ;例如,看看https://github.com/ansible/ansible/commit/a01376a493a755923895893e21ac3ce7e4b12ed2 ; just below the commit message, you can see a link to the pull request that introduced this commit:在提交消息下方,您可以看到一个指向引入此提交的拉取请求的链接:
Furthermore, I can see that information update after the page has loaded, which means there is an explicit javascript request being used to fetch that information.此外,我可以看到页面加载后信息更新,这意味着有一个明确的 javascript 请求用于获取该信息。 By turning on our browser's development features, we can see exactly what's happening.通过打开浏览器的开发功能,我们可以准确地看到正在发生的事情。 In this case, I see a request for:在这种情况下,我看到一个请求:
https://github.com/ansible/ansible/branch_commits/a01376a493a755923895893e21ac3ce7e4b12ed2
And the value returned from that URL is:从该 URL 返回的值是:
<svg class="octicon octicon-git-branch" viewBox="0 0 10 16" version="1.1" width="10" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M10 5c0-1.11-.89-2-2-2a1.993 1.993 0 00-1 3.72v.3c-.02.52-.23.98-.63 1.38-.4.4-.86.61-1.38.63-.83.02-1.48.16-2 .45V4.72a1.993 1.993 0 00-1-3.72C.88 1 0 1.89 0 3a2 2 0 001 1.72v6.56c-.59.35-1 .99-1 1.72 0 1.11.89 2 2 2 1.11 0 2-.89 2-2 0-.53-.2-1-.53-1.36.09-.06.48-.41.59-.47.25-.11.56-.17.94-.17 1.05-.05 1.95-.45 2.75-1.25S8.95 7.77 9 6.73h-.02C9.59 6.37 10 5.73 10 5zM2 1.8c.66 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2C1.35 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2zm0 12.41c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm6-8c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"/></svg>
<ul class="branches-list">
<li class="branch"><a href="/ansible/ansible">devel</a></li>
<li class="pull-request">(<a title="Merged Pull Request: update configuring ansible-galaxy client" href="/ansible/ansible/pull/64796">#64796</a>)</li>
</ul>
In other words, request https://github.com/:owner/:repo/branch_commits/:commit
to get information about the pull request that introduced a commit.换句话说,请求https://github.com/:owner/:repo/branch_commits/:commit
以获取有关引入提交的拉取请求的信息。
That's a nice machine-parseable chunk of HTML that includes the pull request id.这是一个很好的机器可解析的 HTML 块,其中包括拉取请求 ID。 There's probably a better way to do this via the API.通过 API 可能有更好的方法来做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.