[refs #90] some fixes and merge button
This commit is contained in:
parent
f96990bd25
commit
74aee232f9
|
@ -3,12 +3,14 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
before_filter :authenticate_user!
|
||||
load_resource :project
|
||||
#load_and_authorize_resource :pull_request, :through => :project, :find_by => :serial_id #FIXME Disable for development
|
||||
load_resource :pull_request
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def new
|
||||
@pull = PullRequest.default_base_project(@project).pull_requests.new
|
||||
FileUtils.rm_rf @pull.path
|
||||
#@pull.build_issue
|
||||
@pull.issue = @project.issues.new
|
||||
@pull.head_project = @project
|
||||
|
@ -41,6 +43,21 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
def update
|
||||
end
|
||||
|
||||
def merge
|
||||
@pull_request.check
|
||||
@pull_request.merge! current_user
|
||||
redirect_to :show
|
||||
end
|
||||
|
||||
def show
|
||||
@pull = @pull_request
|
||||
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
|
||||
end
|
||||
|
||||
def autocomplete_base_project_name
|
||||
items = Project.accessible_by(current_ability, :membered)
|
||||
items << PullRequest.default_base_project(@project)
|
||||
|
|
|
@ -112,6 +112,8 @@ class Ability
|
|||
can(:create, Comment) {|comment| can? :read, comment.project}
|
||||
can(:update, Comment) {|comment| comment.user_id == user.id or local_admin?(comment.project || comment.commentable.project)}
|
||||
cannot :manage, Comment, :commentable_type => 'Issue', :commentable => {:project => {:has_issues => false}} # switch off issues
|
||||
|
||||
can [:merge], PullRequest, :state => 'ready'
|
||||
end
|
||||
|
||||
# Shared cannot rights for all users (registered, admin)
|
||||
|
|
|
@ -70,6 +70,7 @@ class PullRequest < ActiveRecord::Base
|
|||
if merge
|
||||
merging
|
||||
system("git push origin HEAD")
|
||||
system("git reset --hard HEAD") # for diff maybe FIXME
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -93,11 +94,11 @@ class PullRequest < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def path
|
||||
filename = [base_project.owner.uname, base_project.name, base_ref, head_ref].join('-')
|
||||
filename = [id, base_ref, head_project.owner.uname, head_project.name, head_ref].compact.join('-')
|
||||
if Rails.env == "production"
|
||||
File.join('/srv/rosa_build/shared/tmp', "pull_requests", filename)
|
||||
File.join('/srv/rosa_build/shared/tmp', "pull_requests", base_project.owner.uname, base_project.name, filename)
|
||||
else
|
||||
File.join(Rails.root, "tmp", Rails.env, "pull_requests", filename)
|
||||
File.join(Rails.root, "tmp", Rails.env, "pull_requests", base_project.owner.uname, base_project.name, filename)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,13 +17,3 @@
|
|||
- if can? :update, @project
|
||||
%li= link_to t("project_menu.settings"), edit_project_path(@project), :class => (act == :edit && contr == :projects ? 'active' : nil)
|
||||
%li=link_to t("project_menu.pull_requests"), project_pull_requests_path(@project), :class => (contr == :pull_requests ? 'active' : nil)
|
||||
|
||||
=form_for PullRequest.new, :url => new_project_pull_requests_path, :html => { :method => :post, :class => :form } do |f|
|
||||
=hidden_field_tag :ref, @treeish
|
||||
|
||||
:javascript
|
||||
$(function () {
|
||||
$('#send_pull_request').click(function(){
|
||||
$('#new_pull_request').submit();
|
||||
});
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
- if can? :pull, @project
|
||||
.r{:style => "display: block"}=link_to t("project_menu.pull_request"), '#', :class => 'button', :id => 'send_pull_request'
|
||||
=form_for PullRequest.new, :url => new_project_pull_requests_path, :html => { :method => :post, :class => :form } do |f|
|
||||
=hidden_field_tag :ref, @treeish
|
||||
=hidden_field_tag :treeish, @treeish
|
||||
:javascript
|
||||
$(function () {
|
||||
$('#send_pull_request').click(function(){
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
- commit_id = commit_diff.deleted_file ? @head_commit.parents.first.id : @head_commit.id
|
||||
- commit_id = commit_diff.deleted_file ? @head_commit.parents.try(:first).try(:id) : @head_commit.id
|
||||
.file
|
||||
%a{:name => h(commit_diff.a_path)}
|
||||
.top
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
-#render :partial => 'index_sidebar'
|
||||
-@project.pull_requests.each do |pull|
|
||||
=link_to pull.title, project_pull_request_path(@project, pull)
|
||||
%br
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
-set_meta_tags :title => [title_object(@project), t('.title')]
|
||||
= render :partial => 'submenu'
|
||||
%h3.bpadding10= raw t '.new', {:base => @pull.base_ref, :head => @pull.head_ref}
|
||||
%ul.nav.nav-tabs
|
||||
-t('pull_requests.tabs').each do |base, title|
|
||||
%li
|
||||
%a{"data-toggle" => "tab", :href => "##{base}"}=title
|
||||
.tab-content
|
||||
#discussion.tab-pane.active
|
||||
.leftlist=t('projects.pull_requests.new.base_project')
|
||||
.rightlist= @pull.base_project.full_name
|
||||
.both
|
||||
.leftlist="#{t 'projects.pull_requests.new.base_ref'} #{t 'projects.pull_requests.new.refs'}"
|
||||
.rightlist=@pull.base_ref
|
||||
.both
|
||||
.leftlist=t('projects.pull_requests.new.head_project')
|
||||
.rightlist= @pull.head_project.full_name
|
||||
.both
|
||||
.leftlist="#{t 'projects.pull_requests.new.head_ref'} #{t 'projects.pull_requests.new.refs'}"
|
||||
.rightlist=@pull.head_ref
|
||||
.both
|
||||
.leftlist=t('activerecord.attributes.issue.title')
|
||||
.rightlist=@pull.issue.title
|
||||
.both
|
||||
.leftlist=t('activerecord.attributes.issue.body')
|
||||
.rightlist=@pull.issue.body
|
||||
.both
|
||||
.leftlist=t('activerecord.attributes.issue.state')
|
||||
.rightlist=@pull.issue.state
|
||||
.both
|
||||
- if can? :merge, @pull
|
||||
=form_for PullRequest.new, :url => merge_project_pull_request_path(@project, @pull), :html => { :method => :put, :class => :form } do |f|
|
||||
=f.submit t 'projects.pull_requests.merge'
|
||||
|
||||
#diff.tab-pane
|
||||
-begin
|
||||
=# render_commit_stats(stats)
|
||||
|
||||
= render :partial => 'commit_diff', :collection => @diff
|
||||
- rescue Grit::Git::GitTimeout
|
||||
%p= t 'layout.git.repositories.commit_diff_too_big'
|
||||
#commits.tab-pane ...
|
||||
|
||||
:javascript
|
||||
$(function () {
|
||||
$('.nav.nav-tabs a:first').tab('show');
|
||||
});
|
|
@ -9,6 +9,7 @@ en:
|
|||
base_project: 'Base project'
|
||||
head_project: 'Head project'
|
||||
submit: 'Send pull request'
|
||||
merge: Merge
|
||||
|
||||
pull_requests:
|
||||
tabs:
|
||||
|
|
|
@ -9,6 +9,7 @@ ru:
|
|||
base_project: 'Базовый проект'
|
||||
head_project: 'Проект-источник'
|
||||
submit: 'Создать запрос на слияние'
|
||||
merge: Слияние
|
||||
|
||||
pull_requests:
|
||||
tabs:
|
||||
|
|
|
@ -164,13 +164,16 @@ Rosa::Application.routes.draw do
|
|||
get :find, :on => :collection
|
||||
end
|
||||
resources :pull_requests, :except => [:destroy, :new] do
|
||||
post '/new' => 'pull_requests#new', :on => :collection
|
||||
collection do
|
||||
post '/new' => 'pull_requests#new'
|
||||
get :autocomplete_base_project_name
|
||||
get :autocomplete_head_project_name
|
||||
get :autocomplete_base_ref
|
||||
get :autocomplete_head_ref
|
||||
end
|
||||
member do
|
||||
put :merge, :as => 'merge'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue