diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb index ef008bfb6..4bf4d16fb 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -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) diff --git a/app/models/ability.rb b/app/models/ability.rb index 5321a0223..a185daf6f 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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) diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index c625b8616..54e840c9b 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -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 diff --git a/app/views/projects/base/_submenu.html.haml b/app/views/projects/base/_submenu.html.haml index a0268100d..260315452 100644 --- a/app/views/projects/base/_submenu.html.haml +++ b/app/views/projects/base/_submenu.html.haml @@ -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(); - }); - }) diff --git a/app/views/projects/git/base/_fork.html.haml b/app/views/projects/git/base/_fork.html.haml index a844cafcf..692cb4de3 100644 --- a/app/views/projects/git/base/_fork.html.haml +++ b/app/views/projects/git/base/_fork.html.haml @@ -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(){ diff --git a/app/views/projects/pull_requests/_commit_diff.html.haml b/app/views/projects/pull_requests/_commit_diff.html.haml index fd030b93d..dc7a0c0b9 100644 --- a/app/views/projects/pull_requests/_commit_diff.html.haml +++ b/app/views/projects/pull_requests/_commit_diff.html.haml @@ -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 diff --git a/app/views/projects/pull_requests/index.html.haml b/app/views/projects/pull_requests/index.html.haml index 93a982154..4586780ce 100644 --- a/app/views/projects/pull_requests/index.html.haml +++ b/app/views/projects/pull_requests/index.html.haml @@ -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 diff --git a/app/views/projects/pull_requests/show.html.haml b/app/views/projects/pull_requests/show.html.haml new file mode 100644 index 000000000..e88227f20 --- /dev/null +++ b/app/views/projects/pull_requests/show.html.haml @@ -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'); + }); diff --git a/config/locales/models/pull_request.en.yml b/config/locales/models/pull_request.en.yml index 07697e71a..f7111c923 100644 --- a/config/locales/models/pull_request.en.yml +++ b/config/locales/models/pull_request.en.yml @@ -9,6 +9,7 @@ en: base_project: 'Base project' head_project: 'Head project' submit: 'Send pull request' + merge: Merge pull_requests: tabs: diff --git a/config/locales/models/pull_request.ru.yml b/config/locales/models/pull_request.ru.yml index 42f968efd..03ce62f52 100644 --- a/config/locales/models/pull_request.ru.yml +++ b/config/locales/models/pull_request.ru.yml @@ -9,6 +9,7 @@ ru: base_project: 'Базовый проект' head_project: 'Проект-источник' submit: 'Создать запрос на слияние' + merge: Слияние pull_requests: tabs: diff --git a/config/routes.rb b/config/routes.rb index f793fa022..98f8303fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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