From 6220a3c05aab7ccb8cc6331b1c6b1a99a254a968 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Tue, 14 Jul 2020 13:45:52 +0800 Subject: [PATCH] change branches --- app/controllers/sync_forge_controller.rb | 4 ++-- app/jobs/sync_repository_job.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/sync_forge_controller.rb b/app/controllers/sync_forge_controller.rb index 9930758b5..c208b39dd 100644 --- a/app/controllers/sync_forge_controller.rb +++ b/app/controllers/sync_forge_controller.rb @@ -6,9 +6,9 @@ class SyncForgeController < ApplicationController params.permit! sync_params = params[:sync_params] #以前已同步的项目,那么肯定存在仓库 - if Project.exists?(id: sync_params[:id], identifier: sync_params[:identifier]) + if Project.exists?(identifier: sync_params[:identifier]) Rails.logger.info("=================begin_to_update_project========") - project = Project.find_by(id: sync_params[:id]) + project = Project.find_by(identifier: sync_params[:identifier]) Rails.logger.info("--------project_id:#{project.id}---------------") check_sync_project(project, sync_params) else #新建项目 diff --git a/app/jobs/sync_repository_job.rb b/app/jobs/sync_repository_job.rb index 0aa5dd79a..89d3bacc5 100644 --- a/app/jobs/sync_repository_job.rb +++ b/app/jobs/sync_repository_job.rb @@ -8,7 +8,7 @@ class SyncRepositoryJob < ApplicationJob SyncLog.sync_log("=================begin to sync request trustie repository=====================") path = "#{Rails.root}/public/cache_repository" image_url = repository_params[:git_url] - g_default_branch = repository_params[:default_branch] || "master" + gitlab_branches = repository_params[:gitlab_branches] image_repo_name = image_url.to_s.split('/')&.last&.chomp('.git') unless File.directory?(path) @@ -24,13 +24,13 @@ class SyncRepositoryJob < ApplicationJob if check_clone new_gitlab_url = "http://root:_Trustie_10010@#{gitea_main}/#{user_login}/#{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_project_log("=============force_push_erros==#{path}/#{image_repo_name}++new_gitlab_url+++#{new_gitlab_url}") - SyncLog.sync_log("++++++++++++++++++force_push_erros++++++++++++++++++##{path}/#{image_repo_name}++++++new_gitlab_url+++#{new_gitlab_url}") - else - SyncLog.sync_project_log("=============force_push_success==#{path}/#{image_repo_name}++new_gitlab_url+++#{new_gitlab_url}") + gitlab_branches.each do |branch| + shell5 = system("cd #{path}/#{image_repo_name} && git checkout #{branch} && git push --force --set-upstream origin #{branch}") + if !shell5 + SyncLog.sync_project_log("=============force_push_erros==#{path}/#{image_repo_name}++branch:#{branch}") + else + SyncLog.sync_project_log("=============force_push_success==#{path}/#{image_repo_name}++branch+++#{branch}") + end end else SyncLog.sync_project_log("=============check_clone_erros==#{path}/#{image_repo_name}")