如何使用GitHub API确定提交属于哪个Pull Request?

问题描述 投票:5回答:2

给出一个提交SHA,我想使用GitHub API来确定它属于哪个拉取请求。

GitHub在commit page上显示此信息:

PR link for a commit

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

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

是否可以使用GitHub API获取此信息?我意识到我可以检索该回购的所有最近PR,但这似乎效率很低。

对于上下文:我想从Travis-CI“推送”作业中执行此操作,在该作业中我可以访问SHA,但没有有关是否属于请求请求的任何信息。

travis-ci github-api
2个回答
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

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

https://api.github.com/repos/hammerlab/pileup.js/issues/328

0
投票

[似乎可以在API v.3中使用此新功能:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.