Commit 8269a3a7 authored by Valery Sizov's avatar Valery Sizov

Auto-merge: checking via AJAX

parent f1454504
var MergeRequest = {
diffs_loaded: false,
commits_loaded: false,
opts: false,
init:
function() {
function(opts) {
this.opts = opts;
if($(".automerge_widget").lenght){
$.get(opts.url_to_automerge_check, function(data){
$(".automerge_widget").hide();
$(".automerge_widget." + data.state).show();
}, "json");
}
$(".tabs a").live("click", function() {
$(".tabs a").parent().removeClass("active");
$(this).parent().addClass("active");
......
......@@ -2,7 +2,7 @@ class MergeRequestsController < ApplicationController
before_filter :authenticate_user!
before_filter :project
before_filter :module_enabled
before_filter :merge_request, :only => [:edit, :update, :destroy, :show, :commits, :diffs, :automerge]
before_filter :merge_request, :only => [:edit, :update, :destroy, :show, :commits, :diffs, :automerge, :automerge_check]
layout "project"
# Authorize
......@@ -45,10 +45,6 @@ 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
......@@ -100,6 +96,13 @@ class MergeRequestsController < ApplicationController
end
end
def automerge_check
if @merge_request.unchecked?
@merge_request.check_if_can_be_merged
end
render :json => {:state => @merge_request.human_state}
end
def automerge
render_404 unless @merge_request.open? && @merge_request.can_be_merged?
return access_denied! unless can?(current_user, :accept_mr, @project)
......
......@@ -49,6 +49,15 @@ class MergeRequest < ActiveRecord::Base
where("source_branch like :branch or target_branch like :branch", :branch => branch_name)
end
def human_state
states = {
CAN_BE_MERGED => "can_be_merged",
CANNOT_BE_MERGED => "cannot_be_merged",
UNCHECKED => "unchecked"
}
states[self.state]
end
def validate_branches
if target_branch == source_branch
errors.add :base, "You can not use same branch for source and target branches"
......
......@@ -54,19 +54,26 @@
- if @merge_request.open? && @commits.any? && can?(current_user, :accept_mr, @project)
- if @merge_request.can_be_merged?
.automerge_widget.can_be_merged{:style => "display:none"}
.ui-box.padded
%p
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
= link_to "Accept Merge Request", automerge_project_merge_request_path(@project, @merge_request), :class => "btn small info accept_merge_request", :remote => true
&nbsp;
- else
.automerge_widget.cannot_be_merged{:style => "display:none"}
.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"
.automerge_widget.unchecked
.alert-message
%p
%strong Checking for ability to automatically merge…
= render "merge_requests/commits"
......@@ -87,7 +94,9 @@
:javascript
$(function(){
MergeRequest.init();
MergeRequest.init({
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
});
$(".accept_merge_request").live("ajax:beforeSend", function() {
$(this).replaceWith('#{image_tag "ajax_loader.gif"}');
......
......@@ -103,6 +103,7 @@ Gitlab::Application.routes.draw do
member do
get :diffs
get :automerge
get :automerge_check
end
collection do
......
......@@ -29,6 +29,7 @@ class GitlabMerge
def pull
self.project.repo.git.clone({:branch => merge_request.target_branch}, project.url_to_repo, merge_path)
#TODO When user do not have permissions then raise exception
Dir.chdir(merge_path) do
merge_repo = Grit::Repo.new('.')
merge_repo.git.sh "git config user.name \"#{user.name}\""
......
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