summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDirceu Pereira Tiegs <dirceutiegs@gmail.com>2015-10-19 20:25:35 -0200
committerDirceu Pereira Tiegs <dirceutiegs@gmail.com>2015-10-19 20:25:35 -0200
commit3d50b99d016af91c06a40f7a8bf4c298e241220a (patch)
tree76a081eacbdc19ac85d014b923fa78bfc3581e18 /app
parent6df06ded12878fb7b5fb01626ea40344f22a5c5b (diff)
downloadgitlab-ce-3d50b99d016af91c06a40f7a8bf4c298e241220a.tar.gz
Add option to create merge request when editing/creating a file
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/blob/edit_blob.js.coffee7
-rw-r--r--app/assets/javascripts/blob/new_blob.js.coffee7
-rw-r--r--app/assets/stylesheets/pages/editor.scss4
-rw-r--r--app/controllers/application_controller.rb30
-rw-r--r--app/controllers/projects/blob_controller.rb18
-rw-r--r--app/helpers/merge_requests_helper.rb28
-rw-r--r--app/views/projects/blob/edit.html.haml8
-rw-r--r--app/views/projects/blob/new.html.haml8
8 files changed, 80 insertions, 30 deletions
diff --git a/app/assets/javascripts/blob/edit_blob.js.coffee b/app/assets/javascripts/blob/edit_blob.js.coffee
index 050888f9c15..a6f65642d78 100644
--- a/app/assets/javascripts/blob/edit_blob.js.coffee
+++ b/app/assets/javascripts/blob/edit_blob.js.coffee
@@ -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()
diff --git a/app/assets/javascripts/blob/new_blob.js.coffee b/app/assets/javascripts/blob/new_blob.js.coffee
index 1f36a53f191..f4e06ad088b 100644
--- a/app/assets/javascripts/blob/new_blob.js.coffee
+++ b/app/assets/javascripts/blob/new_blob.js.coffee
@@ -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()
diff --git a/app/assets/stylesheets/pages/editor.scss b/app/assets/stylesheets/pages/editor.scss
index 1d565477dd4..6bc9b1c3eaf 100644
--- a/app/assets/stylesheets/pages/editor.scss
+++ b/app/assets/stylesheets/pages/editor.scss
@@ -63,4 +63,8 @@
margin-top: 0;
padding: $gl-padding
}
+
+ .destination {
+ display: none;
+ }
}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index f0124c6bd60..258e37e98c0 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index 8cc2f21d887..f49c094b591 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -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
diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb
index 728d877ace2..7e8f61fd274 100644
--- a/app/helpers/merge_requests_helper.rb
+++ b/app/helpers/merge_requests_helper.rb
@@ -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?
diff --git a/app/views/projects/blob/edit.html.haml b/app/views/projects/blob/edit.html.haml
index a811adc5094..26216462707 100644
--- a/app/views/projects/blob/edit.html.haml
+++ b/app/views/projects/blob/edit.html.haml
@@ -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
diff --git a/app/views/projects/blob/new.html.haml b/app/views/projects/blob/new.html.haml
index 7975137c37f..0439e55131e 100644
--- a/app/views/projects/blob/new.html.haml
+++ b/app/views/projects/blob/new.html.haml
@@ -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)