Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get number of commits from Github API until certain branch

I want to get how many commits has done until a certain branch created from the Github API.

For example in git cli I'm doing: git log --no-merges --oneline ${branchHash} | wc -l and I can see the number.

From the Github API there's a limit of 100 so if I have more than 100 commits I can't get them all.

Is there any solution for that case?

like image 329
yershalom Avatar asked Dec 10 '17 12:12

yershalom


People also ask

How can I see all branch commits?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

Which command shows limit number of commits?

Which Command is used to show limited number of commits? git log -n Command is used to show limited number of commits.


1 Answers

I wrote a little thing to solve this:

Gist "Easy way to calculate commits count from the GitHub API".

It is based on using the compare URL of the GitHub Commit API, and using the total_commits field:

compare_url = '{}/repos/{}/{}/compare/{}...{}'.format(base_url, owner, repo, first_commit, sha)

commit_count = commit_req.json()['total_commits'] + 1
like image 170
yershalom Avatar answered Oct 28 '22 19:10

yershalom