Skip to content

Add first parent to find commits

What does this MR do?

Add a &first_parent=true option to the List Repository Commits api.

What is the usecase?

In our large repository, we are trying to find all merges into a protected branch. Due to the consistency of the merge method via Merge Requests, we know that following first_parent will yield us all the merges. In our use case, we do not squash, and often have a 10-to-1, or greater, ratio of commits-to-merge-requests in master, and this change allows for significantly fewer pages of results, as we query for this data.

We are using this information to generate a more accurate "age" of a merge request, rather than just using diverged_commits_count. We use the <mr_head>..<head_of_dest_branch> for ref_name, with first_parent set, in order to just get the missing merges, from which we can run some hueristics to determine how out of date an MR is with its target, which we can use to block merges. Specifically, we can say branches which are missing a master merge from 3 or more days ago, cannot be merged into master without merging up and getting a new build.

This is all an effort to maintain a greener master build history.

Screenshots

An example output via curl, of a commit range, with and without first_parent.

10:10 $ curl -I "http://localhost:3000/api/v4/projects/19/repository/commits?ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master&first_parent=true"
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 14389
Content-Type: application/json
Link: <http://localhost:3000/api/v4/projects/19/repository/commits?first_parent=true&id=19&page=2&per_page=20&ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master>; rel="next", <http://localhost:3000/api/v4/projects/19/repository/commits?first_parent=true&id=19&page=1&per_page=20&ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master>; rel="first", <http://localhost:3000/api/v4/projects/19/repository/commits?first_parent=true&id=19&page=23&per_page=20&ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master>; rel="last"
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Next-Page: 2
X-Page: 1
X-Per-Page: 20
X-Prev-Page:
X-Request-Id: 7dRBcfMCKu5
X-Runtime: 0.172677
X-Total: 442
X-Total-Pages: 23
Date: Thu, 29 Aug 2019 17:11:00 GMT


10:11 $ curl -I "http://localhost:3000/api/v4/projects/19/repository/commits?ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master"
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 13887
Content-Type: application/json
Link: <http://localhost:3000/api/v4/projects/19/repository/commits?id=19&page=2&per_page=20&ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master>; rel="next", <http://localhost:3000/api/v4/projects/19/repository/commits?id=19&page=1&per_page=20&ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master>; rel="first", <http://localhost:3000/api/v4/projects/19/repository/commits?id=19&page=164&per_page=20&ref_name=4400e8a54c25c77d55b38b734918b744be26cf19..master>; rel="last"
Vary: Origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Next-Page: 2
X-Page: 1
X-Per-Page: 20
X-Prev-Page:
X-Request-Id: dL1eMCRZcw7
X-Runtime: 0.467808
X-Total: 3278
X-Total-Pages: 164
Date: Thu, 29 Aug 2019 17:11:04 GMT

Does this MR meet the acceptance criteria?

Conformity

Performance and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Johan Henkens

Merge request reports