出现提交的分支列表 [英] List of branches a commit appears on
问题描述
使用GitHub API(v3)我想确定一个提交出现在哪个分支上。我没有找到一种方法直接查询这个,无论是通过repo提交或提交数据对象。另一种解决方案是列出所有分支,并与他们的HEAD进行比较;我猜如果提交不在给定的分支上,比较会失败。
这是通过当前API支持的,我错过了它?如果没有,那么你有一个(更好的)解决方法吗?
解决方案这不可能直接通过GitHub API。
解决方法1:
解决方法2(我认为这可以工作,但不是100%我错过了一个例子):
- get a 所有分支的列表
-
对于每个分支,比较分支和SHA :
https://api.github。 COM /回购/:用户/:回购/比较/:分支...:sha_of_commit
-
如果
状态
属性在响应中是diverged
或ahead
,则提交不在分支中。如果状态
属性的值是后面
或相同
,那么提交就在分支中。
Using the GitHub API (v3) I'd like to figure out which branches a commit appears on. I didn't find a way to directly query this, either through repo commits or the commit data objects. An alternate solution would be to list all the branches, and compare with their HEAD; I guess the comparison would fail if the commit is not on the given branch.
Is this supported via the current API, and I just missed it? If not, do you have a (better) workaround?
That's not possible directly via the GitHub API.
Workaround 1:
- get a list of all branches
- for each branch, get a list of commits on that branch
- check if the commit is in the list of commits for each branch
Workaround 2 (I think this will work, but not 100% sure if I missed a case):
- get a list of all branches
for each branch, compare the branch with the SHA:
https://api.github.com/repos/:user/:repo/compare/:branch...:sha_of_commit
If the value of the
status
attribute in the response isdiverged
orahead
, then the commit is not in the branch. If the value of thestatus
attribute isbehind
oridentical
, then the commit is in the branch.
这篇关于出现提交的分支列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!