diff --git a/app/assets/javascripts/pull_requests.js.coffee b/app/assets/javascripts/pull_requests.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/pull_requests.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/pull_requests.css.scss b/app/assets/stylesheets/pull_requests.css.scss new file mode 100644 index 000000000..f69ac413b --- /dev/null +++ b/app/assets/stylesheets/pull_requests.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the pull_requests controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb new file mode 100644 index 000000000..61fb9c9e4 --- /dev/null +++ b/app/controllers/pull_requests_controller.rb @@ -0,0 +1,36 @@ +class PullRequestsController < ApplicationController + before_filter :find_project_and_repository + before_filter :connect_gitlab, :only => [:index, :show] + + layout "base_projects" + + def index + results = @g.merge_requests(@project.gpid) + end + + def new + + end + + def create + + end + + def show + + end + + private + def connect_gitlab + @g = Gitlab.client + end + + def find_project_and_repository + @project = Project.find(params[:project_id]) + render_404 if @project.gpid.blank? + @repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab") + rescue ActiveRecord::RecordNotFound + render_404 + end + +end diff --git a/app/controllers/pull_rquests_controller.rb b/app/controllers/pull_rquests_controller.rb index 2fcdf79df..230f832bd 100644 --- a/app/controllers/pull_rquests_controller.rb +++ b/app/controllers/pull_rquests_controller.rb @@ -1,17 +1,30 @@ class PullRquestsController < ApplicationController - before_filter :find_project + before_filter :find_project_and_repository + before_filter :connect_gitlab, :only => [:index, :show] + layout "base_projects" def index - + results = @g.merge_requests(@project.gpid) end def new end - def find_project + def create + + end + + private + def connect_gitlab + @g = Gitlab.client + end + + def find_project_and_repository @project = Project.find(params[:project_id]) + render_404 if @project.gpid.blank? + @repository = Repository.where(:project_id => @project.id, :type => "Repository::Gitlab") rescue ActiveRecord::RecordNotFound render_404 end 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/helpers/pull_requests_helper.rb b/app/helpers/pull_requests_helper.rb new file mode 100644 index 000000000..fa8554854 --- /dev/null +++ b/app/helpers/pull_requests_helper.rb @@ -0,0 +1,2 @@ +module PullRequestsHelper +end diff --git a/app/views/projects/_development_group.html.erb b/app/views/projects/_development_group.html.erb index a218e368d..4dec58793 100644 --- a/app/views/projects/_development_group.html.erb +++ b/app/views/projects/_development_group.html.erb @@ -57,11 +57,11 @@ <% end %> -<% if User.current.member_of?(@project) %> +<% if allow_pull_request(@project) %>