From 79c5462a1bb43a8c190d0b9dd0dda9ffa3a26a04 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 23 Jun 2020 11:57:24 +0800 Subject: [PATCH] FIX migration repository job's bug --- app/controllers/projects_controller.rb | 6 ++---- app/jobs/migrate_remote_repository_job.rb | 2 +- app/services/projects/migrate_service.rb | 15 +++++++-------- app/services/repositories/migrate_service.rb | 12 +++++------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a70a380da..9c3188302 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -25,10 +25,8 @@ class ProjectsController < ApplicationController end def migrate - ActiveRecord::Base.transaction do - Projects::MigrateForm.new(mirror_params).validate! - @project = Projects::MigrateService.new(current_user, mirror_params).call - end + Projects::MigrateForm.new(mirror_params).validate! + @project = Projects::MigrateService.new(current_user, mirror_params).call rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index 75cf0613f..bdc7d5e23 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -8,7 +8,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob gitea_repository = Gitea::Repository::MigrateService.new(token, params).call if gitea_repository - repo&.project&.update_columns(gpid: gitea_repository["id"], identifier: gitea_repository["name"]) + repo&.project&.update_columns(gpid: gitea_repository["id"]) repo&.mirror&.update_columns(status: Mirror.statuses[:succeeded]) end end diff --git a/app/services/projects/migrate_service.rb b/app/services/projects/migrate_service.rb index eb24bdc41..2eb9172cb 100644 --- a/app/services/projects/migrate_service.rb +++ b/app/services/projects/migrate_service.rb @@ -8,12 +8,10 @@ class Projects::MigrateService < ApplicationService def call @project = Project.new(project_params) - ActiveRecord::Base.transaction do - if @project.save! - Repositories::MigrateService.new(user, @project, repository_params).call - else - # - end + if @project.save! + Repositories::MigrateService.new(user, @project, repository_params).call + else + # end @project rescue => e @@ -27,11 +25,12 @@ class Projects::MigrateService < ApplicationService { name: params[:name], user_id: params[:user_id], + project_type: set_project_type, description: params[:description], + identifier: params[:repository_name], + is_public: project_secretion[:public], project_category_id: params[:project_category_id], project_language_id: params[:project_language_id], - is_public: project_secretion[:public], - project_type: set_project_type } end diff --git a/app/services/repositories/migrate_service.rb b/app/services/repositories/migrate_service.rb index 090d64739..dad7e3930 100644 --- a/app/services/repositories/migrate_service.rb +++ b/app/services/repositories/migrate_service.rb @@ -9,13 +9,11 @@ class Repositories::MigrateService < ApplicationService def call @repository = Repository.new(repository_params) - ActiveRecord::Base.transaction do - if @repository.save! - @repository.set_mirror! if wrapper_mirror - MigrateRemoteRepositoryJob.perform_later(@repository.id, user.gitea_token, gitea_repository_params) - end - @repository + if @repository.save! + @repository.set_mirror! if wrapper_mirror + MigrateRemoteRepositoryJob.perform_later(@repository.id, user.gitea_token, gitea_repository_params) end + @repository rescue => e puts "create mirror repository service error: #{e.message}" raise Error, e.message @@ -23,7 +21,7 @@ class Repositories::MigrateService < ApplicationService private def repository_params - params.merge(project_id: project.id) + params.merge(project_id: project.id, identifier: params[:identifier]) end def gitea_repository_params