mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-02 19:30:48 +08:00
Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
@@ -10,7 +10,6 @@ class SyncProjectsJob < ApplicationJob
|
||||
|
||||
begin
|
||||
url = "#{gitea_main}/sync_forges" #trustie上的相关路由
|
||||
|
||||
uri = URI.parse(url)
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
http.use_ssl = true
|
||||
@@ -20,16 +19,17 @@ class SyncProjectsJob < ApplicationJob
|
||||
if response.code == '200'
|
||||
target_jsons = eval(response.body)
|
||||
if sync_params[:type] == "Project"
|
||||
SyncLog.sync_log("==========target_jsons: #{target_jsons}============")
|
||||
SyncLog.sync_project_log("==========target_jsons: #{target_jsons}============")
|
||||
update_new_project(target_jsons[:targets_params][0], sync_params[:new_project_id])
|
||||
else
|
||||
SyncLog.sync_project_log("========== #{sync_params[:type]}============")
|
||||
create_target(target_jsons[:targets_params], sync_params[:type].to_s)
|
||||
end
|
||||
else
|
||||
SyncLog.sync_log("==========sync_project_to_forge_failed #{sync_params[:type]}============")
|
||||
SyncLog.sync_project_log("==========sync_project_to_forge_failed #{sync_params[:type]}============")
|
||||
end
|
||||
rescue => e
|
||||
SyncLog.sync_log("==========sync_project_to_forge_failed #{sync_params[:type]}============errors:#{e}")
|
||||
SyncLog.sync_project_log("==========sync_project_to_forge_failed #{sync_params[:type]}============errors:#{e}")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,42 +47,50 @@ class SyncProjectsJob < ApplicationJob
|
||||
end
|
||||
|
||||
def create_target(target_jsons, target_type)
|
||||
SyncLog.sync_log("***【#{target_type}】. begin_to_create_target---------------")
|
||||
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
|
||||
target_jsons.each_with_index do |re,index|
|
||||
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
|
||||
if re[:target_params].present?
|
||||
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}")
|
||||
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
|
||||
re[:target_params].delete(:id)
|
||||
if target_type == "Issue"
|
||||
new_target = target_type.constantize.new(re[:target_params].merge(author_id: u_id))
|
||||
else
|
||||
new_target = target_type.constantize.new(re[:target_params].merge(user_id: u_id))
|
||||
end
|
||||
|
||||
if target_type == "Issue"
|
||||
assing_u_id = User.select(:id, :login).where(login: re[:assign_login]).pluck(:id).first
|
||||
new_target.assigned_to_id = assing_u_id
|
||||
end
|
||||
if new_target.save!
|
||||
if re[:journals].present?
|
||||
create_journals(re[:journals], "Journal", new_target.id)
|
||||
begin
|
||||
SyncLog.sync_project_log("***【#{target_type}】. begin_to_create_target---------------")
|
||||
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
|
||||
target_jsons.each_with_index do |re,index|
|
||||
SyncLog.sync_project_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
|
||||
if re[:target_params].present?
|
||||
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}")
|
||||
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
|
||||
re[:target_params].delete(:id)
|
||||
if target_type == "Issue"
|
||||
new_target = target_type.constantize.new(re[:target_params].merge(author_id: u_id))
|
||||
else
|
||||
new_target = target_type.constantize.new(re[:target_params].merge(user_id: u_id))
|
||||
end
|
||||
if re[:journal_details].present?
|
||||
re[:journal_details].each do |j|
|
||||
JournalDetail.create!(j.merge(journal_id: new_target.id)) if j.present?
|
||||
end
|
||||
|
||||
if target_type == "Issue"
|
||||
assing_u_id = User.select(:id, :login).where(login: re[:assign_login]).pluck(:id).first
|
||||
new_target.assigned_to_id = assing_u_id
|
||||
end
|
||||
if re[:member_roles].present?
|
||||
re[:member_roles].each do |m|
|
||||
MemberRole.create!(m.merge(member_id: new_target.id)) if m.present?
|
||||
if new_target.save!
|
||||
SyncLog.sync_project_log("***【#{target_type}】. create_success---------------")
|
||||
if re[:journals].present?
|
||||
create_journals(re[:journals], "Journal", new_target.id)
|
||||
end
|
||||
if re[:journal_details].present?
|
||||
re[:journal_details].each do |j|
|
||||
JournalDetail.create!(j.merge(journal_id: new_target.id)) if j.present?
|
||||
end
|
||||
end
|
||||
if re[:member_roles].present?
|
||||
re[:member_roles].each do |m|
|
||||
MemberRole.create!(m.merge(member_id: new_target.id)) if m.present?
|
||||
end
|
||||
end
|
||||
else
|
||||
SyncLog.sync_project_log("***【#{target_type}】. create_failed---------------")
|
||||
end
|
||||
end
|
||||
end
|
||||
SyncLog.sync_project_log("***111222. end_to_create_target---------------")
|
||||
rescue => e
|
||||
SyncLog.sync_project_log("=========***【#{target_type}】creat_had_erros:#{e}===================")
|
||||
end
|
||||
SyncLog.sync_log("***111222. end_to_create_target---------------")
|
||||
|
||||
end
|
||||
|
||||
def create_journals(target_jsons, target_type,issue_id)
|
||||
|
||||
@@ -5,12 +5,11 @@ class SyncRepositoryJob < ApplicationJob
|
||||
|
||||
def perform(user_login, identifier, repository_params, gitea_main)
|
||||
#创建临时文件夹 clone 并强推代码
|
||||
SyncLog.sync_log("=================begin to sync request trustie repository:#{repository_params}=====================")
|
||||
SyncLog.sync_log("=================begin to sync request trustie repository=====================")
|
||||
path = "#{Rails.root}/public/cache_repository"
|
||||
image_url = repository_params[:git_url]
|
||||
gitlab_branches = repository_params[:gitlab_branches]
|
||||
image_repo_name = image_url.to_s.split('/')&.last&.chomp('.git')
|
||||
SyncLog.sync_project_log("========gitlab_branches:#{gitlab_branches}===================")
|
||||
unless File.directory?(path)
|
||||
FileUtils.mkdir_p(path)
|
||||
end
|
||||
@@ -20,15 +19,11 @@ class SyncRepositoryJob < ApplicationJob
|
||||
end
|
||||
|
||||
check_clone = system("cd #{path} && git clone #{image_url}")
|
||||
SyncLog.sync_log("========check_clone:====cd #{path} && git clone #{image_url}=====success?:#{check_clone}==============")
|
||||
if check_clone
|
||||
|
||||
new_gitlab_url = "http://root:_Trustie_10010@#{gitea_main}/#{user_login}/#{identifier}.git"
|
||||
shell_remote_1 = system("cd #{path}/#{image_repo_name} && git remote set-url origin #{new_gitlab_url}")
|
||||
gitlab_branches.each do |branch|
|
||||
SyncLog.sync_log("========checkout_branch:#{branch}===================")
|
||||
shell5 = system("cd #{path}/#{image_repo_name} && git checkout #{branch} && git push --force --set-upstream origin #{branch}")
|
||||
SyncLog.sync_log("========checkout_branch_shell5:#{shell5}===================")
|
||||
if !shell5
|
||||
SyncLog.sync_project_log("=============force_push_erros==#{path}/#{image_repo_name}++branch:#{branch}")
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user