Class: Projects::MergeRequestsController

Inherits:
Projects::MergeRequests::ApplicationController
  • Object
show all
Includes:
DiffHelper, IssuableActions, IssuableCollections, RecordUserLastActivity, RendersAssignees, RendersCommits, RendersNotes, SourcegraphDecorator, ToggleAwardEmoji, ToggleSubscriptionAction
Defined in:
app/controllers/projects/merge_requests_controller.rb

Constant Summary

Constants included from CookiesHelper

CookiesHelper::COOKIE_TYPE_ENCRYPTED, CookiesHelper::COOKIE_TYPE_PERMANENT

Instance Method Summary collapse

Methods included from DiffHelper

#apply_diff_view_cookie!, #diff_file_blob_raw_path, #diff_file_blob_raw_url, #diff_file_changed_icon, #diff_file_changed_icon_color, #diff_file_html_data, #diff_file_old_blob_raw_path, #diff_file_old_blob_raw_url, #diff_line_content, #diff_match_line, #diff_options, #diff_view, #diffs_expanded?, #editable_diff?, #inline_diff_btn, #mark_inline_diffs, #parallel_diff_btn, #parallel_diff_discussions, #render_overflow_warning?, #submodule_diff_compare_link, #submodule_link

Methods included from RecordUserLastActivity

#set_user_last_activity

Methods included from CookiesHelper

#set_secure_cookie

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from SortingPreference

#default_sort_order, #legacy_sort_cookie_name, #set_sort_order

Methods included from SortingHelper

#admin_groups_sort_options_hash, #audit_logs_sort_order_hash, #branches_sort_options_hash, #groups_sort_options_hash, #issuable_reverse_sort_order_hash, #issuable_sort_direction_button, #issuable_sort_option_overrides, #issuable_sort_option_title, #label_sort_options_hash, #member_sort_options_hash, #milestone_sort_options_hash, #packages_reverse_sort_order_hash, #packages_sort_direction_button, #packages_sort_option_title, #packages_sort_options_hash, #project_sort_direction_button, #projects_reverse_sort_options_hash, #projects_sort_option_titles, #projects_sort_options_hash, #sort_direction_button, #sort_direction_icon, #sort_options_hash, #sort_title_access_level_asc, #sort_title_access_level_desc, #sort_title_contacted_date, #sort_title_created_date, #sort_title_downvotes, #sort_title_due_date, #sort_title_due_date_later, #sort_title_due_date_soon, #sort_title_expire_date, #sort_title_label_priority, #sort_title_largest_group, #sort_title_largest_repo, #sort_title_last_joined, #sort_title_latest_activity, #sort_title_milestone, #sort_title_milestone_later, #sort_title_milestone_soon, #sort_title_most_stars, #sort_title_name, #sort_title_name_asc, #sort_title_name_desc, #sort_title_oldest_activity, #sort_title_oldest_created, #sort_title_oldest_joined, #sort_title_oldest_last_activity, #sort_title_oldest_signin, #sort_title_oldest_starred, #sort_title_oldest_updated, #sort_title_popularity, #sort_title_priority, #sort_title_recently_created, #sort_title_recently_last_activity, #sort_title_recently_signin, #sort_title_recently_starred, #sort_title_recently_updated, #sort_title_relative_position, #sort_title_size, #sort_title_stars, #sort_title_start_date_later, #sort_title_start_date_soon, #sort_title_upvotes, #sort_value_access_level_asc, #sort_value_access_level_desc, #sort_value_contacted_date, #sort_value_created_date, #sort_value_downvotes, #sort_value_due_date, #sort_value_due_date_later, #sort_value_due_date_soon, #sort_value_expire_date, #sort_value_label_priority, #sort_value_largest_group, #sort_value_largest_repo, #sort_value_last_joined, #sort_value_latest_activity, #sort_value_least_popular, #sort_value_milestone, #sort_value_milestone_later, #sort_value_milestone_soon, #sort_value_most_popular, #sort_value_name, #sort_value_name_desc, #sort_value_oldest_activity, #sort_value_oldest_created, #sort_value_oldest_joined, #sort_value_oldest_last_activity, #sort_value_oldest_signin, #sort_value_oldest_updated, #sort_value_popularity, #sort_value_priority, #sort_value_recently_created, #sort_value_recently_last_activity, #sort_value_recently_signin, #sort_value_recently_updated, #sort_value_relative_position, #sort_value_size, #sort_value_stars_asc, #sort_value_stars_desc, #sort_value_start_date_later, #sort_value_start_date_soon, #sort_value_upvotes, #sortable_item, #starrers_sort_options_hash, #subgroups_sort_options_hash, #tags_sort_options_hash, #users_sort_options_hash

Methods included from ToggleAwardEmoji

#toggle_award_emoji

Methods included from RendersAssignees

#preload_assignees_for_render

Methods included from RendersCommits

#limited_commits, #prepare_commits_for_rendering, #set_commits_for_rendering, #valid_ref?

Methods included from RendersNotes

#prepare_notes_for_rendering

Methods included from IssuableActions

#bulk_update, #check_destroy_confirmation!, #destroy, #realtime_changes

Methods included from ToggleSubscriptionAction

#toggle_subscription

Instance Method Details

#accessibility_reportsObject


168
169
170
171
172
173
174
# File 'app/controllers/projects/merge_requests_controller.rb', line 168

def accessibility_reports
  if @merge_request.has_accessibility_reports?
    reports_response(@merge_request.compare_accessibility_reports)
  else
    head :no_content
  end
end

264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'app/controllers/projects/merge_requests_controller.rb', line 264

def assign_related_issues
  result = ::MergeRequests::AssignIssuesService.new(project, current_user, merge_request: @merge_request).execute

  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"
  end

  redirect_to(merge_request_path(@merge_request))
end

#cancel_auto_mergeObject


240
241
242
243
244
245
246
247
248
# File 'app/controllers/projects/merge_requests_controller.rb', line 240

def cancel_auto_merge
  unless @merge_request.can_cancel_auto_merge?(current_user)
    return access_denied!
  end

  AutoMergeService.new(project, current_user).cancel(@merge_request)

  render json: serialize_widget(@merge_request)
end

#ci_environments_statusObject


285
286
287
288
289
290
291
292
293
294
# File 'app/controllers/projects/merge_requests_controller.rb', line 285

def ci_environments_status
  environments =
    if ci_environments_status_on_merge_result?
      EnvironmentStatus.for_deployed_merge_request(@merge_request, current_user)
    else
      EnvironmentStatus.for_merge_request(@merge_request, current_user)
    end

  render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments)
end

#commit_change_contentObject


236
237
238
# File 'app/controllers/projects/merge_requests_controller.rb', line 236

def commit_change_content
  render partial: 'projects/merge_requests/widget/commit_change_content', layout: false
end

#commitsObject


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/controllers/projects/merge_requests_controller.rb', line 120

def commits
  # Get context commits from repository
  @context_commits =
    set_commits_for_rendering(
      @merge_request.recent_context_commits
    )

  # Get commits from repository
  # or from cache if already merged
  @commits =
    set_commits_for_rendering(
      @merge_request.recent_commits.with_latest_pipeline(@merge_request.source_branch).with_markdown_cache,
      commits_count: @merge_request.commits_count
    )

  render json: { html: view_to_html_string('projects/merge_requests/_commits') }
end

#context_commitsObject


155
156
157
158
159
160
161
162
# File 'app/controllers/projects/merge_requests_controller.rb', line 155

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

#coverage_reportsObject


176
177
178
179
180
181
182
# File 'app/controllers/projects/merge_requests_controller.rb', line 176

def coverage_reports
  if @merge_request.has_coverage_reports?
    reports_response(@merge_request.find_coverage_reports)
  else
    head :no_content
  end
end

#discussionsObject


304
305
306
307
308
# File 'app/controllers/projects/merge_requests_controller.rb', line 304

def discussions
  merge_request.discussions_diffs.load_highlight

  super
end

#editObject


196
197
198
# File 'app/controllers/projects/merge_requests_controller.rb', line 196

def edit
  define_edit_vars
end

#exposed_artifactsObject


188
189
190
191
192
193
194
# File 'app/controllers/projects/merge_requests_controller.rb', line 188

def exposed_artifacts
  if @merge_request.has_exposed_artifacts?
    reports_response(@merge_request.find_exposed_artifacts)
  else
    head :no_content
  end
end

#indexObject


59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/projects/merge_requests_controller.rb', line 59

def index
  @merge_requests = @issuables

  respond_to do |format|
    format.html
    format.json do
      render json: {
        html: view_to_html_string("projects/merge_requests/_merge_requests")
      }
    end
  end
end

#mergeObject


250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'app/controllers/projects/merge_requests_controller.rb', line 250

def merge
  access_check_result = merge_access_check

  return access_check_result if access_check_result

  status = merge!

  if @merge_request.merge_error
    render json: { status: status, merge_error: @merge_request.merge_error }
  else
    render json: { status: status }
  end
end

#pipeline_statusObject


279
280
281
282
283
# File 'app/controllers/projects/merge_requests_controller.rb', line 279

def pipeline_status
  render json: PipelineSerializer
    .new(project: @project, current_user: @current_user)
    .represent_status(head_pipeline)
end

#pipelinesObject


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/projects/merge_requests_controller.rb', line 138

def pipelines
  set_pipeline_variables
  @pipelines = @pipelines.page(params[:page]).per(30)

  Gitlab::PollingInterval.set_header(response, interval: 10_000)

  render json: {
    pipelines: PipelineSerializer
      .new(project: @project, current_user: @current_user)
      .with_pagination(request, response)
      .represent(@pipelines),
    count: {
      all: @pipelines.count
    }
  }
end

#rebaseObject


296
297
298
299
300
301
302
# File 'app/controllers/projects/merge_requests_controller.rb', line 296

def rebase
  @merge_request.rebase_async(current_user.id)

  head :ok
rescue MergeRequest::RebaseLockTimeout => e
  render json: { merge_error: e.message }, status: :conflict
end

#remove_wipObject


228
229
230
231
232
233
234
# File 'app/controllers/projects/merge_requests_controller.rb', line 228

def remove_wip
  @merge_request = ::MergeRequests::UpdateService
    .new(project, current_user, wip_event: 'unwip')
    .execute(@merge_request)

  render json: serialize_widget(@merge_request)
end

#showObject


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/projects/merge_requests_controller.rb', line 72

def show
  close_merge_request_if_no_source_project
  @merge_request.check_mergeability(async: true)

  respond_to do |format|
    format.html do
      # use next to appease Rubocop
      next render('invalid') if target_branch_missing?

      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
      @issuable_sidebar = serializer.represent(@merge_request, serializer: 'sidebar')
      @current_user_data = UserSerializer.new(project: @project).represent(current_user, {}, MergeRequestUserEntity).to_json
      @show_whitespace_default = current_user.nil? || current_user.show_whitespace_in_diffs
      @file_by_file_default = Feature.enabled?(:view_diffs_file_by_file, default_enabled: true) && 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?
      @endpoint_metadata_url = (@project, @merge_request)

      set_pipeline_variables

      render
    end

    format.json do
      Gitlab::PollingInterval.set_header(response, interval: 10_000)

      render json: serializer.represent(@merge_request, serializer: params[:serializer])
    end

    format.patch do
      break render_404 unless @merge_request.diff_refs

      send_git_patch @project.repository, @merge_request.diff_refs
    end

    format.diff do
      break render_404 unless @merge_request.diff_refs

      send_git_diff @project.repository, @merge_request.diff_refs
    end
  end
end

#terraform_reportsObject


184
185
186
# File 'app/controllers/projects/merge_requests_controller.rb', line 184

def terraform_reports
  reports_response(@merge_request.find_terraform_reports)
end

#test_reportsObject


164
165
166
# File 'app/controllers/projects/merge_requests_controller.rb', line 164

def test_reports
  reports_response(@merge_request.compare_test_reports)
end

#updateObject


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'app/controllers/projects/merge_requests_controller.rb', line 200

def update
  @merge_request = ::MergeRequests::UpdateService.new(project, current_user, merge_request_update_params).execute(@merge_request)

  respond_to do |format|
    format.html do
      if @merge_request.errors.present?
        define_edit_vars

        render :edit
      else
        redirect_to project_merge_request_path(@merge_request.target_project, @merge_request)
      end
    end

    format.json do
      if merge_request.errors.present?
        render json: @merge_request.errors, status: :bad_request
      else
        render json: serializer.represent(@merge_request, serializer: 'basic')
      end
    end
  end
rescue ActiveRecord::StaleObjectError
  define_edit_vars if request.format.html?

  render_conflict_response
end