Raw gitlab automerge feature
This commit is contained in:
parent
8ee0993fdf
commit
78d620b3b6
|
@ -2,7 +2,7 @@ class MergeRequestsController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :project
|
before_filter :project
|
||||||
before_filter :module_enabled
|
before_filter :module_enabled
|
||||||
before_filter :merge_request, :only => [:edit, :update, :destroy, :show, :commits, :diffs]
|
before_filter :merge_request, :only => [:edit, :update, :destroy, :show, :commits, :diffs, :automerge]
|
||||||
layout "project"
|
layout "project"
|
||||||
|
|
||||||
# Authorize
|
# Authorize
|
||||||
|
@ -95,6 +95,22 @@ class MergeRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def automerge
|
||||||
|
message = ""
|
||||||
|
if GitlabMerge.new(@merge_request).merge
|
||||||
|
@merge_request.update_attributes(
|
||||||
|
:author_id_of_changes => current_user.id,
|
||||||
|
:closed => true
|
||||||
|
)
|
||||||
|
@merge_request.reload_code
|
||||||
|
message = "Successfully merged"
|
||||||
|
else
|
||||||
|
message = "Can not be merged"
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to [@merge_request.project, @merge_request], :alert => message
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@merge_request.destroy
|
@merge_request.destroy
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ Gitlab::Application.routes.draw do
|
||||||
resources :merge_requests do
|
resources :merge_requests do
|
||||||
member do
|
member do
|
||||||
get :diffs
|
get :diffs
|
||||||
|
get :automerge
|
||||||
end
|
end
|
||||||
|
|
||||||
collection do
|
collection do
|
||||||
|
|
26
lib/gitlab_merge.rb
Normal file
26
lib/gitlab_merge.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
class GitlabMerge
|
||||||
|
attr_accessor :project, :merge_path, :merge_request
|
||||||
|
|
||||||
|
def initialize(merge_request)
|
||||||
|
self.merge_request = merge_request
|
||||||
|
self.project = merge_request.project
|
||||||
|
self.merge_path = File.join(Rails.root, "tmp", "merge_repo", project.path)
|
||||||
|
FileUtils.rm_rf(merge_path)
|
||||||
|
FileUtils.mkdir_p merge_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def merge
|
||||||
|
self.project.repo.git.clone({:branch => merge_request.target_branch}, project.url_to_repo, merge_path)
|
||||||
|
output = ""
|
||||||
|
Dir.chdir(merge_path) do
|
||||||
|
merge_repo = Grit::Repo.new('.')
|
||||||
|
output = merge_repo.git.pull({}, "origin", merge_request.source_branch)
|
||||||
|
if output =~ /Automatic merge failed/
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
merge_repo.git.push({}, "origin", merge_request.target_branch)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue