0

For example, my project id is 385, and I want to retrive all commits of branch 'V3.53.5' with gitlab api v4, the url is http://{ip}/api/v4/projects/385/repository/commits/?ref_name=V3.53.5&per_page=9999, the problem is that it only return some commits even with the parameter per_page=9999.

While gitlab api v3 doesn't have this problem. I cant get all commits with http://{ip}/api/v3/projects/385/repository/commits/?ref_name=V3.53.5&per_page=9999

But I just want to use api v4, what should I do? I don't find an answer to my question in Gitlab API docs

Crypto营长
  • 149
  • 3
  • 14

2 Answers2

3

GitLab API has a max 100 per page: https://docs.gitlab.com/ee/api/#pagination

What you should do is retrieve X-Total-Pages: <total_pages> and iterate over each page adding the URL parameter &page=<page>

djuarezg
  • 2,307
  • 2
  • 20
  • 34
0

I have done sth very similar with it. I set the perpage , got the total-pages as a response and loope it.

req_data = requests.get(GET_PROJECT_MEMBERS_URL.format(
        project_id), headers=headers_data)
    if req_data.status_code != 200:
        return 0
    else:
        All_Pages = req_data.headers["X-Total-Pages"]
        for current_page_number in range(1, int(All_Pages)+1):
            current_resp = requests.get(GET_PROJECT_MEMBERS_WITH_ID_PAGE.format(
                project_id, project_id, current_page_number), headers=headers_data)
            current_merbersdata = current_resp.json()
            for member in current_merbersdata:
                print(member['username'])

And static apis

GET_PROJECT_MEMBERS_URL = "https://xxx/api/v4/projects/{}/members/all"
GET_PROJECT_MEMBERS_WITH_ID_PAGE = "https://xxxx/api/v4/projects/{}/members/all?id={}&page={}&per_page=20"




                    
B.Kingsun
  • 350
  • 3
  • 11