Add option to create merge request when editing/creating a file
This commit is contained in:
parent
6df06ded12
commit
3d50b99d01
8 changed files with 80 additions and 30 deletions
|
@ -11,6 +11,13 @@ class @EditBlob
|
|||
if ace_mode
|
||||
editor.getSession().setMode "ace/mode/" + ace_mode
|
||||
|
||||
$('#new_branch').keyup ->
|
||||
if $(this).val() != $('#original_branch').val()
|
||||
$('.form-group.destination').show()
|
||||
else
|
||||
$('.form-group.destination').hide()
|
||||
$('#create_merge_request').prop('checked', false)
|
||||
|
||||
$(".js-commit-button").click ->
|
||||
$("#file-content").val editor.getValue()
|
||||
$(".file-editor form").submit()
|
||||
|
|
|
@ -11,6 +11,13 @@ class @NewBlob
|
|||
if ace_mode
|
||||
editor.getSession().setMode "ace/mode/" + ace_mode
|
||||
|
||||
$('#new_branch').keyup ->
|
||||
if $(this).val() != $('#original_branch').val()
|
||||
$('.form-group.destination').show()
|
||||
else
|
||||
$('.form-group.destination').hide()
|
||||
$('#create_merge_request').prop('checked', false)
|
||||
|
||||
$(".js-commit-button").click ->
|
||||
$("#file-content").val editor.getValue()
|
||||
$(".file-editor form").submit()
|
||||
|
|
|
@ -63,4 +63,8 @@
|
|||
margin-top: 0;
|
||||
padding: $gl-padding
|
||||
}
|
||||
|
||||
.destination {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
helper_method :abilities, :can?, :current_application_settings
|
||||
helper_method :import_sources_enabled?, :github_import_enabled?, :github_import_configured?, :gitlab_import_enabled?, :gitlab_import_configured?, :bitbucket_import_enabled?, :bitbucket_import_configured?, :gitorious_import_enabled?, :google_code_import_enabled?, :fogbugz_import_enabled?, :git_import_enabled?
|
||||
helper_method :new_mr_from_push_event, :new_mr_path_for_fork_from_push_event, :new_mr_path_from_push_event
|
||||
|
||||
rescue_from Encoding::CompatibilityError do |exception|
|
||||
log_exception(exception)
|
||||
|
@ -343,4 +344,33 @@ class ApplicationController < ActionController::Base
|
|||
def git_import_enabled?
|
||||
current_application_settings.import_sources.include?('git')
|
||||
end
|
||||
|
||||
# new merge requests routing helpers
|
||||
def new_mr_path_from_push_event(event, target_branch=nil)
|
||||
target_project = event.project.forked_from_project || event.project
|
||||
new_namespace_project_merge_request_path(
|
||||
event.project.namespace,
|
||||
event.project,
|
||||
new_mr_from_push_event(event, target_project, target_branch)
|
||||
)
|
||||
end
|
||||
|
||||
def new_mr_path_for_fork_from_push_event(event, target_branch=nil)
|
||||
new_namespace_project_merge_request_path(
|
||||
event.project.namespace,
|
||||
event.project,
|
||||
new_mr_from_push_event(event, event.project.forked_from_project, target_branch)
|
||||
)
|
||||
end
|
||||
|
||||
def new_mr_from_push_event(event, target_project, target_branch)
|
||||
{
|
||||
merge_request: {
|
||||
source_project_id: event.project.id,
|
||||
target_project_id: target_project.id,
|
||||
source_branch: event.branch_name,
|
||||
target_branch: target_branch || target_project.repository.root_ref
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,14 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
if result[:status] == :success
|
||||
flash[:notice] = "The changes have been successfully committed"
|
||||
respond_to do |format|
|
||||
format.html { redirect_to namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @file_path)) }
|
||||
format.html do
|
||||
url = if params[:create_merge_request]
|
||||
new_mr_path_from_push_event(current_user.recent_push(@project.id), @ref)
|
||||
else
|
||||
namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @file_path))
|
||||
end
|
||||
redirect_to url
|
||||
end
|
||||
format.json { render json: { message: "success", filePath: namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @file_path)) } }
|
||||
end
|
||||
else
|
||||
|
@ -52,7 +59,14 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
if result[:status] == :success
|
||||
flash[:notice] = "Your changes have been successfully committed"
|
||||
respond_to do |format|
|
||||
format.html { redirect_to after_edit_path }
|
||||
format.html do
|
||||
url = if params[:create_merge_request]
|
||||
new_mr_path_from_push_event(current_user.recent_push(@project.id), @ref)
|
||||
else
|
||||
after_edit_path
|
||||
end
|
||||
redirect_to url
|
||||
end
|
||||
format.json { render json: { message: "success", filePath: after_edit_path } }
|
||||
end
|
||||
else
|
||||
|
|
|
@ -1,32 +1,4 @@
|
|||
module MergeRequestsHelper
|
||||
def new_mr_path_from_push_event(event)
|
||||
target_project = event.project.forked_from_project || event.project
|
||||
new_namespace_project_merge_request_path(
|
||||
event.project.namespace,
|
||||
event.project,
|
||||
new_mr_from_push_event(event, target_project)
|
||||
)
|
||||
end
|
||||
|
||||
def new_mr_path_for_fork_from_push_event(event)
|
||||
new_namespace_project_merge_request_path(
|
||||
event.project.namespace,
|
||||
event.project,
|
||||
new_mr_from_push_event(event, event.project.forked_from_project)
|
||||
)
|
||||
end
|
||||
|
||||
def new_mr_from_push_event(event, target_project)
|
||||
{
|
||||
merge_request: {
|
||||
source_project_id: event.project.id,
|
||||
target_project_id: target_project.id,
|
||||
source_branch: event.branch_name,
|
||||
target_branch: target_project.repository.root_ref
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def mr_css_classes(mr)
|
||||
classes = "merge-request"
|
||||
classes << " closed" if mr.closed?
|
||||
|
|
|
@ -23,9 +23,17 @@
|
|||
.col-sm-10
|
||||
= text_field_tag 'new_branch', @ref, class: "form-control"
|
||||
|
||||
.form-group.destination
|
||||
.col-sm-offset-2.col-sm-10
|
||||
.checkbox
|
||||
= label_tag :create_merge_request do
|
||||
= check_box_tag :create_merge_request, 1, false
|
||||
Start a new merge request
|
||||
|
||||
= hidden_field_tag 'last_commit', @last_commit
|
||||
= hidden_field_tag 'content', '', id: "file-content"
|
||||
= hidden_field_tag 'from_merge_request_id', params[:from_merge_request_id]
|
||||
= hidden_field_tag 'original_branch', @ref
|
||||
= render 'projects/commit_button', ref: @ref, cancel_path: @after_edit_path
|
||||
|
||||
:javascript
|
||||
|
|
|
@ -17,7 +17,15 @@
|
|||
.col-sm-10
|
||||
= text_field_tag 'new_branch', @ref, class: "form-control js-quick-submit"
|
||||
|
||||
.form-group.destination
|
||||
.col-sm-offset-2.col-sm-10
|
||||
.checkbox
|
||||
= label_tag :create_merge_request do
|
||||
= check_box_tag :create_merge_request, 1, false
|
||||
Start a new merge request
|
||||
|
||||
= hidden_field_tag 'content', '', id: 'file-content'
|
||||
= hidden_field_tag 'original_branch', @ref
|
||||
= render 'projects/commit_button', ref: @ref,
|
||||
cancel_path: namespace_project_tree_path(@project.namespace, @project, @id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue