From 2381a78e1bca53cb48d764545d539c5bba185233 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 22 Jul 2016 10:23:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=AC=A1=E6=95=B0=E6=AF=94?= =?UTF-8?q?=E8=BE=83=E5=A4=9A=E7=9A=84=E9=A1=B9=E7=9B=AE=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/gitlab_forge_acts_update.rake | 32 +++++++++++++++++++ lib/tasks/gitlab_trustie_acts.rake | 41 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 lib/tasks/gitlab_forge_acts_update.rake create mode 100644 lib/tasks/gitlab_trustie_acts.rake diff --git a/lib/tasks/gitlab_forge_acts_update.rake b/lib/tasks/gitlab_forge_acts_update.rake new file mode 100644 index 000000000..2248f3b87 --- /dev/null +++ b/lib/tasks/gitlab_forge_acts_update.rake @@ -0,0 +1,32 @@ +namespace :gitlab do + desc "sync gitlab's commit acts to trustie" + task :forge_acts_update => :environment do + g = Gitlab.client + ids = [2,847,931,942] + projects = Project.find(ids) + projects.each do |project| + c = Commit.where(:project_id => project.id) + if c.blank? + begin + 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 + puts "#{pages}" + puts "project id is #{project.id}" + # api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态 + (0..pages).each do |page| + commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page) + commits.each do |commit| + Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at) + end + end + rescue Exception => e + puts e + end + end + end + end +end diff --git a/lib/tasks/gitlab_trustie_acts.rake b/lib/tasks/gitlab_trustie_acts.rake new file mode 100644 index 000000000..8c3568397 --- /dev/null +++ b/lib/tasks/gitlab_trustie_acts.rake @@ -0,0 +1,41 @@ +namespace :gitlab do + desc "sync gitlab's commit acts to trustie" + task :acts_to_trustie => :environment do + begin + projects = Project.where(:status => 1) + projects.each do |project| + c = Commit.find_by_sql("SELECT * FROM `commits` where project_id = #{project.id} order by committed_on limit 1;") + g_project = g.project(project.gpid) + end + rescue Exception => e + puts e + end + g = Gitlab.client + ids = [2,847,931,942] + projects = Project.find(ids) + projects.each do |project| + c = Commit.where(:project_id => project.id) + if c.blank? + begin + 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 + puts "#{pages}" + puts "project id is #{project.id}" + # api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态 + (0..pages).each do |page| + commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page) + commits.each do |commit| + Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at) + end + end + rescue Exception => e + puts e + end + end + end + end +end