Commit 8269a3a735d6b1195ef0263716845ef3d2ab3327
1 parent
f1454504
Exists in
master
and in
4 other branches
Auto-merge: checking via AJAX
Showing
6 changed files
with
43 additions
and
10 deletions
Show diff stats
app/assets/javascripts/merge_requests.js
| 1 | var MergeRequest = { | 1 | var MergeRequest = { |
| 2 | diffs_loaded: false, | 2 | diffs_loaded: false, |
| 3 | commits_loaded: false, | 3 | commits_loaded: false, |
| 4 | + opts: false, | ||
| 4 | 5 | ||
| 5 | init: | 6 | init: |
| 6 | - function() { | 7 | + function(opts) { |
| 8 | + this.opts = opts; | ||
| 9 | + | ||
| 10 | + if($(".automerge_widget").lenght){ | ||
| 11 | + $.get(opts.url_to_automerge_check, function(data){ | ||
| 12 | + $(".automerge_widget").hide(); | ||
| 13 | + $(".automerge_widget." + data.state).show(); | ||
| 14 | + }, "json"); | ||
| 15 | + } | ||
| 16 | + | ||
| 7 | $(".tabs a").live("click", function() { | 17 | $(".tabs a").live("click", function() { |
| 8 | $(".tabs a").parent().removeClass("active"); | 18 | $(".tabs a").parent().removeClass("active"); |
| 9 | $(this).parent().addClass("active"); | 19 | $(this).parent().addClass("active"); |
app/controllers/merge_requests_controller.rb
| @@ -2,7 +2,7 @@ class MergeRequestsController < ApplicationController | @@ -2,7 +2,7 @@ class MergeRequestsController < ApplicationController | ||
| 2 | before_filter :authenticate_user! | 2 | before_filter :authenticate_user! |
| 3 | before_filter :project | 3 | before_filter :project |
| 4 | before_filter :module_enabled | 4 | before_filter :module_enabled |
| 5 | - before_filter :merge_request, :only => [:edit, :update, :destroy, :show, :commits, :diffs, :automerge] | 5 | + before_filter :merge_request, :only => [:edit, :update, :destroy, :show, :commits, :diffs, :automerge, :automerge_check] |
| 6 | layout "project" | 6 | layout "project" |
| 7 | 7 | ||
| 8 | # Authorize | 8 | # Authorize |
| @@ -45,10 +45,6 @@ class MergeRequestsController < ApplicationController | @@ -45,10 +45,6 @@ class MergeRequestsController < ApplicationController | ||
| 45 | # or from cache if already merged | 45 | # or from cache if already merged |
| 46 | @commits = @merge_request.commits | 46 | @commits = @merge_request.commits |
| 47 | 47 | ||
| 48 | - if @merge_request.unchecked? | ||
| 49 | - @merge_request.check_if_can_be_merged | ||
| 50 | - end | ||
| 51 | - | ||
| 52 | respond_to do |format| | 48 | respond_to do |format| |
| 53 | format.html | 49 | format.html |
| 54 | format.js | 50 | format.js |
| @@ -100,6 +96,13 @@ class MergeRequestsController < ApplicationController | @@ -100,6 +96,13 @@ class MergeRequestsController < ApplicationController | ||
| 100 | end | 96 | end |
| 101 | end | 97 | end |
| 102 | 98 | ||
| 99 | + def automerge_check | ||
| 100 | + if @merge_request.unchecked? | ||
| 101 | + @merge_request.check_if_can_be_merged | ||
| 102 | + end | ||
| 103 | + render :json => {:state => @merge_request.human_state} | ||
| 104 | + end | ||
| 105 | + | ||
| 103 | def automerge | 106 | def automerge |
| 104 | render_404 unless @merge_request.open? && @merge_request.can_be_merged? | 107 | render_404 unless @merge_request.open? && @merge_request.can_be_merged? |
| 105 | return access_denied! unless can?(current_user, :accept_mr, @project) | 108 | return access_denied! unless can?(current_user, :accept_mr, @project) |
app/models/merge_request.rb
| @@ -49,6 +49,15 @@ class MergeRequest < ActiveRecord::Base | @@ -49,6 +49,15 @@ class MergeRequest < ActiveRecord::Base | ||
| 49 | where("source_branch like :branch or target_branch like :branch", :branch => branch_name) | 49 | where("source_branch like :branch or target_branch like :branch", :branch => branch_name) |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | + def human_state | ||
| 53 | + states = { | ||
| 54 | + CAN_BE_MERGED => "can_be_merged", | ||
| 55 | + CANNOT_BE_MERGED => "cannot_be_merged", | ||
| 56 | + UNCHECKED => "unchecked" | ||
| 57 | + } | ||
| 58 | + states[self.state] | ||
| 59 | + end | ||
| 60 | + | ||
| 52 | def validate_branches | 61 | def validate_branches |
| 53 | if target_branch == source_branch | 62 | if target_branch == source_branch |
| 54 | errors.add :base, "You can not use same branch for source and target branches" | 63 | errors.add :base, "You can not use same branch for source and target branches" |
app/views/merge_requests/show.html.haml
| @@ -54,18 +54,25 @@ | @@ -54,18 +54,25 @@ | ||
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | - if @merge_request.open? && @commits.any? && can?(current_user, :accept_mr, @project) | 56 | - if @merge_request.open? && @commits.any? && can?(current_user, :accept_mr, @project) |
| 57 | - - if @merge_request.can_be_merged? | 57 | + .automerge_widget.can_be_merged{:style => "display:none"} |
| 58 | .ui-box.padded | 58 | .ui-box.padded |
| 59 | %p | 59 | %p |
| 60 | You can accept this request automatically. If you still want to do it manually - #{link_to "click here", "#", :class => "how_to_merge_link vlink", :title => "How To Merge"} for instructions | 60 | You can accept this request automatically. If you still want to do it manually - #{link_to "click here", "#", :class => "how_to_merge_link vlink", :title => "How To Merge"} for instructions |
| 61 | = link_to "Accept Merge Request", automerge_project_merge_request_path(@project, @merge_request), :class => "btn small info accept_merge_request", :remote => true | 61 | = link_to "Accept Merge Request", automerge_project_merge_request_path(@project, @merge_request), :class => "btn small info accept_merge_request", :remote => true |
| 62 | | 62 | |
| 63 | - | ||
| 64 | - - else | 63 | + |
| 64 | + .automerge_widget.cannot_be_merged{:style => "display:none"} | ||
| 65 | .alert-message | 65 | .alert-message |
| 66 | %p | 66 | %p |
| 67 | %strong This request cant be merged with GitLab. You should do it manually | 67 | %strong This request cant be merged with GitLab. You should do it manually |
| 68 | = link_to "Show how to merge", "#", :class => "how_to_merge_link btn small padded", :title => "How To Merge" | 68 | = link_to "Show how to merge", "#", :class => "how_to_merge_link btn small padded", :title => "How To Merge" |
| 69 | + | ||
| 70 | + .automerge_widget.unchecked | ||
| 71 | + .alert-message | ||
| 72 | + %p | ||
| 73 | + %strong Checking for ability to automatically merge… | ||
| 74 | + | ||
| 75 | + | ||
| 69 | 76 | ||
| 70 | 77 | ||
| 71 | = render "merge_requests/commits" | 78 | = render "merge_requests/commits" |
| @@ -87,7 +94,9 @@ | @@ -87,7 +94,9 @@ | ||
| 87 | 94 | ||
| 88 | :javascript | 95 | :javascript |
| 89 | $(function(){ | 96 | $(function(){ |
| 90 | - MergeRequest.init(); | 97 | + MergeRequest.init({ |
| 98 | + url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}", | ||
| 99 | + }); | ||
| 91 | 100 | ||
| 92 | $(".accept_merge_request").live("ajax:beforeSend", function() { | 101 | $(".accept_merge_request").live("ajax:beforeSend", function() { |
| 93 | $(this).replaceWith('#{image_tag "ajax_loader.gif"}'); | 102 | $(this).replaceWith('#{image_tag "ajax_loader.gif"}'); |
config/routes.rb
lib/gitlab_merge.rb
| @@ -29,6 +29,7 @@ class GitlabMerge | @@ -29,6 +29,7 @@ class GitlabMerge | ||
| 29 | 29 | ||
| 30 | def pull | 30 | def pull |
| 31 | self.project.repo.git.clone({:branch => merge_request.target_branch}, project.url_to_repo, merge_path) | 31 | self.project.repo.git.clone({:branch => merge_request.target_branch}, project.url_to_repo, merge_path) |
| 32 | + #TODO When user do not have permissions then raise exception | ||
| 32 | Dir.chdir(merge_path) do | 33 | Dir.chdir(merge_path) do |
| 33 | merge_repo = Grit::Repo.new('.') | 34 | merge_repo = Grit::Repo.new('.') |
| 34 | merge_repo.git.sh "git config user.name \"#{user.name}\"" | 35 | merge_repo.git.sh "git config user.name \"#{user.name}\"" |