diff --git a/app/controllers/api/v1/projects/sync_repositories_controller.rb b/app/controllers/api/v1/projects/sync_repositories_controller.rb index 7a74bddc..2306283f 100644 --- a/app/controllers/api/v1/projects/sync_repositories_controller.rb +++ b/app/controllers/api/v1/projects/sync_repositories_controller.rb @@ -17,9 +17,10 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController return render_error("请输入正确的同步方向!") if params[:sync_direction].blank? @sync_repositories = SyncRepository.where(project: @project, sync_direction: params[:sync_direction]) @sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories, enable: true) - @sync_repositories.each do |item| - TouchSyncJob.perform_later(item) - end + # 全部分支同步暂时不做 + # @sync_repositories.each do |item| + # TouchSyncJob.perform_later(item) + # end @sync_repository_branches.each do |item| TouchSyncJob.perform_later(item) end @@ -44,10 +45,12 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController def change_enable return render_error("请输入正确的分支名称") if params[:gitlink_branch_name].blank? || params[:external_branch_name].blank? return render_error("请输入正确的状态") if params[:enable].blank? - @sync_repository_branches = SyncRepositoryBranch.where(gitlink_branch_name: params[:gitlink_branch_name], external_branch_name: params[:external_branch_name]) + @sync_repository_branches = SyncRepositoryBranch.joins(:sync_repository).where(sync_repositories: {project_id: @project.id}, gitlink_branch_name: params[:gitlink_branch_name], external_branch_name: params[:external_branch_name]) if @sync_repository_branches.update_all({enable: params[:enable]}) @sync_repository_branches.each do |branch| - if branch&.sync_repository&.sync_direction.to_i == 1 + branch_sync_direction = branch&.sync_repository&.sync_direction.to_i + TouchSyncJob.perform_later(branch) if params[:enable] && branch_sync_direction == params[:first_sync_direction].to_i + if branch_sync_direction == 1 Reposync::UpdateBranchStatusService.call(branch&.sync_repository&.repo_name, branch.gitlink_branch_name, params[:enable]) else Reposync::UpdateBranchStatusService.call(branch&.sync_repository&.repo_name, branch.external_branch_name, params[:enable]) diff --git a/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder b/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder index 018668b8..a716148b 100644 --- a/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder +++ b/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder @@ -5,7 +5,7 @@ json.sync_repository_branches @group_sync_repository_branch.each do |item| branches = @sync_repository_branches.where(gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(updated_at: :desc) branch = branches.first json.type branch&.sync_repository&.type - json.sync_time branch.sync_time.strftime("%Y-%m-%d %H:%M:%S") + json.sync_time branch.sync_time.present? ? branch.sync_time.strftime("%Y-%m-%d %H:%M:%S") : nil json.sync_status branch.sync_status json.enable branch.enable json.reposync_branch_ids branches.pluck(:reposync_branch_id)