List of branches a commit appears on

前端 未结 3 1607
你的背包
你的背包 2021-01-13 11:58

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 12:46

    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.

提交回复
热议问题