dev_partners
cxt 6 years ago
commit 8502336b2a

@ -53,12 +53,15 @@ class WelcomeController < ApplicationController
local_shixun = LocalShixun.create!(name: shixun.name, description: shixun.description, user_id: User.current.id, status: 0, local_shixun = LocalShixun.create!(name: shixun.name, description: shixun.description, user_id: User.current.id, status: 0,
trainee: shixun.trainee, webssh: shixun.webssh, multi_webssh: shixun.multi_webssh, trainee: shixun.trainee, webssh: shixun.webssh, multi_webssh: shixun.multi_webssh,
can_copy: shixun.can_copy, identifier: generate_identifier, shixun_id: shixun.id, can_copy: shixun.can_copy, identifier: generate_identifier, shixun_id: shixun.id,
use_scope: shixun.use_scope, visits: 1, evaluate_script: shixun.evaluate_script) use_scope: shixun.use_scope, visits: 1, evaluate_script: shixun.evaluate_script,
local_giturl: shixun.git_url)
# 同步镜像 # 同步镜像
if shixun.mirror_repositories.present? if shixun.mirror_repositories.present?
shixun.mirror_repositories.each do |mirror| shixun.mirror_repositories.each do |mirror|
LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id) # 本地版的mirror id和线上的可能不一样所以按名字取然后再存
# local_mirror = MirrorRepository.where(type_name: mirror.type_name).first.try(:id)
LocalMirrorRepository.create!(:local_shixun_id => local_shixun.id, :mirror_repository_id => mirror.id, type_name: mirror.type_name)
end end
end end
@ -97,10 +100,10 @@ class WelcomeController < ApplicationController
end end
end end
end end
render :json => {status: 0, message: "同步成功"} render :json => {status: 0, message: "success"}
rescue Exception => e rescue Exception => e
logger.error("shixun_local_in ##{e.message}") logger.error("shixun_local_in ##{e.message}")
render :json => {status: -1, message: "同步失败#{e.message}"} render :json => {status: -1, message: "error#{e.message}"}
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
@ -123,7 +126,8 @@ class WelcomeController < ApplicationController
local_mirrors = LocalMirrorRepository.where(local_shixun_id: local_shixun.id) local_mirrors = LocalMirrorRepository.where(local_shixun_id: local_shixun.id)
if local_mirrors.present? if local_mirrors.present?
local_mirrors.each do |local_mirror| local_mirrors.each do |local_mirror|
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror.mirror_repository_id) local_mirror_new = MirrorRepository.where(type_name: local_mirror.try(:type_name)).first
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => local_mirror_new.id)
end end
end end
@ -147,6 +151,16 @@ class WelcomeController < ApplicationController
raise "版本库创建失败" if shixun.gpid.blank? # 若和gitlab没同步成功则抛出异常 raise "版本库创建失败" if shixun.gpid.blank? # 若和gitlab没同步成功则抛出异常
g = Gitlab.client g = Gitlab.client
shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace) shixun.update_column(:git_url, g.project(shixun.gpid).path_with_namespace)
local_git_path = local_shixun.local_giturl.split('/').last if local_shixun.local_giturl.present?
new_giturl = "http://educoder:xinhu1ji2qu3@"+g.project(shixun.gpid).http_url_to_repo.split('//').last
# 如果有目录才执行
if system("cd tmp/repositories/#{local_git_path}")
system("cd tmp/repositories/#{local_git_path};git remote remove origin;git remote add origin #{new_giturl};
git add .;git commit -m '..';git push origin master")
end
# http://Hjqreturn:xinhu1ji2qu3@bdgit.educoder.net/Hjqreturn/pgfqe6ch8.git (fetch)
# 同步关卡信息 # 同步关卡信息
local_challenges = LocalChallenge.where(local_shixun_id: local_shixun.id) local_challenges = LocalChallenge.where(local_shixun_id: local_shixun.id)

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>Educoder</title><script type="text/javascript">window.__isR=!0</script><link rel="stylesheet" href="/react/build/css/css_min_all.css"><link rel="stylesheet" href="/assets/iconfont/iconfont.css"><link href="/react/build/./static/css/main.49649fc6.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="md_div" style="display:none"></div><div id="root" class="page -layout-v -fit"></div><div id="picture_display" style="display:none"></div><script type="text/javascript" src="/react/build/js/js_min_all.js"></script><script type="text/javascript" src="/assets/kindeditor/kindeditor.js"></script><script type="text/javascript" src="/react/build/js/create_kindeditor.js"></script><script type="text/javascript" src="/javascripts/educoder/edu_application.js"></script><script type="text/javascript" src="/react/build/./static/js/main.b4aeaf4b.js"></script></body></html> <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>Educoder</title><script type="text/javascript">window.__isR=!0</script><link rel="stylesheet" href="/react/build/css/css_min_all.css"><link rel="stylesheet" href="/assets/iconfont/iconfont.css"><link href="/react/build/./static/css/main.42f9c555.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="md_div" style="display:none"></div><div id="root" class="page -layout-v -fit"></div><div id="picture_display" style="display:none"></div><script type="text/javascript" src="/react/build/js/js_min_all.js"></script><script type="text/javascript" src="/assets/kindeditor/kindeditor.js"></script><script type="text/javascript" src="/react/build/js/create_kindeditor.js"></script><script type="text/javascript" src="/javascripts/educoder/edu_application.js"></script><script type="text/javascript" src="/react/build/./static/js/main.5036f33d.js"></script></body></html>

@ -0,0 +1,5 @@
class AddLocalGiturlToLocalShixuns < ActiveRecord::Migration
def change
add_column :local_shixuns, :local_giturl, :string
end
end

@ -0,0 +1,5 @@
class AddTypeNameToLocalMirrorRepositories < ActiveRecord::Migration
def change
add_column :local_mirror_repositories, :type_name, :string
end
end
Loading…
Cancel
Save