简体   繁体   English

如何使用 Github API 从合并到 master 的分支中获取 PR 信息?

[英]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-1patch-2patch-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.

相关问题 如何检查master是否已合并到当前分支 - How do I check if master has been merged into current branch 使用 Github Desktop,我有一个分支; 如何从 MASTER 获取最新代码? - Using Github Desktop, I have a branch; How do I get LATEST code from MASTER? 如何锁定分支与母版合并? - How do I lock a branch from being merged with master? 在GitHub中合并+压缩PR到master后,如何同步你的git dev分支? - How to sync up your git dev branch after you've merged+squashed a PR to master, in GitHub? 如何验证git项目的release分支的修补程序已全部合并到master中? - How can I verify that a git project's release branch's fixes have all been merged into master? 我如何知道一个分支是否已经合并到 master 中? - How can I know if a branch has been already merged into master? Git:如何删除已经提交,推送并合并到master的分支? - Git: How do I remove a branch that has already been committed, pushed, and merged into master? 如何在github上删除以前与master合并的分支 - How to remove previously merged branch with master on github 我在git的错误分支上创建了一个分支,并将旧分支合并到master中,如何从另一个分支中删除提交? - I created a branch off of the wrong branch in git and already merged the old branch into master, how do I remove the commits from the other branch? Github将Master转移到PR分支吗? - Github move master to branch with PR?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM