summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorrandx <dmitriy.zaporozhets@gmail.com>2012-03-30 08:05:04 +0300
committerrandx <dmitriy.zaporozhets@gmail.com>2012-03-30 08:05:04 +0300
commit411d84f385364be987380da5f0216048073609c9 (patch)
treecc9e86019b41b2d3401131bfc6dc1f685422dab1 /app
parentcd74f9da91cb1b798a8654f725b502bac256228d (diff)
downloadgitlab-ce-411d84f385364be987380da5f0216048073609c9.tar.gz
Better merge handling. show if MR can be accepted or not
Diffstat (limited to 'app')
-rw-r--r--app/controllers/merge_requests_controller.rb23
-rw-r--r--app/models/merge_request.rb32
-rw-r--r--app/views/merge_requests/show.html.haml18
3 files changed, 44 insertions, 29 deletions
diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb
index b45338d7938..d0750f68135 100644
--- a/app/controllers/merge_requests_controller.rb
+++ b/app/controllers/merge_requests_controller.rb
@@ -45,6 +45,10 @@ class MergeRequestsController < ApplicationController
# or from cache if already merged
@commits = @merge_request.commits
+ if @merge_request.unchecked?
+ @merge_request.check_if_can_be_merged
+ end
+
respond_to do |format|
format.html
format.js
@@ -96,23 +100,8 @@ class MergeRequestsController < ApplicationController
end
def automerge
- render_404 unless @merge_request.open?
-
- message = ""
-
- if GitlabMerge.new(@merge_request).merge
- @merge_request.merge!(current_user.id)
- message = "Successfully merged"
- else
- @merge_request.mark_as_unmergable
- message = "Can not be merged"
- end
-
- redirect_to [@merge_request.project, @merge_request], :alert => message
- rescue => ex
- @merge_request.mark_as_unmergable
- message = "Can not be merged"
- ensure
+ render_404 unless @merge_request.open? && @merge_request.can_be_merged?
+ message = @merge_request.automerge! ? "Successfully merged" : "Can not be merged"
redirect_to [@merge_request.project, @merge_request], :alert => message
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 6d59ce563e1..6eb54343d42 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -1,6 +1,10 @@
require File.join(Rails.root, "app/models/commit")
class MergeRequest < ActiveRecord::Base
+ UNCHECKED = 1
+ CAN_BE_MERGED = 2
+ CANNOT_BE_MERGED = 3
+
belongs_to :project
belongs_to :author, :class_name => "User"
belongs_to :assignee, :class_name => "User"
@@ -56,8 +60,21 @@ class MergeRequest < ActiveRecord::Base
self.reloaded_diffs
end
+ def unchecked?
+ state == UNCHECKED
+ end
+
def can_be_merged?
- auto_merge
+ state == CAN_BE_MERGED
+ end
+
+ def check_if_can_be_merged
+ self.state = if GitlabMerge.new(self).can_be_merged?
+ CAN_BE_MERGED
+ else
+ CANNOT_BE_MERGED
+ end
+ self.save
end
def new?
@@ -123,8 +140,7 @@ class MergeRequest < ActiveRecord::Base
end
def mark_as_unmergable
- self.auto_merge = false
- save
+ # TODO: write some code here
end
def reloaded_commits
@@ -153,6 +169,16 @@ class MergeRequest < ActiveRecord::Base
:author_id => user_id
)
end
+
+ def automerge!
+ if GitlabMerge.new(self).merge
+ self.merge!(current_user.id)
+ true
+ end
+ rescue
+ self.mark_as_unmergable
+ false
+ end
end
# == Schema Information
#
diff --git a/app/views/merge_requests/show.html.haml b/app/views/merge_requests/show.html.haml
index ea46695364c..1b8a25f2dd4 100644
--- a/app/views/merge_requests/show.html.haml
+++ b/app/views/merge_requests/show.html.haml
@@ -54,18 +54,18 @@
- if @merge_request.open? && @commits.any?
- if @merge_request.can_be_merged?
- .alert-message.block-message.success
- %p You can try to merge this request with GitLab. If failed you can always do it manually
+ .alert-message.info
+ %p
+ You can accept this request automatically. If you still want to do it manually - #{link_to "click here", "#", :class => "how_to_merge_link cwhite", :title => "How To Merge"} for instructions
.alert-actions
- = link_to "Try Merge it!", automerge_project_merge_request_path(@project, @merge_request), :class => "btn small success"
+ = link_to "Accept Merge Request", automerge_project_merge_request_path(@project, @merge_request), :class => "btn small info"
&nbsp;
- = link_to "Show how to merge", "#", :class => "how_to_merge_link btn small padded", :title => "How To Merge"
+
- else
- .alert-message.block-message
- %p This request cant be merged with GitLab. You should do it manually
- .alert-actions
- %span.btn.small.disabled Try Merge it!
- = link_to "Show how to merge", "#", :class => "how_to_merge_link btn small padded success", :title => "How To Merge"
+ .alert-message
+ %p
+ %strong This request cant be merged with GitLab. You should do it manually &nbsp;
+ = link_to "Show how to merge", "#", :class => "how_to_merge_link btn small padded", :title => "How To Merge"
= render "merge_requests/commits"