From 7c4759f3b7f1b19e8c2059059c3cefbc42c2c798 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 1 Aug 2016 15:52:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=B7=A6=E4=BE=A7?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0pull=20request=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_rquests_controller.rb | 3 ++- app/views/projects/_development_group.html.erb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/pull_rquests_controller.rb b/app/controllers/pull_rquests_controller.rb index 2fcdf79df..c3f7c2925 100644 --- a/app/controllers/pull_rquests_controller.rb +++ b/app/controllers/pull_rquests_controller.rb @@ -1,5 +1,5 @@ class PullRquestsController < ApplicationController - before_filter :find_project + before_filter :find_project_and_repository layout "base_projects" def index @@ -12,6 +12,7 @@ class PullRquestsController < ApplicationController def find_project @project = Project.find(params[:project_id]) + @repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab") rescue ActiveRecord::RecordNotFound render_404 end diff --git a/app/views/projects/_development_group.html.erb b/app/views/projects/_development_group.html.erb index a218e368d..0647fcd1e 100644 --- a/app/views/projects/_development_group.html.erb +++ b/app/views/projects/_development_group.html.erb @@ -59,9 +59,9 @@ <% if User.current.member_of?(@project) %> <% end %> From 685f9d8090702cb81b39313cf434f39587c5158d Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 1 Aug 2016 16:19:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=B7=A6=E4=BE=A7?= =?UTF-8?q?=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_rquests_controller.rb | 2 +- app/helpers/application_helper.rb | 12 ++++++++++++ app/views/projects/_development_group.html.erb | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/pull_rquests_controller.rb b/app/controllers/pull_rquests_controller.rb index c3f7c2925..aaef56595 100644 --- a/app/controllers/pull_rquests_controller.rb +++ b/app/controllers/pull_rquests_controller.rb @@ -10,7 +10,7 @@ class PullRquestsController < ApplicationController end - def find_project + def find_project_and_repository @project = Project.find(params[:project_id]) @repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab") rescue ActiveRecord::RecordNotFound diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d64d95223..9d0439120 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -814,6 +814,18 @@ module ApplicationHelper return @result end + # 必须是项目成,项目必须提交过代码 + def allow_pull_request project + return false if project.gpid.nil? + g = Gitlab.client + count = g.user_static(project.gpid, :rev => "master").count + if User.current.member_of?(project) && count > 0 + true + else + false + end + end + # 判断版本库是否初始为gitlab def rep_is_gitlab?(project) rep = project.repositories.where("type =?", "Repository::Gitlab") diff --git a/app/views/projects/_development_group.html.erb b/app/views/projects/_development_group.html.erb index 0647fcd1e..d8d25dd3d 100644 --- a/app/views/projects/_development_group.html.erb +++ b/app/views/projects/_development_group.html.erb @@ -57,9 +57,9 @@ <% end %> -<% if User.current.member_of?(@project) %> +<% if allow_pull_request(@project) %>