2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-13 22:12:31 +00:00
|
|
|
class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationController
|
2016-03-15 16:18:47 +00:00
|
|
|
include ToggleSubscriptionAction
|
2016-03-21 13:12:52 +00:00
|
|
|
include IssuableActions
|
2017-03-31 03:06:09 +00:00
|
|
|
include RendersNotes
|
2017-08-23 16:53:29 +00:00
|
|
|
include RendersCommits
|
2019-09-24 18:06:05 +00:00
|
|
|
include RendersAssignees
|
2016-04-16 19:09:08 +00:00
|
|
|
include ToggleAwardEmoji
|
2016-07-23 23:28:12 +00:00
|
|
|
include IssuableCollections
|
2019-02-05 14:55:31 +00:00
|
|
|
include RecordUserLastActivity
|
2020-01-08 06:08:13 +00:00
|
|
|
include SourcegraphDecorator
|
2020-09-03 21:08:18 +00:00
|
|
|
include DiffHelper
|
2021-07-28 09:09:47 +00:00
|
|
|
include Gitlab::Cache::Helpers
|
2016-03-03 17:38:44 +00:00
|
|
|
|
2021-08-20 09:09:16 +00:00
|
|
|
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
|
2020-10-28 09:08:37 +00:00
|
|
|
skip_before_action :merge_request, only: [:index, :bulk_update, :export_csv]
|
2020-09-03 21:08:18 +00:00
|
|
|
before_action :apply_diff_view_cookie!, only: [:show]
|
2021-03-16 18:11:53 +00:00
|
|
|
before_action :disable_query_limiting, only: [:assign_related_issues, :update]
|
2017-11-01 17:35:14 +00:00
|
|
|
before_action :authorize_update_issuable!, only: [:close, :edit, :update, :remove_wip, :sort]
|
2020-05-13 09:08:37 +00:00
|
|
|
before_action :authorize_read_actual_head_pipeline!, only: [
|
|
|
|
:test_reports,
|
|
|
|
:exposed_artifacts,
|
|
|
|
:coverage_reports,
|
|
|
|
:terraform_reports,
|
2020-12-08 15:09:45 +00:00
|
|
|
:accessibility_reports,
|
2021-02-03 18:09:25 +00:00
|
|
|
:codequality_reports,
|
|
|
|
:codequality_mr_diff_reports
|
2020-05-13 09:08:37 +00:00
|
|
|
]
|
2017-11-07 13:34:12 +00:00
|
|
|
before_action :set_issuables_index, only: [:index]
|
2016-10-07 16:16:42 +00:00
|
|
|
before_action :authenticate_user!, only: [:assign_related_issues]
|
2017-12-20 09:01:21 +00:00
|
|
|
before_action :check_user_can_push_to_source_branch!, only: [:rebase]
|
2022-02-15 15:15:04 +00:00
|
|
|
|
2019-10-09 21:06:24 +00:00
|
|
|
before_action only: [:show] do
|
2020-06-11 12:08:54 +00:00
|
|
|
push_frontend_feature_flag(:file_identifier_hash)
|
2022-02-16 06:12:24 +00:00
|
|
|
push_frontend_feature_flag(:merge_request_widget_graphql, project, default_enabled: :yaml)
|
|
|
|
push_frontend_feature_flag(:core_security_mr_widget_counts, project)
|
|
|
|
push_frontend_feature_flag(:paginated_notes, project, default_enabled: :yaml)
|
|
|
|
push_frontend_feature_flag(:confidential_notes, project, default_enabled: :yaml)
|
2021-08-25 12:11:32 +00:00
|
|
|
push_frontend_feature_flag(:restructured_mr_widget, project, default_enabled: :yaml)
|
2022-02-16 06:12:24 +00:00
|
|
|
push_frontend_feature_flag(:refactor_mr_widgets_extensions, project, default_enabled: :yaml)
|
2022-04-20 15:10:23 +00:00
|
|
|
push_frontend_feature_flag(:refactor_mr_widget_test_summary, project, default_enabled: :yaml)
|
2022-02-16 06:12:24 +00:00
|
|
|
push_frontend_feature_flag(:rebase_without_ci_ui, project, default_enabled: :yaml)
|
2022-03-15 12:07:44 +00:00
|
|
|
push_frontend_feature_flag(:issue_assignees_widget, @project, default_enabled: :yaml)
|
2022-04-01 18:08:46 +00:00
|
|
|
push_frontend_feature_flag(:realtime_labels, project, default_enabled: :yaml)
|
2022-04-20 21:08:12 +00:00
|
|
|
push_frontend_feature_flag(:updated_diff_expansion_buttons, project, default_enabled: :yaml)
|
2019-10-09 21:06:24 +00:00
|
|
|
end
|
2016-10-07 16:16:42 +00:00
|
|
|
|
2022-02-15 15:15:04 +00:00
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:permit_all_shared_groups_for_approval, @project, default_enabled: :yaml)
|
|
|
|
end
|
|
|
|
|
2019-06-22 18:05:17 +00:00
|
|
|
around_action :allow_gitaly_ref_name_caching, only: [:index, :show, :discussions]
|
2019-04-04 20:22:11 +00:00
|
|
|
|
2020-09-18 06:09:31 +00:00
|
|
|
after_action :log_merge_request_show, only: [:show]
|
|
|
|
|
2020-10-02 12:09:03 +00:00
|
|
|
feature_category :code_review, [
|
|
|
|
:assign_related_issues, :bulk_update, :cancel_auto_merge,
|
2021-04-12 15:09:30 +00: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 18:15:19 +00:00
|
|
|
feature_category :code_testing, [:test_reports, :coverage_reports]
|
|
|
|
feature_category :code_quality, [:codequality_reports, :codequality_mr_diff_reports]
|
2022-01-13 15:14:46 +00:00
|
|
|
feature_category :code_testing, [:accessibility_reports]
|
2021-01-07 12:10:24 +00:00
|
|
|
feature_category :infrastructure_as_code, [:terraform_reports]
|
2021-04-12 15:09:30 +00:00
|
|
|
feature_category :continuous_integration, [:pipeline_status, :pipelines, :exposed_artifacts]
|
2020-07-07 09:08:57 +00:00
|
|
|
|
2021-12-07 12:10:33 +00:00
|
|
|
urgency :high, [:export_csv]
|
2021-12-09 12:15:43 +00:00
|
|
|
urgency :low, [
|
|
|
|
:index,
|
|
|
|
:show,
|
|
|
|
:commits,
|
|
|
|
:bulk_update,
|
|
|
|
:edit,
|
|
|
|
:update,
|
|
|
|
:cancel_auto_merge,
|
|
|
|
:merge,
|
|
|
|
:ci_environments_status,
|
|
|
|
:destroy,
|
|
|
|
:rebase,
|
2022-02-24 18:19:04 +00:00
|
|
|
:discussions,
|
2022-03-23 09:07:30 +00:00
|
|
|
:pipelines,
|
|
|
|
:test_reports
|
2021-12-09 12:15:43 +00:00
|
|
|
]
|
2022-03-24 12:07:26 +00:00
|
|
|
urgency :low, [
|
|
|
|
:codequality_mr_diff_reports,
|
2022-03-25 03:08:30 +00:00
|
|
|
:codequality_reports
|
2022-03-24 12:07:26 +00:00
|
|
|
]
|
2022-04-27 15:10:01 +00:00
|
|
|
urgency :low, [:pipeline_status, :pipelines, :exposed_artifacts]
|
2021-12-07 12:10:33 +00:00
|
|
|
|
2011-11-28 07:39:43 +00:00
|
|
|
def index
|
2017-11-07 13:34:12 +00:00
|
|
|
@merge_requests = @issuables
|
2017-02-15 22:13:53 +00:00
|
|
|
|
2015-03-12 23:20:58 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2022-03-17 21:08:35 +00:00
|
|
|
format.atom { render layout: 'xml' }
|
2015-03-12 23:20:58 +00:00
|
|
|
format.json do
|
|
|
|
render json: {
|
2018-11-27 16:53:16 +00:00
|
|
|
html: view_to_html_string("projects/merge_requests/_merge_requests")
|
2015-03-12 23:20:58 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2011-11-28 07:39:43 +00:00
|
|
|
end
|
|
|
|
|
2021-07-28 09:09:47 +00:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
2011-11-28 07:39:43 +00:00
|
|
|
def show
|
2018-06-05 11:43:29 +00:00
|
|
|
close_merge_request_if_no_source_project
|
2022-01-29 00:14:30 +00:00
|
|
|
@merge_request.check_mergeability(async: true)
|
2017-09-19 10:55:37 +00:00
|
|
|
|
2011-11-28 20:16:57 +00:00
|
|
|
respond_to do |format|
|
2017-05-09 04:15:34 +00:00
|
|
|
format.html do
|
2018-06-05 11:44:07 +00:00
|
|
|
# use next to appease Rubocop
|
|
|
|
next render('invalid') if target_branch_missing?
|
|
|
|
|
2019-09-24 18:06:05 +00:00
|
|
|
preload_assignees_for_render(@merge_request)
|
|
|
|
|
2017-06-13 22:12:31 +00:00
|
|
|
# Build a note object for comment form
|
|
|
|
@note = @project.notes.new(noteable: @merge_request)
|
|
|
|
|
|
|
|
@noteable = @merge_request
|
2020-08-04 18:09:49 +00:00
|
|
|
@commits_count = @merge_request.commits_count + @merge_request.context_commits_count
|
2021-04-29 15:10:07 +00:00
|
|
|
@diffs_count = get_diffs_count
|
2018-11-27 16:53:16 +00:00
|
|
|
@issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
|
2020-12-04 03:09:49 +00:00
|
|
|
@current_user_data = UserSerializer.new(project: @project).represent(current_user, {}, MergeRequestCurrentUserEntity).to_json
|
2019-09-16 09:06:25 +00:00
|
|
|
@show_whitespace_default = current_user.nil? || current_user.show_whitespace_in_diffs
|
2020-12-06 06:09:43 +00:00
|
|
|
@file_by_file_default = current_user&.view_diffs_file_by_file
|
2020-03-17 18:09:44 +00:00
|
|
|
@coverage_path = coverage_reports_project_merge_request_path(@project, @merge_request, format: :json) if @merge_request.has_coverage_reports?
|
2021-04-02 21:09:22 +00:00
|
|
|
@update_current_user_path = expose_path(api_v4_user_preferences_path)
|
2020-07-16 18:09:35 +00:00
|
|
|
@endpoint_metadata_url = endpoint_metadata_url(@project, @merge_request)
|
2017-06-13 22:12:31 +00:00
|
|
|
|
|
|
|
set_pipeline_variables
|
2017-09-19 10:55:37 +00:00
|
|
|
|
2022-04-06 06:08:32 +00:00
|
|
|
@number_of_pipelines = @pipelines.size
|
2021-09-07 06:11:06 +00:00
|
|
|
|
2018-02-07 10:29:01 +00:00
|
|
|
render
|
2017-05-09 04:15:34 +00:00
|
|
|
end
|
2016-06-28 16:25:32 +00:00
|
|
|
|
2016-07-03 21:01:13 +00:00
|
|
|
format.json do
|
2017-05-18 20:14:48 +00:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
|
|
|
|
2021-09-07 06:11:06 +00:00
|
|
|
if params[:serializer] == 'sidebar_extras'
|
2021-08-13 21:09:54 +00:00
|
|
|
cache_context = [
|
|
|
|
params[:serializer],
|
|
|
|
current_user&.cache_key,
|
2021-11-08 06:09:59 +00:00
|
|
|
@merge_request.merge_request_assignees.map(&:cache_key),
|
|
|
|
@merge_request.merge_request_reviewers.map(&:cache_key)
|
2021-08-13 21:09:54 +00:00
|
|
|
]
|
|
|
|
|
2021-07-28 09:09:47 +00:00
|
|
|
render_cached(@merge_request,
|
|
|
|
with: serializer,
|
2021-08-13 21:09:54 +00:00
|
|
|
cache_context: -> (_) { [Digest::SHA256.hexdigest(cache_context.to_s)] },
|
2021-07-28 09:09:47 +00:00
|
|
|
serializer: params[:serializer])
|
|
|
|
else
|
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer])
|
|
|
|
end
|
2016-07-03 21:01:13 +00:00
|
|
|
end
|
|
|
|
|
2019-01-16 12:09:29 +00:00
|
|
|
format.patch do
|
2018-04-18 09:19:40 +00:00
|
|
|
break render_404 unless @merge_request.diff_refs
|
2016-07-03 21:01:13 +00:00
|
|
|
|
|
|
|
send_git_patch @project.repository, @merge_request.diff_refs
|
2016-06-10 12:57:50 +00:00
|
|
|
end
|
2016-07-03 21:01:13 +00:00
|
|
|
|
2016-05-12 18:50:49 +00:00
|
|
|
format.diff do
|
2018-04-18 09:19:40 +00:00
|
|
|
break render_404 unless @merge_request.diff_refs
|
2016-05-12 18:50:49 +00:00
|
|
|
|
2016-06-08 12:30:15 +00:00
|
|
|
send_git_diff @project.repository, @merge_request.diff_refs
|
2016-05-12 18:50:49 +00:00
|
|
|
end
|
2012-11-22 20:50:36 +00:00
|
|
|
end
|
2012-07-04 22:26:23 +00:00
|
|
|
end
|
2021-07-28 09:09:47 +00:00
|
|
|
# rubocop:enable Metrics/AbcSize
|
2012-07-04 22:26:23 +00:00
|
|
|
|
2015-05-29 04:09:28 +00:00
|
|
|
def commits
|
2020-08-04 18:09:49 +00:00
|
|
|
# Get context commits from repository
|
|
|
|
@context_commits =
|
|
|
|
set_commits_for_rendering(
|
|
|
|
@merge_request.recent_context_commits
|
|
|
|
)
|
|
|
|
|
2017-06-13 22:12:31 +00:00
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
2017-11-10 19:57:11 +00:00
|
|
|
@commits =
|
2019-11-15 15:06:12 +00:00
|
|
|
set_commits_for_rendering(
|
2021-08-26 03:09:01 +00:00
|
|
|
@merge_request.recent_commits(load_from_gitaly: true).with_latest_pipeline(@merge_request.source_branch).with_markdown_cache,
|
2020-07-01 15:08:45 +00:00
|
|
|
commits_count: @merge_request.commits_count
|
2019-11-15 15:06:12 +00:00
|
|
|
)
|
2016-08-04 13:56:54 +00:00
|
|
|
|
2017-06-13 22:12:31 +00:00
|
|
|
render json: { html: view_to_html_string('projects/merge_requests/_commits') }
|
2016-07-27 16:54:04 +00:00
|
|
|
end
|
|
|
|
|
2016-07-23 00:28:39 +00:00
|
|
|
def pipelines
|
2019-06-28 14:40:34 +00:00
|
|
|
set_pipeline_variables
|
2021-06-30 18:07:05 +00:00
|
|
|
@pipelines = @pipelines.page(params[:page])
|
2016-07-26 00:30:52 +00:00
|
|
|
|
2017-06-13 22:12:31 +00:00
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
2017-04-05 14:36:14 +00:00
|
|
|
|
2022-04-06 06:08:32 +00:00
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@pipelines),
|
|
|
|
count: {
|
|
|
|
all: @pipelines.count
|
2017-07-14 15:52:54 +00:00
|
|
|
}
|
2022-04-06 06:08:32 +00:00
|
|
|
}
|
2011-11-28 07:39:43 +00:00
|
|
|
end
|
|
|
|
|
2021-02-10 09:09:38 +00: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 15:08:59 +00:00
|
|
|
def context_commits
|
|
|
|
# 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 06:05:07 +00:00
|
|
|
def test_reports
|
2019-04-16 11:06:52 +00:00
|
|
|
reports_response(@merge_request.compare_test_reports)
|
2018-08-02 06:05:07 +00:00
|
|
|
end
|
|
|
|
|
2020-05-13 09:08:37 +00: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 18:09:44 +00: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 18:09:25 +00:00
|
|
|
def codequality_mr_diff_reports
|
2021-07-02 18:08:28 +00:00
|
|
|
reports_response(@merge_request.find_codequality_mr_diff_reports, head_pipeline)
|
2021-02-03 18:09:25 +00:00
|
|
|
end
|
|
|
|
|
2020-12-08 15:09:45 +00:00
|
|
|
def codequality_reports
|
|
|
|
reports_response(@merge_request.compare_codequality_reports)
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
def terraform_reports
|
|
|
|
reports_response(@merge_request.find_terraform_reports)
|
|
|
|
end
|
|
|
|
|
2019-10-21 15:05:58 +00: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 12:04:24 +00:00
|
|
|
def edit
|
2017-06-13 22:12:31 +00:00
|
|
|
define_edit_vars
|
2015-12-08 12:04:24 +00:00
|
|
|
end
|
|
|
|
|
2011-11-28 07:39:43 +00:00
|
|
|
def update
|
2021-05-12 03:10:21 +00:00
|
|
|
@merge_request = ::MergeRequests::UpdateService.new(project: project, current_user: current_user, params: merge_request_update_params).execute(@merge_request)
|
2014-02-18 14:24:19 +00:00
|
|
|
|
2017-01-16 18:43:03 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2018-10-12 15:06:56 +00:00
|
|
|
if @merge_request.errors.present?
|
2017-06-13 22:12:31 +00:00
|
|
|
define_edit_vars
|
|
|
|
|
2017-01-16 18:43:03 +00:00
|
|
|
render :edit
|
2018-10-12 15:06:56 +00:00
|
|
|
else
|
|
|
|
redirect_to project_merge_request_path(@merge_request.target_project, @merge_request)
|
2015-03-06 13:03:41 +00:00
|
|
|
end
|
2014-02-18 14:24:19 +00:00
|
|
|
end
|
2017-01-16 18:43:03 +00:00
|
|
|
|
|
|
|
format.json do
|
2018-10-12 15:06:56 +00:00
|
|
|
if merge_request.errors.present?
|
|
|
|
render json: @merge_request.errors, status: :bad_request
|
|
|
|
else
|
2021-12-02 09:10:59 +00:00
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer] || 'basic')
|
2018-10-12 15:06:56 +00:00
|
|
|
end
|
2017-01-16 18:43:03 +00:00
|
|
|
end
|
2011-11-28 07:39:43 +00:00
|
|
|
end
|
2016-08-01 15:34:17 +00:00
|
|
|
rescue ActiveRecord::StaleObjectError
|
2017-06-13 22:12:31 +00:00
|
|
|
define_edit_vars if request.format.html?
|
|
|
|
|
2017-01-16 18:43:03 +00:00
|
|
|
render_conflict_response
|
2011-11-28 07:39:43 +00:00
|
|
|
end
|
|
|
|
|
2016-02-27 03:34:32 +00:00
|
|
|
def remove_wip
|
2017-06-13 22:12:31 +00:00
|
|
|
@merge_request = ::MergeRequests::UpdateService
|
2021-05-12 03:10:21 +00:00
|
|
|
.new(project: project, current_user: current_user, params: { wip_event: 'unwip' })
|
2017-05-09 04:15:34 +00:00
|
|
|
.execute(@merge_request)
|
2016-02-27 03:34:32 +00:00
|
|
|
|
2017-12-07 21:56:59 +00:00
|
|
|
render json: serialize_widget(@merge_request)
|
2016-02-27 03:34:32 +00:00
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
def commit_change_content
|
|
|
|
render partial: 'projects/merge_requests/widget/commit_change_content', layout: false
|
2012-04-16 19:08:03 +00:00
|
|
|
end
|
|
|
|
|
2019-05-22 11:45:27 +00:00
|
|
|
def cancel_auto_merge
|
|
|
|
unless @merge_request.can_cancel_auto_merge?(current_user)
|
2016-10-27 12:04:43 +00:00
|
|
|
return access_denied!
|
|
|
|
end
|
2015-11-02 16:27:38 +00:00
|
|
|
|
2019-05-22 11:45:27 +00:00
|
|
|
AutoMergeService.new(project, current_user).cancel(@merge_request)
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2017-12-07 21:56:59 +00:00
|
|
|
render json: serialize_widget(@merge_request)
|
2015-11-02 16:27:38 +00:00
|
|
|
end
|
|
|
|
|
2015-08-11 12:33:31 +00:00
|
|
|
def merge
|
2018-10-24 09:14:16 +00:00
|
|
|
access_check_result = merge_access_check
|
|
|
|
|
|
|
|
return access_check_result if access_check_result
|
2013-02-27 18:20:31 +00:00
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
status = merge!
|
2015-11-02 16:27:38 +00:00
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
if @merge_request.merge_error
|
|
|
|
render json: { status: status, merge_error: @merge_request.merge_error }
|
2012-04-16 20:05:08 +00:00
|
|
|
else
|
2017-05-09 04:15:34 +00:00
|
|
|
render json: { status: status }
|
2012-04-16 20:05:08 +00:00
|
|
|
end
|
2012-03-29 15:03:05 +00:00
|
|
|
end
|
|
|
|
|
2016-08-08 22:30:01 +00:00
|
|
|
def assign_related_issues
|
2021-05-12 03:10:21 +00:00
|
|
|
result = ::MergeRequests::AssignIssuesService.new(project: project, current_user: current_user, params: { merge_request: @merge_request }).execute
|
2016-08-08 22:30:01 +00:00
|
|
|
|
2017-06-13 22:12:31 +00: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 22:30:01 +00:00
|
|
|
end
|
2017-06-13 22:12:31 +00:00
|
|
|
|
|
|
|
redirect_to(merge_request_path(@merge_request))
|
2016-08-08 22:30:01 +00:00
|
|
|
end
|
|
|
|
|
2017-03-17 06:58:12 +00:00
|
|
|
def pipeline_status
|
2017-02-27 19:17:21 +00:00
|
|
|
render json: PipelineSerializer
|
2017-05-09 04:15:34 +00:00
|
|
|
.new(project: @project, current_user: @current_user)
|
2019-07-22 18:16:15 +00:00
|
|
|
.represent_status(head_pipeline)
|
2017-02-27 19:17:21 +00:00
|
|
|
end
|
|
|
|
|
2016-10-07 22:10:06 +00:00
|
|
|
def ci_environments_status
|
2019-11-29 15:06:43 +00:00
|
|
|
environments =
|
|
|
|
if ci_environments_status_on_merge_result?
|
2020-01-10 03:07:46 +00:00
|
|
|
EnvironmentStatus.for_deployed_merge_request(@merge_request, current_user)
|
2019-11-29 15:06:43 +00:00
|
|
|
else
|
|
|
|
EnvironmentStatus.for_merge_request(@merge_request, current_user)
|
|
|
|
end
|
2016-10-05 11:52:15 +00:00
|
|
|
|
2018-10-09 16:17:40 +00:00
|
|
|
render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments)
|
2012-12-11 03:14:05 +00:00
|
|
|
end
|
|
|
|
|
2017-12-20 09:01:21 +00:00
|
|
|
def rebase
|
2019-06-21 16:56:47 +00:00
|
|
|
@merge_request.rebase_async(current_user.id)
|
2017-12-20 09:01:21 +00:00
|
|
|
|
2018-11-22 17:47:29 +00:00
|
|
|
head :ok
|
2019-10-22 00:06:05 +00:00
|
|
|
rescue MergeRequest::RebaseLockTimeout => e
|
|
|
|
render json: { merge_error: e.message }, status: :conflict
|
2017-12-20 09:01:21 +00:00
|
|
|
end
|
|
|
|
|
2018-12-16 16:00:43 +00:00
|
|
|
def discussions
|
2019-09-16 15:06:26 +00:00
|
|
|
merge_request.discussions_diffs.load_highlight
|
2018-12-16 16:00:43 +00:00
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2020-10-28 09:08:37 +00: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 15:12:47 +00: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 09:08:37 +00:00
|
|
|
redirect_to(index_path, notice: message)
|
|
|
|
end
|
|
|
|
|
2011-11-28 07:39:43 +00:00
|
|
|
protected
|
|
|
|
|
2016-03-15 16:18:47 +00:00
|
|
|
alias_method :subscribable_resource, :merge_request
|
2016-03-21 13:12:52 +00:00
|
|
|
alias_method :issuable, :merge_request
|
2016-04-16 19:09:08 +00:00
|
|
|
alias_method :awardable, :merge_request
|
2011-12-15 21:57:46 +00:00
|
|
|
|
2019-08-21 10:13:45 +00:00
|
|
|
def sorting_field
|
2019-01-07 00:00:48 +00:00
|
|
|
MergeRequest::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:27:38 +00:00
|
|
|
def merge_params
|
2017-06-21 15:30:45 +00:00
|
|
|
params.permit(merge_params_attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_params_attributes
|
2019-11-15 15:06:12 +00:00
|
|
|
MergeRequest::KNOWN_MERGE_PARAMS
|
2015-11-02 16:27:38 +00:00
|
|
|
end
|
|
|
|
|
2019-05-22 11:45:27 +00: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 16:13:56 +00:00
|
|
|
end
|
2016-06-28 16:25:32 +00:00
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
private
|
|
|
|
|
2021-04-29 15:10:07 +00: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 15:08:56 +00:00
|
|
|
def merge_request_update_params
|
|
|
|
merge_request_params.merge!(params.permit(:merge_request_diff_head_sha))
|
|
|
|
end
|
|
|
|
|
2019-07-22 18:16:15 +00: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 11:34:41 +00:00
|
|
|
def ci_environments_status_on_merge_result?
|
|
|
|
params[:environment_target] == 'merge_commit'
|
|
|
|
end
|
|
|
|
|
2018-06-05 11:44:07 +00:00
|
|
|
def target_branch_missing?
|
|
|
|
@merge_request.has_no_commits? && !@merge_request.target_branch_exists?
|
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
def merge!
|
2019-05-22 11:45:27 +00:00
|
|
|
# Disable the CI check if auto_merge_strategy is specified since we have
|
2017-05-09 04:15:34 +00:00
|
|
|
# to wait until CI completes to know
|
2019-05-22 11:45:27 +00:00
|
|
|
unless @merge_request.mergeable?(skip_ci_check: auto_merge_requested?)
|
2017-05-09 04:15:34 +00:00
|
|
|
return :failed
|
|
|
|
end
|
|
|
|
|
2021-05-12 03:10:21 +00:00
|
|
|
merge_service = ::MergeRequests::MergeService.new(project: @project, current_user: current_user, params: merge_params)
|
2018-10-24 09:14:16 +00:00
|
|
|
|
|
|
|
unless merge_service.hooks_validation_pass?(@merge_request)
|
|
|
|
return :hook_validation_error
|
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
return :sha_mismatch if params[:sha] != @merge_request.diff_head_sha
|
|
|
|
|
2019-11-15 15:06:12 +00:00
|
|
|
@merge_request.update(merge_error: nil, squash: params.fetch(:squash, false))
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2019-05-22 11:45:27 +00:00
|
|
|
if auto_merge_requested?
|
2019-06-06 07:25:06 +00:00
|
|
|
if merge_request.auto_merge_enabled?
|
|
|
|
# TODO: We should have a dedicated endpoint for updating merge params.
|
2019-09-18 14:02:45 +00:00
|
|
|
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/63130.
|
2019-06-06 07:25:06 +00: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 04:15:34 +00:00
|
|
|
else
|
2018-05-30 16:18:04 +00:00
|
|
|
@merge_request.merge_async(current_user.id, merge_params)
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
:success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-07 21:56:59 +00:00
|
|
|
def serialize_widget(merge_request)
|
2020-04-21 15:21:10 +00: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 21:56:59 +00:00
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
def serializer
|
2020-04-21 15:21:10 +00:00
|
|
|
@serializer ||= MergeRequestSerializer.new(current_user: current_user, project: merge_request.project)
|
2017-05-09 04:15:34 +00:00
|
|
|
end
|
2017-06-13 22:12:31 +00:00
|
|
|
|
|
|
|
def define_edit_vars
|
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
2018-09-12 16:39:34 +00:00
|
|
|
@noteable = @merge_request
|
2018-09-14 15:59:28 +00: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 12:29:19 +00:00
|
|
|
@mr_presenter = @merge_request.present(current_user: current_user)
|
2017-06-13 22:12:31 +00:00
|
|
|
end
|
2017-11-07 13:34:12 +00:00
|
|
|
|
2018-02-20 12:33:49 +00:00
|
|
|
def finder_type
|
|
|
|
MergeRequestsFinder
|
2017-11-07 13:34:12 +00:00
|
|
|
end
|
2017-12-20 09:01:21 +00: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 18:09:45 +00:00
|
|
|
.new(current_user, container: @merge_request.source_project)
|
2017-12-20 09:01:21 +00:00
|
|
|
.can_push_to_branch?(@merge_request.source_branch)
|
|
|
|
|
|
|
|
access_denied! unless access_check
|
2022-02-10 18:18:16 +00:00
|
|
|
|
|
|
|
access_denied! unless merge_request.permits_force_push?
|
2017-12-20 09:01:21 +00:00
|
|
|
end
|
2018-01-15 15:21:04 +00:00
|
|
|
|
2018-10-24 09:14:16 +00:00
|
|
|
def merge_access_check
|
|
|
|
access_denied! unless @merge_request.can_be_merged_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2021-03-16 18:11:53 +00:00
|
|
|
def disable_query_limiting
|
2021-03-25 03:09:35 +00: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 15:21:04 +00:00
|
|
|
end
|
2019-04-16 11:06:52 +00:00
|
|
|
|
2020-09-10 12:08:54 +00: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 11:06:52 +00: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 15:06:33 +00:00
|
|
|
raise "Failed to build comparison response as comparison yielded unknown status '#{report_comparison[:status]}'"
|
2019-04-16 11:06:52 +00:00
|
|
|
end
|
|
|
|
end
|
2019-08-21 05:42:28 +00:00
|
|
|
|
2020-09-18 06:09:31 +00: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 15:05:58 +00:00
|
|
|
def authorize_read_actual_head_pipeline!
|
2019-08-21 05:42:28 +00:00
|
|
|
return render_404 unless can?(current_user, :read_build, merge_request.actual_head_pipeline)
|
|
|
|
end
|
2020-07-16 18:09:35 +00:00
|
|
|
|
|
|
|
def endpoint_metadata_url(project, merge_request)
|
2022-03-09 12:07:06 +00:00
|
|
|
params = request.query_parameters.merge(view: 'inline', diff_head: true)
|
2020-09-16 06:09:24 +00:00
|
|
|
|
2020-07-16 18:09:35 +00:00
|
|
|
diffs_metadata_project_json_merge_request_path(project, merge_request, 'json', params)
|
|
|
|
end
|
2011-11-28 07:39:43 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Projects::MergeRequestsController.prepend_mod_with('Projects::MergeRequestsController')
|