You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trustieforge/lib/tasks/gitlab_act_project.rake

33 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

namespace :gitlab do
desc "sync gitlab's commit acts to trustie"
task :forge_acts => :environment do
g = Gitlab.client
projects = Project.find_by_sql("select * from projects where gpid is not null and id not in (2,847,931,942)")
projects.each do |project|
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 "Some wrong with project #{project.id}"
# Project.where(:id => project.id).first.update_column(:gpid, nil)
# Repository.where(:project_id => project.id).first.destroy
# try
puts e
end
end
end
end