Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

question from:https://stackoverflow.com/questions/65945635/list-branches-that-specific-commit-part-of-through-github-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
202 views
Welcome To Ask or Share your Answers For Others

1 Answer

That's not possible directly via the GitHub API.

Workaround 1:

  1. get a list of all branches
  2. for each branch, get a list of commits on that branch
  3. 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):

  1. get a list of all branches
  2. for each branch, compare the branch with the SHA:

    https://api.github.com/repos/:user/:repo/compare/:branch...:sha_of_commit

  3. If the value of the status attribute in the response is diverged or ahead, then the commit is not in the branch. If the value of the status attribute is behind or identical, then the commit is in the branch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[1] html - How to create even cell spacing within a

548k questions

547k answers

4 comments

86.3k users

...