Merge Button v1 complete

This commit is contained in:
Dmitriy Zaporozhets 2012-03-30 20:49:34 +03:00
parent 464cd59dff
commit 90748cf724
6 changed files with 31 additions and 25 deletions

View file

@ -102,6 +102,7 @@ class MergeRequestsController < ApplicationController
def automerge
render_404 unless @merge_request.open? && @merge_request.can_be_merged?
return access_denied! unless can?(current_user, :accept_mr, @project)
@merge_request.automerge!(current_user)
end

View file

@ -46,6 +46,7 @@ class Ability
:admin_team_member,
:admin_merge_request,
:admin_note,
:accept_mr,
:admin_wiki
] if project.master_access_for?(user) || project.owner == user

View file

@ -73,7 +73,7 @@ class MergeRequest < ActiveRecord::Base
end
def check_if_can_be_merged
self.state = if GitlabMerge.new(self).can_be_merged?
self.state = if GitlabMerge.new(self, self.author).can_be_merged?
CAN_BE_MERGED
else
CANNOT_BE_MERGED
@ -175,7 +175,7 @@ class MergeRequest < ActiveRecord::Base
end
def automerge!(current_user)
if GitlabMerge.new(self).merge
if GitlabMerge.new(self, current_user).merge
self.merge!(current_user.id)
true
end

View file

@ -52,7 +52,8 @@
Closed by #{@merge_request.closed_event.author_name}
%small #{time_ago_in_words(@merge_request.closed_event.created_at)} ago.
- if @merge_request.open? && @commits.any?
- if @merge_request.open? && @commits.any? && can?(current_user, :accept_mr, @project)
- if @merge_request.can_be_merged?
.ui-box.padded
%p

View file

@ -30,8 +30,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t.integer "assignee_id"
t.integer "author_id"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "closed", :default => false, :null => false
t.integer "position", :default => 0
t.boolean "critical", :default => false, :null => false
@ -43,8 +43,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
create_table "keys", :force => true do |t|
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "key"
t.string "title"
t.string "identifier"
@ -59,12 +59,12 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t.integer "assignee_id"
t.string "title"
t.boolean "closed", :default => false, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "st_commits"
t.text "st_diffs"
t.boolean "merged", :default => false, :null => false
t.integer "state", :default => 1, :null => false
t.boolean "auto_merge", :default => true, :null => false
end
add_index "merge_requests", ["project_id"], :name => "index_merge_requests_on_project_id"
@ -74,8 +74,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t.string "noteable_id"
t.string "noteable_type"
t.integer "author_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_id"
t.string "attachment"
t.string "line_code"
@ -88,8 +88,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t.string "name"
t.string "path"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "private_flag", :default => true, :null => false
t.string "code"
t.integer "owner_id"
@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t.text "content"
t.integer "author_id", :null => false
t.integer "project_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "file_name"
t.datetime "expires_at"
end
@ -146,8 +146,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name"
t.boolean "admin", :default => false, :null => false
t.integer "projects_limit", :default => 10
@ -166,16 +166,16 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
create_table "users_projects", :force => true do |t|
t.integer "user_id", :null => false
t.integer "project_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_access", :default => 0, :null => false
end
create_table "web_hooks", :force => true do |t|
t.string "url"
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "wikis", :force => true do |t|

View file

@ -1,7 +1,8 @@
class GitlabMerge
attr_accessor :project, :merge_path, :merge_request
attr_accessor :project, :merge_path, :merge_request, :user
def initialize(merge_request)
def initialize(merge_request, user)
self.user = user
self.merge_request = merge_request
self.project = merge_request.project
self.merge_path = File.join(Rails.root, "tmp", "merge_repo", project.path, merge_request.id.to_s)
@ -30,7 +31,9 @@ class GitlabMerge
self.project.repo.git.clone({:branch => merge_request.target_branch}, project.url_to_repo, merge_path)
Dir.chdir(merge_path) do
merge_repo = Grit::Repo.new('.')
output = merge_repo.git.pull({}, "origin", merge_request.source_branch)
merge_repo.git.sh "git config user.name \"#{user.name}\""
merge_repo.git.sh "git config user.email \"#{user.email}\""
output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch)
yield(merge_repo, output)
end
end