Commit 3d50b99d authored by Dirceu Pereira Tiegs's avatar Dirceu Pereira Tiegs

Add option to create merge request when editing/creating a file

parent 6df06ded
...@@ -11,6 +11,13 @@ class @EditBlob ...@@ -11,6 +11,13 @@ class @EditBlob
if ace_mode if ace_mode
editor.getSession().setMode "ace/mode/" + 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 -> $(".js-commit-button").click ->
$("#file-content").val editor.getValue() $("#file-content").val editor.getValue()
$(".file-editor form").submit() $(".file-editor form").submit()
......
...@@ -11,6 +11,13 @@ class @NewBlob ...@@ -11,6 +11,13 @@ class @NewBlob
if ace_mode if ace_mode
editor.getSession().setMode "ace/mode/" + 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 -> $(".js-commit-button").click ->
$("#file-content").val editor.getValue() $("#file-content").val editor.getValue()
$(".file-editor form").submit() $(".file-editor form").submit()
......
...@@ -63,4 +63,8 @@ ...@@ -63,4 +63,8 @@
margin-top: 0; margin-top: 0;
padding: $gl-padding padding: $gl-padding
} }
.destination {
display: none;
}
} }
...@@ -22,6 +22,7 @@ class ApplicationController < ActionController::Base ...@@ -22,6 +22,7 @@ class ApplicationController < ActionController::Base
helper_method :abilities, :can?, :current_application_settings 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 :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| rescue_from Encoding::CompatibilityError do |exception|
log_exception(exception) log_exception(exception)
...@@ -343,4 +344,33 @@ class ApplicationController < ActionController::Base ...@@ -343,4 +344,33 @@ class ApplicationController < ActionController::Base
def git_import_enabled? def git_import_enabled?
current_application_settings.import_sources.include?('git') current_application_settings.import_sources.include?('git')
end 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 end
...@@ -27,7 +27,14 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -27,7 +27,14 @@ class Projects::BlobController < Projects::ApplicationController
if result[:status] == :success if result[:status] == :success
flash[:notice] = "The changes have been successfully committed" flash[:notice] = "The changes have been successfully committed"
respond_to do |format| 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)) } } format.json { render json: { message: "success", filePath: namespace_project_blob_path(@project.namespace, @project, File.join(@target_branch, @file_path)) } }
end end
else else
...@@ -52,7 +59,14 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -52,7 +59,14 @@ class Projects::BlobController < Projects::ApplicationController
if result[:status] == :success if result[:status] == :success
flash[:notice] = "Your changes have been successfully committed" flash[:notice] = "Your changes have been successfully committed"
respond_to do |format| 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 } } format.json { render json: { message: "success", filePath: after_edit_path } }
end end
else else
......
module MergeRequestsHelper 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) def mr_css_classes(mr)
classes = "merge-request" classes = "merge-request"
classes << " closed" if mr.closed? classes << " closed" if mr.closed?
......
...@@ -23,9 +23,17 @@ ...@@ -23,9 +23,17 @@
.col-sm-10 .col-sm-10
= text_field_tag 'new_branch', @ref, class: "form-control" = 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 'last_commit', @last_commit
= hidden_field_tag 'content', '', id: "file-content" = hidden_field_tag 'content', '', id: "file-content"
= hidden_field_tag 'from_merge_request_id', params[:from_merge_request_id] = 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 = render 'projects/commit_button', ref: @ref, cancel_path: @after_edit_path
:javascript :javascript
......
...@@ -17,7 +17,15 @@ ...@@ -17,7 +17,15 @@
.col-sm-10 .col-sm-10
= text_field_tag 'new_branch', @ref, class: "form-control js-quick-submit" = 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 'content', '', id: 'file-content'
= hidden_field_tag 'original_branch', @ref
= render 'projects/commit_button', ref: @ref, = render 'projects/commit_button', ref: @ref,
cancel_path: namespace_project_tree_path(@project.namespace, @project, @id) cancel_path: namespace_project_tree_path(@project.namespace, @project, @id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment