forked from jasder/forgeplus
sync_forge_job的修改
This commit is contained in:
parent
934595c6a4
commit
98c5372d61
|
@ -1,4 +1,6 @@
|
|||
class SyncForgeController < ApplicationController
|
||||
skip_before_action :user_setup
|
||||
skip_before_action :check_sign
|
||||
|
||||
def create
|
||||
SyncForgeJob.perform_later(params[:sync_params])
|
||||
|
|
|
@ -39,15 +39,20 @@ class SyncForgeJob < ApplicationJob
|
|||
result = Gitea::User::GenerateTokenService.new(owner_params["login"], user_password).call
|
||||
new_user.gitea_token = result['sha1']
|
||||
end
|
||||
end
|
||||
if new_user.gitea_uid.present? && new_user.save!
|
||||
|
||||
if new_user.save!
|
||||
owner_extension_params = owner_extension_params["user_extensions"] if old_version_source.include?(platform) #trustie上需要
|
||||
if owner_extension_params.present?
|
||||
owner_extension_params = owner_extension_params&.except!(*keys_other_delete).merge(user_id: new_user.id)
|
||||
UserExtension.create!(owner_extension_params)
|
||||
end
|
||||
end
|
||||
end
|
||||
if new_user.present?
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
Watcher&.where(user_id: user_params["id"]).update_all(user_id: new_user.id)
|
||||
ProjectTrend&.where(user_id: user_params["id"]).update_all(user_id: new_user.id)
|
||||
sync_roles(roles_params, platform)
|
||||
all_target_params.each do |project|
|
||||
target_params = {
|
||||
|
@ -58,7 +63,9 @@ class SyncForgeJob < ApplicationJob
|
|||
project_score_params: project["project_score_params"],
|
||||
pull_request_params: project["pull_request_params"],
|
||||
repo_params: project["repo_params"],
|
||||
commit_params: project["commit_params"]
|
||||
commit_params: project["commit_params"],
|
||||
watchers_params: project["watchers_params"],
|
||||
praise_trends_params: project["praise_trends_params"]
|
||||
}
|
||||
sync_projects(new_user, user_params["id"],target_params, platform)
|
||||
end
|
||||
|
@ -97,16 +104,29 @@ class SyncForgeJob < ApplicationJob
|
|||
version_params = targets[:versions_params]
|
||||
member_params = targets[:member_params]
|
||||
project_score = targets[:project_score_params]
|
||||
project = project["project"] if old_version_source.include?(platform) #trustie上需要
|
||||
repo_params = targets[:repo_params]
|
||||
praise_trends_params = targets[:praise_trends_params]
|
||||
watchers_params = targets[:watchers_params]
|
||||
|
||||
if old_version_source.include?(platform) #trustie上需要
|
||||
project = project["project"]
|
||||
repo_params = repo_params["gitlab"]
|
||||
end
|
||||
|
||||
if project.present?
|
||||
unless Project.exists?(identifier: project["identifier"])
|
||||
new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id))
|
||||
if new_project.save!
|
||||
if repo_params.present?
|
||||
repository_params = {
|
||||
hidden: project["is_public"],
|
||||
user_id: new_user.id,
|
||||
identifier: project["identifier"]
|
||||
}
|
||||
Repositories::CreateService.new(new_user, new_project, repository_params).call
|
||||
# SyncRepositoryJob.perform_later(new_user.login, project["identifier"]) #暂时不迁移版本库
|
||||
end
|
||||
|
||||
project_score = project_score["project_score"] if old_version_source.include?(platform) #trustie上需要
|
||||
if project_score.present?
|
||||
ProjectScore.create!(project_score&.except!(*score_to_delete).merge(project_id: new_project.id))
|
||||
|
@ -116,6 +136,9 @@ class SyncForgeJob < ApplicationJob
|
|||
sync_commits(new_project.id,new_project.gpid, commit_params,platform)
|
||||
sync_pull_requests(new_project.id,new_user.id, pr_params,platform)
|
||||
sync_versions(new_project.id, new_user.id, version_params,platform)
|
||||
sync_watchers(new_project.id, watchers_params, platform)
|
||||
sync_praises(new_project.id,praise_trends_params,platform)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -125,6 +148,52 @@ class SyncForgeJob < ApplicationJob
|
|||
end
|
||||
end
|
||||
|
||||
def sync_watchers(project_id, watchers_params, platform)
|
||||
Rails.logger.info("#######______sync_watchers_start__#######")
|
||||
roles_other_delete = %w(id watchable_id)
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
|
||||
if watchers_params.present?
|
||||
Watcher.transaction do
|
||||
watchers_params.each do |r|
|
||||
r = r["watcher"] if old_version_source.include?(platform) #trustie上需要
|
||||
Watcher.create!(r&.except!(*roles_other_delete).merge(watchable_id: project_id)) if r.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
Rails.logger.info("#######______sync_watchers_end__#######")
|
||||
rescue Exception => e
|
||||
Rails.logger.info("#######_______sync_watchers__failed__#########{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def sync_praises(project_id, praises_params, platform)
|
||||
Rails.logger.info("#######______sync_praises_start__#######")
|
||||
roles_other_delete = %w(id praise_tread_object_id created_at updated_at)
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
|
||||
if praises_params.present?
|
||||
PraiseTread.transaction do
|
||||
praises_params.each do |r|
|
||||
r = r["praise_tread"] if old_version_source.include?(platform) #trustie上需要
|
||||
PraiseTread.create!(r&.except!(*roles_other_delete).merge(praise_tread_object_id: project_id)) if r.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
Rails.logger.info("#######______sync_praises_end__#######")
|
||||
rescue Exception => e
|
||||
Rails.logger.info("#######_______sync_praises__failed__#########{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def sync_roles(roles,platform)
|
||||
Rails.logger.info("#######______sync_roles_start__#######")
|
||||
roles_other_delete = %w(id)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
class SyncRepositoryJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(login,identifier)
|
||||
Rails.logger.info("#######__________begin_sync_repository_________####")
|
||||
gitea_test_ssh = "sshpass -p '@pd:lk4+407' ssh -o StrictHostKeyChecking=no -p 30122 root@123.59.135.93"
|
||||
gitea_jump_ssh = "sshpass -p '#pd:lk3+407' ssh -o StrictHostKeyChecking=no -p 30122 root@10.9.69.134"
|
||||
gitea_user_repo = "/home/git/gitea-repositories/#{login}"
|
||||
git_clone_bare = "git clone --bare http://git.trustie.net/#{login}/#{identifier}.git"
|
||||
|
||||
gitea_repos = system("#{gitea_test_ssh} && #{gitea_jump_ssh} && cd #{gitea_user_repo} && rm -rf #{identifier}.git && #{git_clone_bare}")
|
||||
|
||||
if gitea_repos
|
||||
Rails.logger.info("########________gitea_clone_success__________##############")
|
||||
else
|
||||
Rails.logger.info("########________gitea_clone_failed_____user_loigin:_#{login}_identifier:__#{identifier}")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -3,10 +3,10 @@ class UserExtension < ApplicationRecord
|
|||
enum identity: { teacher: 0, student: 1, professional: 2, developer: 3, enterprise: 4, unselect: -1 }
|
||||
|
||||
belongs_to :user, touch: true
|
||||
belongs_to :school, optional: true
|
||||
belongs_to :department, optional: true
|
||||
# belongs_to :school, optional: true
|
||||
# belongs_to :department, optional: true
|
||||
|
||||
before_save :set_laboratory_school
|
||||
# before_save :set_laboratory_school
|
||||
|
||||
def identity_text
|
||||
I18n.t("user.identity.#{identity}")
|
||||
|
|
|
@ -48,7 +48,8 @@ class Repositories::CreateService < ApplicationService
|
|||
def gitea_repository_params
|
||||
hash = {
|
||||
name: params[:identifier],
|
||||
private: !params[:hidden]
|
||||
private: !params[:hidden],
|
||||
readme: "ReadMe"
|
||||
# "auto_init": true,
|
||||
# "description": "string",
|
||||
# "gitignores": "string",
|
||||
|
|
Loading…
Reference in New Issue