如何使用GitHub API确定提交所属的Pull Request?

dan*_*nvk 5 github-api travis-ci

给定提交SHA,我想使用GitHub API来确定它所属的拉取请求.

GitHub在提交页面上显示此信息:

提交的PR链接

但是,此信息不在该提交的API响应中:

curl --silent 'https://api.github.com/repos/hammerlab/pileup.js/commits/ee49f07dba3821109b3cf45404446f434a897558' | grep 328
(nothing)
Run Code Online (Sandbox Code Playgroud)

是否可以使用GitHub API获取此信息?我意识到我可以抓住所有最近的PR回购,但这似乎效率低下.

对于上下文:我想从Travis-CI"推送"作业中执行此操作,在该作业中我可以访问SHA,但不知道它是否是拉取请求的一部分.

Iva*_*zak 8

使用支持此功能的Search API是可能的:

https://help.github.com/articles/searching-issues/#search-by-the-commit-shas-within-a-pull-request

例如:

https://api.github.com/search/issues?q=ee49f07dba3821109b3cf45404446f434a897558
Run Code Online (Sandbox Code Playgroud)

返回单个结果,即此拉取请求:

https://api.github.com/repos/hammerlab/pileup.js/issues/328
Run Code Online (Sandbox Code Playgroud)


小智 8

在 API v.3 中使用这个新功能似乎是可能的:

https://developer.github.com/v3/repos/commits/#list-pull-requests-related-with-a-commit

这是语法GET /repos/:owner/:repo/commits/:commit_sha/pulls。希望有帮助!