diff --git a/Gemfile b/Gemfile index 72bd03c7b..58ccbc011 100644 --- a/Gemfile +++ b/Gemfile @@ -50,10 +50,10 @@ gem 'elasticsearch-model' gem 'elasticsearch-rails' #rails 3.2.22.2 bug - # gem "test-unit", "~>3.0" + gem "test-unit", "~>3.0" ### profile - # gem 'oneapm_rpm' + gem 'oneapm_rpm' group :development do gem 'grape-swagger' diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 9dd6e6358..b68db3563 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -101,16 +101,16 @@ class PullRequestsController < ApplicationController request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch, :target_project_id => target_project_id) @fork_project_name = Project.find(params[:target_project_id]).try(:name) @fork_pr_message = true if @fork_project_name - # 发送消息 - #send_message(User.current.id, target_project_id, title) - # 创建Trustie数据 - #PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id) + # 向管理员发送消息 + send_message_to_manager(params[:target_project_id].to_i, request.id, 1) + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id, :title => title) else + @project_member = Member.where(:project_id => @project.id) request = @g.create_merge_request(@project.gpid, title, User.current.gid, :description => description, :source_branch => source_branch, :target_branch => target_branch) # 发送消息 - #send_message(User.current.id, @project.id, title) + send_message_to_manager(@project.id, request.id, 1) # 创建Trustie数据 - #PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id) + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id, :title => title) respond_to do |format| format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} end @@ -189,7 +189,9 @@ class PullRequestsController < ApplicationController def accept_pull_request begin status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) - PullRequest.create(:pull_request_id => status.id, :user_id => User.current.id, :gpid => status.project_id) + # 接受后,给用户发消息 + send_message_to_author(@project.id, status.author.try(:user_name), params[:id], 2) + respond_to do |format| format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} end @@ -214,7 +216,13 @@ class PullRequestsController < ApplicationController # @return [Gitlab::ObjectifiedHash] Information about updated merge request. def update_pull_request begin - @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) + request = @g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state]) + user = User.find_by_login(request.author.try(:username)) + status = params[:state] == "close" ? 4 : 3 + send_message_to_manager(@project.id, params[:id], status) + if !is_project_manager?(user.id, @project.id) + send_message_to_author(@project, user.login, request.id, status) + end respond_to do |format| format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)} end @@ -320,8 +328,29 @@ class PullRequestsController < ApplicationController end end - def send_message user_id, project_id, title - self.forge_acts << ForgeMessage.new(:user_id => user_id, :project_id => project_id, :title => title) + def send_message_to_manager project_id, pull_request_id, status + project = Project.find(project_id) + project.members.each do |member| + if is_project_manager?(member.user_id, project_id) && User.current.id != member.user_id + add_message(member.user_id, project_id, pull_request_id, status) + end + end + end + + def send_message_to_author(project_id, user_login, request_id, status) + user = get_user_by_login_and(user_login) + if user.id != User.current.id + add_message(user.id, project_id, request_id, status) + end + end + + def add_message(user_id, project_id, pull_request_id, status) + ForgeMessage.create(:user_id => user_id, + :project_id => project_id, + :forge_message_id => pull_request_id, + :forge_message_type => "PullRequest", + :viewed => true, + :status => status) end def authorize_logged diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 4dd3399a3..98024954d 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -90,6 +90,20 @@ module UsersHelper end end + # 获取pullrequest消息状态 + def pull_request_message_status ma + case ma.status + when 1 + "创建了PullRequest:" + when 2 + "接受了PullRequest:" + when 3 + "重新打开了PullRequest:" + when 4 + "关闭了PullRequest:" + end + + end # 判断当前用户能否对消息进行操作 def allow_to_show applied_message (User.current.id == applied_message.user_id && applied_message.status == 1) ? true : false diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ec13ff16b..92f9b56a6 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -1,6 +1,6 @@ class PullRequest < ActiveRecord::Base # status 1:创建 2:接受 3:重新打开 4:关闭 - attr_accessible :gpid, :pull_request_id, :user_id, :status + attr_accessible :gpid, :pull_request_id, :user_id, :project_id, :title validates_uniqueness_of :pull_request_id has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy diff --git a/app/views/users/_user_message_forge.html.erb b/app/views/users/_user_message_forge.html.erb index 38d610aea..5204a9bff 100644 --- a/app/views/users/_user_message_forge.html.erb +++ b/app/views/users/_user_message_forge.html.erb @@ -194,24 +194,29 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% end %> - + <% end %> <% end %> \ No newline at end of file diff --git a/db/migrate/20161129032534_add_status_to_pull_requests.rb b/db/migrate/20161129032534_add_status_to_pull_requests.rb deleted file mode 100644 index a8ad71125..000000000 --- a/db/migrate/20161129032534_add_status_to_pull_requests.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddStatusToPullRequests < ActiveRecord::Migration - def change - add_column :pull_requests, :status, :integer, :default => false - end -end diff --git a/db/migrate/20161130031415_add_titil_to_pull_requsts.rb b/db/migrate/20161130031415_add_titil_to_pull_requsts.rb new file mode 100644 index 000000000..cc3ce3fef --- /dev/null +++ b/db/migrate/20161130031415_add_titil_to_pull_requsts.rb @@ -0,0 +1,5 @@ +class AddTitilToPullRequsts < ActiveRecord::Migration + def change + add_column :pull_requests, :title, :string + end +end