第二仓库

dev_daiao
daiao 5 years ago
parent ba608c56bc
commit 2e5eba9ce2

@ -198,14 +198,17 @@ class ChallengesController < ApplicationController
# 测试集变化则需要更新(输入、 输出、 是否隐藏) # 测试集变化则需要更新(输入、 输出、 是否隐藏)
if sets_output != params_output || sets_open != params_hidden || sets_input != params_input || set_score != params_score if sets_output != params_output || sets_open != params_hidden || sets_input != params_input || set_score != params_score
test_set.delete_all unless test_set.blank? test_set.delete_all unless test_set.blank?
params[:test_set].each_with_index do |set, index| params[:test_set].each_with_index do |set, index|
TestSet.create(:challenge_id => @challenge.id, # last 末尾匹配, full: 全完匹配
:input => "#{set[:input]}", match_rule = params[:match_rule] == 'last' ? 'last' : 'full'
:output => "#{set[:output]}", TestSet.create(:challenge_id => @challenge.id,
:is_public => params_hidden[index], :input => "#{set[:input]}",
:score => set[:score], :output => "#{set[:output]}",
:position => (index + 1)) :is_public => params_hidden[index],
end :score => set[:score],
:match_rule => "#{match_rule}",
:position => (index + 1))
end
@challenge.update_column(:modify_time, Time.now) @challenge.update_column(:modify_time, Time.now)
# 测试集的 # 测试集的
@shixun.myshixuns.update_all(:system_tip => 0) @shixun.myshixuns.update_all(:system_tip => 0)

@ -537,7 +537,7 @@ class GamesController < ApplicationController
game_challenge.test_sets.each do |test_set| game_challenge.test_sets.each do |test_set|
input = test_set.input.nil? ? "" : test_set.input.gsub("\r\n", "\n") input = test_set.input.nil? ? "" : test_set.input.gsub("\r\n", "\n")
output = test_set.output.nil? ? "" : test_set.output.gsub("\r\n", "\n") output = test_set.output.nil? ? "" : test_set.output.gsub("\r\n", "\n")
test_cases = {:input => input, :output => output} test_cases = {:input => input, :output => output, :matchRule => test_set.match_rule}
testSet << test_cases testSet << test_cases
end end
@ -560,6 +560,13 @@ class GamesController < ApplicationController
# needPortMapping web类型需要pod端口映射 # needPortMapping web类型需要pod端口映射
br_params[:needPortMapping] = 8080 if @myshixun.mirror_name.include?("Web") br_params[:needPortMapping] = 8080 if @myshixun.mirror_name.include?("Web")
# 私密仓库的设置
secret_rep = @shixun.shixun_secret_repository
if secret_rep&.repo_name
secretGitUrl = repo_url secret_rep.repo_path
br_params.merge({secretGitUrl: secretGitUrl, secretDir: secret_rep.secret_dir_path})
end
# 中间层交互 # 中间层交互
uri = "#{shixun_tomcat}/bridge/game/gameEvaluate" uri = "#{shixun_tomcat}/bridge/game/gameEvaluate"
res = interface_post uri, br_params, 502, "gameEvaluate failed" res = interface_post uri, br_params, 502, "gameEvaluate failed"

@ -473,6 +473,17 @@ class ShixunsController < ApplicationController
@shixun.shixun_service_configs.create!(config) if name.present? @shixun.shixun_service_configs.create!(config) if name.present?
end end
end end
# 添加第二仓库
if params[:is_secret_repository]
add_secret_repositoy
else
# 如果有仓库,就要删
if @shixun.shixun_secret_repository&.repo_name
GitService.delete_repository(repo_path: @shixun.shixun_secret_repository.repo_path)
@shixun.shixun_secret_repository.destroy
end
end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("实训保存失败") tip_exception("实训保存失败")
@ -819,6 +830,29 @@ class ShixunsController < ApplicationController
end end
end end
# 设置私密版本库的在tpm中的目录
def set_secret_dir
raise("设置路径不能为空") if params[:secret_dir_path].blank?
@shixun.shixun_secret_repository.update_attribute(:secret_dir_path, params[:secret_dir_path])
normal_status("设置成功")
end
def secret_repository
begin
@repo_path = @shixun.shixun_secret_repository&.repo_path
@repo_url = repo_url @repo_path
@trees = GitService.file_tree(repo_path: @repo_path, path: params[:path])
logger.info("#11@@#@#@#@111#@@@@###{@trees}")
if @trees
logger.info("#@@#@#@#@#@@@@###{@trees.try(:count)}")
@latest_commit = [GitService.commits(repo_path: @repo_path).first]
Rails.logger.info("########## #{@latest_commit}")
end
rescue Exception => e
logger.error(e.message)
end
end
include GitCommon include GitCommon
def update_file def update_file
@ -990,4 +1024,13 @@ private
modify_shixun = ShixunModify.exists?(:myshixun_id => current_myshixun.id, :shixun_id => @shixun.id, :status => 1) modify_shixun = ShixunModify.exists?(:myshixun_id => current_myshixun.id, :shixun_id => @shixun.id, :status => 1)
games.size != min_challenges.size || modify_shixun games.size != min_challenges.size || modify_shixun
end end
# 添加私密仓库
def add_secret_repositoy
# 防止跟tpm版本库重名加了前缀secret
repo_path = repo_namespace(current_user.login, "secret_#{@shixun.identifier}")
GitService.add_repository(repo_path: repo_path)
@shixun.shixun_secret_repository.create!(repo_name: repo_path.split(".")[0])
end
end end

@ -38,6 +38,9 @@ class Shixun < ApplicationRecord
has_one :shixun_info, dependent: :destroy has_one :shixun_info, dependent: :destroy
# 第二版本库
has_one :shixun_secret_repository, dependent: :destroy
belongs_to :user belongs_to :user
# 实训服务配置 # 实训服务配置
has_many :shixun_service_configs, :dependent => :destroy has_many :shixun_service_configs, :dependent => :destroy

@ -0,0 +1,11 @@
class ShixunSecretRepository < ApplicationRecord
# repo_name: 仓库名
# secret_dir_name: 在tpm仓库的那个目录下
belongs_to :shixun
def repo_path
"#{repo_name}.git"
end
end

@ -1,2 +1,3 @@
class TestSet < ApplicationRecord class TestSet < ApplicationRecord
# match_rule: 匹配规则: full 完全匹配, last 末尾匹配
end end

@ -0,0 +1,7 @@
json.trees @trees
if @trees.present?
json.partial! 'shixuns/commit', locals: { commits: @latest_commit }
end
json.git_url @repo_url

@ -197,6 +197,8 @@ Rails.application.routes.draw do
get :get_script_contents get :get_script_contents
get :get_custom_script get :get_custom_script
post :repository post :repository
post :secret_repository
post :set_secret_dir
post :commits post :commits
post :file_content post :file_content
post :update_file post :update_file

@ -0,0 +1,10 @@
class CreateShixunSecretRepositories < ActiveRecord::Migration[5.2]
def change
create_table :shixun_secret_repositories do |t|
t.references :shixun
t.string :repo_name
t.string :secret_dir_path
t.timestamps
end
end
end

@ -0,0 +1,7 @@
class AddMatchRuleForTestSets < ActiveRecord::Migration[5.2]
def change
add_column :test_sets, :match_rule, :string
TestSet.update_all(match_rule: 'full')
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ShixunSecretRepository, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save