Get all commits from the gitlab api in a specific period

I have been trying to work with the gitlab api to get all my commits back between now and 2 months ago. The problem I have been running into is that I dont get more then 20 commits back. Nowhere i can find how to change it.
This is the link I have been working with:
https://gitlab.com/api/v4/projects/xxx/repository/commits?ref_name=master&since=2019-06-01T20:10:10Z&until=2019-09-01T20:10:10Z&all=true

thanks for your help

Hi @RoelVoordendag and welcome to the GitLab Community forums.

It sounds like you’re hitting the default of 20 items listed per page in the api (default: 20 , max: 100 )

https://docs.gitlab.com/ee/api/#pagination

To print the max of 100 results per “page”, use &per_page=100.
To fetch more than one hundred, you’ll need to use per_page=100 in combination with &page=#, incrementing page number by 1 for each set of 100 results.

https://gitlab.com/api/v4/projects/xxx/repository/commits?ref_name=master&since=2019-06-01T20:10:10Z&until=2019-09-01T20:10:10Z&all=true&per_page=100&page=x
2 Likes

Thanks for the help!

1 Like

@gitlab-greg could you please tell what is the parameter all used for though, when I used it with path or ref_name it gives me back an empty array but if I remove all=true it does show some results.

@aravinds257

The path parameter is used to specify which file path you’d like to list commits for.

The ref_name is used to specifiy the “name of a repository branch, tag or revision range” you’d like to list commits of". Listing repository commits with ref_name provided will only return commits for the given branch. If ref_name is not provided, you’ll see commits for the default branch by default.

The all parameter is used to retrieve every commit from the repository.
all used in combination with path will list all commits to that file across branches, tags and revision ranges, and all used without specifying a ref_name will list all commits to the repository.

This information can be found in the documentation here: Commits API | GitLab

Gitlab documentation is not so detailed as compared to what you have explained.
I also thought path with all should give me all commits. But strangely for my usecase path gives me the latest commits, path with all as true does gives me 2-3 or 0 commits and same is with path with all as true and ref_name.
Thats why had raised this topic, if you can guide me

Hi Team,

I have similar scenario to find out the commit authors for the last 1 year on the default branch - more specifically for python files(only files ending with .py) Is there any ways for this?

I am able to get the details from a git command for this usage. But cloning a large set of repos and iterating is not the ideal way.

git shortlog -sn --since=“366 days” – “*.py” | sort -f | uniq -i

I could only find a attribute for specifc path but not a specific file extension. Here is my api request.

curl https://gitlab.com/api/v4/projects/xxx/repository/commits?since=2022-11-11T20:10:10Z&per_page=100&page=1 | jq -r .[ ].author_name | sort -f | uniq -i

I found another api which gives me all files from a commit Commits API | GitLab . I thought of iterating through all diff files and getting the author name only if he/she contributed to .py file.

But this process seems to be expensive when compared to git cloning. Any thoughts on this?