Commit d7511a4b authored by Rubén Dávila's avatar Rubén Dávila Committed by Robert Speicher
Browse files

Create reverse branch and generate MR with new branch. #3409

parent d3c24373
...@@ -2,7 +2,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -2,7 +2,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_action :module_enabled before_action :module_enabled
before_action :merge_request, only: [ before_action :merge_request, only: [
:edit, :update, :show, :diffs, :commits, :builds, :merge, :merge_check, :edit, :update, :show, :diffs, :commits, :builds, :merge, :merge_check,
:ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds :ci_status, :toggle_subscription, :cancel_merge_when_build_succeeds,
:revert
] ]
before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits, :builds] before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits, :builds]
before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds] before_action :validates_merge_request, only: [:show, :diffs, :commits, :builds]
...@@ -192,7 +193,16 @@ def merge ...@@ -192,7 +193,16 @@ def merge
end end
def revert def revert
redirect_to new_namespace_project_merge_request_url(@project.namespace, @project) @repository.find_or_create_branch(@merge_request.reverse_branch_name, @merge_request.target_branch)
url_params = { merge_request: {
source_branch: @merge_request.reverse_branch_name,
target_branch: @merge_request.target_branch,
source_project_id: @merge_request.target_project_id,
target_project_id: @merge_request.target_project_id
}}
redirect_to new_namespace_project_merge_request_url(@project.namespace, @project, url_params)
end end
def branch_from def branch_from
......
...@@ -532,4 +532,8 @@ def diff_refs ...@@ -532,4 +532,8 @@ def diff_refs
[diff_base_commit, last_commit] [diff_base_commit, last_commit]
end end
def reverse_branch_name
"revert-#{id}-#{target_branch}"
end
end end
...@@ -137,6 +137,10 @@ def add_branch(user, branch_name, target) ...@@ -137,6 +137,10 @@ def add_branch(user, branch_name, target)
find_branch(branch_name) find_branch(branch_name)
end end
def find_or_create_branch(name, ref)
find_branch(name) or add_branch(name, ref)
end
def add_tag(tag_name, ref, message = nil) def add_tag(tag_name, ref, message = nil)
expire_tags_cache expire_tags_cache
......
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