From f979e80f24a73c3850e1db2b8c2518c83ae12c93 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 20 Jul 2016 17:05:55 +0800 Subject: [PATCH] =?UTF-8?q?Gitlab=E6=95=B0=E6=8D=AE=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=8F=8A=E8=BF=81=E7=A7=BB=EF=BC=8C=E4=B8=BB=E8=A6=81=E6=98=AF?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/changeset.rb | 4 +--- lib/tasks/gitlab_act_project.rake | 15 ++++++++------- lib/tasks/gitlab_unused.rake | 11 +++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 lib/tasks/gitlab_unused.rake 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