List of branches a commit appears on

前端 未结 3 1608
你的背包
你的背包 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:31

    GitLab API

    Following Ivan Zuzak's solution number 2, to know if a commit is on a branch:

    Use GitLab's repository compare API, and compare from the branch, to the commit

    GET /projects/:id/repository/compare?from=&to=
    

    If the commits list is empty, then yes, the commit is on that branch.

    In Python, using python-gitlab:

    def is_commit_on_branch(project, commit, branch):
        c = project.repository_compare(branch, commit)
        return not c['commits']
    

提交回复
热议问题