2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationController
|
2016-06-02 11:05:42 +05:30
|
|
|
include ToggleSubscriptionAction
|
|
|
|
include IssuableActions
|
2018-03-17 18:26:18 +05:30
|
|
|
include RendersCommits
|
2019-12-04 20:38:33 +05:30
|
|
|
include RendersAssignees
|
2016-06-16 23:09:34 +05:30
|
|
|
include ToggleAwardEmoji
|
2016-09-13 17:45:13 +05:30
|
|
|
include IssuableCollections
|
2019-03-02 22:35:43 +05:30
|
|
|
include RecordUserLastActivity
|
2020-03-13 15:44:24 +05:30
|
|
|
include SourcegraphDecorator
|
2020-11-24 15:15:51 +05:30
|
|
|
include DiffHelper
|
2021-10-27 15:23:28 +05:30
|
|
|
include Gitlab::Cache::Helpers
|
2023-03-04 22:38:38 +05:30
|
|
|
include ::Observability::ContentSecurityPolicy
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }
|
2021-01-29 00:20:46 +05:30
|
|
|
skip_before_action :merge_request, only: [:index, :bulk_update, :export_csv]
|
2023-03-04 22:38:38 +05:30
|
|
|
before_action :apply_diff_view_cookie!, only: [:show, :diffs]
|
2021-04-29 21:17:54 +05:30
|
|
|
before_action :disable_query_limiting, only: [:assign_related_issues, :update]
|
2018-03-17 18:26:18 +05:30
|
|
|
before_action :authorize_update_issuable!, only: [:close, :edit, :update, :remove_wip, :sort]
|
2020-05-24 23:13:21 +05:30
|
|
|
before_action :authorize_read_actual_head_pipeline!, only: [
|
|
|
|
:test_reports,
|
|
|
|
:exposed_artifacts,
|
|
|
|
:coverage_reports,
|
|
|
|
:terraform_reports,
|
2021-02-22 17:27:13 +05:30
|
|
|
:accessibility_reports,
|
2021-03-11 19:13:27 +05:30
|
|
|
:codequality_reports,
|
|
|
|
:codequality_mr_diff_reports
|
2020-05-24 23:13:21 +05:30
|
|
|
]
|
2018-03-17 18:26:18 +05:30
|
|
|
before_action :set_issuables_index, only: [:index]
|
2023-04-23 21:23:45 +05:30
|
|
|
before_action :check_search_rate_limit!, only: [:index], if: -> { params[:search].present? }
|
2016-11-03 12:29:30 +05:30
|
|
|
before_action :authenticate_user!, only: [:assign_related_issues]
|
2018-03-17 18:26:18 +05:30
|
|
|
before_action :check_user_can_push_to_source_branch!, only: [:rebase]
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
before_action only: :index do
|
|
|
|
push_frontend_feature_flag(:mr_approved_filter, type: :ops)
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
before_action only: [:show, :diffs] do
|
2023-06-20 00:43:36 +05:30
|
|
|
push_frontend_feature_flag(:content_editor_on_issues, project&.group)
|
|
|
|
push_force_frontend_feature_flag(:content_editor_on_issues, project&.content_editor_on_issues_feature_flag_enabled?)
|
2022-04-04 11:22:00 +05:30
|
|
|
push_frontend_feature_flag(:core_security_mr_widget_counts, project)
|
2022-07-16 23:28:13 +05:30
|
|
|
push_frontend_feature_flag(:issue_assignees_widget, @project)
|
2022-07-23 23:45:48 +05:30
|
|
|
push_frontend_feature_flag(:refactor_security_extension, @project)
|
2023-06-20 00:43:36 +05:30
|
|
|
push_frontend_feature_flag(:deprecate_vulnerabilities_feedback, @project)
|
2022-07-16 23:28:13 +05:30
|
|
|
push_frontend_feature_flag(:moved_mr_sidebar, project)
|
2023-06-20 00:43:36 +05:30
|
|
|
push_frontend_feature_flag(:single_file_file_by_file, project)
|
2022-08-13 15:12:31 +05:30
|
|
|
push_frontend_feature_flag(:mr_experience_survey, project)
|
2023-03-04 22:38:38 +05:30
|
|
|
push_frontend_feature_flag(:realtime_mr_status_change, project)
|
2023-07-09 08:55:56 +05:30
|
|
|
push_frontend_feature_flag(:realtime_approvals, project)
|
2023-05-27 22:25:52 +05:30
|
|
|
push_frontend_feature_flag(:saved_replies, current_user)
|
2023-06-20 00:43:36 +05:30
|
|
|
push_frontend_feature_flag(:code_quality_inline_drawer, project)
|
|
|
|
push_frontend_feature_flag(:hide_create_issue_resolve_all, project)
|
|
|
|
push_frontend_feature_flag(:auto_merge_labels_mr_widget, project)
|
2023-07-09 08:55:56 +05:30
|
|
|
push_force_frontend_feature_flag(:summarize_my_code_review, summarize_my_code_review_enabled?)
|
|
|
|
push_frontend_feature_flag(:mr_activity_filters, current_user)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
around_action :allow_gitaly_ref_name_caching, only: [:index, :show, :diffs, :discussions]
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
after_action :log_merge_request_show, only: [:show, :diffs]
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
feature_category :code_review_workflow, [
|
2022-10-11 01:57:18 +05:30
|
|
|
:assign_related_issues, :bulk_update, :cancel_auto_merge,
|
|
|
|
:commit_change_content, :commits, :context_commits, :destroy,
|
|
|
|
:discussions, :edit, :index, :merge, :rebase, :remove_wip,
|
2023-03-04 22:38:38 +05:30
|
|
|
:show, :diffs, :toggle_award_emoji, :toggle_subscription, :update
|
2022-10-11 01:57:18 +05:30
|
|
|
]
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
feature_category :code_testing, [:test_reports, :coverage_reports]
|
|
|
|
feature_category :code_quality, [:codequality_reports, :codequality_mr_diff_reports]
|
2022-03-02 08:16:31 +05:30
|
|
|
feature_category :code_testing, [:accessibility_reports]
|
2021-03-08 18:12:59 +05:30
|
|
|
feature_category :infrastructure_as_code, [:terraform_reports]
|
2021-04-29 21:17:54 +05:30
|
|
|
feature_category :continuous_integration, [:pipeline_status, :pipelines, :exposed_artifacts]
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
urgency :high, [:export_csv]
|
|
|
|
urgency :low, [
|
|
|
|
:index,
|
|
|
|
:show,
|
2023-03-04 22:38:38 +05:30
|
|
|
:diffs,
|
2022-01-26 12:08:38 +05:30
|
|
|
:commits,
|
|
|
|
:bulk_update,
|
|
|
|
:edit,
|
|
|
|
:update,
|
|
|
|
:cancel_auto_merge,
|
|
|
|
:merge,
|
|
|
|
:ci_environments_status,
|
|
|
|
:destroy,
|
|
|
|
:rebase,
|
2022-05-07 20:08:51 +05:30
|
|
|
:discussions,
|
2022-06-21 17:19:12 +05:30
|
|
|
:pipelines,
|
2022-08-13 15:12:31 +05:30
|
|
|
:coverage_reports,
|
2022-07-16 23:28:13 +05:30
|
|
|
:test_reports,
|
2022-06-21 17:19:12 +05:30
|
|
|
:codequality_mr_diff_reports,
|
2022-07-16 23:28:13 +05:30
|
|
|
:codequality_reports,
|
|
|
|
:terraform_reports
|
2022-01-26 12:08:38 +05:30
|
|
|
]
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low, [:pipeline_status, :pipelines, :exposed_artifacts]
|
2022-01-26 12:08:38 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def index
|
2018-03-17 18:26:18 +05:30
|
|
|
@merge_requests = @issuables
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2022-05-07 20:08:51 +05:30
|
|
|
format.atom { render layout: 'xml' }
|
2015-04-26 12:48:37 +05:30
|
|
|
format.json do
|
|
|
|
render json: {
|
2019-02-15 15:39:39 +05:30
|
|
|
html: view_to_html_string("projects/merge_requests/_merge_requests")
|
2015-04-26 12:48:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2023-03-04 22:38:38 +05:30
|
|
|
show_merge_request
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
def diffs
|
|
|
|
show_merge_request
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
def commits
|
2020-10-24 23:57:45 +05:30
|
|
|
# Get context commits from repository
|
|
|
|
@context_commits =
|
|
|
|
set_commits_for_rendering(
|
|
|
|
@merge_request.recent_context_commits
|
|
|
|
)
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
per_page = [(params[:per_page] || MergeRequestDiff::COMMITS_SAFE_SIZE).to_i, MergeRequestDiff::COMMITS_SAFE_SIZE].min
|
|
|
|
recent_commits = @merge_request.recent_commits(load_from_gitaly: true, limit: per_page, page: params[:page]).with_latest_pipeline(@merge_request.source_branch).with_markdown_cache
|
|
|
|
@next_page = recent_commits.next_page
|
|
|
|
@commits = set_commits_for_rendering(
|
|
|
|
recent_commits,
|
|
|
|
commits_count: @merge_request.commits_count
|
|
|
|
)
|
2023-07-09 08:55:56 +05:30
|
|
|
commits_count = @merge_request.preparing? ? '-' : @merge_request.commits_count + @merge_request.context_commits_count
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
render json: { html: view_to_html_string('projects/merge_requests/_commits'), next_page: @next_page, count: commits_count }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def pipelines
|
2019-07-31 22:56:46 +05:30
|
|
|
set_pipeline_variables
|
2021-09-30 23:02:18 +05:30
|
|
|
@pipelines = @pipelines.page(params[:page])
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
render json: {
|
|
|
|
pipelines: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
|
|
|
.with_pagination(request, response)
|
|
|
|
.represent(@pipelines),
|
|
|
|
count: {
|
|
|
|
all: @pipelines.count
|
2017-09-10 17:25:29 +05:30
|
|
|
}
|
2022-06-21 17:19:12 +05:30
|
|
|
}
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
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-03-13 15:44:24 +05:30
|
|
|
def context_commits
|
|
|
|
# Get commits from repository
|
|
|
|
# or from cache if already merged
|
2022-10-11 01:57:18 +05:30
|
|
|
commits = ContextCommitsFinder.new(project, @merge_request, {
|
|
|
|
search: params[:search],
|
|
|
|
author: params[:author],
|
|
|
|
committed_before: convert_date_to_epoch(params[:committed_before]),
|
|
|
|
committed_after: convert_date_to_epoch(params[:committed_after]),
|
|
|
|
limit: params[:limit]
|
|
|
|
}).execute
|
2020-03-13 15:44:24 +05:30
|
|
|
render json: CommitEntity.represent(commits, { type: :full, request: merge_request })
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
def test_reports
|
2019-07-07 11:18:12 +05:30
|
|
|
reports_response(@merge_request.compare_test_reports)
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def accessibility_reports
|
|
|
|
if @merge_request.has_accessibility_reports?
|
|
|
|
reports_response(@merge_request.compare_accessibility_reports)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def coverage_reports
|
|
|
|
if @merge_request.has_coverage_reports?
|
|
|
|
reports_response(@merge_request.find_coverage_reports)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
def codequality_mr_diff_reports
|
2021-09-30 23:02:18 +05:30
|
|
|
reports_response(@merge_request.find_codequality_mr_diff_reports, head_pipeline)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def codequality_reports
|
|
|
|
reports_response(@merge_request.compare_codequality_reports)
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
def terraform_reports
|
|
|
|
reports_response(@merge_request.find_terraform_reports)
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def exposed_artifacts
|
|
|
|
if @merge_request.has_exposed_artifacts?
|
|
|
|
reports_response(@merge_request.find_exposed_artifacts)
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def edit
|
2017-09-10 17:25:29 +05:30
|
|
|
define_edit_vars
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def update
|
2021-06-08 01:23:25 +05:30
|
|
|
@merge_request = ::MergeRequests::UpdateService.new(project: project, current_user: current_user, params: merge_request_update_params).execute(@merge_request)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2019-02-15 15:39:39 +05:30
|
|
|
if @merge_request.errors.present?
|
2017-09-10 17:25:29 +05:30
|
|
|
define_edit_vars
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
render :edit
|
2019-02-15 15:39:39 +05:30
|
|
|
else
|
|
|
|
redirect_to project_merge_request_path(@merge_request.target_project, @merge_request)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
format.json do
|
2019-02-15 15:39:39 +05:30
|
|
|
if merge_request.errors.present?
|
|
|
|
render json: @merge_request.errors, status: :bad_request
|
|
|
|
else
|
2022-01-26 12:08:38 +05:30
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer] || 'basic')
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
rescue ActiveRecord::StaleObjectError
|
2017-09-10 17:25:29 +05:30
|
|
|
define_edit_vars if request.format.html?
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
render_conflict_response
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def remove_wip
|
2017-09-10 17:25:29 +05:30
|
|
|
@merge_request = ::MergeRequests::UpdateService
|
2022-07-23 23:45:48 +05:30
|
|
|
.new(project: project, current_user: current_user, params: { wip_event: 'ready' })
|
2017-08-17 22:00:37 +05:30
|
|
|
.execute(@merge_request)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
render json: serialize_widget(@merge_request)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def commit_change_content
|
|
|
|
render partial: 'projects/merge_requests/widget/commit_change_content', layout: false
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def cancel_auto_merge
|
|
|
|
unless @merge_request.can_cancel_auto_merge?(current_user)
|
2017-08-17 22:00:37 +05:30
|
|
|
return access_denied!
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
AutoMergeService.new(project, current_user).cancel(@merge_request)
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
render json: serialize_widget(@merge_request)
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
def merge
|
2018-12-13 13:39:08 +05:30
|
|
|
access_check_result = merge_access_check
|
|
|
|
|
|
|
|
return access_check_result if access_check_result
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
status = merge!
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
Gitlab::ApplicationContext.push(merge_action_status: status.to_s)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if @merge_request.merge_error
|
|
|
|
render json: { status: status, merge_error: @merge_request.merge_error }
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2017-08-17 22:00:37 +05:30
|
|
|
render json: { status: status }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def assign_related_issues
|
2021-06-08 01:23:25 +05:30
|
|
|
result = ::MergeRequests::AssignIssuesService.new(project: project, current_user: current_user, params: { merge_request: @merge_request }).execute
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
case result[:count]
|
|
|
|
when 0
|
2023-04-23 21:23:45 +05:30
|
|
|
flash[:alert] = _("Failed to assign you issues related to the merge request.")
|
2017-09-10 17:25:29 +05:30
|
|
|
else
|
2023-04-23 21:23:45 +05:30
|
|
|
flash[:notice] = n_("An issue has been assigned to you.", "%d issues have been assigned to you.", result[:count])
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
redirect_to(merge_request_path(@merge_request))
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def pipeline_status
|
|
|
|
render json: PipelineSerializer
|
|
|
|
.new(project: @project, current_user: @current_user)
|
2019-09-04 21:01:54 +05:30
|
|
|
.represent_status(head_pipeline)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def ci_environments_status
|
2020-01-01 13:55:28 +05:30
|
|
|
environments =
|
|
|
|
if ci_environments_status_on_merge_result?
|
2020-03-13 15:44:24 +05:30
|
|
|
EnvironmentStatus.for_deployed_merge_request(@merge_request, current_user)
|
2020-01-01 13:55:28 +05:30
|
|
|
else
|
|
|
|
EnvironmentStatus.for_merge_request(@merge_request, current_user)
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def rebase
|
2022-08-27 11:52:29 +05:30
|
|
|
@merge_request.rebase_async(current_user.id, skip_ci: Gitlab::Utils.to_boolean(merge_params[:skip_ci], default: false))
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
head :ok
|
2019-12-26 22:10:19 +05:30
|
|
|
rescue MergeRequest::RebaseLockTimeout => e
|
|
|
|
render json: { merge_error: e.message }, status: :conflict
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def discussions
|
2019-12-04 20:38:33 +05:30
|
|
|
merge_request.discussions_diffs.load_highlight
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
super
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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-11-11 11:23:49 +05:30
|
|
|
message = _('Your CSV export has started. It will be emailed to %{email} when complete.') % { email: current_user.notification_email_or_default }
|
2021-01-29 00:20:46 +05:30
|
|
|
redirect_to(index_path, notice: message)
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
protected
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
alias_method :subscribable_resource, :merge_request
|
|
|
|
alias_method :issuable, :merge_request
|
2016-06-16 23:09:34 +05:30
|
|
|
alias_method :awardable, :merge_request
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def sorting_field
|
2019-03-02 22:35:43 +05:30
|
|
|
MergeRequest::SORTING_PREFERENCE_FIELD
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
def merge_params
|
2017-09-10 17:25:29 +05:30
|
|
|
params.permit(merge_params_attributes)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def merge_params_attributes
|
2019-12-26 22:10:19 +05:30
|
|
|
MergeRequest::KNOWN_MERGE_PARAMS
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
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-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
# NOTE: Remove this disable with add_prepared_state_to_mr FF removal
|
|
|
|
# rubocop: disable Metrics/AbcSize
|
2023-03-04 22:38:38 +05:30
|
|
|
def show_merge_request
|
|
|
|
close_merge_request_if_no_source_project
|
|
|
|
@merge_request.check_mergeability(async: true)
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
# NOTE: Remove the created_at check when removing the FF check
|
|
|
|
if ::Feature.enabled?(:add_prepared_state_to_mr, @merge_request.project) &&
|
|
|
|
@merge_request.created_at < 5.minutes.ago &&
|
|
|
|
!@merge_request.prepared?
|
|
|
|
|
|
|
|
@merge_request.prepare
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
# use next to appease Rubocop
|
|
|
|
next render('invalid') if target_branch_missing?
|
|
|
|
|
|
|
|
render_html_page
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
Gitlab::PollingInterval.set_header(response, interval: 10_000)
|
|
|
|
|
|
|
|
if params[:serializer] == 'sidebar_extras'
|
|
|
|
cache_context = [
|
|
|
|
params[:serializer],
|
|
|
|
current_user&.cache_key,
|
|
|
|
@merge_request.merge_request_assignees.map(&:cache_key),
|
|
|
|
@merge_request.merge_request_reviewers.map(&:cache_key)
|
|
|
|
]
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
render_cached(
|
|
|
|
@merge_request,
|
|
|
|
with: serializer,
|
|
|
|
cache_context: ->(_) { [Digest::SHA256.hexdigest(cache_context.to_s)] },
|
|
|
|
serializer: params[:serializer]
|
|
|
|
)
|
2023-03-04 22:38:38 +05:30
|
|
|
else
|
|
|
|
render json: serializer.represent(@merge_request, serializer: params[:serializer])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
format.patch do
|
2023-03-17 16:20:25 +05:30
|
|
|
next render_404 unless @merge_request.diff_refs
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
send_git_patch @project.repository, @merge_request.diff_refs
|
|
|
|
end
|
|
|
|
|
|
|
|
format.diff do
|
2023-03-17 16:20:25 +05:30
|
|
|
next render_404 unless @merge_request.diff_refs
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
send_git_diff @project.repository, @merge_request.diff_refs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
# rubocop: enable Metrics/AbcSize
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
def render_html_page
|
|
|
|
preload_assignees_for_render(@merge_request)
|
|
|
|
|
|
|
|
# Build a note object for comment form
|
|
|
|
@note = @project.notes.new(noteable: @merge_request)
|
|
|
|
|
|
|
|
@noteable = @merge_request
|
|
|
|
@commits_count = @merge_request.commits_count + @merge_request.context_commits_count
|
|
|
|
@diffs_count = get_diffs_count
|
|
|
|
@issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
|
|
|
|
@current_user_data = Gitlab::Json.dump(UserSerializer.new(project: @project).represent(current_user, {}, MergeRequestCurrentUserEntity))
|
|
|
|
@show_whitespace_default = current_user.nil? || current_user.show_whitespace_in_diffs
|
|
|
|
@file_by_file_default = current_user&.view_diffs_file_by_file
|
|
|
|
@coverage_path = coverage_reports_project_merge_request_path(@project, @merge_request, format: :json) if @merge_request.has_coverage_reports?
|
|
|
|
@update_current_user_path = expose_path(api_v4_user_preferences_path)
|
|
|
|
@endpoint_metadata_url = endpoint_metadata_url(@project, @merge_request)
|
|
|
|
@endpoint_diff_batch_url = endpoint_diff_batch_url(@project, @merge_request)
|
2023-04-23 21:23:45 +05:30
|
|
|
@diffs_batch_cache_key = @merge_request.merge_head_diff&.id if merge_request.diffs_batch_cache_with_max_age?
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
set_pipeline_variables
|
|
|
|
|
|
|
|
@number_of_pipelines = @pipelines.size
|
|
|
|
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
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-07-28 23:09:34 +05:30
|
|
|
def merge_request_update_params
|
|
|
|
merge_request_params.merge!(params.permit(:merge_request_diff_head_sha))
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def head_pipeline
|
|
|
|
strong_memoize(:head_pipeline) do
|
|
|
|
pipeline = @merge_request.head_pipeline
|
|
|
|
pipeline if can?(current_user, :read_pipeline, pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def ci_environments_status_on_merge_result?
|
|
|
|
params[:environment_target] == 'merge_commit'
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
def target_branch_missing?
|
|
|
|
@merge_request.has_no_commits? && !@merge_request.target_branch_exists?
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def merge!
|
2019-09-04 21:01:54 +05:30
|
|
|
# Disable the CI check if auto_merge_strategy is specified since we have
|
2017-08-17 22:00:37 +05:30
|
|
|
# to wait until CI completes to know
|
2019-09-04 21:01:54 +05:30
|
|
|
unless @merge_request.mergeable?(skip_ci_check: auto_merge_requested?)
|
2017-08-17 22:00:37 +05:30
|
|
|
return :failed
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
squashing = params.fetch(:squash, false)
|
2021-06-08 01:23:25 +05:30
|
|
|
merge_service = ::MergeRequests::MergeService.new(project: @project, current_user: current_user, params: merge_params)
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
unless merge_service.hooks_validation_pass?(@merge_request, validate_squash_message: squashing)
|
2018-12-13 13:39:08 +05:30
|
|
|
return :hook_validation_error
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
return :sha_mismatch if params[:sha] != @merge_request.diff_head_sha
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
@merge_request.update(merge_error: nil, squash: squashing)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
if auto_merge_requested?
|
|
|
|
if merge_request.auto_merge_enabled?
|
|
|
|
# TODO: We should have a dedicated endpoint for updating merge params.
|
2019-12-04 20:38:33 +05:30
|
|
|
# See https://gitlab.com/gitlab-org/gitlab-foss/issues/63130.
|
2019-09-04 21:01:54 +05:30
|
|
|
AutoMergeService.new(project, current_user, merge_params).update(merge_request)
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
2019-09-04 21:01:54 +05:30
|
|
|
AutoMergeService.new(project, current_user, merge_params)
|
2023-05-27 22:25:52 +05:30
|
|
|
.execute(merge_request, params[:auto_merge_strategy] || AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
else
|
2018-11-08 19:23:39 +05:30
|
|
|
@merge_request.merge_async(current_user.id, merge_params)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
:success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def serialize_widget(merge_request)
|
2020-04-22 19:07:51 +05:30
|
|
|
cached_data = serializer.represent(merge_request, serializer: 'poll_cached_widget')
|
|
|
|
widget_data = serializer.represent(merge_request, serializer: 'poll_widget')
|
|
|
|
cached_data.merge!(widget_data)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def serializer
|
2020-04-22 19:07:51 +05:30
|
|
|
@serializer ||= MergeRequestSerializer.new(current_user: current_user, project: merge_request.project)
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def define_edit_vars
|
|
|
|
@source_project = @merge_request.source_project
|
|
|
|
@target_project = @merge_request.target_project
|
2018-12-05 23:21:45 +05:30
|
|
|
@noteable = @merge_request
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
# FIXME: We have to assign a presenter to another instance variable
|
|
|
|
# due to class_name checks being made with issuable classes
|
|
|
|
@mr_presenter = @merge_request.present(current_user: current_user)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def finder_type
|
|
|
|
MergeRequestsFinder
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def check_user_can_push_to_source_branch!
|
2023-03-17 16:20:25 +05:30
|
|
|
result = MergeRequests::RebaseService
|
|
|
|
.new(project: @merge_request.source_project, current_user: current_user)
|
|
|
|
.validate(@merge_request)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
return if result.success?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
render json: { merge_error: result.message }, status: :forbidden
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def merge_access_check
|
|
|
|
access_denied! unless @merge_request.can_be_merged_by?(current_user)
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def disable_query_limiting
|
|
|
|
# Also see https://gitlab.com/gitlab-org/gitlab/-/issues/20827
|
|
|
|
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/20824')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
case report_comparison[:status]
|
|
|
|
when :parsing
|
|
|
|
::Gitlab::PollingInterval.set_header(response, interval: 3000)
|
|
|
|
|
|
|
|
render json: '', status: :no_content
|
|
|
|
when :parsed
|
2023-01-13 00:05:48 +05:30
|
|
|
render json: Gitlab::Json.dump(report_comparison[:data]), status: :ok
|
2019-07-07 11:18:12 +05:30
|
|
|
when :error
|
|
|
|
render json: { status_reason: report_comparison[:status_reason] }, status: :bad_request
|
|
|
|
else
|
2019-12-26 22:10:19 +05:30
|
|
|
raise "Failed to build comparison response as comparison yielded unknown status '#{report_comparison[:status]}'"
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def log_merge_request_show
|
|
|
|
return unless current_user && @merge_request
|
|
|
|
|
|
|
|
::Gitlab::Search::RecentMergeRequests.new(user: current_user).log_view(@merge_request)
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def authorize_read_actual_head_pipeline!
|
2019-09-04 21:01:54 +05:30
|
|
|
return render_404 unless can?(current_user, :read_build, merge_request.actual_head_pipeline)
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
def show_whitespace
|
|
|
|
current_user&.show_whitespace_in_diffs ? '0' : '1'
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def endpoint_metadata_url(project, merge_request)
|
2023-01-13 00:05:48 +05:30
|
|
|
params = request.query_parameters.merge(view: 'inline', diff_head: true, w: show_whitespace)
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
diffs_metadata_project_json_merge_request_path(project, merge_request, 'json', params)
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
def endpoint_diff_batch_url(project, merge_request)
|
|
|
|
per_page = current_user&.view_diffs_file_by_file ? '1' : '5'
|
|
|
|
params = request.query_parameters.merge(view: 'inline', diff_head: true, w: show_whitespace, page: '0', per_page: per_page)
|
2023-04-23 21:23:45 +05:30
|
|
|
params[:ck] = merge_request.merge_head_diff&.id if merge_request.diffs_batch_cache_with_max_age?
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
diffs_batch_project_json_merge_request_path(project, merge_request, 'json', params)
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
def convert_date_to_epoch(date)
|
|
|
|
Date.strptime(date, "%Y-%m-%d")&.to_time&.to_i if date
|
|
|
|
rescue Date::Error, TypeError
|
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
def summarize_my_code_review_enabled?
|
|
|
|
namespace = project&.group&.root_ancestor
|
|
|
|
return false if namespace.nil?
|
|
|
|
|
|
|
|
Feature.enabled?(:summarize_my_code_review, current_user) &&
|
|
|
|
namespace.group_namespace? &&
|
|
|
|
namespace.licensed_feature_available?(:summarize_my_mr_code_review) &&
|
|
|
|
Gitlab::Llm::StageCheck.available?(namespace, :summarize_my_mr_code_review) &&
|
|
|
|
merge_request.send_to_ai?
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Projects::MergeRequestsController.prepend_mod_with('Projects::MergeRequestsController')
|