pullrequest发送消息

This commit is contained in:
daiao 2016-12-01 11:31:48 +08:00
parent 9fa4b5613a
commit 2e5cd96bb9
8 changed files with 80 additions and 36 deletions

View File

@ -97,16 +97,31 @@ 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, request.id)
# fork项目的pullrequest发送消息
# 向管理员发送消息
@project_member = Member.where(:project_id => params[:target_project_id].to_i)
unless @project_member.nil?
@project_member.each do |mem|
if is_project_manager?(mem.user_id, params[:target_project_id].to_i) && mem.user_id != User.current.id
send_message(mem.user_id, params[:target_project_id].to_i, request.id, 1)
end
end
end
# 创建Trustie数据
PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id)
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, request.id)
unless @project_member.nil?
@project_member.each do |mem|
if is_project_manager?(mem.user_id, @project.id) && mem.user_id != User.current.id
send_message(mem.user_id, @project.id, request.id, 1)
end
end
end
# 创建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
@ -180,6 +195,14 @@ class PullRequestsController < ApplicationController
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)
# 接受后,给用户发消息
request = @g.merge_request(@project.gpid, params[:id])
if User.current.login != request.author.try(:username)
message_user = User.where( :login => request.author.try(:username) ).first
send_message(message_user.id, @project.id, request.id, 2)
end
respond_to do |format|
format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)}
end
@ -205,6 +228,25 @@ class PullRequestsController < ApplicationController
def update_pull_request
begin
@g.update_merge_request(@project.gpid, params[:id], User.current.gid, :state_event => params[:state])
# 自己关闭/重新打开 就给每个管理员发送消息,如果是管理员关闭/重新打开,就给用户发消息
request = @g.merge_request(@project.gpid, params[:id])
@project_member = Member.where(:project_id => @project.id)
# 发送消息
if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login == request.author.try(:username)
unless @project_member.nil?
@project_member.each do |mem|
if is_project_manager?(mem.user_id, @project.id) && mem.user_id != User.current.id
send_message(mem.user_id, @project.id, request.id, params[:state] == "close" ? 4 : 3)
end
end
end
end
if ( params[:state] == "close" || params[:state] == "reopen" ) && User.current.login != request.author.try(:username)
message_user = User.where( :login => request.author.try(:username) ).first
send_message(message_user.id, @project.id, request.id, params[:state] == "close" ? 4 : 3)
end
respond_to do |format|
format.html{redirect_to project_pull_request_path(params[:id], :project_id => @project.id)}
end
@ -295,9 +337,9 @@ class PullRequestsController < ApplicationController
end
private
def send_message user_id, project_id, pull_request_id
def send_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)
:forge_message_id => pull_request_id, :forge_message_type => "PullRequest", :viewed => true, :status => status)
end
def authorize_logged

View File

@ -96,11 +96,11 @@ module UsersHelper
when 1
"创建了PullRequest:"
when 2
"接受了您的PullRequest:"
"接受了PullRequest:"
when 3
"重新打开了PullRequest:"
when 4
"关闭了您的PullRequest:"
"关闭了PullRequest:"
end
end

View File

@ -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

View File

@ -27,17 +27,17 @@
<!--quality_analysis-->
<% unless @entries.nil? %>
<a href="<%= @zip_path %>" class="btn_zipdown fr" onclick="">ZIP下载</a>
<% if User.current.member_of?(@project) && @project.is_public? %>
<% if quality_analysis(User.current.try(:login), @repository.id).nil? %>
<%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fr" %>
<% else %>
<%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fr" %>
<% end %>
<% end %>
<% end %>
<% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %>
<%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fr" %>
<%# if User.current.member_of?(@project) && @project.is_public? %>
<%# if quality_analysis(User.current.try(:login), @repository.id).nil? %>
<%#= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fr" %>
<%# else %>
<%#= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fr" %>
<%# end %>
<%# end %>
<% end %>
<%# unless QualityAnalysis.where(:project_id => @project.id).first.nil? %>
<%#= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fr" %>
<%# end %>
<div class="fl mt5 ml15">
<%=link_to "代码统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :creator => @creator, :default_branch => @g_default_branch ), :class => "fl vl_zip" %>

View File

@ -304,7 +304,7 @@
</a>
</li>
<li class="homepageNewsPubType fl">
<%=link_to User.find(ma.course_message.user).show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<%=link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">发布了问卷:</span>
</li>
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
@ -327,7 +327,7 @@
</a>
</li>
<li class="homepageNewsPubType fl">
<%=link_to User.find(ma.course_message.author).show_name, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<%=link_to User.find(ma.course_message.author_id).show_name, user_path(ma.course_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">
<%= ma.course_message.parent_id.nil? ? "发布了班级帖子:" : "评论了班级帖子:" %></span></li>
<% if ma.course_message.parent_id.nil? %>
@ -423,7 +423,7 @@
</a>
</li>
<li class="homepageNewsPubType fl">
<%= link_to User.find(ma.course_message.user).show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<%= link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl" : "homepageNewsType fl" %>">在班级中留言了:</span>
</li>
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
@ -447,7 +447,7 @@
</a>
</li>
<li class="homepageNewsPubType fl">
<%= link_to User.find(ma.course_message.user).show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<%= link_to ma.course_message.user.show_name, user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl" : "homepageNewsType fl" %>">
<% if ma.course_message.m_parent_id.nil? %>
回复了您的<span class="fontBlue2" title="作业:<%=ma.course_message.jour.name %>">作业</span>

View File

@ -162,7 +162,7 @@
<% if ma.forge_message_type == "Message" %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.forge_message.author), :width => "30", :height => "30"), user_path(ma.forge_message.author), :target => '_blank' %></a></li>
<li class="homepageNewsPubType fl"><%=link_to User.find(ma.forge_message.author).show_name, user_path(ma.forge_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<li class="homepageNewsPubType fl"><%=link_to User.find(ma.forge_message.author_id).show_name, user_path(ma.forge_message.author), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>"><%= ma.forge_message.parent_id.nil? ? "发布了项目帖子:" : "评论了项目帖子:" %></span></li>
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
<%= link_to ma.forge_message.subject, board_message_path(ma.forge_message.board_id, ma.forge_message.parent_id ? ma.forge_message.parent_id : ma.forge_message.id), :class => "#{ma.viewed==0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
@ -181,7 +181,7 @@
</a>
</li>
<li class="homepageNewsPubType fl">
<%=link_to User.find(ma.forge_message.author).show_name, user_path(ma.forge_message.author),
<%=link_to User.find(ma.forge_message.author_id).show_name, user_path(ma.forge_message.author),
:class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">评论了新闻:</span>
</li>
@ -195,22 +195,24 @@
</ul>
<% end %>
<% if ma.forge_message_type == "PullRequest" && is_project_manager?( User.current.id, ma.forge_message.project_id) %>
<% if ma.forge_message_type == "PullRequest" %>
<ul class="homepageNewsList fl">
<li class="homepageNewsPortrait fl">
<a href="javascript:void(0);">
<%=link_to image_tag(url_to_avatar(ma.forge_message.author), :width => "30", :height => "30"), user_path(ma.forge_message.author), :target => '_blank' %>
<% send_message_user = PullRequest.where(:pull_request_id => ma.forge_message_id) %>
<% author = User.find(send_message_user[0].user_id) %>
<%= link_to image_tag(url_to_avatar(author), :width => "30", :height => "30"), user_path(author), :target => '_blank' %>
</a>
</li>
<li class="homepageNewsPubType fl">
<%=link_to User.find(ma.forge_message.author).show_name, user_path(ma.forge_message.author),
:class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<%= link_to User.find(send_message_user[0].user_id).show_name, user_path(send_message_user[0].user_id),
:class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>">
<%= pull_request_message_status(ma) %>
</span>
</li>
<li class="homepageNewsContent fl">
<%= link_to "#{ma.forge_message.forge_message_id.title}", {:controller => 'pull_requests', :action => 'show', :id => ma.forge_message.project_id },
<%= link_to "#{send_message_user[0].title}", project_pull_requests_path(ma.project_id),
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
</li>

View File

@ -1,5 +0,0 @@
class AddStatusToPullRequests < ActiveRecord::Migration
def change
add_column :pull_requests, :status, :integer, :default => false
end
end

View File

@ -0,0 +1,5 @@
class AddTitilToPullRequsts < ActiveRecord::Migration
def change
add_column :pull_requests, :title, :string
end
end