dev_partners
huang 6 years ago
parent 3135f36cae
commit fe1b87f9d6

@ -53,7 +53,8 @@ class WelcomeController < ApplicationController
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,
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?
@ -97,10 +98,10 @@ class WelcomeController < ApplicationController
end
end
end
render :json => {status: 0, message: "同步成功"}
render :json => {status: 0, message: "success"}
rescue Exception => e
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
end
@ -147,6 +148,14 @@ class WelcomeController < ApplicationController
raise "版本库创建失败" if shixun.gpid.blank? # 若和gitlab没同步成功则抛出异常
g = Gitlab.client
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
system("cd tmp/repositories/#{local_git_path}")
system("git remote remove origin")
system("git remote add origin #{new_giturl}")
system("git add .")
system("git commit -m 'first commit'")
system("git push origin master")
# 同步关卡信息
local_challenges = LocalChallenge.where(local_shixun_id: local_shixun.id)

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

File diff suppressed because one or more lines are too long

@ -0,0 +1,3 @@
mysql -uroot -p1234;
use 20180311;
source local_shixuns.sql
Loading…
Cancel
Save