[refs #90] branch, merge validation
This commit is contained in:
parent
e211fa2fc3
commit
4f1d23a2a4
|
@ -947,3 +947,7 @@ div#git_help_data p {
|
||||||
.atom_icon {
|
.atom_icon {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tab-content.pull_diff_fix {
|
||||||
|
display: block;
|
||||||
|
}
|
|
@ -10,26 +10,22 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@pull = PullRequest.default_base_project(@project).pull_requests.new
|
@pull = PullRequest.default_base_project(@project).pull_requests.new
|
||||||
#@pull.build_issue
|
|
||||||
@pull.issue = @project.issues.new
|
@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.head_project = @project
|
||||||
|
@pull.base_ref = (params[:pull_request][:base_ref].presence if params[:pull_request]) || @pull.base_project.default_branch
|
||||||
@pull.base_ref = @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.head_ref = params[:treeish].presence || @pull.head_project.default_branch
|
@pull.state = @pull.soft_check
|
||||||
if @pull.save
|
if @pull.state == 'already'
|
||||||
@pull.check
|
flash[:warning] = I18n.t('projects.pull_requests.up_to_date', :base_ref => @pull.base_ref, :head_ref => @pull.head_ref)
|
||||||
if @pull.state == 'already'
|
else
|
||||||
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
|
|
||||||
repo = Git::Repository.new(@pull.path)
|
repo = Git::Repository.new(@pull.path)
|
||||||
@base_commit = repo.commits(@pull.base_ref).first
|
@base_commit = repo.commits(@pull.base_ref).first
|
||||||
@head_commit = repo.commits(@pull.head_branch).first
|
@head_commit = repo.commits(@pull.head_branch).first
|
||||||
@diff = Grit::Repo.new(@pull.path).diff @base_commit, @head_commit
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,13 +33,9 @@ class Projects::PullRequestsController < Projects::BaseController
|
||||||
@pull = @project.pull_requests.new(params[:pull_request]) # FIXME need validation!
|
@pull = @project.pull_requests.new(params[:pull_request]) # FIXME need validation!
|
||||||
@pull.issue.user, @pull.issue.project = current_user, @pull.base_project
|
@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_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
|
if @pull.save
|
||||||
@pull.check
|
@pull.check
|
||||||
puts "!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
||||||
puts "pull state is #{@pull.state}"
|
|
||||||
if @pull.state == 'already'
|
if @pull.state == 'already'
|
||||||
@pull.destroy
|
@pull.destroy
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,21 @@ class PullRequest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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)
|
def merge!(who)
|
||||||
return false unless can_merge?
|
return false unless can_merge?
|
||||||
Dir.chdir(path) do
|
Dir.chdir(path) do
|
||||||
|
|
|
@ -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
|
.file
|
||||||
%a{:name => h(commit_diff.a_path)}
|
%a{:name => h(commit_diff.a_path)}
|
||||||
.top
|
.top
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
-t('pull_requests.tabs').each do |base, title|
|
-t('pull_requests.tabs').each do |base, title|
|
||||||
%li
|
%li
|
||||||
%a{"data-toggle" => "tab", :href => "##{base}"}=title
|
%a{"data-toggle" => "tab", :href => "##{base}"}=title
|
||||||
.tab-content
|
.tab-content.pull_diff_fix
|
||||||
#discussion.tab-pane.active
|
#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
|
.leftlist=f.label :base_project, t('.base_project'), :class => :label
|
||||||
.rightlist
|
.rightlist
|
||||||
= @pull.base_project.full_name
|
= @pull.base_project.full_name
|
||||||
|
@ -37,11 +37,10 @@
|
||||||
.leftlist for debug
|
.leftlist for debug
|
||||||
.rightlist=@pull.state
|
.rightlist=@pull.state
|
||||||
.both
|
.both
|
||||||
|
|
||||||
.leftlist
|
.leftlist
|
||||||
\
|
.rightlist=f.submit t(@pull.state != 'already' ? '.submit' : '.update'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing')#, :id => 'create_pull'
|
||||||
.rightlist=f.submit t('.submit'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing'), :id => 'create_pull'
|
|
||||||
.both
|
.both
|
||||||
|
|
||||||
#diff.tab-pane
|
#diff.tab-pane
|
||||||
-begin
|
-begin
|
||||||
=# render_commit_stats(stats)
|
=# render_commit_stats(stats)
|
||||||
|
|
|
@ -9,6 +9,7 @@ en:
|
||||||
base_project: Base project
|
base_project: Base project
|
||||||
head_project: Head project
|
head_project: Head project
|
||||||
submit: Send pull request
|
submit: Send pull request
|
||||||
|
update: Update commits
|
||||||
merge: Merge
|
merge: Merge
|
||||||
duplicate: 'There is already a pull request for %{head_ref}'
|
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}'
|
up_to_date: 'The %{base_ref} branch is already up-to-date with %{head_ref}'
|
||||||
|
|
|
@ -9,6 +9,7 @@ ru:
|
||||||
base_project: Базовый проект
|
base_project: Базовый проект
|
||||||
head_project: Проект-источник
|
head_project: Проект-источник
|
||||||
submit: Создать запрос на слияние
|
submit: Создать запрос на слияние
|
||||||
|
update: Обновить коммиты
|
||||||
merge: Слияние
|
merge: Слияние
|
||||||
duplicate: 'Уже существует запрос на слияние %{head_ref}'
|
duplicate: 'Уже существует запрос на слияние %{head_ref}'
|
||||||
up_to_date: 'Ветка %{base_ref} на данный момент уже содержит последние изменения %{head_ref}'
|
up_to_date: 'Ветка %{base_ref} на данный момент уже содержит последние изменения %{head_ref}'
|
||||||
|
|
Loading…
Reference in New Issue