Commit 1e4dcd28 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'commits-api-trailers' into 'master'

Optionally include trailers in the commits API

See merge request gitlab-org/gitlab!63228
parents 15243640 b8fefa07
......@@ -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