Merge branch 'develop' of https://git.trustie.net/jacknudt/trustieforge into develop

This commit is contained in:
Tim 2016-07-19 16:44:14 +08:00
commit ce5cf8bf4f
8 changed files with 2763 additions and 2327 deletions

View File

@ -82,8 +82,8 @@ class QualityAnalysisController < ApplicationController
end
end
# sonar 缓冲,数据
sleep(3)
# sonar 缓冲,sonar生成数据
sleep(10)
# 获取sonar output结果
console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"]

View File

@ -47,13 +47,11 @@ module RepositoriesHelper
end
# 获取文件目录的最新动态
def get_trees_last_changes(project_id, rev, ent_name)
g = Gitlab.client
def get_trees_last_changes(project_id, rev, ent_name, g)
begin
tree_changes = g.rep_last_changes(project_id, :rev => rev, :path => ent_name)
tree_changes
rescue
logger.error("faile to get tress activities!")
rescue Exception => e
puts e
end
end

View File

@ -64,14 +64,12 @@ class Changeset < ActiveRecord::Base
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
}
after_create :scan_for_issues,:refresh_changests#:be_user_score # user_score
after_update :be_user_score
# after_create :scan_for_issues,:refresh_changests#:be_user_score # user_score
# after_update :be_user_score
after_destroy :down_user_score
before_create :before_create_cs
# fq
# after_create :act_as_activity
# end
# before_create :before_create_cs
after_create :act_as_forge_activity
def revision=(r)
write_attribute :revision, (r.nil? ? nil : r.to_s)
@ -117,6 +115,12 @@ class Changeset < ActiveRecord::Base
self.user = repository.find_committer_user(self.committer)
end
# 项目中提交动态类型Changeset
# type0 为老版本即Trsutie数据 1为gitlab中获取的动态
def act_as_forge_activity
self.acts << ForgeActivity.new(:user_id => self.user_id, :project_id => self.project_id, :type => true)
end
def scan_for_issues
scan_comment_for_issue_ids
end

View File

@ -23,46 +23,52 @@ class ForgeActivity < ActiveRecord::Base
after_create :add_user_activity, :add_org_activity
before_destroy :destroy_user_activity, :destroy_org_activity
#在个人动态里面增加当前动态
# 在个人动态里面增加当前动态
# 版本库提交动态不显示在用户动态中
def add_user_activity
user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'").first
if user_activity
user_activity.save
else
if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil?
user_activity = UserActivity.where("act_type = 'Message' and act_id = #{self.forge_act.parent.id}").first
user_activity.created_at = self.created_at
if self.forge_act_type != "Changeset"
user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'").first
if user_activity
user_activity.save
else
user_activity = UserActivity.new
user_activity.act_id = self.forge_act_id
user_activity.act_type = self.forge_act_type
user_activity.container_type = "Project"
user_activity.container_id = self.project_id
user_activity.user_id = self.user_id
user_activity.save
if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil?
user_activity = UserActivity.where("act_type = 'Message' and act_id = #{self.forge_act.parent.id}").first
user_activity.created_at = self.created_at
user_activity.save
else
user_activity = UserActivity.new
user_activity.act_id = self.forge_act_id
user_activity.act_type = self.forge_act_type
user_activity.container_type = "Project"
user_activity.container_id = self.project_id
user_activity.user_id = self.user_id
user_activity.save
end
end
end
end
# 项目提交动态不显示在组织动态中
def add_org_activity
org_activity = OrgActivity.where("org_act_type = '#{self.forge_act_type.to_s}' and org_act_id = #{self.forge_act_id}").first
if org_activity
org_activity.updated_at = self.updated_at
org_activity.save
else
if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil?
org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.forge_act.parent.id}").first
org_activity.created_at = self.created_at
if self.forge_act_type != "Changeset"
org_activity = OrgActivity.where("org_act_type = '#{self.forge_act_type.to_s}' and org_act_id = #{self.forge_act_id}").first
if org_activity
org_activity.updated_at = self.updated_at
org_activity.save
else
OrgActivity.create(:user_id => self.user_id,
:org_act_id => self.forge_act_id,
:org_act_type => self.forge_act_type,
:container_id => self.project_id,
:container_type => 'Project',
:created_at => self.created_at,
:updated_at => self.updated_at)
if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil?
org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.forge_act.parent.id}").first
org_activity.created_at = self.created_at
org_activity.save
else
OrgActivity.create(:user_id => self.user_id,
:org_act_id => self.forge_act_id,
:org_act_type => self.forge_act_type,
:container_id => self.project_id,
:container_type => 'Project',
:created_at => self.created_at,
:updated_at => self.updated_at)
end
end
end
end

View File

@ -4,7 +4,7 @@
<% sub_path = entry.path[0] == "/" ? entry.path.sub("/", "") : entry.path %>
<% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(sub_path) %>
<% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %>
<% latest_changes = get_trees_last_changes(@project.gpid, @rev, ent_path) %>
<% latest_changes = get_trees_last_changes(@project.gpid, @rev, ent_path, @g) %>
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>">
<td style="padding-left: <%=18 * depth%>px;" class="filename_no_report hidden">

View File

@ -0,0 +1,6 @@
class AddTypeToChangeset < ActiveRecord::Migration
def change
add_column :changesets, :project_id, :integer
add_column :changesets, :type, :integer, :default => false
end
end

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
namespace :gitlab do
desc "sync gitlab's commit acts to trustie"
task :forge_acts => :environment do
begin
g = Gitlab.client
projects = Project.find_by_sql("select * from projects where gpid is not null")
projects.each do |project|
g_project = g.project(project.gpid)
# 获取默认分支
g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
# 总的提交次数
commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
pages = commit_count / 20 + 1
pages.each do |page|
commits = g.commits(g_project.gpid, :ref_name => g_default_branch, :page => page)
commits.each do |commit|
Changeset.create(:project_id => project.id, :repository_id => project.gpid, :revision => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
end
end
end
rescue Exception => e
puts e
end
end
end