Commit b8fefa07 authored by Yorick Peterse's avatar Yorick Peterse

Optionally include trailers in the commits API

This adds the `trailers` option to the project commits API. When
enabled, Gitaly will parse the Git trailers into a structured object,
which is then presented in the API response.

The API to obtain merge request commits doesn't support this option at
this time. Said API retrieves data from the database. The Gitaly RPC
used to populate that data doesn't support parsing Git trailers at this
time, and extending it will likely require a fair amount of work. As
such, we only extend the regular commits API for the time being.

See https://gitlab.com/gitlab-org/release-tools/-/merge_requests/1464
and https://gitlab.com/gitlab-org/release-tools/-/issues/500 for more
information.

Changelog: added
parent 8d4dcf93
......@@ -28,6 +28,7 @@ GET /projects/:id/repository/commits
| `with_stats` | boolean | no | Stats about each commit are added to the response |
| `first_parent` | boolean | no | Follow only the first parent commit upon seeing a merge commit |
| `order` | string | no | List commits in order. Possible values: `default`, [`topo`](https://git-scm.com/docs/git-log#Documentation/git-log.txt---topo-order). Defaults to `default`, the commits are shown in reverse chronological order. |
| `trailers` | boolean | no | Parse and include [Git trailers](https://git-scm.com/docs/git-interpret-trailers) for every commit |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits"
......
# frozen_string_literal: true
require 'mime/types'
module API
......@@ -41,6 +40,7 @@ module API
optional :with_stats, type: Boolean, desc: 'Stats about each commit will be added to the response'
optional :first_parent, type: Boolean, desc: 'Only include the first parent of merges'
optional :order, type: String, desc: 'List commits in order', default: 'default', values: %w[default topo]
optional :trailers, type: Boolean, desc: 'Parse and include Git trailers for every commit', default: false
use :pagination
end
get ':id/repository/commits' do
......@@ -62,7 +62,8 @@ module API
after: after,
all: all,
first_parent: first_parent,
order: order)
order: order,
trailers: params[:trailers])
serializer = with_stats ? Entities::CommitWithStats : Entities::Commit
......
......@@ -9,6 +9,7 @@ module API
expose :safe_message, as: :message
expose :author_name, :author_email, :authored_date
expose :committer_name, :committer_email, :committed_date
expose :trailers
expose :web_url do |commit, _options|
Gitlab::UrlBuilder.build(commit)
......
......@@ -284,6 +284,18 @@ RSpec.describe API::Commits do
end
end
end
context 'with the optional trailers parameter' do
it 'includes the Git trailers' do
get api("/projects/#{project_id}/repository/commits?ref_name=6d394385cf567f80a8fd85055db1ab4c5295806f&trailers=true", current_user)
commit = json_response[0]
expect(commit['trailers']).to eq(
'Signed-off-by' => 'Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>'
)
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment