2016-07-22 10:23:12 +08:00
|
|
|
|
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|
|
2016-07-22 10:34:59 +08:00
|
|
|
|
# c = Commit.where(:project_id => project.id)
|
|
|
|
|
# if c.blank?
|
2016-07-22 10:23:12 +08:00
|
|
|
|
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
|
2016-07-22 10:34:59 +08:00
|
|
|
|
# end
|
2016-07-22 10:23:12 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|