[refs #90] branch, merge validation

This commit is contained in:
Alexander Machehin 2012-05-24 23:10:49 +06:00
parent e211fa2fc3
commit 4f1d23a2a4
7 changed files with 36 additions and 24 deletions

View File

@ -947,3 +947,7 @@ div#git_help_data p {
.atom_icon {
vertical-align: top;
}
.tab-content.pull_diff_fix {
display: block;
}

View File

@ -10,26 +10,22 @@ class Projects::PullRequestsController < Projects::BaseController
def new
@pull = PullRequest.default_base_project(@project).pull_requests.new
#@pull.build_issue
@pull.issue = @project.issues.new
if params[:pull_request] && params[:pull_request][:issue_attributes]
@pull.issue.title = params[:pull_request][:issue_attributes][:title].presence
@pull.issue.body = params[:pull_request][:issue_attributes][:body].presence
end
@pull.head_project = @project
@pull.base_ref = @pull.base_project.default_branch
@pull.head_ref = params[:treeish].presence || @pull.head_project.default_branch
if @pull.save
@pull.check
if @pull.state == 'already'
record.errors.add(:head_ref, I18n.t('projects.pull_requests.up_to_date', :base_ref => record.base_ref, :head_ref => record.head_ref))
flash[:error] = t('flash.pull_request.create_error')
flash[:warning] = @pull.errors.full_messages.join('. ')
end
@pull.base_ref = (params[:pull_request][:base_ref].presence if params[:pull_request]) || @pull.base_project.default_branch
@pull.head_ref = params[:treeish].presence || (params[:pull_request][:head_ref].presence if params[:pull_request]) || @pull.head_project.default_branch
@pull.state = @pull.soft_check
if @pull.state == 'already'
flash[:warning] = I18n.t('projects.pull_requests.up_to_date', :base_ref => @pull.base_ref, :head_ref => @pull.head_ref)
else
repo = Git::Repository.new(@pull.path)
@base_commit = repo.commits(@pull.base_ref).first
@head_commit = repo.commits(@pull.head_branch).first
@diff = Grit::Repo.new(@pull.path).diff @base_commit, @head_commit
else
flash[:error] = t('flash.pull_request.create_error')
flash[:warning] = @pull.errors.full_messages.join('. ')
end
end
@ -37,13 +33,9 @@ class Projects::PullRequestsController < Projects::BaseController
@pull = @project.pull_requests.new(params[:pull_request]) # FIXME need validation!
@pull.issue.user, @pull.issue.project = current_user, @pull.base_project
@pull.base_project, @pull.head_project = PullRequest.default_base_project(@project), @project
#@pull.base_ref = params[:base_ref] # FIXME need validation!
#@pull.head_ref = params[:head_ref] # FIXME need validation!
if @pull.save
@pull.check
puts "!!!!!!!!!!!!!!!!!!!!!!!!"
puts "pull state is #{@pull.state}"
if @pull.state == 'already'
@pull.destroy

View File

@ -74,6 +74,21 @@ class PullRequest < ActiveRecord::Base
end
end
def soft_check
ret = merge
if ret =~ /Already up-to-date/
'already'
elsif ret =~ /Merge made by the 'recursive' strategy/
system("cd #{path} && git reset --hard HEAD^") # remove merge commit
'ready'
elsif ret =~ /Automatic merge failed/
system("cd #{path} && git reset --hard HEAD")
'block'
else
raise ret
end
end
def merge!(who)
return false unless can_merge?
Dir.chdir(path) do

View File

@ -1,4 +1,4 @@
- commit_id = commit_diff.deleted_file ? @head_commit.parents.try(:first).try(:id) : @head_commit.id
- commit_id = commit_diff.deleted_file ? @base_commit.id : @head_commit.id
.file
%a{:name => h(commit_diff.a_path)}
.top

View File

@ -5,9 +5,9 @@
-t('pull_requests.tabs').each do |base, title|
%li
%a{"data-toggle" => "tab", :href => "##{base}"}=title
.tab-content
.tab-content.pull_diff_fix
#discussion.tab-pane.active
=form_for @pull, :url => project_pull_requests_path, :html => {:class => 'well well-large'} do |f|
=form_for @pull, :url => (@pull.state != 'already' ? project_pull_requests_path : new_project_pull_requests_path), :html => {:class => 'well well-large'} do |f|
.leftlist=f.label :base_project, t('.base_project'), :class => :label
.rightlist
= @pull.base_project.full_name
@ -37,11 +37,10 @@
.leftlist for debug
.rightlist=@pull.state
.both
.leftlist
\ 
.rightlist=f.submit t('.submit'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing'), :id => 'create_pull'
.rightlist=f.submit t(@pull.state != 'already' ? '.submit' : '.update'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing')#, :id => 'create_pull'
.both
#diff.tab-pane
-begin
=# render_commit_stats(stats)

View File

@ -9,6 +9,7 @@ en:
base_project: Base project
head_project: Head project
submit: Send pull request
update: Update commits
merge: Merge
duplicate: 'There is already a pull request for %{head_ref}'
up_to_date: 'The %{base_ref} branch is already up-to-date with %{head_ref}'

View File

@ -9,6 +9,7 @@ ru:
base_project: Базовый проект
head_project: Проект-источник
submit: Создать запрос на слияние
update: Обновить коммиты
merge: Слияние
duplicate: 'Уже существует запрос на слияние %{head_ref}'
up_to_date: 'Ветка %{base_ref} на данный момент уже содержит последние изменения %{head_ref}'