[go: up one dir, main page]

Skip to content

Merge Request commits API never populates trailers

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

The commits returned by the GET /projects/:id/merge_requests/:merge_request_iid/commits API always returns empty commits[].trailers and commits[].extended_trailers attributes.

The commit[].trailers attribute is documented for merge request commits here: https://docs.gitlab.com/ee/api/merge_requests.html#get-single-merge-request-commits

Example Project

Merge request commit has empty trailers:

$ curl --silent "https://gitlab.com/api/v4/projects/278964/merge_requests/136998/commits" | jq
[
  {
    "id": "f4ad42c30a33a04bc49598abfcfe39499327dfba",
    "short_id": "f4ad42c3",
    "created_at": "2023-11-24T13:37:46.000Z",
    "parent_ids": [],
    "title": "Introduce `extended_trailers` field in commits API",
    "message": "Introduce `extended_trailers` field in commits API\n\nAdds a new field that correctly supports all commit trailers. Unlike\nthe existing `trailers` field, this will return an array of values\nwhere the same key is used multiple times, e.g. \"Cc\".\n\nThis functionality will eventually be moved over to the `trailers`\nfield once the original functionality has been deprecated. This\nis a breaking change to the API and therefore can't be performed\nin this commit.\n\nChangelog: added\n",
    "author_name": "Robert May",
    "author_email": "rmay@gitlab.com",
    "authored_date": "2023-11-15T13:09:14.000Z",
    "committer_name": "Robert May",
    "committer_email": "rmay@gitlab.com",
    "committed_date": "2023-11-24T13:37:46.000Z",
    "trailers": {},
    "extended_trailers": {},
    "web_url": "https://gitlab.com/gitlab-org/gitlab/-/commit/f4ad42c30a33a04bc49598abfcfe39499327dfba"
  }
]

Repository commits for the same ref similar has no trailers when trailers=True not passed

$ curl --silent "https://gitlab.com/api/v4/projects/278964/repository/commits?ref_name=f4ad42c30a33a04bc49598abfcfe39499327dfba^-1" | jq
[
  {
    "id": "f4ad42c30a33a04bc49598abfcfe39499327dfba",
    "short_id": "f4ad42c3",
    "created_at": "2023-11-24T13:37:46.000+00:00",
    "parent_ids": [
      "8be0f7f78be14ca09828fe794f44e68465e33235"
    ],
    "title": "Introduce `extended_trailers` field in commits API",
    "message": "Introduce `extended_trailers` field in commits API\n\nAdds a new field that correctly supports all commit trailers. Unlike\nthe existing `trailers` field, this will return an array of values\nwhere the same key is used multiple times, e.g. \"Cc\".\n\nThis functionality will eventually be moved over to the `trailers`\nfield once the original functionality has been deprecated. This\nis a breaking change to the API and therefore can't be performed\nin this commit.\n\nChangelog: added\n",
    "author_name": "Robert May",
    "author_email": "rmay@gitlab.com",
    "authored_date": "2023-11-15T13:09:14.000+00:00",
    "committer_name": "Robert May",
    "committer_email": "rmay@gitlab.com",
    "committed_date": "2023-11-24T13:37:46.000+00:00",
    "trailers": {},
    "extended_trailers": {},
    "web_url": "https://gitlab.com/gitlab-org/gitlab/-/commit/f4ad42c30a33a04bc49598abfcfe39499327dfba"
  }
]

Repository commits return the trailers if trailer=True is passed:

$ curl --silent "https://gitlab.com/api/v4/projects/278964/repository/commits?ref_name=f4ad42c30a33a04bc49598abfcfe39499327dfba^-1&trailers=True" | jq
[
  {
    "id": "f4ad42c30a33a04bc49598abfcfe39499327dfba",
    "short_id": "f4ad42c3",
    "created_at": "2023-11-24T13:37:46.000+00:00",
    "parent_ids": [
      "8be0f7f78be14ca09828fe794f44e68465e33235"
    ],
    "title": "Introduce `extended_trailers` field in commits API",
    "message": "Introduce `extended_trailers` field in commits API\n\nAdds a new field that correctly supports all commit trailers. Unlike\nthe existing `trailers` field, this will return an array of values\nwhere the same key is used multiple times, e.g. \"Cc\".\n\nThis functionality will eventually be moved over to the `trailers`\nfield once the original functionality has been deprecated. This\nis a breaking change to the API and therefore can't be performed\nin this commit.\n\nChangelog: added\n",
    "author_name": "Robert May",
    "author_email": "rmay@gitlab.com",
    "authored_date": "2023-11-15T13:09:14.000+00:00",
    "committer_name": "Robert May",
    "committer_email": "rmay@gitlab.com",
    "committed_date": "2023-11-24T13:37:46.000+00:00",
    "trailers": {
      "Changelog": "added"
    },
    "extended_trailers": {
      "Changelog": [
        "added"
      ]
    },
    "web_url": "https://gitlab.com/gitlab-org/gitlab/-/commit/f4ad42c30a33a04bc49598abfcfe39499327dfba"
  }
]

What is the current bug behavior?

The commits[].trailers attribute is always empty when returned by /projects/:id/merge_requests/:merge_request_iid/commits even when the commits contain trailers.

What is the expected correct behavior?

That the commits[].trailers are populated for merge request commits.

Relevant logs and/or screenshots

Output of checks

Results of GitLab application Check

Seen on GitLab.com

Possible fixes

The issue might be due to the fact that the /projects/:id/merge_requests/:merge_request_iid/commits API does not accept a trailers boolean to enable these attributes unlike the /projects/:id/repository/commits API which does have the boolean input value: https://docs.gitlab.com/ee/api/commits.html#list-repository-commits (assuming these perhaps share the same backend code).

Adding the trailers=<True|False> input option to the /projects/:id/merge_requests/:merge_request_iid/commits would allow the trailers to be returned in the same way they are for repository commits.

GET /projects/:id/repository/commits/:sha also does not return trailers, though it would very useful if that did too. https://docs.gitlab.com/ee/api/commits.html#get-a-single-commit

Edited by 🤖 GitLab Bot 🤖