mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-02 19:30:48 +08:00
qianyi datas
This commit is contained in:
69
app/jobs/sync_projects_job.rb
Normal file
69
app/jobs/sync_projects_job.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
class SyncProjectsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
require 'uri'
|
||||
require 'net/http'
|
||||
|
||||
def perform(sync_params)
|
||||
SyncLog.sync_log.info("==========begin to sync #{sync_params[:type]} to forge============")
|
||||
begin
|
||||
gitea_main = "https://trustie.net"
|
||||
if request.subdomain === 'testforgeplus'
|
||||
gitea_main = "https://ucloudtest.trustie.net/"
|
||||
end
|
||||
|
||||
url = "#{gitea_main}/sync_forges" #trustie上的相关路由
|
||||
|
||||
sync_json = {
|
||||
"sync_params": sync_params
|
||||
}
|
||||
uri = URI.parse(url)
|
||||
if api_host
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
http.use_ssl = true
|
||||
response = http.send_request('GET', uri.path, sync_params, {'Content-Type' => 'application/json'})
|
||||
if response.status == 200
|
||||
target_jsons = response.body
|
||||
if target_jsons.present? && sync_params[:type]
|
||||
create_target(eval(target_jsons), sync_params[:type].to_s)
|
||||
end
|
||||
else
|
||||
SyncLog.sync_log.info("==========bsync_user_to_forge_failed #{sync_params[:type]}============")
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
SyncLog.sync_log.info("==========bsync_user_to_forge_failed #{sync_params[:type]}============errors:#{e}")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create_target(target_jsons, target_type)
|
||||
target_jsons.each do |re|
|
||||
|
||||
u_id = User.select(:id, :login).where(login: re[:user_login]).pluck(:id).first
|
||||
|
||||
new_target = target_type.constantize.new(re[:target_params].merge(user_id: u_id))
|
||||
if target_type == "Project"
|
||||
create_target(re[:issues_params], "Issue") if re[:issues_params].present?
|
||||
create_target(re[:member_params], "Member") if re[:member_params].present?
|
||||
create_target(re[:versions_params], "Version") if re[:versions_params].present?
|
||||
create_target(re[:watcher_params], "Watcher") if re[:watcher_params].present?
|
||||
create_target(re[:praise_treads], "PraiseTread") if re[:praise_treads].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
|
||||
if re[:journals].present?
|
||||
create_target(re[:journals], "Journal")
|
||||
end
|
||||
end
|
||||
if new_target.save!
|
||||
if re[:journal_details].present?
|
||||
re[:journal_details].each do |j|
|
||||
JournalDetail.create!(j[:journal_detail].merge(journal_id: new_target.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
40
app/jobs/sync_repository_job.rb
Normal file
40
app/jobs/sync_repository_job.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
class SyncRepositoryJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
#同步 trustie的仓库
|
||||
|
||||
def perform(repository, repository_params)
|
||||
#创建临时文件夹 clone 并强推代码
|
||||
SyncLog.sync_log("=================begin to sync repository=====================")
|
||||
path = "#{Rails.root}/public/cache_repository"
|
||||
unless File.directory?(path)
|
||||
FileUtils.mkdir_p(path)
|
||||
end
|
||||
image_url = repository_params[:url]
|
||||
g_default_branch = repository_params[:default_branch]
|
||||
image_repo_name = image_url.to_s.split('/')&.last&.chomp('.git')
|
||||
check_clone = system("cd #{path} and git clone #{image_url}")
|
||||
|
||||
gitea_main = "testgitea.trustie.net"
|
||||
if request.subdomain === 'testforgeplus'
|
||||
gitea_main = "testgitea2.trustie.net"
|
||||
elsif request.subdomain === 'forge'
|
||||
gitea_main = "gitea.trustie.net"
|
||||
end
|
||||
|
||||
if check_clone
|
||||
new_gitlab_url = "http://root:_Trustie_10010@#{gitea_main}/#{repository.user.login}/#{repository.identifier}.git"
|
||||
|
||||
shell_remote_1 = system("cd #{path}/#{image_repo_name} && git remote set-url origin #{new_gitlab_url}")
|
||||
|
||||
shell5 = system("cd #{path}/#{image_repo_name} && git checkout #{g_default_branch} && git push --force --set-upstream origin #{g_default_branch}")
|
||||
if !shell5
|
||||
SyncLog.sync_log("++++++++++++++++++force_push_erros++++++++++++++++++##{path}/#{image_repo_name}++++++new_gitlab_url+++#{new_gitlab_url}")
|
||||
end
|
||||
else
|
||||
SyncLog.sync_log("++++++++++++++++++check_clone_erros++++++++++++++++++#{image_repo_name}")
|
||||
end
|
||||
SyncLog.sync_log("=================end to sync repository=====================#{image_repo_name}")
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user