From e4d43cc16379c86df6978e3177c083d5765515c6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 29 Nov 2016 12:25:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=A1=B9=E7=9B=AEpull=20request=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=B6=88=E6=81=AF=E6=A1=86=E6=9E=B6=E6=90=AD?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 12 +++++++++++ app/models/forge_message.rb | 2 +- app/models/pull_request.rb | 5 ++++- app/views/pull_requests/_form.html.erb | 2 +- app/views/users/_user_message_forge.html.erb | 20 +++++++++++++++++++ ...61129032534_add_status_to_pull_requests.rb | 5 +++++ ...9033440_add_project_id_to_pull_requests.rb | 5 +++++ 7 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20161129032534_add_status_to_pull_requests.rb create mode 100644 db/migrate/20161129033440_add_project_id_to_pull_requests.rb diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index e4a2dc9df..ff74eb9f3 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -97,8 +97,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) else 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) + # 创建Trustie数据 + PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => @project.id) respond_to do |format| format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} end @@ -287,6 +295,10 @@ class PullRequestsController < ApplicationController end private + def send_message user_id, project_id, title + self.forge_acts << ForgeMessage.new(:user_id => user_id, :project_id => project_id, :title => title) + end + def authorize_logged if !User.current.logged? redirect_to signin_path diff --git a/app/models/forge_message.rb b/app/models/forge_message.rb index 8bf754719..bc514025e 100644 --- a/app/models/forge_message.rb +++ b/app/models/forge_message.rb @@ -6,7 +6,7 @@ class ForgeMessage < ActiveRecord::Base belongs_to :forge_message ,:polymorphic => true belongs_to :project belongs_to :user - has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy + has_many :message_alls, :class_name => 'MessageAll', :as => :message, :dependent => :destroy validates :user_id,presence: true validates :project_id,presence: true diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index f40397cf0..ec13ff16b 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -1,4 +1,7 @@ class PullRequest < ActiveRecord::Base - attr_accessible :gpid, :pull_request_id, :user_id + # status 1:创建 2:接受 3:重新打开 4:关闭 + attr_accessible :gpid, :pull_request_id, :user_id, :status validates_uniqueness_of :pull_request_id + + has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy end diff --git a/app/views/pull_requests/_form.html.erb b/app/views/pull_requests/_form.html.erb index d76c3e8a8..0aa2a1177 100644 --- a/app/views/pull_requests/_form.html.erb +++ b/app/views/pull_requests/_form.html.erb @@ -112,4 +112,4 @@ var defaultBranch = $("#targetBranch option:first-child").val(); $("#targetBranch").val(defaultBranch); }); - \ No newline at end of file + diff --git a/app/views/users/_user_message_forge.html.erb b/app/views/users/_user_message_forge.html.erb index 71b051a30..00b141d31 100644 --- a/app/views/users/_user_message_forge.html.erb +++ b/app/views/users/_user_message_forge.html.erb @@ -194,4 +194,24 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • <% 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 new file mode 100644 index 000000000..a8ad71125 --- /dev/null +++ b/db/migrate/20161129032534_add_status_to_pull_requests.rb @@ -0,0 +1,5 @@ +class AddStatusToPullRequests < ActiveRecord::Migration + def change + add_column :pull_requests, :status, :integer, :default => false + end +end diff --git a/db/migrate/20161129033440_add_project_id_to_pull_requests.rb b/db/migrate/20161129033440_add_project_id_to_pull_requests.rb new file mode 100644 index 000000000..563ddf91b --- /dev/null +++ b/db/migrate/20161129033440_add_project_id_to_pull_requests.rb @@ -0,0 +1,5 @@ +class AddProjectIdToPullRequests < ActiveRecord::Migration + def change + add_column :pull_requests, :project_id, :integer + end +end From b2de81394ea95d55845245d44ca4093a65465ae9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 29 Nov 2016 14:44:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=A1=B9=E7=9B=AEPullRequest=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E6=98=BE=E7=A4=BA=E5=88=9B=E5=BB=BA=E8=80=85?= =?UTF-8?q?=E7=9A=84=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 10 +++++----- app/helpers/application_helper.rb | 2 +- app/views/pull_requests/_pull_requests_list.html.erb | 2 +- app/views/users/_user_message_forge.html.erb | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index ff74eb9f3..0b6a73440 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -92,21 +92,21 @@ class PullRequestsController < ApplicationController if compare_pull_request(source_branch, target_project_id, target_branch) # 如果传送了目标项目ID即向fork源项目发送请求 # if params[:forked_project_id] && params[:source_project] == "forked_project_name" - if params[:target_project_id].to_i != @project.id + if !params[:target_project_id].blank? target_project_id = params[:forked_project_id].to_i 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) + #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) + #PullRequest.create(:pull_request_id => request.id, :user_id => User.current.id, :status => 1, :project_id => target_project_id) else 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(User.current.id, @project.id, title) # 创建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) respond_to do |format| format.js{redirect_to project_pull_request_path(request.id, :project_id => @project.id)} end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8301407ae..e9bbcaafe 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,7 +75,7 @@ module ApplicationHelper # 通过系统外部用户名查找用户,如果用户不存在则用邮箱替换 def get_user_by_login_and login user = User.find_by_login(login) - user.nil? ? User.find(2) : user + (user.nil? || login == "root") ? User.find(2) : user end # 重置user_path,目的是将id转换成用户名 diff --git a/app/views/pull_requests/_pull_requests_list.html.erb b/app/views/pull_requests/_pull_requests_list.html.erb index 57a1874ca..2258962a6 100644 --- a/app/views/pull_requests/_pull_requests_list.html.erb +++ b/app/views/pull_requests/_pull_requests_list.html.erb @@ -12,7 +12,7 @@ <%= link_to "", project_pull_request_path(request.id, :project_id => @project.id), :class => "issues_icons_mes fr mr5 ml5" %>
    -

    由 <%= link_to User.find(request.author.id).try(:show_name), user_path(get_user_by_login_and(request.author.try(:username))), :class => "linkBlue2" %> 创建于<%= time_tag(request.created_at) %>前

    +

    由 <%= link_to get_user_by_login_and(request.author.try(:username)).try(:show_name), user_path(get_user_by_login_and(request.author.try(:username))), :class => "linkBlue2" %> 创建于<%= time_tag(request.created_at) %>前

    <%= time_tag(request.updated_at) %>前更新

    <%= @project.name+"/"+request.source_branch %>合并到<%= request.target_branch %>

    diff --git a/app/views/users/_user_message_forge.html.erb b/app/views/users/_user_message_forge.html.erb index 00b141d31..54eea89c0 100644 --- a/app/views/users/_user_message_forge.html.erb +++ b/app/views/users/_user_message_forge.html.erb @@ -195,7 +195,7 @@ <% end %> + <%# end %>--> <% end %> \ No newline at end of file