2012-09-27 20:59:42 +02:00
|
|
|
class MergeRequestsController < ProjectResourceController
|
2012-02-06 18:40:32 +01:00
|
|
|
before_filter :module_enabled
|
2012-12-19 04:14:05 +01:00
|
|
|
before_filter :merge_request, only: [:edit, :update, :show, :commits, :diffs, :automerge, :automerge_check, :ci_status]
|
2012-11-22 21:50:36 +01:00
|
|
|
before_filter :validates_merge_request, only: [:show, :diffs]
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :define_show_vars, only: [:show, :diffs]
|
2011-12-15 22:57:46 +01:00
|
|
|
|
|
|
|
# Allow read any merge_request
|
|
|
|
before_filter :authorize_read_merge_request!
|
|
|
|
|
|
|
|
# Allow write(create) merge_request
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :authorize_write_merge_request!, only: [:new, :create]
|
2011-12-15 22:57:46 +01:00
|
|
|
|
|
|
|
# Allow modify merge_request
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :authorize_modify_merge_request!, only: [:close, :edit, :update, :sort]
|
2011-12-15 22:57:46 +01:00
|
|
|
|
2011-11-28 08:39:43 +01:00
|
|
|
def index
|
2012-10-09 21:09:46 +02:00
|
|
|
@merge_requests = MergeRequestsLoadContext.new(project, current_user, params).execute
|
2011-11-28 08:39:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2011-11-28 21:16:57 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2012-02-24 08:16:06 +01:00
|
|
|
format.js
|
2011-11-28 21:16:57 +01:00
|
|
|
|
2012-11-22 21:50:36 +01:00
|
|
|
format.diff { render text: @merge_request.to_diff }
|
|
|
|
format.patch { render text: @merge_request.to_patch }
|
|
|
|
end
|
2012-07-05 00:26:23 +02:00
|
|
|
end
|
|
|
|
|
2011-11-28 21:16:57 +01:00
|
|
|
def diffs
|
2011-11-29 19:06:37 +01:00
|
|
|
@diffs = @merge_request.diffs
|
|
|
|
@commit = @merge_request.last_commit
|
2012-02-24 21:19:47 +01:00
|
|
|
|
|
|
|
@comments_allowed = true
|
|
|
|
@line_notes = @merge_request.notes.where("line_code is not null")
|
2011-11-28 08:39:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2012-06-12 16:43:16 +02:00
|
|
|
@merge_request = @project.merge_requests.new(params[:merge_request])
|
2011-11-28 08:39:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@merge_request = @project.merge_requests.new(params[:merge_request])
|
|
|
|
@merge_request.author = current_user
|
|
|
|
|
2012-06-13 08:03:53 +02:00
|
|
|
if @merge_request.save
|
|
|
|
@merge_request.reload_code
|
|
|
|
redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.'
|
|
|
|
else
|
2012-10-09 21:09:46 +02:00
|
|
|
render action: "new"
|
2011-11-28 08:39:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-08-11 00:07:50 +02:00
|
|
|
if @merge_request.update_attributes(params[:merge_request].merge(author_id_of_changes: current_user.id))
|
2012-06-13 08:03:53 +02:00
|
|
|
@merge_request.reload_code
|
|
|
|
@merge_request.mark_as_unchecked
|
|
|
|
redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.'
|
|
|
|
else
|
|
|
|
render action: "edit"
|
2011-11-28 08:39:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-16 21:08:03 +02:00
|
|
|
def automerge_check
|
2012-10-09 21:09:46 +02:00
|
|
|
if @merge_request.unchecked?
|
2012-04-16 21:08:03 +02:00
|
|
|
@merge_request.check_if_can_be_merged
|
|
|
|
end
|
2012-08-11 00:07:50 +02:00
|
|
|
render json: {state: @merge_request.human_state}
|
2013-01-05 22:09:26 +01:00
|
|
|
rescue Gitlab::SatelliteNotExistError
|
|
|
|
render json: {state: :no_satellite}
|
2012-04-16 21:08:03 +02:00
|
|
|
end
|
|
|
|
|
2012-03-29 17:03:05 +02:00
|
|
|
def automerge
|
2012-03-30 19:49:34 +02:00
|
|
|
return access_denied! unless can?(current_user, :accept_mr, @project)
|
2012-04-16 22:05:08 +02:00
|
|
|
if @merge_request.open? && @merge_request.can_be_merged?
|
2012-06-03 20:29:20 +02:00
|
|
|
@merge_request.should_remove_source_branch = params[:should_remove_source_branch]
|
2012-04-16 22:05:08 +02:00
|
|
|
@merge_request.automerge!(current_user)
|
|
|
|
@status = true
|
|
|
|
else
|
|
|
|
@status = false
|
|
|
|
end
|
2012-03-29 17:03:05 +02:00
|
|
|
end
|
|
|
|
|
2012-03-13 22:54:49 +01:00
|
|
|
def branch_from
|
2013-01-04 07:43:25 +01:00
|
|
|
@commit = @repository.commit(params[:ref])
|
2012-08-25 00:22:45 +02:00
|
|
|
@commit = CommitDecorator.decorate(@commit)
|
2012-03-13 22:54:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def branch_to
|
2013-01-04 07:43:25 +01:00
|
|
|
@commit = @repository.commit(params[:ref])
|
2012-08-25 00:22:45 +02:00
|
|
|
@commit = CommitDecorator.decorate(@commit)
|
2012-03-13 22:54:49 +01:00
|
|
|
end
|
|
|
|
|
2012-12-11 04:14:05 +01:00
|
|
|
def ci_status
|
|
|
|
status = project.gitlab_ci_service.commit_status(merge_request.last_commit.sha)
|
|
|
|
response = { status: status }
|
|
|
|
|
|
|
|
render json: response
|
|
|
|
end
|
|
|
|
|
2011-11-28 08:39:43 +01:00
|
|
|
protected
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
@merge_request ||= @project.merge_requests.find(params[:id])
|
|
|
|
end
|
2011-12-15 22:57:46 +01:00
|
|
|
|
|
|
|
def authorize_modify_merge_request!
|
2012-02-21 23:31:18 +01:00
|
|
|
return render_404 unless can?(current_user, :modify_merge_request, @merge_request)
|
2011-12-15 22:57:46 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_merge_request!
|
2012-02-21 23:31:18 +01:00
|
|
|
return render_404 unless can?(current_user, :admin_merge_request, @merge_request)
|
2011-12-15 22:57:46 +01:00
|
|
|
end
|
2012-02-06 18:40:32 +01:00
|
|
|
|
|
|
|
def module_enabled
|
|
|
|
return render_404 unless @project.merge_requests_enabled
|
|
|
|
end
|
2012-06-29 20:55:22 +02:00
|
|
|
|
|
|
|
def validates_merge_request
|
|
|
|
# Show git not found page if target branch doesnt exist
|
2012-10-09 21:09:46 +02:00
|
|
|
return git_not_found! unless @project.repo.heads.map(&:name).include?(@merge_request.target_branch)
|
2012-06-29 20:55:22 +02:00
|
|
|
|
|
|
|
# Show git not found page if source branch doesnt exist
|
|
|
|
# and there is no saved commits between source & target branch
|
|
|
|
return git_not_found! if !@project.repo.heads.map(&:name).include?(@merge_request.source_branch) && @merge_request.commits.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def define_show_vars
|
|
|
|
# Build a note object for comment form
|
2012-08-11 00:07:50 +02:00
|
|
|
@note = @project.notes.new(noteable: @merge_request)
|
2012-06-29 20:55:22 +02:00
|
|
|
|
2012-10-09 21:09:46 +02:00
|
|
|
# Get commits from repository
|
2012-06-29 20:55:22 +02:00
|
|
|
# or from cache if already merged
|
|
|
|
@commits = @merge_request.commits
|
2012-07-22 13:08:24 +02:00
|
|
|
@commits = CommitDecorator.decorate(@commits)
|
2012-06-29 20:55:22 +02:00
|
|
|
end
|
2011-11-28 08:39:43 +01:00
|
|
|
end
|