Commit 15a5a2ad authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch '24742-1st-contribution' into 'master'

Expose first_contribution for merge request API

Closes #24742

See merge request gitlab-org/gitlab!26926
parents c5aacd26 c6519577
---
title: Add first_contribution to single merge request API
merge_request: 26926
author:
type: added
......@@ -668,6 +668,7 @@ dependent on the `merge_status`. It'll return `false` unless `merge_status` is
},
"diverged_commits_count": 2,
"rebase_in_progress": false,
"first_contribution": false,
"task_completion_status":{
"count":0,
"completed_count":0
......
......@@ -39,6 +39,16 @@ module API
expose :diverged_commits_count, as: :diverged_commits_count, if: -> (_, options) { options[:include_diverged_commits_count] }
# We put this into an option because list of TODOs API will attach their
# targets with Entities::MergeRequest instead of
# Entities::MergeRequestBasic, but this attribute cannot be eagerly
# loaded in batch for now. The list of merge requests API will
# use Entities::MergeRequestBasic which does not support this, and
# we always enable this for the single merge request API. This way
# we avoid N+1 queries in the TODOs API and can still enable it for
# the single merge request API.
expose :first_contribution?, as: :first_contribution, if: -> (_, options) { options[:include_first_contribution] }
def build_available?(options)
options[:project]&.feature_available?(:builds, options[:current_user])
end
......
......@@ -267,6 +267,7 @@ module API
current_user: current_user,
project: user_project,
render_html: params[:render_html],
include_first_contribution: true,
include_diverged_commits_count: params[:include_diverged_commits_count],
include_rebase_in_progress: params[:include_rebase_in_progress]
end
......
......@@ -892,6 +892,7 @@ describe API::MergeRequests do
expect(json_response['merge_error']).to eq(merge_request.merge_error)
expect(json_response['user']['can_merge']).to be_truthy
expect(json_response).not_to include('rebase_in_progress')
expect(json_response['first_contribution']).to be_falsy
expect(json_response['has_conflicts']).to be_falsy
expect(json_response['blocking_discussions_resolved']).to be_truthy
expect(json_response['references']['short']).to eq("!#{merge_request.iid}")
......@@ -915,6 +916,21 @@ describe API::MergeRequests do
expect(json_response).to include('rebase_in_progress')
end
context 'when author is not a member without any merged merge requests' do
let(:non_member) { create(:user) }
before do
merge_request.update(author: non_member)
end
it 'exposes first_contribution as true' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['first_contribution']).to be_truthy
end
end
context 'merge_request_metrics' do
let(:pipeline) { create(:ci_empty_pipeline) }
......
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