Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
commit
1baeab14c2
|
@ -46,12 +46,12 @@ class SyncForgeController < ApplicationController
|
||||||
SyncRepositoryJob.perform_later(sync_params[:owner_login], sync_params[:identifier], sync_params[:repository], get_sudomain) if sync_params[:repository].present?
|
SyncRepositoryJob.perform_later(sync_params[:owner_login], sync_params[:identifier], sync_params[:repository], get_sudomain) if sync_params[:repository].present?
|
||||||
check_new_project(project, sync_params)
|
check_new_project(project, sync_params)
|
||||||
else
|
else
|
||||||
SyncLog.sync_log("=============new_project_create_failed, trustie_project_id==:#{params[:sync_params][:id]}")
|
SyncLog.sync_project_log("=============new_project_create_failed, trustie_project_id==:#{params[:sync_params][:id]}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
SyncLog.sync_log("=============sync_has_errors:==#{e.message}, project_id==:#{params[:sync_params][:id]}")
|
SyncLog.sync_project_log("=============sync_has_errors:==#{e.message}, project_id==:#{params[:sync_params][:id]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_users
|
def sync_users
|
||||||
|
@ -75,28 +75,28 @@ class SyncForgeController < ApplicationController
|
||||||
|
|
||||||
username = new_user.login
|
username = new_user.login
|
||||||
password = "12345678"
|
password = "12345678"
|
||||||
if new_user.save!
|
# if new_user.save!
|
||||||
SyncLog.sync_log("=================sync_to_user_success==#{new_user.login}")
|
# SyncLog.sync_log("=================sync_to_user_success==#{new_user.login}")
|
||||||
else
|
# else
|
||||||
SyncLog.sync_log("=================sync_to_user_failed,user_login==#{new_user.login}")
|
# SyncLog.sync_log("=================sync_to_user_failed,user_login==#{new_user.login}")
|
||||||
end
|
|
||||||
# ActiveRecord::Base.transaction do
|
|
||||||
# interactor = Gitea::RegisterInteractor.call({username: username, email: new_user.mail, password: password})
|
|
||||||
# if interactor.success?
|
|
||||||
# gitea_user = interactor.result
|
|
||||||
# result = Gitea::User::GenerateTokenService.new(username, password).call
|
|
||||||
# new_user.gitea_token = result['sha1']
|
|
||||||
# new_user.gitea_uid = gitea_user['id']
|
|
||||||
# if new_user.save!
|
|
||||||
# UserExtension.create!(u[:user_extensions][:user_extensions].merge(user_id: new_user.id)) if u[:user_extensions].present? && u[:user_extensions][:user_extensions].present?
|
|
||||||
# else
|
|
||||||
# SyncLog.sync_log("=================sync_to_user_failed,user_login==#{new_user.login}")
|
|
||||||
# end
|
|
||||||
# else
|
|
||||||
# SyncLog.sync_log("=============sync_to_user_failed,user_login====#{new_user.login}")
|
|
||||||
# SyncLog.sync_log("=================sync_to_user_failed,user_login====#{new_user.login}")
|
|
||||||
# end
|
|
||||||
# end
|
# end
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
interactor = Gitea::RegisterInteractor.call({username: username, email: new_user.mail, password: password})
|
||||||
|
if interactor.success?
|
||||||
|
gitea_user = interactor.result
|
||||||
|
result = Gitea::User::GenerateTokenService.new(username, password).call
|
||||||
|
new_user.gitea_token = result['sha1']
|
||||||
|
new_user.gitea_uid = gitea_user['id']
|
||||||
|
if new_user.save!
|
||||||
|
UserExtension.create!(u[:user_extensions][:user_extensions].merge(user_id: new_user.id)) if u[:user_extensions].present? && u[:user_extensions][:user_extensions].present?
|
||||||
|
else
|
||||||
|
SyncLog.sync_log("=================sync_to_user_failed,user_login==#{new_user.login}")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
SyncLog.sync_log("=============sync_to_user_failed,user_login====#{new_user.login}")
|
||||||
|
SyncLog.sync_log("=================sync_to_user_failed,user_login====#{new_user.login}")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# normal_status(1, "completed_sync")
|
# normal_status(1, "completed_sync")
|
||||||
|
@ -206,18 +206,35 @@ class SyncForgeController < ApplicationController
|
||||||
token: get_token,
|
token: get_token,
|
||||||
parent_id: project_id
|
parent_id: project_id
|
||||||
}
|
}
|
||||||
|
SyncLog.sync_log("***2--02. sync_projects_params-#{sync_projects_params}--------------")
|
||||||
|
SyncProjectsJob.perform_later(sync_projects_params, gitea_main)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sync_projects_params = {
|
new_diff_ids = diff_issue_ids.in_groups_of(200).map{|k| k.reject(&:blank?)}
|
||||||
type: "Issue",
|
diff_len = new_diff_ids.length
|
||||||
ids: diff_issue_ids,
|
(1..diff_len).each do |len|
|
||||||
token: get_token,
|
sync_projects_params = {
|
||||||
parent_id: project_id
|
type: "Issue",
|
||||||
}
|
ids: new_diff_ids[len-1],
|
||||||
|
token: get_token,
|
||||||
|
parent_id: project_id
|
||||||
|
}
|
||||||
|
SyncLog.sync_log("***2--030#{len}. sync_projects_params_groups-#{sync_projects_params}--------------")
|
||||||
|
SyncProjectsJob.perform_later(sync_projects_params, gitea_main)
|
||||||
|
end
|
||||||
|
# sync_projects_params = {
|
||||||
|
# type: "Issue",
|
||||||
|
# ids: diff_issue_ids,
|
||||||
|
# token: get_token,
|
||||||
|
# parent_id: project_id
|
||||||
|
# }
|
||||||
|
# SyncLog.sync_log("***2--03. sync_projects_params_groups-#{sync_projects_params}--------------")
|
||||||
|
# SyncProjectsJob.perform_later(sync_projects_params, gitea_main)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
SyncLog.sync_log("***2--02. sync_projects_params-#{sync_projects_params}--------------")
|
|
||||||
SyncProjectsJob.perform_later(sync_projects_params, gitea_main) if sync_projects_params.present?
|
# SyncProjectsJob.perform_later(sync_projects_params, gitea_main) if sync_projects_params.present?
|
||||||
SyncLog.sync_log("***2. end_to_syncissues---------------")
|
SyncLog.sync_log("***2. end_to_syncissues---------------")
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
SyncLog.sync_log("=========change_project_issues_errors:#{e}===================")
|
SyncLog.sync_log("=========change_project_issues_errors:#{e}===================")
|
||||||
|
|
|
@ -15,11 +15,11 @@ class SyncProjectsJob < ApplicationJob
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
response = http.send_request('GET', uri.path, sync_params.to_json, {'Content-Type' => 'application/json'})
|
response = http.send_request('GET', uri.path, sync_params.to_json, {'Content-Type' => 'application/json'})
|
||||||
|
|
||||||
SyncLog.sync_log("==========response_status::#{response.code}============")
|
SyncLog.sync_log("=======#{sync_params[:parent_id].present? ? sync_params[:parent_id] : sync_params[:new_project_id]}===response_status::#{response.code}============")
|
||||||
if response.code == '200'
|
if response.code == '200'
|
||||||
target_jsons = eval(response.body)
|
target_jsons = eval(response.body)
|
||||||
if sync_params[:type] == "Project"
|
if sync_params[:type] == "Project"
|
||||||
SyncLog.sync_log("==========target_jsons: #{target_jsons}============")
|
# SyncLog.sync_log("==========target_jsons: #{target_jsons}============")
|
||||||
update_new_project(target_jsons[:targets_params][0], sync_params[:new_project_id])
|
update_new_project(target_jsons[:targets_params][0], sync_params[:new_project_id])
|
||||||
else
|
else
|
||||||
SyncLog.sync_log("========== #{sync_params[:type]}============")
|
SyncLog.sync_log("========== #{sync_params[:type]}============")
|
||||||
|
@ -47,10 +47,10 @@ class SyncProjectsJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_target(target_jsons, target_type)
|
def create_target(target_jsons, target_type)
|
||||||
begin
|
SyncLog.sync_log("***【#{target_type}】. begin_to_create_target---------------")
|
||||||
SyncLog.sync_log("***【#{target_type}】. begin_to_create_target---------------")
|
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
|
||||||
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
|
target_jsons.each_with_index do |re,index|
|
||||||
target_jsons.each_with_index do |re,index|
|
begin
|
||||||
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
|
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
|
||||||
if re[:target_params].present?
|
if re[:target_params].present?
|
||||||
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}")
|
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}")
|
||||||
|
@ -59,7 +59,7 @@ class SyncProjectsJob < ApplicationJob
|
||||||
if target_type == "Issue"
|
if target_type == "Issue"
|
||||||
is_exists = Issue.exists?(author_id: u_id, project_id: re[:target_params][:project_id], subject: re[:target_params][:subject])
|
is_exists = Issue.exists?(author_id: u_id, project_id: re[:target_params][:project_id], subject: re[:target_params][:subject])
|
||||||
unless is_exists
|
unless is_exists
|
||||||
version_name = re[:target_params][:re_version]
|
version_name = re[:re_version]
|
||||||
version_id = Version.where(project_id: re[:target_params][:project_id], name: version_name)&.first&.id if version_name.present?
|
version_id = Version.where(project_id: re[:target_params][:project_id], name: version_name)&.first&.id if version_name.present?
|
||||||
assing_u_id = User.select(:id, :login).where(login: re[:assign_login]).pluck(:id).first
|
assing_u_id = User.select(:id, :login).where(login: re[:assign_login]).pluck(:id).first
|
||||||
new_target = target_type.constantize.new(re[:target_params].merge(author_id: u_id))
|
new_target = target_type.constantize.new(re[:target_params].merge(author_id: u_id))
|
||||||
|
@ -85,7 +85,7 @@ class SyncProjectsJob < ApplicationJob
|
||||||
new_target = target_type.constantize.new(re[:target_params].merge(user_id: u_id))
|
new_target = target_type.constantize.new(re[:target_params].merge(user_id: u_id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !is_exists && new_target.save!
|
if !is_exists && new_target.save!
|
||||||
SyncLog.sync_log("***【#{target_type}】. create_success---------------")
|
SyncLog.sync_log("***【#{target_type}】. create_success---------------")
|
||||||
if re[:journals].present?
|
if re[:journals].present?
|
||||||
|
@ -107,11 +107,14 @@ class SyncProjectsJob < ApplicationJob
|
||||||
SyncLog.sync_log("***【#{target_type}】. create_failed---or has_exists---------------")
|
SyncLog.sync_log("***【#{target_type}】. create_failed---or has_exists---------------")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
SyncLog.sync_log("***111222. end_to_create_target---------------")
|
||||||
|
rescue => e
|
||||||
|
SyncLog.sync_log("=========***【#{target_type}】creat_had_erros:#{e}===================")
|
||||||
|
next
|
||||||
end
|
end
|
||||||
SyncLog.sync_log("***111222. end_to_create_target---------------")
|
|
||||||
rescue => e
|
|
||||||
SyncLog.sync_log("=========***【#{target_type}】creat_had_erros:#{e}===================")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,28 +122,35 @@ class SyncProjectsJob < ApplicationJob
|
||||||
SyncLog.sync_log("***【#{target_type}】. begin_to_create_target---------------")
|
SyncLog.sync_log("***【#{target_type}】. begin_to_create_target---------------")
|
||||||
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
|
return SyncLog.sync_log("*** no target_jsons") if target_jsons.blank?
|
||||||
target_jsons.each_with_index do |re,index|
|
target_jsons.each_with_index do |re,index|
|
||||||
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
|
begin
|
||||||
if re[:target_params].present?
|
SyncLog.sync_log("***user_login:#{re[:user_login]}----target_type:#{target_type}-----#{index+1}")
|
||||||
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
|
if re[:target_params].present?
|
||||||
is_exists = Journal.exists?(user_id: u_id, journalized_id: re[:target_params][:journalized_id], created_on: re[:target_params][:created_on].to_s.to_time)
|
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
|
||||||
|
is_exists = Journal.exists?(user_id: u_id, journalized_id: re[:target_params][:journalized_id], created_on: re[:target_params][:created_on].to_s.to_time)
|
||||||
if is_exists
|
|
||||||
SyncLog.sync_log("***00000. Journal:#{re[:target_params][:id]}-is exists--------------")
|
if is_exists
|
||||||
else
|
SyncLog.sync_log("***00000. Journal:#{re[:target_params][:id]}-is exists--------------")
|
||||||
re[:target_params].delete(:id)
|
|
||||||
new_target = Journal.new(re[:target_params].merge(user_id: u_id))
|
|
||||||
new_target.journalized_id = issue_id
|
|
||||||
if new_target.save!
|
|
||||||
if re[:journal_details].present?
|
|
||||||
re[:journal_details].each do |j|
|
|
||||||
JournalDetail.create!(j.merge(journal_id: new_target.id))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
SyncLog.sync_log("***111222. journal_create failed---------------")
|
re[:target_params].delete(:id)
|
||||||
|
new_target = Journal.new(re[:target_params].merge(user_id: u_id))
|
||||||
|
new_target.journalized_id = issue_id
|
||||||
|
if new_target.save!
|
||||||
|
if re[:journal_details].present?
|
||||||
|
re[:journal_details].each do |j|
|
||||||
|
JournalDetail.create!(j.merge(journal_id: new_target.id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
SyncLog.sync_log("***111222. journal_create failed---------------")
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
SyncLog.sync_log("***111222. journal_create failed---#{e}------------")
|
||||||
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
SyncLog.sync_log("***111222. end_to_create_journal---------------")
|
SyncLog.sync_log("***111222. end_to_create_journal---------------")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue