diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 3a772eb6b..a9c3687a1 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -57,9 +57,7 @@ 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, :project_id, :repository_id, :revision, :committer, :comments, :committed_on - attr_accessible :type - + attr_accessible :type, :project_id, :repository_id, :revision, :committer, :comments, :committed_on scope :visible, lambda {|*args| includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args)) } diff --git a/lib/tasks/gitlab_act_project.rake b/lib/tasks/gitlab_act_project.rake index 962dac221..142d5bf89 100644 --- a/lib/tasks/gitlab_act_project.rake +++ b/lib/tasks/gitlab_act_project.rake @@ -1,11 +1,11 @@ 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 = Project.find_by_sql("select * from projects where gpid is not null and id != 2") - projects.each do |project| + 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 and id > 265") + projects.each do |project| + begin g_project = g.project(project.gpid) # 获取默认分支 g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch @@ -13,15 +13,16 @@ namespace :gitlab do commit_count = g.user_static(project.gpid, :rev => g_default_branch).count pages = commit_count / 20 + 1 puts "#{pages}" + puts "project id is #{project.id}" (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, :type => true) end end + rescue Exception => e + puts e end - rescue Exception => e - puts e end end end diff --git a/lib/tasks/gitlab_unused.rake b/lib/tasks/gitlab_unused.rake new file mode 100644 index 000000000..0b90d9352 --- /dev/null +++ b/lib/tasks/gitlab_unused.rake @@ -0,0 +1,11 @@ +namespace :gitlab do + desc "sync gitlab's commit acts to trustie" + task :unused => :environment do + begin + Project.where("id in (161,236,266)").update_all(:gpid => nil) + Repository.where("project_id in (161,236,266)").destroy_all + rescue Exception => e + puts e + end + end +end