Github API: Retrieve all commits for all branches for a repo

后端 未结 4 1290
时光取名叫无心
时光取名叫无心 2020-11-30 20:12

According to the V2 documentation, you can list all commits for a branch with:

commits/list/:user_id/:repository/:branch

I am not seeing th

4条回答
  •  爱一瞬间的悲伤
    2020-11-30 20:57

    I asked this same question for GitHub support, and they answered me this:

    GETing /repos/:owner/:repo/commits should do the trick. You can pass the branch name in the sha parameter. For example, to get the first page of commits from the '3.0.0-wip' branch of the twitter/bootstrap repository, you would use the following curl request:

    curl https://api.github.com/repos/twitter/bootstrap/commits?sha=3.0.0-wip
    

    The docs also describe how to use pagination to get the remaining commits for this branch.

    As long as you are making authenticated requests, you can make up to 5,000 requests per hour.

    I used the rails github-api in my app as follows(using https://github.com/peter-murach/github gem):

    github_connection = Github.new :client_id => 'your_id', :client_secret => 'your_secret', :oauth_token => 'your_oath_token'
    branches_info = {}
    all_branches = git_connection.repos.list_branches owner,repo_name
    all_branches.body.each do |branch|
        branches_info["#{branch.name}".to_s] = "#{branch.commit.url}"
    end
    branches_info.keys.each do |branch|
        commits_list.push (git_connection.repos.commits.list owner,repo_name, start_date,      end_date, :sha => "branch_name")
    end
    

提交回复
热议问题