changeset关联

This commit is contained in:
huang 2016-07-19 17:38:11 +08:00
parent cf04bb5ec6
commit 0c0dfbd093
2 changed files with 6 additions and 5 deletions

View File

@ -22,9 +22,7 @@ class Changeset < ActiveRecord::Base
#after_save :be_user_score # user_score
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
# fq
has_many :forge_activities, :class_name => 'ForgeActivity', :as => :forge_act, :dependent => :destroy
# end
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
#Added by nie
has_one :project_status, :dependent => :destroy
@ -59,6 +57,8 @@ class Changeset < ActiveRecord::Base
validates :committed_on, presence: true
validates :commit_date, presence: true
validates :scmid, uniqueness: {scope: :repository_id, allow_nil: true}
attr_accessible :product
attr_accessible :type
scope :visible, lambda {|*args|
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))

View File

@ -3,7 +3,8 @@ namespace :gitlab do
task :forge_acts => :environment do
begin
g = Gitlab.client
projects = Project.find_by_sql("select * from projects where gpid is not null")
# projects = Project.find_by_sql("select * from projects where gpid is not null")
projects = Project.find("select * from projects where gpid is not null and id != 2")
projects.each do |project|
g_project = g.project(project.gpid)
# 获取默认分支
@ -15,7 +16,7 @@ namespace :gitlab do
(0..pages).each do |page|
commits = g.commits(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)
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, :type => true)
end
end
end