2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationController
|
2016-03-15 12:18:47 -04:00
|
|
|
include ToggleSubscriptionAction
|
2016-03-21 09:12:52 -04:00
|
|
|
include IssuableActions
|
2017-03-30 23:06:09 -04:00
|
|
|
include RendersNotes
|
2017-08-23 12:53:29 -04:00
|
|
|
include RendersCommits
|
2019-09-24 14:06:05 -04:00
|
|
|
include RendersAssignees
|
2016-04-16 15:09:08 -04:00
|
|
|
include ToggleAwardEmoji
|
2016-07-23 19:28:12 -04:00
|
|
|
include IssuableCollections
|
2019-02-05 09:55:31 -05:00
|
|
|
include RecordUserLastActivity
|
2020-01-08 01:08:13 -05:00
|
|
|
include SourcegraphDecorator
|
2020-09-03 17:08:18 -04:00
|
|
|
include DiffHelper
|
2021-07-28 05:09:47 -04:00
|
|
|
include Gitlab::Cache::Helpers
|
2016-03-03 12:38:44 -05:00
|
|
|
|
2021-08-20 05:09:16 -04:00
|
|
|
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
|
2020-10-28 05:08:37 -04:00
|
|
|
skip_before_action :merge_request, only: [:index, :bulk_update, :export_csv]
|
2020-09-03 17:08:18 -04:00
|
|
|
before_action :apply_diff_view_cookie!, only: [:show]
|
2021-03-16 14:11:53 -04:00
|
|
|
before_action :disable_query_limiting, only: [:assign_related_issues, :update]
|
2017-11-01 13:35:14 -04:00
|
|
|
before_action :authorize_update_issuable!, only: [:close, :edit, :update, :remove_wip, :sort]
|
2020-05-13 05:08:37 -04:00
|
|
|
before_action :authorize_read_actual_head_pipeline!, only: [
|
|
|
|
:test_reports,
|
|
|
|
:exposed_artifacts,
|
|
|
|
:coverage_reports,
|
|
|
|
:terraform_reports,
|
2020-12-08 10:09:45 -05:00
|
|
|
:accessibility_reports,
|
2021-02-03 13:09:25 -05:00
|
|
|
:codequality_reports,
|
|
|
|
:codequality_mr_diff_reports
|
2020-05-13 05:08:37 -04:00
|
|
|
]
|
2017-11-07 08:34:12 -05:00
|
|
|
before_action :set_issuables_index, only: [:index]
|
2016-10-07 12:16:42 -04:00
|
|
|
before_action :authenticate_user!, only: [:assign_related_issues]
|
2017-12-20 04:01:21 -05:00
|
|
|
before_action :check_user_can_push_to_source_branch!, only: [:rebase]
|
2019-10-09 17:06:24 -04:00
|
|
|
before_action only: [:show] do
|
2020-06-11 08:08:54 -04:00
|
|
|
push_frontend_feature_flag(:file_identifier_hash)
|
2021-03-02 01:10:53 -05:00
|
|
|
push_frontend_feature_flag(:merge_request_widget_graphql, @project, default_enabled: :yaml)
|
2021-02-16 13:09:24 -05:00
|
|
|
push_frontend_feature_flag(:default_merge_ref_for_diffs, @project, default_enabled: :yaml)
|
2020-11-23 13:09:14 -05:00
|
|
|
push_frontend_feature_flag(:core_security_mr_widget_counts, @project)
|
2021-02-04 07:09:25 -05:00
|
|
|
push_frontend_feature_flag(:paginated_notes, @project, default_enabled: :yaml)
|
2021-03-22 11:09:31 -04:00
|
|
|
push_frontend_feature_flag(:confidential_notes, @project, default_enabled: :yaml)
|
2021-04-08 11:09:06 -04:00
|
|
|
push_frontend_feature_flag(:improved_emoji_picker, project, default_enabled: :yaml)
|
2021-05-18 14:10:54 -04:00
|
|
|
push_frontend_feature_flag(:diffs_virtual_scrolling, project, default_enabled: :yaml)
|
2021-08-25 08:11:32 -04:00
|
|
|
push_frontend_feature_flag(:restructured_mr_widget, project, default_enabled: :yaml)
|
2021-09-29 02:09:19 -04:00
|
|
|
push_frontend_feature_flag(:mr_changes_fluid_layout, project, default_enabled: :yaml)
|
2021-10-25 08:10:19 -04:00
|
|
|
push_frontend_feature_flag(:mr_attention_requests, project, default_enabled: :yaml)
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2021-04-16 05:09:16 -04:00
|
|
|
# Usage data feature flags
|
|
|
|
push_frontend_feature_flag(:users_expanding_widgets_usage_data, @project, default_enabled: :yaml)
|
2021-04-28 11:09:35 -04:00
|
|
|
push_frontend_feature_flag(:diff_settings_usage_data, default_enabled: :yaml)
|
2021-07-28 11:09:57 -04:00
|
|
|
push_frontend_feature_flag(:diff_searching_usage_data, @project, default_enabled: :yaml)
|
2019-10-09 17:06:24 -04:00
|
|
|
end
|
2016-10-07 12:16:42 -04:00
|
|
|
|
2019-10-16 05:07:51 -04:00
|
|
|
before_action do
|
2021-05-06 17:10:07 -04:00
|
|
|
push_frontend_feature_flag(:show_relevant_approval_rule_approvers, @project, default_enabled: :yaml)
|
2019-10-16 05:07:51 -04:00
|
|
|
end
|
|
|
|
|
2019-06-22 14:05:17 -04:00
|
|
|
around_action :allow_gitaly_ref_name_caching, only: [:index, :show, :discussions]
|
2019-04-04 16:22:11 -04:00
|
|
|
|
2020-09-18 02:09:31 -04:00
|
|
|
after_action :log_merge_request_show, only: [:show]
|
|
|
|
|
2020-10-02 08:09:03 -04:00
|
|
|
feature_category :code_review, [
|
|
|
|
:assign_related_issues, :bulk_update, :cancel_auto_merge,
|
2021-04-12 11:09:30 -04:00
|
|
|
:commit_change_content, :commits, :context_commits, :destroy,
|
|
|
|
:discussions, :edit, :index, :merge, :rebase, :remove_wip,
|
|
|
|
:show, :toggle_award_emoji, :toggle_subscription, :update
|
|
|
|
]
|
|
|
|
|
2021-12-01 13:15:19 -05:00
|
|
|
feature_category :code_testing, [:test_reports, :coverage_reports]
|
|
|
|
feature_category :code_quality, [:codequality_reports, :codequality_mr_diff_reports]
|
2020-10-02 08:09:03 -04:00
|
|
|
feature_category :accessibility_testing, [:accessibility_reports]
|
2021-01-07 07:10:24 -05:00
|
|
|
feature_category :infrastructure_as_code, [:terraform_reports]
|
2021-04-12 11:09:30 -04:00
|
|
|
feature_category :continuous_integration, [:pipeline_status, :pipelines, :exposed_artifacts]
|
2020-07-07 05:08:57 -04:00
|
|
|
|
2021-12-07 07:10:33 -05:00
|
|
|
urgency :high, [:export_csv]
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def index
|
2017-11-07 08:34:12 -05:00
|
|
|
@merge_requests = @issuables
|
2017-02-15 17:13:53 -05:00
|
|
|
|
2015-03-12 19:20:58 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2021-08-20 05:09:16 -04:00
|
|
|
format.atom { render layout: 'xml.atom' }
|
2015-03-12 19:20:58 -04:00
|
|
|
format.json do
|
|
|
|
render json: {
|
2018-11-27 11:53:16 -05:00
|
|
|
html: view_to_html_string("projects/merge_requests/_merge_requests")
|
2015-03-12 19:20:58 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2021-07-28 05:09:47 -04:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
2011-11-28 02:39:43 -05:00
|
|
|
def show
|
2018-06-05 07:43:29 -04:00
|
|
|
close_merge_request_if_no_source_project
|
2021-04-07 05:09:06 -04:00
|
|
|
|
|
|
|
if Feature.disabled?(:check_mergeability_async_in_widget, @project, default_enabled: :yaml)
|
|
|
|
@merge_request.check_mergeability(async: true)
|
|
|
|
end
|
2017-09-19 06:55:37 -04:00
|
|
|
|
2011-11-28 15:16:57 -05:00
|
|
|
respond_to do |format|
|
2017-05-09 00:15:34 -04:00
|
|
|
format.html do
|
2018-06-05 07:44:07 -04:00
|
|
|
# use next to appease Rubocop
|
|
|
|
next render('invalid') if target_branch_missing?
|
|
|
|
|
2019-09-24 14:06:05 -04:00
|
|
|
preload_assignees_for_render(@merge_request)
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
# Build a note object for comment form
|
|
|
|
@note = @project.notes.new(noteable: @merge_request)
|
|
|
|
|
|
|
|
@noteable = @merge_request
|
2020-08-04 14:09:49 -04:00
|
|
|
@commits_count = @merge_request.commits_count + @merge_request.context_commits_count
|
2021-04-29 11:10:07 -04:00
|
|
|
@diffs_count = get_diffs_count
|
2018-11-27 11:53:16 -05:00
|
|
|
@issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
|
2020-12-03 22:09:49 -05:00
|
|
|
@current_user_data = UserSerializer.new(project: @project).represent(current_user, {}, MergeRequestCurrentUserEntity).to_json
|
2019-09-16 05:06:25 -04:00
|
|
|
@show_whitespace_default = current_user.nil? || current_user.show_whitespace_in_diffs
|
2020-12-06 01:09:43 -05:00
|
|
|
@file_by_file_default = current_user&.view_diffs_file_by_file
|
2020-03-17 14:09:44 -04:00
|
|
|
@coverage_path = coverage_reports_project_merge_request_path(@project, @merge_request, format: :json) if @merge_request.has_coverage_reports?
|
2021-04-02 17:09:22 -04:00
|
|
|
@update_current_user_path = expose_path(api_v4_user_preferences_path)
|
2020-07-16 14:09:35 -04:00
|
|
|
@endpoint_metadata_url = endpoint_metadata_url(@project, @merge_request)
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
set_pipeline_variables
|
2017-09-19 06:55:37 -04:00
|
|
|
|
2021-09-07 02:11:06 -04:00
|
|
|
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/336891') do
|
|
|
|
@number_of_pipelines = @pipelines.size
|
|
|
|
end
|
|
|
|
|
2018-02-07 05:29:01 -05:00
|
|
|
render
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2016-07-03 17:01:13 -04:00
|
|
|
format.json do
|
2017-05-18 16:14:48 -04:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
|
|
|
|
2021-09-07 02:11:06 -04:00
|
|
|
if params[:serializer] == 'sidebar_extras'
|
2021-08-13 17:09:54 -04:00
|
|
|
cache_context = [
|
|
|
|
params[:serializer],
|
|
|
|
current_user&.cache_key,
|
2021-11-08 01:09:59 -05:00
|
|
|
@merge_request.merge_request_assignees.map(&:cache_key),
|
|
|
|
@merge_request.merge_request_reviewers.map(&:cache_key)
|
2021-08-13 17:09:54 -04:00
|
|
|
]
|
|
|
|
|
2021-07-28 05:09:47 -04:00
|
|
|
render_cached(@merge_request,
|
|
|
|
with: serializer,
|
2021-08-13 17:09:54 -04:00
|
|
|
cache_context: -> (_) { [Digest::SHA256.hexdigest(cache_context.to_s)] },
|
2021-07-28 05:09:47 -04:00
|
|
|
serializer: params[:serializer])
|
|
|
|
else
|
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer])
|
|
|
|
end
|
2016-07-03 17:01:13 -04:00
|
|
|
end
|
|
|
|
|
2019-01-16 07:09:29 -05:00
|
|
|
format.patch do
|
2018-04-18 05:19:40 -04:00
|
|
|
break render_404 unless @merge_request.diff_refs
|
2016-07-03 17:01:13 -04:00
|
|
|
|
|
|
|
send_git_patch @project.repository, @merge_request.diff_refs
|
2016-06-10 08:57:50 -04:00
|
|
|
end
|
2016-07-03 17:01:13 -04:00
|
|
|
|
2016-05-12 14:50:49 -04:00
|
|
|
format.diff do
|
2018-04-18 05:19:40 -04:00
|
|
|
break render_404 unless @merge_request.diff_refs
|
2016-05-12 14:50:49 -04:00
|
|
|
|
2016-06-08 08:30:15 -04:00
|
|
|
send_git_diff @project.repository, @merge_request.diff_refs
|
2016-05-12 14:50:49 -04:00
|
|
|
end
|
2012-11-22 15:50:36 -05:00
|
|
|
end
|
2012-07-04 18:26:23 -04:00
|
|
|
end
|
2021-07-28 05:09:47 -04:00
|
|
|
# rubocop:enable Metrics/AbcSize
|
2012-07-04 18:26:23 -04:00
|
|
|
|
2015-05-29 00:09:28 -04:00
|
|
|
def commits
|
2020-08-04 14:09:49 -04:00
|
|
|
# Get context commits from repository
|
|
|
|
@context_commits =
|
|
|
|
set_commits_for_rendering(
|
|
|
|
@merge_request.recent_context_commits
|
|
|
|
)
|
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
2017-11-10 14:57:11 -05:00
|
|
|
@commits =
|
2019-11-15 10:06:12 -05:00
|
|
|
set_commits_for_rendering(
|
2021-08-25 23:09:01 -04:00
|
|
|
@merge_request.recent_commits(load_from_gitaly: true).with_latest_pipeline(@merge_request.source_branch).with_markdown_cache,
|
2020-07-01 11:08:45 -04:00
|
|
|
commits_count: @merge_request.commits_count
|
2019-11-15 10:06:12 -05:00
|
|
|
)
|
2016-08-04 09:56:54 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
render json: { html: view_to_html_string('projects/merge_requests/_commits') }
|
2016-07-27 12:54:04 -04:00
|
|
|
end
|
|
|
|
|
2016-07-22 20:28:39 -04:00
|
|
|
def pipelines
|
2019-06-28 10:40:34 -04:00
|
|
|
set_pipeline_variables
|
2021-06-30 14:07:05 -04:00
|
|
|
@pipelines = @pipelines.page(params[:page])
|
2016-07-25 20:30:52 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
2017-04-05 10:36:14 -04:00
|
|
|
|
2021-09-22 11:12:06 -04:00
|
|
|
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/336891') do
|
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@pipelines),
|
|
|
|
count: {
|
|
|
|
all: @pipelines.count
|
|
|
|
}
|
2017-07-14 11:52:54 -04:00
|
|
|
}
|
2021-09-22 11:12:06 -04:00
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2021-02-10 04:09:38 -05:00
|
|
|
def sast_reports
|
|
|
|
reports_response(merge_request.compare_sast_reports(current_user), head_pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
def secret_detection_reports
|
|
|
|
reports_response(merge_request.compare_secret_detection_reports(current_user), head_pipeline)
|
|
|
|
end
|
|
|
|
|
2020-01-29 10:08:59 -05:00
|
|
|
def context_commits
|
|
|
|
return render_404 unless project.context_commits_enabled?
|
|
|
|
|
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
|
|
|
commits = ContextCommitsFinder.new(project, @merge_request, { search: params[:search], limit: params[:limit], offset: params[:offset] }).execute
|
|
|
|
render json: CommitEntity.represent(commits, { type: :full, request: merge_request })
|
|
|
|
end
|
|
|
|
|
2018-08-02 02:05:07 -04:00
|
|
|
def test_reports
|
2019-04-16 07:06:52 -04:00
|
|
|
reports_response(@merge_request.compare_test_reports)
|
2018-08-02 02:05:07 -04:00
|
|
|
end
|
|
|
|
|
2020-05-13 05:08:37 -04:00
|
|
|
def accessibility_reports
|
|
|
|
if @merge_request.has_accessibility_reports?
|
|
|
|
reports_response(@merge_request.compare_accessibility_reports)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-17 14:09:44 -04:00
|
|
|
def coverage_reports
|
|
|
|
if @merge_request.has_coverage_reports?
|
|
|
|
reports_response(@merge_request.find_coverage_reports)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
def codequality_mr_diff_reports
|
2021-07-02 14:08:28 -04:00
|
|
|
reports_response(@merge_request.find_codequality_mr_diff_reports, head_pipeline)
|
2021-02-03 13:09:25 -05:00
|
|
|
end
|
|
|
|
|
2020-12-08 10:09:45 -05:00
|
|
|
def codequality_reports
|
|
|
|
reports_response(@merge_request.compare_codequality_reports)
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
def terraform_reports
|
|
|
|
reports_response(@merge_request.find_terraform_reports)
|
|
|
|
end
|
|
|
|
|
2019-10-21 11:05:58 -04:00
|
|
|
def exposed_artifacts
|
|
|
|
if @merge_request.has_exposed_artifacts?
|
|
|
|
reports_response(@merge_request.find_exposed_artifacts)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-08 07:04:24 -05:00
|
|
|
def edit
|
2017-06-13 18:12:31 -04:00
|
|
|
define_edit_vars
|
2015-12-08 07:04:24 -05:00
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
def update
|
2021-05-11 23:10:21 -04:00
|
|
|
@merge_request = ::MergeRequests::UpdateService.new(project: project, current_user: current_user, params: merge_request_update_params).execute(@merge_request)
|
2014-02-18 09:24:19 -05:00
|
|
|
|
2017-01-16 13:43:03 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2018-10-12 11:06:56 -04:00
|
|
|
if @merge_request.errors.present?
|
2017-06-13 18:12:31 -04:00
|
|
|
define_edit_vars
|
|
|
|
|
2017-01-16 13:43:03 -05:00
|
|
|
render :edit
|
2018-10-12 11:06:56 -04:00
|
|
|
else
|
|
|
|
redirect_to project_merge_request_path(@merge_request.target_project, @merge_request)
|
2015-03-06 08:03:41 -05:00
|
|
|
end
|
2014-02-18 09:24:19 -05:00
|
|
|
end
|
2017-01-16 13:43:03 -05:00
|
|
|
|
|
|
|
format.json do
|
2018-10-12 11:06:56 -04:00
|
|
|
if merge_request.errors.present?
|
|
|
|
render json: @merge_request.errors, status: :bad_request
|
|
|
|
else
|
2021-12-02 04:10:59 -05:00
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer] || 'basic')
|
2018-10-12 11:06:56 -04:00
|
|
|
end
|
2017-01-16 13:43:03 -05:00
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
2016-08-01 11:34:17 -04:00
|
|
|
rescue ActiveRecord::StaleObjectError
|
2017-06-13 18:12:31 -04:00
|
|
|
define_edit_vars if request.format.html?
|
|
|
|
|
2017-01-16 13:43:03 -05:00
|
|
|
render_conflict_response
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
|
|
|
|
2016-02-26 22:34:32 -05:00
|
|
|
def remove_wip
|
2017-06-13 18:12:31 -04:00
|
|
|
@merge_request = ::MergeRequests::UpdateService
|
2021-05-11 23:10:21 -04:00
|
|
|
.new(project: project, current_user: current_user, params: { wip_event: 'unwip' })
|
2017-05-09 00:15:34 -04:00
|
|
|
.execute(@merge_request)
|
2016-02-26 22:34:32 -05:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
render json: serialize_widget(@merge_request)
|
2016-02-26 22:34:32 -05:00
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def commit_change_content
|
|
|
|
render partial: 'projects/merge_requests/widget/commit_change_content', layout: false
|
2012-04-16 15:08:03 -04:00
|
|
|
end
|
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
def cancel_auto_merge
|
|
|
|
unless @merge_request.can_cancel_auto_merge?(current_user)
|
2016-10-27 08:04:43 -04:00
|
|
|
return access_denied!
|
|
|
|
end
|
2015-11-02 11:27:38 -05:00
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
AutoMergeService.new(project, current_user).cancel(@merge_request)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
render json: serialize_widget(@merge_request)
|
2015-11-02 11:27:38 -05:00
|
|
|
end
|
|
|
|
|
2015-08-11 08:33:31 -04:00
|
|
|
def merge
|
2018-10-24 05:14:16 -04:00
|
|
|
access_check_result = merge_access_check
|
|
|
|
|
|
|
|
return access_check_result if access_check_result
|
2013-02-27 13:20:31 -05:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
status = merge!
|
2015-11-02 11:27:38 -05:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
if @merge_request.merge_error
|
|
|
|
render json: { status: status, merge_error: @merge_request.merge_error }
|
2012-04-16 16:05:08 -04:00
|
|
|
else
|
2017-05-09 00:15:34 -04:00
|
|
|
render json: { status: status }
|
2012-04-16 16:05:08 -04:00
|
|
|
end
|
2012-03-29 11:03:05 -04:00
|
|
|
end
|
|
|
|
|
2016-08-08 18:30:01 -04:00
|
|
|
def assign_related_issues
|
2021-05-11 23:10:21 -04:00
|
|
|
result = ::MergeRequests::AssignIssuesService.new(project: project, current_user: current_user, params: { merge_request: @merge_request }).execute
|
2016-08-08 18:30:01 -04:00
|
|
|
|
2017-06-13 18:12:31 -04:00
|
|
|
case result[:count]
|
|
|
|
when 0
|
|
|
|
flash[:error] = "Failed to assign you issues related to the merge request"
|
|
|
|
when 1
|
|
|
|
flash[:notice] = "1 issue has been assigned to you"
|
|
|
|
else
|
|
|
|
flash[:notice] = "#{result[:count]} issues have been assigned to you"
|
2016-08-08 18:30:01 -04:00
|
|
|
end
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
redirect_to(merge_request_path(@merge_request))
|
2016-08-08 18:30:01 -04:00
|
|
|
end
|
|
|
|
|
2017-03-17 02:58:12 -04:00
|
|
|
def pipeline_status
|
2017-02-27 14:17:21 -05:00
|
|
|
render json: PipelineSerializer
|
2017-05-09 00:15:34 -04:00
|
|
|
.new(project: @project, current_user: @current_user)
|
2019-07-22 14:16:15 -04:00
|
|
|
.represent_status(head_pipeline)
|
2017-02-27 14:17:21 -05:00
|
|
|
end
|
|
|
|
|
2016-10-07 18:10:06 -04:00
|
|
|
def ci_environments_status
|
2019-11-29 10:06:43 -05:00
|
|
|
environments =
|
|
|
|
if ci_environments_status_on_merge_result?
|
2020-01-09 22:07:46 -05:00
|
|
|
EnvironmentStatus.for_deployed_merge_request(@merge_request, current_user)
|
2019-11-29 10:06:43 -05:00
|
|
|
else
|
|
|
|
EnvironmentStatus.for_merge_request(@merge_request, current_user)
|
|
|
|
end
|
2016-10-05 07:52:15 -04:00
|
|
|
|
2018-10-09 12:17:40 -04:00
|
|
|
render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments)
|
2012-12-10 22:14:05 -05:00
|
|
|
end
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
def rebase
|
2019-06-21 12:56:47 -04:00
|
|
|
@merge_request.rebase_async(current_user.id)
|
2017-12-20 04:01:21 -05:00
|
|
|
|
2018-11-22 12:47:29 -05:00
|
|
|
head :ok
|
2019-10-21 20:06:05 -04:00
|
|
|
rescue MergeRequest::RebaseLockTimeout => e
|
|
|
|
render json: { merge_error: e.message }, status: :conflict
|
2017-12-20 04:01:21 -05:00
|
|
|
end
|
|
|
|
|
2018-12-16 11:00:43 -05:00
|
|
|
def discussions
|
2019-09-16 11:06:26 -04:00
|
|
|
merge_request.discussions_diffs.load_highlight
|
2018-12-16 11:00:43 -05:00
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2020-10-28 05:08:37 -04:00
|
|
|
def export_csv
|
|
|
|
IssuableExportCsvWorker.perform_async(:merge_request, current_user.id, project.id, finder_options.to_h) # rubocop:disable CodeReuse/Worker
|
|
|
|
|
|
|
|
index_path = project_merge_requests_path(project)
|
2021-09-16 11:12:47 -04:00
|
|
|
message = _('Your CSV export has started. It will be emailed to %{email} when complete.') % { email: current_user.notification_email_or_default }
|
2020-10-28 05:08:37 -04:00
|
|
|
redirect_to(index_path, notice: message)
|
|
|
|
end
|
|
|
|
|
2011-11-28 02:39:43 -05:00
|
|
|
protected
|
|
|
|
|
2016-03-15 12:18:47 -04:00
|
|
|
alias_method :subscribable_resource, :merge_request
|
2016-03-21 09:12:52 -04:00
|
|
|
alias_method :issuable, :merge_request
|
2016-04-16 15:09:08 -04:00
|
|
|
alias_method :awardable, :merge_request
|
2011-12-15 16:57:46 -05:00
|
|
|
|
2019-08-21 06:13:45 -04:00
|
|
|
def sorting_field
|
2019-01-06 19:00:48 -05:00
|
|
|
MergeRequest::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:27:38 -05:00
|
|
|
def merge_params
|
2017-06-21 11:30:45 -04:00
|
|
|
params.permit(merge_params_attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_params_attributes
|
2019-11-15 10:06:12 -05:00
|
|
|
MergeRequest::KNOWN_MERGE_PARAMS
|
2015-11-02 11:27:38 -05:00
|
|
|
end
|
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
def auto_merge_requested?
|
|
|
|
# Support params[:merge_when_pipeline_succeeds] during the transition period
|
|
|
|
params[:auto_merge_strategy].present? || params[:merge_when_pipeline_succeeds].present?
|
2016-06-24 12:13:56 -04:00
|
|
|
end
|
2016-06-28 12:25:32 -04:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
private
|
|
|
|
|
2021-04-29 11:10:07 -04:00
|
|
|
def get_diffs_count
|
|
|
|
if show_only_context_commits?
|
|
|
|
@merge_request.context_commits_diff.raw_diffs.size
|
|
|
|
else
|
|
|
|
@merge_request.diff_size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-29 11:08:56 -04:00
|
|
|
def merge_request_update_params
|
|
|
|
merge_request_params.merge!(params.permit(:merge_request_diff_head_sha))
|
|
|
|
end
|
|
|
|
|
2019-07-22 14:16:15 -04:00
|
|
|
def head_pipeline
|
|
|
|
strong_memoize(:head_pipeline) do
|
|
|
|
pipeline = @merge_request.head_pipeline
|
|
|
|
pipeline if can?(current_user, :read_pipeline, pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-29 07:34:41 -04:00
|
|
|
def ci_environments_status_on_merge_result?
|
|
|
|
params[:environment_target] == 'merge_commit'
|
|
|
|
end
|
|
|
|
|
2018-06-05 07:44:07 -04:00
|
|
|
def target_branch_missing?
|
|
|
|
@merge_request.has_no_commits? && !@merge_request.target_branch_exists?
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def merge!
|
2019-05-22 07:45:27 -04:00
|
|
|
# Disable the CI check if auto_merge_strategy is specified since we have
|
2017-05-09 00:15:34 -04:00
|
|
|
# to wait until CI completes to know
|
2019-05-22 07:45:27 -04:00
|
|
|
unless @merge_request.mergeable?(skip_ci_check: auto_merge_requested?)
|
2017-05-09 00:15:34 -04:00
|
|
|
return :failed
|
|
|
|
end
|
|
|
|
|
2021-05-11 23:10:21 -04:00
|
|
|
merge_service = ::MergeRequests::MergeService.new(project: @project, current_user: current_user, params: merge_params)
|
2018-10-24 05:14:16 -04:00
|
|
|
|
|
|
|
unless merge_service.hooks_validation_pass?(@merge_request)
|
|
|
|
return :hook_validation_error
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
return :sha_mismatch if params[:sha] != @merge_request.diff_head_sha
|
|
|
|
|
2019-11-15 10:06:12 -05:00
|
|
|
@merge_request.update(merge_error: nil, squash: params.fetch(:squash, false))
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2019-05-22 07:45:27 -04:00
|
|
|
if auto_merge_requested?
|
2019-06-06 03:25:06 -04:00
|
|
|
if merge_request.auto_merge_enabled?
|
|
|
|
# TODO: We should have a dedicated endpoint for updating merge params.
|
2019-09-18 10:02:45 -04:00
|
|
|
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/63130.
|
2019-06-06 03:25:06 -04:00
|
|
|
AutoMergeService.new(project, current_user, merge_params).update(merge_request)
|
|
|
|
else
|
|
|
|
AutoMergeService.new(project, current_user, merge_params)
|
|
|
|
.execute(merge_request,
|
|
|
|
params[:auto_merge_strategy] || AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS)
|
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
else
|
2018-05-30 12:18:04 -04:00
|
|
|
@merge_request.merge_async(current_user.id, merge_params)
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
:success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
def serialize_widget(merge_request)
|
2020-04-21 11:21:10 -04:00
|
|
|
cached_data = serializer.represent(merge_request, serializer: 'poll_cached_widget')
|
|
|
|
widget_data = serializer.represent(merge_request, serializer: 'poll_widget')
|
|
|
|
cached_data.merge!(widget_data)
|
2017-12-07 16:56:59 -05:00
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def serializer
|
2020-04-21 11:21:10 -04:00
|
|
|
@serializer ||= MergeRequestSerializer.new(current_user: current_user, project: merge_request.project)
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
2017-06-13 18:12:31 -04:00
|
|
|
|
|
|
|
def define_edit_vars
|
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
2018-09-12 12:39:34 -04:00
|
|
|
@noteable = @merge_request
|
2018-09-14 11:59:28 -04:00
|
|
|
|
|
|
|
# FIXME: We have to assign a presenter to another instance variable
|
|
|
|
# due to class_name checks being made with issuable classes
|
2018-09-07 08:29:19 -04:00
|
|
|
@mr_presenter = @merge_request.present(current_user: current_user)
|
2017-06-13 18:12:31 -04:00
|
|
|
end
|
2017-11-07 08:34:12 -05:00
|
|
|
|
2018-02-20 07:33:49 -05:00
|
|
|
def finder_type
|
|
|
|
MergeRequestsFinder
|
2017-11-07 08:34:12 -05:00
|
|
|
end
|
2017-12-20 04:01:21 -05:00
|
|
|
|
|
|
|
def check_user_can_push_to_source_branch!
|
|
|
|
return access_denied! unless @merge_request.source_branch_exists?
|
|
|
|
|
|
|
|
access_check = ::Gitlab::UserAccess
|
2020-07-21 14:09:45 -04:00
|
|
|
.new(current_user, container: @merge_request.source_project)
|
2017-12-20 04:01:21 -05:00
|
|
|
.can_push_to_branch?(@merge_request.source_branch)
|
|
|
|
|
|
|
|
access_denied! unless access_check
|
|
|
|
end
|
2018-01-15 10:21:04 -05:00
|
|
|
|
2018-10-24 05:14:16 -04:00
|
|
|
def merge_access_check
|
|
|
|
access_denied! unless @merge_request.can_be_merged_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
def disable_query_limiting
|
2021-03-24 23:09:35 -04:00
|
|
|
# Also see https://gitlab.com/gitlab-org/gitlab/-/issues/20827
|
|
|
|
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/20824')
|
2018-01-15 10:21:04 -05:00
|
|
|
end
|
2019-04-16 07:06:52 -04:00
|
|
|
|
2020-09-10 08:08:54 -04:00
|
|
|
def reports_response(report_comparison, pipeline = nil)
|
|
|
|
if pipeline&.active?
|
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3000)
|
|
|
|
|
|
|
|
render json: '', status: :no_content && return
|
|
|
|
end
|
|
|
|
|
2019-04-16 07:06:52 -04:00
|
|
|
case report_comparison[:status]
|
|
|
|
when :parsing
|
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3000)
|
|
|
|
|
|
|
|
render json: '', status: :no_content
|
|
|
|
when :parsed
|
|
|
|
render json: report_comparison[:data].to_json, status: :ok
|
|
|
|
when :error
|
|
|
|
render json: { status_reason: report_comparison[:status_reason] }, status: :bad_request
|
|
|
|
else
|
2019-11-07 10:06:33 -05:00
|
|
|
raise "Failed to build comparison response as comparison yielded unknown status '#{report_comparison[:status]}'"
|
2019-04-16 07:06:52 -04:00
|
|
|
end
|
|
|
|
end
|
2019-08-21 01:42:28 -04:00
|
|
|
|
2020-09-18 02:09:31 -04:00
|
|
|
def log_merge_request_show
|
|
|
|
return unless current_user && @merge_request
|
|
|
|
|
|
|
|
::Gitlab::Search::RecentMergeRequests.new(user: current_user).log_view(@merge_request)
|
|
|
|
end
|
|
|
|
|
2019-10-21 11:05:58 -04:00
|
|
|
def authorize_read_actual_head_pipeline!
|
2019-08-21 01:42:28 -04:00
|
|
|
return render_404 unless can?(current_user, :read_build, merge_request.actual_head_pipeline)
|
|
|
|
end
|
2020-07-16 14:09:35 -04:00
|
|
|
|
|
|
|
def endpoint_metadata_url(project, merge_request)
|
|
|
|
params = request.query_parameters
|
2020-11-19 13:09:13 -05:00
|
|
|
params[:view] = "inline"
|
2020-07-16 14:09:35 -04:00
|
|
|
|
2021-02-16 13:09:24 -05:00
|
|
|
if Feature.enabled?(:default_merge_ref_for_diffs, project, default_enabled: :yaml)
|
2020-09-16 02:09:24 -04:00
|
|
|
params = params.merge(diff_head: true)
|
|
|
|
end
|
|
|
|
|
2020-07-16 14:09:35 -04:00
|
|
|
diffs_metadata_project_json_merge_request_path(project, merge_request, 'json', params)
|
|
|
|
end
|
2011-11-28 02:39:43 -05:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Projects::MergeRequestsController.prepend_mod_with('Projects::MergeRequestsController')
|