Commit c6519577 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Expose first_contribution for merge request API

Only for getting a single merge request
parent 61cdcb8f
---
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 ...@@ -668,6 +668,7 @@ dependent on the `merge_status`. It'll return `false` unless `merge_status` is
}, },
"diverged_commits_count": 2, "diverged_commits_count": 2,
"rebase_in_progress": false, "rebase_in_progress": false,
"first_contribution": false,
"task_completion_status":{ "task_completion_status":{
"count":0, "count":0,
"completed_count":0 "completed_count":0
......
...@@ -39,6 +39,16 @@ module API ...@@ -39,6 +39,16 @@ module API
expose :diverged_commits_count, as: :diverged_commits_count, if: -> (_, options) { options[:include_diverged_commits_count] } 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) def build_available?(options)
options[:project]&.feature_available?(:builds, options[:current_user]) options[:project]&.feature_available?(:builds, options[:current_user])
end end
......
...@@ -267,6 +267,7 @@ module API ...@@ -267,6 +267,7 @@ module API
current_user: current_user, current_user: current_user,
project: user_project, project: user_project,
render_html: params[:render_html], render_html: params[:render_html],
include_first_contribution: true,
include_diverged_commits_count: params[:include_diverged_commits_count], include_diverged_commits_count: params[:include_diverged_commits_count],
include_rebase_in_progress: params[:include_rebase_in_progress] include_rebase_in_progress: params[:include_rebase_in_progress]
end end
......
...@@ -892,6 +892,7 @@ describe API::MergeRequests do ...@@ -892,6 +892,7 @@ describe API::MergeRequests do
expect(json_response['merge_error']).to eq(merge_request.merge_error) expect(json_response['merge_error']).to eq(merge_request.merge_error)
expect(json_response['user']['can_merge']).to be_truthy expect(json_response['user']['can_merge']).to be_truthy
expect(json_response).not_to include('rebase_in_progress') 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['has_conflicts']).to be_falsy
expect(json_response['blocking_discussions_resolved']).to be_truthy expect(json_response['blocking_discussions_resolved']).to be_truthy
expect(json_response['references']['short']).to eq("!#{merge_request.iid}") expect(json_response['references']['short']).to eq("!#{merge_request.iid}")
...@@ -915,6 +916,21 @@ describe API::MergeRequests do ...@@ -915,6 +916,21 @@ describe API::MergeRequests do
expect(json_response).to include('rebase_in_progress') expect(json_response).to include('rebase_in_progress')
end 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 context 'merge_request_metrics' do
let(:pipeline) { create(:ci_empty_pipeline) } 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