| @@ -0,0 +1,75 @@ | |||
| class Action::NodeInputsController < ApplicationController | |||
| before_action :require_admin, except: [:index] | |||
| before_action :find_action_node | |||
| def index | |||
| @node_inputs = @node.action_node_inputs | |||
| respond_to do |format| | |||
| format.html | |||
| format.json | |||
| end | |||
| end | |||
| def create | |||
| @node_input = Action::NodeInput.new(node_input_params) | |||
| @node_input.action_node = @node | |||
| respond_to do |format| | |||
| if @node_input.save | |||
| format.html { redirect_to action_node_node_inputs_path(@node), notice: '创建成功.' } | |||
| format.json { render_ok(data: @node_input.as_json) } | |||
| else | |||
| format.html { render :new } | |||
| format.json { render json: @node_input.errors, status: -1 } | |||
| end | |||
| end | |||
| end | |||
| def new | |||
| end | |||
| def show | |||
| end | |||
| def edit | |||
| end | |||
| def update | |||
| @node_input.update(node_input_params) | |||
| respond_to do |format| | |||
| format.html { redirect_to action_node_node_inputs_path(@node), notice: '更新成功.' } | |||
| format.json { render_ok(data: @node_input.as_json) } | |||
| end | |||
| end | |||
| def destroy | |||
| if @node_input.destroy! | |||
| flash[:success] = '删除成功' | |||
| else | |||
| flash[:danger] = '删除失败' | |||
| end | |||
| redirect_to "api/actions/nodes" | |||
| end | |||
| private | |||
| def find_action_node | |||
| @node = Action::Node.find(params[:node_id]) | |||
| if params[:id].present? | |||
| @node_input = @node.action_node_inputs.find(params[:id]) | |||
| else | |||
| @node_input = Action::NodeInput.new | |||
| end | |||
| end | |||
| def node_input_params | |||
| if params.require(:action_node_input) | |||
| params.require(:action_node_input).permit(:name, :input_type, :description, :is_required, :sort_no) | |||
| else | |||
| params.permit(:name, :input_type, :description, :is_required, :sort_no) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,76 @@ | |||
| class Action::NodeSelectsController < ApplicationController | |||
| before_action :require_admin, except: [:index] | |||
| before_action :find_action_node | |||
| def index | |||
| @node_selects = @node.action_node_selects | |||
| respond_to do |format| | |||
| format.html | |||
| format.json | |||
| end | |||
| end | |||
| def create | |||
| @node_select = Action::NodeSelect.new(node_select_params) | |||
| @node_select.action_node = @node | |||
| respond_to do |format| | |||
| if @node_select.save | |||
| format.html { redirect_to action_node_node_selects_path(@node), notice: '创建成功.' } | |||
| format.json { render_ok(data: @node_select.as_json) } | |||
| else | |||
| format.html { render :new } | |||
| format.json { render json: @node_select.errors, status: -1 } | |||
| end | |||
| end | |||
| end | |||
| def new | |||
| end | |||
| def show | |||
| end | |||
| def edit | |||
| end | |||
| def update | |||
| @node_select.update(node_select_params) | |||
| respond_to do |format| | |||
| format.html { redirect_to action_node_node_selects_path(@node), notice: '更新成功.' } | |||
| format.json { render_ok(data: @node_select.as_json) } | |||
| end | |||
| end | |||
| def destroy | |||
| if @node_select.destroy! | |||
| flash[:success] = '删除成功' | |||
| else | |||
| flash[:danger] = '删除失败' | |||
| end | |||
| redirect_to "api/actions/nodes" | |||
| end | |||
| private | |||
| def find_action_node | |||
| @node = Action::Node.find(params[:node_id]) | |||
| if params[:id].present? | |||
| @node_select = @node.action_node_selects.find(params[:id]) | |||
| else | |||
| @node_select = Action::NodeSelect.new | |||
| end | |||
| end | |||
| def node_select_params | |||
| if params.require(:action_node_select) | |||
| params.require(:action_node_select).permit(:name, :val, :val_ext, :description, :sort_no) | |||
| else | |||
| params.permit(:name, :val, :val_ext, :description, :sort_no) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,64 @@ | |||
| class Action::NodeTypesController < ApplicationController | |||
| before_action :require_admin, except: [:index] | |||
| before_action :find_node_type, except: [:index, :create, :new] | |||
| def index | |||
| @node_types = Action::NodeType.all | |||
| end | |||
| def create | |||
| @node_type = Action::NodeType.new(node_types_params) | |||
| respond_to do |format| | |||
| if @node_type.save | |||
| format.html { redirect_to action_node_types_path, notice: '创建成功.' } | |||
| format.json { render_ok(data: @node_type.as_json) } | |||
| else | |||
| format.html { render :new } | |||
| format.json { render json: @node_type.errors, status: -1 } | |||
| end | |||
| end | |||
| end | |||
| def show | |||
| end | |||
| def new | |||
| @node_type = Action::NodeType.new | |||
| end | |||
| def edit | |||
| end | |||
| def update | |||
| @node_type.update(node_types_params) | |||
| respond_to do |format| | |||
| format.html { redirect_to action_node_types_path, notice: '更新成功.' } | |||
| format.json { render_ok(data: @node_type.as_json) } | |||
| end | |||
| end | |||
| def destroy | |||
| if @node_type.destroy! | |||
| flash[:success] = '删除成功' | |||
| else | |||
| flash[:danger] = '删除失败' | |||
| end | |||
| redirect_to action_node_types_path | |||
| end | |||
| private | |||
| def find_node_type | |||
| @node_type = Action::NodeType.find(params[:id]) | |||
| end | |||
| def node_types_params | |||
| if params.require(:action_node_type) | |||
| params.require(:action_node_type).permit(:name, :description, :sort_no) | |||
| else | |||
| params.permit(:name, :description, :sort_no) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,69 @@ | |||
| class Action::NodesController < ApplicationController | |||
| before_action :require_admin, except: [:index] | |||
| before_action :find_action_node, except: [:index, :create, :new] | |||
| def index | |||
| @node_types = Action::NodeType.all | |||
| @no_type_nodes = Action::Node.where(action_node_types_id: nil) | |||
| respond_to do |format| | |||
| format.html { @nodes = Action::Node.all } | |||
| format.json | |||
| end | |||
| end | |||
| def create | |||
| @node = Action::Node.new(node_params) | |||
| respond_to do |format| | |||
| if @node.save | |||
| format.html { redirect_to action_nodes_path, notice: '创建成功.' } | |||
| format.json { render_ok(data: @node.as_json) } | |||
| else | |||
| format.html { render :new } | |||
| format.json { render json: @node.errors, status: -1 } | |||
| end | |||
| end | |||
| end | |||
| def new | |||
| @node = Action::Node.new | |||
| end | |||
| def show | |||
| end | |||
| def edit | |||
| end | |||
| def update | |||
| @node.update(node_params) | |||
| respond_to do |format| | |||
| format.html { redirect_to action_nodes_path, notice: '更新成功.' } | |||
| format.json { render_ok(data: @node.as_json) } | |||
| end | |||
| end | |||
| def destroy | |||
| if @node.destroy! | |||
| flash[:success] = '删除成功' | |||
| else | |||
| flash[:danger] = '删除失败' | |||
| end | |||
| redirect_to action_nodes_path | |||
| end | |||
| private | |||
| def find_action_node | |||
| @node = Action::Node.find(params[:id]) | |||
| end | |||
| def node_params | |||
| if params.require(:action_node) | |||
| params.require(:action_node).permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) | |||
| else | |||
| params.permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,68 @@ | |||
| class Action::TemplatesController < ApplicationController | |||
| before_action :require_admin, except: [:index] | |||
| before_action :find_action_template, except: [:index, :create, :new] | |||
| def index | |||
| @templates = Action::Template.all | |||
| respond_to do |format| | |||
| format.html | |||
| format.json | |||
| end | |||
| end | |||
| def create | |||
| @template = Action::Template.new(templates_params) | |||
| respond_to do |format| | |||
| if @template.save | |||
| format.html { redirect_to action_templates_path, notice: '创建成功.' } | |||
| format.json { render_ok(data: @template.as_json) } | |||
| else | |||
| format.html { render :new } | |||
| format.json { render json: @template.errors, status: -1 } | |||
| end | |||
| end | |||
| end | |||
| def show | |||
| end | |||
| def new | |||
| @template = Action::Template.new | |||
| end | |||
| def edit | |||
| end | |||
| def update | |||
| @template.update(templates_params) | |||
| respond_to do |format| | |||
| format.html { redirect_to action_templates_path, notice: '更新成功.' } | |||
| format.json { render_ok(data: @template.as_json) } | |||
| end | |||
| end | |||
| def destroy | |||
| if @template.destroy! | |||
| flash[:success] = '删除成功' | |||
| else | |||
| flash[:danger] = '删除失败' | |||
| end | |||
| redirect_to action_templates_path | |||
| end | |||
| private | |||
| def find_action_template | |||
| @template = Action::Template.find(params[:id]) | |||
| end | |||
| def templates_params | |||
| if params.require(:action_template) | |||
| params.require(:action_template).permit(:name, :description, :img, :sort_no, :json, :yaml) | |||
| else | |||
| params.permit(:name, :description, :img, :sort_no, :json, :yaml) | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,148 @@ | |||
| class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController | |||
| before_action :require_public_and_member_above, except: [:sync] | |||
| before_action :load_project, only: [:sync] | |||
| def index | |||
| @sync_repositories = @project.sync_repositories | |||
| @group_sync_repository = @project.sync_repositories.group(:type, :external_repo_address, :sync_granularity, :external_token).count | |||
| end | |||
| def create | |||
| @sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2 = Api::V1::Projects::SyncRepositories::CreateService.call(@project, sync_repository_params) | |||
| rescue Exception => e | |||
| uid_logger_error(e.message) | |||
| tip_exception(e.message) | |||
| end | |||
| def update_info | |||
| return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present? | |||
| Api::V1::Projects::SyncRepositories::UpdateService.call(@project, params[:sync_repository_ids], sync_repository_update_params) | |||
| render_ok | |||
| rescue Exception => e | |||
| uid_logger_error(e.message) | |||
| tip_exception(e.message) | |||
| end | |||
| def sync | |||
| return render_error("请输入正确的同步方向!") if params[:sync_direction].blank? | |||
| if params[:repo_type].present? | |||
| @sync_repositories = SyncRepository.where(project: @project, type: params[:repo_type], sync_direction: params[:sync_direction]) | |||
| else | |||
| @sync_repositories = SyncRepository.where(project: @project, sync_direction: params[:sync_direction]) | |||
| end | |||
| branch = params[:payload].present? ? JSON.parse(params[:payload])["ref"].split("/")[-1] : params[:ref].split("/")[-1] rescue nil | |||
| if params[:sync_direction].to_i == 1 | |||
| @sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories, gitlink_branch_name: branch, enable: true) | |||
| else | |||
| @sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories, external_branch_name: branch, enable: true) | |||
| end | |||
| # 全部分支同步暂时不做 | |||
| # @sync_repositories.each do |item| | |||
| # TouchSyncJob.perform_later(item) | |||
| # end | |||
| @sync_repository_branches.each do |item| | |||
| TouchSyncJob.set(wait: 5.seconds).perform_later(item) | |||
| end | |||
| rescue Exception => e | |||
| uid_logger_error(e.message) | |||
| tip_exception(e.message) | |||
| end | |||
| def unbind | |||
| return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present? | |||
| @sync_repositories = SyncRepository.where(id: params[:sync_repository_ids].split(",")) | |||
| @sync_repositories.each do |repo| | |||
| # Reposync::DeleteRepoService.call(repo.repo_name) # 解绑操作放在回调里 | |||
| Api::V1::Projects::Webhooks::DeleteService.call(@project, repo.webhook_gid) | |||
| repo.destroy | |||
| end | |||
| render_ok | |||
| rescue Exception => e | |||
| uid_logger_error(e.message) | |||
| tip_exception(e.message) | |||
| end | |||
| def change_enable | |||
| return render_error("请输入正确的仓库类型") if params[:repo_type].blank? | |||
| 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.joins(:sync_repository).where(sync_repositories: {project_id: @project.id, type: params[:repo_type]}, 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| | |||
| branch_sync_direction = branch&.sync_repository&.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]) | |||
| end | |||
| TouchSyncJob.perform_later(branch) if params[:enable] && branch_sync_direction == params[:first_sync_direction].to_i | |||
| end | |||
| render_ok | |||
| else | |||
| render_error("更新失败!") | |||
| end | |||
| rescue Exception => e | |||
| uid_logger_error(e.message) | |||
| tip_exception(e.message) | |||
| end | |||
| def create_branch | |||
| return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present? | |||
| return render_error("请输入正确的Gitlink分支名称") unless params[:gitlink_branch_name].present? | |||
| return render_error("请输入正确的外部仓库分支名称") unless params[:external_branch_name].present? | |||
| return render_error("请输入正确的首次同步方向") unless params[:first_sync_direction].present? | |||
| params[:sync_repository_ids].split(",").each do |id| | |||
| repo = SyncRepository.find_by_id id | |||
| branch = Reposync::CreateSyncBranchService.call(repo.repo_name, params[:gitlink_branch_name], params[:external_branch_name]) | |||
| return render_error(branch[2]) if branch[0].to_i !=0 | |||
| sync_branch = SyncRepositoryBranch.create!(sync_repository_id: id, gitlink_branch_name: params[:gitlink_branch_name], external_branch_name: params[:external_branch_name], reposync_branch_id: branch[1]['id']) | |||
| TouchSyncJob.perform_later(sync_branch) if params[:first_sync_direction].to_i == repo.sync_direction | |||
| end | |||
| render_ok | |||
| rescue Exception => e | |||
| uid_logger_error(e.message) | |||
| tip_exception(e.message) | |||
| end | |||
| def branches | |||
| return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present? | |||
| @sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: params[:sync_repository_ids].split(",")) | |||
| @sync_repository_branches = @sync_repository_branches.ransack(gitlink_branch_name_or_external_branch_name_cont: params[:branch_name]).result if params[:branch_name].present? | |||
| @group_sync_repository_branch = @sync_repository_branches.joins(:sync_repository).group("sync_repositories.type, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").select("sync_repositories.type as type,max(sync_repository_branches.updated_at) as updated_at, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").sort_by{|i|i.updated_at} | |||
| @each_json = [] | |||
| @group_sync_repository_branch.each do |item| | |||
| branches = @sync_repository_branches.joins(:sync_repository).where(sync_repositories: {type: item.type}, gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(updated_at: :desc) | |||
| branch = branches.first | |||
| @each_json << { | |||
| gitlink_branch_name: item.gitlink_branch_name, | |||
| external_branch_name: item.external_branch_name, | |||
| type: branch&.sync_repository&.type, | |||
| sync_time: branch.sync_time.present? ? branch.sync_time.strftime("%Y-%m-%d %H:%M:%S") : nil, | |||
| sync_status: branch.sync_status, | |||
| enable: branch.enable, | |||
| enable_num: branch.enable ? 1 : 0, | |||
| created_at: branch.created_at.to_i, | |||
| reposync_branch_ids: branches.pluck(:reposync_branch_id) | |||
| } | |||
| end | |||
| @each_json = @each_json.sort_by{|h| [-h[:enable_num], h[:created_at]]} | |||
| render :json => {total_count: @group_sync_repository_branch.count, sync_repository_branches: @each_json} | |||
| end | |||
| def history | |||
| return render_error("请输入正确的同步分支ID") unless params[:reposync_branch_ids] | |||
| @branch = SyncRepositoryBranch.find_by(reposync_branch_id: params[:reposync_branch_ids].split(",")[0]) | |||
| _, @reposync_branch_logs, @total_count, _ = Reposync::GetLogsService.call(nil, params[:reposync_branch_ids], page, limit) | |||
| end | |||
| private | |||
| def sync_repository_params | |||
| params.permit(:type, :external_token, :external_repo_address, :sync_granularity, :external_branch_name, :gitlink_branch_name, :first_sync_direction) | |||
| end | |||
| def sync_repository_update_params | |||
| params.permit(:external_token, :external_repo_address) | |||
| end | |||
| end | |||
| @@ -64,10 +64,9 @@ class RepositoriesController < ApplicationController | |||
| @entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name) | |||
| else | |||
| @entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call | |||
| return render_not_found if @entries.is_a?(Array) && @entries.blank? | |||
| @entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : [] | |||
| @path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" | |||
| @repo_detail = $gitea_client.get_repos_by_owner_repo(@owner.login, @project.identifier) | |||
| return render_not_found if @entries.blank? && !@repo_detail["empty"] | |||
| end | |||
| end | |||
| @@ -0,0 +1,2 @@ | |||
| module Action::NodeHelper | |||
| end | |||
| @@ -0,0 +1,24 @@ | |||
| class TouchSyncJob < ApplicationJob | |||
| queue_as :default | |||
| def perform(touchable) | |||
| puts "aaaa" | |||
| case touchable.class.to_s | |||
| when 'SyncRepositories::Github' || 'SyncRepositories::Gitee' | |||
| Reposync::SyncRepoService.call(touchable.repo_name) | |||
| when 'SyncRepositoryBranch' | |||
| sync_repository = touchable.sync_repository | |||
| result = [] | |||
| if sync_repository.sync_direction == 1 | |||
| result = Reposync::SyncBranchService.call(sync_repository.repo_name, touchable.gitlink_branch_name, sync_repository.sync_direction) | |||
| else | |||
| result = Reposync::SyncBranchService.call(sync_repository.repo_name, touchable.external_branch_name, sync_repository.sync_direction) | |||
| end | |||
| if result.is_a?(Array) && result[0].to_i == 0 | |||
| touchable.update_attributes!({sync_status: 1, sync_time: Time.now}) | |||
| else | |||
| touchable.update_attributes!({sync_status: 2, sync_time: Time.now}) | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,71 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: action_nodes | |||
| # | |||
| # id :integer not null, primary key | |||
| # name :string(255) | |||
| # full_name :string(255) | |||
| # description :string(255) | |||
| # icon :string(255) | |||
| # action_node_types_id :integer | |||
| # is_local :boolean default("0") | |||
| # local_url :string(255) | |||
| # yaml :text(65535) | |||
| # sort_no :integer default("0") | |||
| # use_count :integer default("0") | |||
| # user_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_action_nodes_on_action_types_id (action_node_types_id) | |||
| # index_action_nodes_on_user_id (user_id) | |||
| # | |||
| class Action::Node < ApplicationRecord | |||
| self.table_name = 'action_nodes' | |||
| default_scope { order(sort_no: :asc) } | |||
| has_many :action_node_inputs, :class_name => 'Action::NodeInput', foreign_key: "action_nodes_id" | |||
| has_many :action_node_selects, :class_name => 'Action::NodeSelect', foreign_key: "action_nodes_id" | |||
| belongs_to :action_node_type, :class_name => 'Action::NodeType', foreign_key: "action_node_types_id" | |||
| belongs_to :user, optional: true | |||
| # def content_yaml | |||
| # "foo".to_yaml | |||
| # <<~YAML | |||
| # - name: Set up JDK ${{ matrix.java }} | |||
| # uses: actions/setup-java@v3 | |||
| # with: | |||
| # distribution: 'temurin' | |||
| # java-version: ${{ matrix.java }} | |||
| # YAML | |||
| # end | |||
| def yaml_hash | |||
| <<~YAML | |||
| name: Check dist | |||
| on: | |||
| push: | |||
| branches: | |||
| - main | |||
| paths-ignore: | |||
| - '**.md' | |||
| pull_request: | |||
| paths-ignore: | |||
| - '**.md' | |||
| workflow_dispatch: | |||
| jobs: | |||
| call-check-dist: | |||
| name: Check dist/ | |||
| uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main | |||
| with: | |||
| node-version: '20.x' | |||
| YAML | |||
| end | |||
| end | |||
| @@ -0,0 +1,27 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: action_node_inputs | |||
| # | |||
| # id :integer not null, primary key | |||
| # action_nodes_id :integer | |||
| # name :string(255) | |||
| # input_type :string(255) | |||
| # description :string(255) | |||
| # is_required :boolean default("0") | |||
| # sort_no :string(255) default("0") | |||
| # user_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_action_node_inputs_on_action_nodes_id (action_nodes_id) | |||
| # index_action_node_inputs_on_user_id (user_id) | |||
| # | |||
| class Action::NodeInput < ApplicationRecord | |||
| self.table_name = 'action_node_inputs' | |||
| default_scope { order(sort_no: :asc) } | |||
| belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id" | |||
| end | |||
| @@ -0,0 +1,39 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: action_node_selects | |||
| # | |||
| # id :integer not null, primary key | |||
| # action_nodes_id :integer | |||
| # name :string(255) | |||
| # val :string(255) | |||
| # val_ext :string(255) | |||
| # description :string(255) | |||
| # download_url :string(255) | |||
| # sort_no :integer default("0") | |||
| # use_count :integer default("0") | |||
| # user_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_action_node_selects_on_action_nodes_id (action_nodes_id) | |||
| # index_action_node_selects_on_name (name) | |||
| # index_action_node_selects_on_user_id (user_id) | |||
| # | |||
| class Action::NodeSelect < ApplicationRecord | |||
| self.table_name = 'action_node_selects' | |||
| default_scope { order(sort_no: :asc) } | |||
| belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id" | |||
| belongs_to :user, optional: true | |||
| def value | |||
| if self.val_ext.blank? | |||
| self.val | |||
| else | |||
| "#{self.val}@#{self.val_ext}" | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,18 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: action_node_types | |||
| # | |||
| # id :integer not null, primary key | |||
| # name :string(255) | |||
| # description :string(255) | |||
| # sort_no :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| class Action::NodeType < ApplicationRecord | |||
| self.table_name = 'action_node_types' | |||
| default_scope { order(sort_no: :asc) } | |||
| has_many :action_nodes, :class_name => 'Action::Node', foreign_key: "action_node_types_id" | |||
| end | |||
| @@ -0,0 +1,20 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: action_templates | |||
| # | |||
| # id :integer not null, primary key | |||
| # name :string(255) | |||
| # description :string(255) | |||
| # img :string(255) | |||
| # sort_no :string(255) default("0") | |||
| # json :text(65535) | |||
| # yaml :text(65535) | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| class Action::Template < ApplicationRecord | |||
| self.table_name = 'action_templates' | |||
| default_scope { order(sort_no: :asc) } | |||
| end | |||
| @@ -55,14 +55,13 @@ | |||
| # default_branch :string(255) default("master") | |||
| # website :string(255) | |||
| # lesson_url :string(255) | |||
| # use_blockchain :boolean default("0") | |||
| # is_pinned :boolean default("0") | |||
| # recommend_index :integer default("0") | |||
| # use_blockchain :boolean default("0") | |||
| # pr_view_admin :boolean default("0") | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_projects_on_forked_count (forked_count) | |||
| # index_projects_on_forked_from_project_id (forked_from_project_id) | |||
| # index_projects_on_identifier (identifier) | |||
| # index_projects_on_invite_code (invite_code) | |||
| @@ -72,7 +71,6 @@ | |||
| # index_projects_on_license_id (license_id) | |||
| # index_projects_on_name (name) | |||
| # index_projects_on_platform (platform) | |||
| # index_projects_on_praises_count (praises_count) | |||
| # index_projects_on_project_category_id (project_category_id) | |||
| # index_projects_on_project_language_id (project_language_id) | |||
| # index_projects_on_project_type (project_type) | |||
| @@ -80,7 +78,6 @@ | |||
| # index_projects_on_rgt (rgt) | |||
| # index_projects_on_status (status) | |||
| # index_projects_on_updated_on (updated_on) | |||
| # index_projects_on_user_id (user_id) | |||
| # | |||
| class Project < ApplicationRecord | |||
| @@ -140,6 +137,7 @@ class Project < ApplicationRecord | |||
| has_many :commit_logs, dependent: :destroy | |||
| has_many :daily_project_statistics, dependent: :destroy | |||
| has_one :project_dataset, dependent: :destroy | |||
| has_many :sync_repositories, dependent: :destroy | |||
| after_create :incre_user_statistic, :incre_platform_statistic | |||
| after_save :check_project_members | |||
| before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data | |||
| @@ -23,6 +23,7 @@ class ProjectUnit < ApplicationRecord | |||
| def self.init_types(project_id, project_type='common') | |||
| unit_types = project_type == 'sync_mirror' ? ProjectUnit::unit_types.except("pulls") : ProjectUnit::unit_types | |||
| unit_types = unit_types.except("dataset") | |||
| unit_types.each do |_, v| | |||
| self.create!(project_id: project_id, unit_type: v) | |||
| end | |||
| @@ -0,0 +1,22 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: sync_repositories | |||
| # | |||
| # id :integer not null, primary key | |||
| # project_id :integer | |||
| # type :string(255) | |||
| # repo_name :string(255) | |||
| # external_repo_address :string(255) | |||
| # sync_granularity :integer | |||
| # sync_direction :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_sync_repositories_on_project_id (project_id) | |||
| # | |||
| class SyncRepositories::Gitee < SyncRepository | |||
| end | |||
| @@ -0,0 +1,21 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: sync_repositories | |||
| # | |||
| # id :integer not null, primary key | |||
| # project_id :integer | |||
| # type :string(255) | |||
| # repo_name :string(255) | |||
| # external_repo_address :string(255) | |||
| # sync_granularity :integer | |||
| # sync_direction :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_sync_repositories_on_project_id (project_id) | |||
| # | |||
| class SyncRepositories::Github < SyncRepository | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: sync_repositories | |||
| # | |||
| # id :integer not null, primary key | |||
| # project_id :integer | |||
| # type :string(255) | |||
| # repo_name :string(255) | |||
| # external_repo_address :string(255) | |||
| # sync_granularity :integer | |||
| # sync_direction :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # external_token :string(255) | |||
| # webhook_gid :integer | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_sync_repositories_on_project_id (project_id) | |||
| # | |||
| class SyncRepository < ApplicationRecord | |||
| belongs_to :project | |||
| has_many :sync_repository_branches, dependent: :destroy | |||
| before_destroy :unbind_reposyncer | |||
| validates :repo_name, uniqueness: { message: "已存在" } | |||
| def unbind_reposyncer | |||
| Reposync::DeleteRepoService.call(self.repo_name) rescue nil | |||
| end | |||
| end | |||
| @@ -0,0 +1,38 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: sync_repository_branches | |||
| # | |||
| # id :integer not null, primary key | |||
| # sync_repository_id :integer | |||
| # gitlink_branch_name :string(255) | |||
| # external_branch_name :string(255) | |||
| # sync_time :datetime | |||
| # sync_status :integer default("0") | |||
| # reposync_branch_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # enable :boolean default("1") | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_sync_repository_branches_on_sync_repository_id (sync_repository_id) | |||
| # | |||
| class SyncRepositoryBranch < ApplicationRecord | |||
| belongs_to :sync_repository | |||
| before_destroy :unbind_reposyncer | |||
| enum sync_status: {success: 1, failure: 2} | |||
| def unbind_reposyncer | |||
| if self.sync_repository.sync_direction.to_i == 1 | |||
| Reposync::DeleteBranchService.call(self.sync_repository&.repo_name, self.gitlink_branch_name) rescue nil | |||
| else | |||
| Reposync::DeleteBranchService.call(self.sync_repository&.repo_name, self.external_branch_name) rescue nil | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,109 @@ | |||
| class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :type, :external_token, :external_repo_address, :sync_granularity, :external_branch_name, :gitlink_branch_name, :first_sync_direction | |||
| attr_accessor :sync_repository1, :sync_repository2, :sync_repository_branch1, :sync_repository_branch2, :gitea_webhook | |||
| validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github)} | |||
| validates :external_repo_address, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } | |||
| validates :sync_granularity, :first_sync_direction, inclusion: {in: [1,2]} | |||
| validate :check_gitlink_branch_name | |||
| def initialize(project, params) | |||
| @project = project | |||
| @type = params[:type] | |||
| @external_token = params[:external_token] | |||
| @external_repo_address = params[:external_repo_address] | |||
| @sync_granularity = params[:sync_granularity].to_i | |||
| @external_branch_name = params[:external_branch_name] | |||
| @gitlink_branch_name = params[:gitlink_branch_name] | |||
| @first_sync_direction = params[:first_sync_direction].to_i | |||
| end | |||
| def call | |||
| raise Error, errors.full_messages.join(",") unless valid? | |||
| create_webhook | |||
| if sync_granularity == 2 | |||
| # 创建两个不同方向的同步仓库 | |||
| create_sync_repository | |||
| # 创建两个不同方向的同步分支 | |||
| create_sync_repository_branch | |||
| # 第一次同步 | |||
| touch_first_sync_branch | |||
| else | |||
| create_sync_repository | |||
| touch_first_sync | |||
| end | |||
| [@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2] | |||
| end | |||
| def check_gitlink_branch_name | |||
| if sync_granularity == 2 | |||
| result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(project&.owner&.login, project&.identifier) rescue nil | |||
| raise Error, '分支不存在' if !result.include?(gitlink_branch_name) | |||
| end | |||
| end | |||
| private | |||
| def create_sync_repository | |||
| repository1 = Reposync::CreateSyncRepoService.call(repo_name(1), gitlink_repo_address, gitlink_token, external_repo_address, external_token, sync_granularity, 1) | |||
| repository2 = Reposync::CreateSyncRepoService.call(repo_name(2), gitlink_repo_address, gitlink_token, external_repo_address, external_token, sync_granularity, 2) | |||
| raise Error, '创建同步仓库失败' if repository1[0].to_i > 0 || repository2[0].to_i > 0 | |||
| @sync_repository1 = SyncRepository.create!(project: project, type: type, repo_name: repo_name(1), external_repo_address: external_repo_address, external_token: external_token, sync_granularity: sync_granularity, sync_direction: 1, webhook_gid: @gitea_webhook["id"]) | |||
| @sync_repository2 = SyncRepository.create!(project: project, type: type, repo_name: repo_name(2), external_repo_address: external_repo_address, external_token: external_token, sync_granularity: sync_granularity, sync_direction: 2, webhook_gid: @gitea_webhook["id"]) | |||
| end | |||
| def create_sync_repository_branch | |||
| branch1 = Reposync::CreateSyncBranchService.call(repo_name(1),gitlink_branch_name, external_branch_name) | |||
| branch2 = Reposync::CreateSyncBranchService.call(repo_name(2),gitlink_branch_name, external_branch_name) | |||
| raise Error, '创建同步仓库分支失败' if branch1[0].to_i > 0 || branch2[0].to_i > 0 | |||
| @sync_repository_branch1 = SyncRepositoryBranch.create!(sync_repository: @sync_repository1, gitlink_branch_name: gitlink_branch_name, external_branch_name: external_branch_name, reposync_branch_id: branch1[1]["id"]) | |||
| @sync_repository_branch2 = SyncRepositoryBranch.create!(sync_repository: @sync_repository2, gitlink_branch_name: gitlink_branch_name, external_branch_name: external_branch_name, reposync_branch_id: branch2[1]["id"]) | |||
| end | |||
| def touch_first_sync | |||
| first_sync_direction == 1 ? TouchSyncJob.perform_later(@sync_repository1) : TouchSyncJob.perform_later(@sync_repository2) | |||
| end | |||
| def touch_first_sync_branch | |||
| first_sync_direction == 1 ? TouchSyncJob.perform_later(@sync_repository_branch1) : TouchSyncJob.perform_later(@sync_repository_branch2) | |||
| end | |||
| def create_webhook | |||
| url = "" | |||
| if type == "SyncRepositories::Gitee" | |||
| url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync?sync_direction=1&repo_type=SyncRepositories::Gitee" | |||
| else | |||
| url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync?sync_direction=1&repo_type=SyncRepositories::Github" | |||
| end | |||
| webhook_params = { | |||
| active: true, | |||
| branch_filter: '*', | |||
| http_method: 'POST', | |||
| url: url, | |||
| content_type: 'json', | |||
| type: 'reposync', | |||
| events: ["push"] | |||
| } | |||
| @gitea_webhook = Api::V1::Projects::Webhooks::CreateService.call(project, webhook_params) | |||
| end | |||
| def repo_name(sync_direction) | |||
| if type == "SyncRepositories::Gitee" | |||
| return "gitee:#{project.id}:#{sync_granularity}:#{sync_direction}" | |||
| else | |||
| return "github:#{project.id}:#{sync_granularity}:#{sync_direction}" | |||
| end | |||
| end | |||
| def gitlink_repo_address | |||
| "#{EduSetting.get("gitlink_repo_domain")}/#{project.owner&.login}/#{project.identifier}.git" | |||
| end | |||
| def gitlink_token | |||
| EduSetting.get("gitlink_admin_token") | |||
| end | |||
| end | |||
| @@ -0,0 +1,40 @@ | |||
| class Api::V1::Projects::SyncRepositories::UpdateService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :external_token, :external_repo_address, :sync_repositories | |||
| attr_accessor :sync_repository1, :sync_repository2 | |||
| validates :external_repo_address, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" } | |||
| validates :external_token, presence: true | |||
| #Api::V1::Projects::SyncRepositories::UpdateService.call(Project.last, "21,22", {external_repo_address: "https://github.com/viletyy/testdevops.git", external_token:"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"}) | |||
| def initialize(project, sync_repository_ids, params) | |||
| @project = project | |||
| @sync_repositories = SyncRepository.where(project_id: project.id, id: sync_repository_ids.split(",")) | |||
| @external_token = params[:external_token] | |||
| @external_repo_address = params[:external_repo_address] | |||
| end | |||
| def call | |||
| raise Error, errors.full_messages.join(",") unless valid? | |||
| update_sync_repository | |||
| end | |||
| private | |||
| def update_sync_repository | |||
| @sync_repositories.each do |repo| | |||
| Reposync::UpdateRepoAddrService.call(repo&.repo_name, internal_repo_address, internal_token, external_repo_address, external_token) | |||
| repo.update_attributes!({external_repo_address: external_repo_address, external_token: external_token}) | |||
| end | |||
| end | |||
| def internal_repo_address | |||
| "#{EduSetting.get("gitlink_repo_domain")}/#{project.owner&.login}/#{project.identifier}.git" | |||
| end | |||
| def internal_token | |||
| EduSetting.get("gitlink_admin_token") | |||
| end | |||
| end | |||
| @@ -8,7 +8,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService | |||
| validates :active, inclusion: {in: [true, false]} | |||
| validates :http_method, inclusion: { in: %w(POST GET), message: "请输入正确的请求方式"} | |||
| validates :content_type, inclusion: { in: %w(json form), message: "请输入正确的Content Type"} | |||
| validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu softbot), message: "请输入正确的Webhook Type"} | |||
| validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu softbot reposync), message: "请输入正确的Webhook Type"} | |||
| def initialize(project, params, token=nil) | |||
| @project = project | |||
| @owner = project&.owner.login | |||
| @@ -18,6 +18,8 @@ class Projects::ForkService < ApplicationService | |||
| :license_id, :ignore_id, {repository: [:identifier, :hidden]}] | |||
| result = Gitea::Repository::ForkService.new(@project.owner, @target_owner, @project.identifier, @organization, @new_identifier).call | |||
| Rails.logger.info("##### ForkService #{@project.identifier} result======#{result}") | |||
| raise Error, 'fork失败' if result.blank? or result['id'].blank? | |||
| clone_project.owner = @target_owner | |||
| clone_project.forked_from_project_id = @project.id | |||
| clone_project.gpid = result['id'] | |||
| @@ -41,7 +43,7 @@ class Projects::ForkService < ApplicationService | |||
| clone_project | |||
| end | |||
| rescue => e | |||
| puts "clone project service error: #{e.message}" | |||
| Rails.logger.info "fork project service error: #{e.message}" | |||
| raise Error, e.message | |||
| end | |||
| @@ -0,0 +1,115 @@ | |||
| class Reposync::ClientService < ApplicationService | |||
| attr_reader :url, :params | |||
| def initialize(options={}) | |||
| @url = options[:url] | |||
| @params = options[:params] | |||
| end | |||
| def post(url, params={}) | |||
| puts "[reposync][POST] request params: #{params}" | |||
| conn.post do |req| | |||
| req.url full_url(url) | |||
| req.body = params[:data].to_json | |||
| end | |||
| end | |||
| def get(url, params={}) | |||
| puts "[reposync][GET] request params: #{params}" | |||
| conn.get do |req| | |||
| req.url full_url(url, 'get') | |||
| params.each_pair do |key, value| | |||
| req.params["#{key}"] = value | |||
| end | |||
| end | |||
| end | |||
| def delete(url, params={}) | |||
| puts "[reposync][DELETE] request params: #{params}" | |||
| conn.delete do |req| | |||
| req.url full_url(url) | |||
| req.body = params[:data].to_json | |||
| end | |||
| end | |||
| def patch(url, params={}) | |||
| puts "[reposync][PATCH] request params: #{params}" | |||
| conn.patch do |req| | |||
| req.url full_url(url) | |||
| req.body = params[:data].to_json | |||
| end | |||
| end | |||
| def put(url, params={}) | |||
| puts "[reposync][PUT] request params: #{params}" | |||
| conn.put do |req| | |||
| req.url full_url(url) | |||
| req.body = params[:data].to_json | |||
| end | |||
| end | |||
| def conn | |||
| @client ||= begin | |||
| Faraday.new(url: domain) do |req| | |||
| req.request :url_encoded | |||
| req.headers['Content-Type'] = 'application/json' | |||
| req.adapter Faraday.default_adapter | |||
| req.options.timeout = 100 # open/read timeout in seconds | |||
| req.options.open_timeout = 10 # connection open timeout in seconds | |||
| end | |||
| end | |||
| @client | |||
| end | |||
| def domain | |||
| EduSetting.get("reposync_api_domain") || "http://106.75.110.152:50087" | |||
| end | |||
| def full_url(api_rest, action='post') | |||
| url = [domain, api_rest].join('').freeze | |||
| url = action === 'get' ? url : URI.escape(url) | |||
| url = URI.escape(url) unless url.ascii_only? | |||
| puts "[reposync] request url: #{url}" | |||
| return url | |||
| end | |||
| def log_error(status, body) | |||
| puts "[reposync] status: #{status}" | |||
| puts "[reposync] body: #{body}" | |||
| end | |||
| def render_response(response) | |||
| status = response.status | |||
| body = JSON.parse(response&.body) | |||
| log_error(status, body) | |||
| if status == 200 | |||
| if body["code_status"].to_i == 0 | |||
| return [body["code_status"], body["data"], body["msg"]] | |||
| else | |||
| puts "[reposync][ERROR] code: #{body["code_status"]}" | |||
| puts "[reposync][ERROR] message: #{body["msg"]}" | |||
| return [body["code_status"], body["data"], body["msg"]] | |||
| end | |||
| end | |||
| end | |||
| def render_list_response(response) | |||
| status = response.status | |||
| body = JSON.parse(response&.body) | |||
| log_error(status, body) | |||
| if status == 200 | |||
| if body["code_status"].to_i == 0 | |||
| return [body["code_status"], body["data"], body["total"], body["msg"]] | |||
| else | |||
| puts "[reposync][ERROR] code: #{body["code_status"]}" | |||
| puts "[reposync][ERROR] message: #{body["msg"]}" | |||
| return [body["code_status"], body["data"], body["total"], body["msg"]] | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,30 @@ | |||
| class Reposync::CreateSyncBranchService < Reposync::ClientService | |||
| attr_accessor :repo_name, :internal_branch_name, :external_branch_name, :enable | |||
| def initialize(repo_name, internal_branch_name, external_branch_name, enable=true) | |||
| @repo_name = repo_name | |||
| @internal_branch_name = internal_branch_name | |||
| @external_branch_name = external_branch_name | |||
| @enable = enable | |||
| end | |||
| def call | |||
| result = post(url, request_params) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def request_params | |||
| Hash.new.merge(data: { | |||
| internal_branch_name: internal_branch_name, | |||
| external_branch_name: external_branch_name, | |||
| enable: enable | |||
| }.stringify_keys) | |||
| end | |||
| def url | |||
| "/cerobot/sync/#{repo_name}/branch".freeze | |||
| end | |||
| end | |||
| @@ -0,0 +1,38 @@ | |||
| class Reposync::CreateSyncRepoService < Reposync::ClientService | |||
| attr_accessor :repo_name, :internal_repo_address, :inter_token, :external_repo_address, :exter_token, :sync_granularity, :sync_direction, :enable | |||
| def initialize(repo_name, internal_repo_address, inter_token, external_repo_address, exter_token, sync_granularity, sync_direction, enable=true) | |||
| @repo_name = repo_name | |||
| @internal_repo_address = internal_repo_address | |||
| @inter_token = inter_token | |||
| @external_repo_address = external_repo_address | |||
| @exter_token = exter_token | |||
| @sync_granularity = sync_granularity | |||
| @sync_direction = sync_direction | |||
| @enable = enable | |||
| end | |||
| def call | |||
| result = post(url, request_params) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def request_params | |||
| Hash.new.merge(data: { | |||
| repo_name: repo_name, | |||
| enable: enable, | |||
| internal_repo_address: internal_repo_address, | |||
| inter_token: inter_token, | |||
| external_repo_address: external_repo_address, | |||
| exter_token: exter_token, | |||
| sync_granularity: sync_granularity, | |||
| sync_direction: sync_direction | |||
| }.stringify_keys) | |||
| end | |||
| def url | |||
| "/cerobot/sync/repo".freeze | |||
| end | |||
| end | |||
| @@ -0,0 +1,19 @@ | |||
| class Reposync::DeleteBranchService < Reposync::ClientService | |||
| attr_accessor :repo_name, :branch_name | |||
| def initialize(repo_name, branch_name) | |||
| @repo_name = repo_name | |||
| @branch_name = branch_name | |||
| end | |||
| def call | |||
| result = delete(url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| "/cerobot/sync/#{repo_name}/branch/#{branch_name}" | |||
| end | |||
| end | |||
| @@ -0,0 +1,18 @@ | |||
| class Reposync::DeleteRepoService < Reposync::ClientService | |||
| attr_accessor :repo_name | |||
| def initialize(repo_name) | |||
| @repo_name = repo_name | |||
| end | |||
| def call | |||
| result = delete(url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| "/cerobot/sync/repo/#{repo_name}" | |||
| end | |||
| end | |||
| @@ -0,0 +1,33 @@ | |||
| class Reposync::GetLogsService < Reposync::ClientService | |||
| attr_accessor :repo_name, :branch_id, :page_num, :page_size | |||
| def initialize(repo_name=nil, branch_id=nil, page_num=1, page_size=10) | |||
| @repo_name = repo_name | |||
| @branch_id = branch_id | |||
| @page_num = page_num | |||
| @page_size = page_size | |||
| end | |||
| def call | |||
| result = get(url, request_params) | |||
| response = render_list_response(result) | |||
| end | |||
| private | |||
| def request_params | |||
| params = { | |||
| page_num: page_num, | |||
| page_size: page_size, | |||
| create_sort: true | |||
| } | |||
| params.merge!(repo_name: repo_name) if repo_name.present? | |||
| params.merge!(branch_id: branch_id) if branch_id.present? | |||
| return params.stringify_keys | |||
| end | |||
| def url | |||
| "/cerobot/sync/repo/logs" | |||
| end | |||
| end | |||
| @@ -0,0 +1,30 @@ | |||
| class Reposync::GetSyncBranchesService < Reposync::ClientService | |||
| attr_accessor :repo_name, :page, :limit, :create_sort | |||
| def initialize(repo_name, page=1, limit=10, create_sort=false) | |||
| @repo_name = repo_name | |||
| @page = page | |||
| @limit = limit | |||
| @create_sort = create_sort | |||
| end | |||
| def call | |||
| result = get(url, request_params) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def request_params | |||
| { | |||
| page: page, | |||
| limit: limit, | |||
| create_sort: create_sort | |||
| }.stringify_keys | |||
| end | |||
| def url | |||
| "/cerobot/sync/#{repo_name}/branch".freeze | |||
| end | |||
| end | |||
| @@ -0,0 +1,28 @@ | |||
| class Reposync::GetSyncReposService < Reposync::ClientService | |||
| attr_accessor :page, :limit, :create_sort | |||
| def initialize(page=1, limit=10, create_sort=false) | |||
| @page = page | |||
| @limit = limit | |||
| @create_sort = create_sort | |||
| end | |||
| def call | |||
| result = get(url, request_params) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def request_params | |||
| { | |||
| page: page, | |||
| limit: limit, | |||
| create_sort: create_sort | |||
| }.stringify_keys | |||
| end | |||
| def url | |||
| "/cerobot/sync/repo".freeze | |||
| end | |||
| end | |||
| @@ -0,0 +1,22 @@ | |||
| class Reposync::SyncBranchService < Reposync::ClientService | |||
| attr_accessor :repo_name, :branch_name, :sync_direct | |||
| def initialize(repo_name, branch_name, sync_direct) | |||
| @repo_name = repo_name | |||
| @branch_name = branch_name | |||
| @sync_direct = sync_direct | |||
| end | |||
| def call | |||
| result = post(url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| "/cerobot/sync/#{repo_name}/branch/#{branch_name}?sync_direct=#{sync_direct}" | |||
| end | |||
| end | |||
| @@ -0,0 +1,18 @@ | |||
| class Reposync::SyncRepoService < Reposync::ClientService | |||
| attr_accessor :repo_name | |||
| def initialize(repo_name) | |||
| @repo_name = repo_name | |||
| end | |||
| def call | |||
| result = post(url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| "/cerobot/sync/repo/#{repo_name}" | |||
| end | |||
| end | |||
| @@ -0,0 +1,21 @@ | |||
| class Reposync::UpdateBranchStatusService < Reposync::ClientService | |||
| attr_accessor :repo_name, :branch_name, :enable | |||
| def initialize(repo_name, branch_name, enable) | |||
| @repo_name = repo_name | |||
| @branch_name = branch_name | |||
| @enable = enable | |||
| end | |||
| def call | |||
| result = put(url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| "/cerobot/sync/#{repo_name}/branch/#{branch_name}?enable=#{enable}" | |||
| end | |||
| end | |||
| @@ -0,0 +1,31 @@ | |||
| class Reposync::UpdateRepoAddrService < Reposync::ClientService | |||
| attr_accessor :repo_name, :internal_repo_address, :inter_token, :external_repo_address, :exter_token | |||
| def initialize(repo_name, internal_repo_address, inter_token, external_repo_address, exter_token) | |||
| @repo_name = repo_name | |||
| @internal_repo_address = internal_repo_address | |||
| @inter_token = inter_token | |||
| @external_repo_address = external_repo_address | |||
| @exter_token = exter_token | |||
| end | |||
| def call | |||
| result = put(url, request_params) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def request_params | |||
| Hash.new.merge(data: { | |||
| internal_repo_address: internal_repo_address, | |||
| inter_token: inter_token, | |||
| external_repo_address: external_repo_address, | |||
| exter_token: exter_token | |||
| }.stringify_keys) | |||
| end | |||
| def url | |||
| "/cerobot/sync/repo/#{repo_name}/repo_addr".freeze | |||
| end | |||
| end | |||
| @@ -0,0 +1,19 @@ | |||
| class Reposync::UpdateRepoStatusService < Reposync::ClientService | |||
| attr_accessor :repo_name, :enable | |||
| def initialize(repo_name, enable) | |||
| @repo_name = repo_name | |||
| @enable = enable | |||
| end | |||
| def call | |||
| result = put(url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| "/cerobot/sync/repo/#{repo_name}?enable=#{enable}".freeze | |||
| end | |||
| end | |||
| @@ -0,0 +1,39 @@ | |||
| <%= form_with(model: node_input, url: action_node_node_inputs_path(@node), local: true) do |form| %> | |||
| <% if node_input.errors.any? %> | |||
| <div id="error_explanation"> | |||
| <h2><%= pluralize(node_input.errors.count, "error") %> prohibited this node_input from being saved:</h2> | |||
| <ul> | |||
| <% node_input.errors.full_messages.each do |message| %> | |||
| <li><%= message %></li> | |||
| <% end %> | |||
| </ul> | |||
| </div> | |||
| <% end %> | |||
| <div class="field"> | |||
| <%= form.label :name, "参数名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :input_type, "参数类型" %> | |||
| <%= form.text_field :input_type %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :is_required, "是否必填项" %> | |||
| <%= form.check_box("is_required", {}, "true", "false") %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存") %> | |||
| </div> | |||
| <% end %> | |||
| @@ -0,0 +1,6 @@ | |||
| json.extract! node_input, :id, :name, :input_type, :description | |||
| if node_input.input_type.to_s == "select" | |||
| json.select node.action_node_selects do |node_select| | |||
| json.partial! "node_select", locals: { node_select: node_select, node: node } | |||
| end | |||
| end | |||
| @@ -0,0 +1,4 @@ | |||
| json.extract! node_select, :id, :version | |||
| if node.is_local? | |||
| json.local_url node.local_url | |||
| end | |||
| @@ -0,0 +1,47 @@ | |||
| <h1>编辑 | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>--> | |||
| </h1> | |||
| <%= form_with(model: @node_input, url: action_node_node_input_path(@node,@node_input), local: true) do |form| %> | |||
| <% if @node_input.errors.any? %> | |||
| <div id="error_explanation"> | |||
| <h2><%= pluralize(@node_input.errors.count, "error") %> prohibited this node_input from being saved:</h2> | |||
| <ul> | |||
| <% @node_input.errors.full_messages.each do |message| %> | |||
| <li><%= message %></li> | |||
| <% end %> | |||
| </ul> | |||
| </div> | |||
| <% end %> | |||
| <div class="field"> | |||
| <%= form.label :name, "参数名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :input_type, "参数类型" %> | |||
| <%= form.text_field :input_type %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :is_required, "是否必填项" %> | |||
| <%= form.check_box("is_required", {}, "true", "false") %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存赛事") %> | |||
| </div> | |||
| <% end %> | |||
| <%= link_to 'Back', action_node_node_inputs_path(@node) %> | |||
| @@ -0,0 +1,46 @@ | |||
| <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> | |||
| <h1>action 节点参数配置<%= link_to '>>>Back action节点首页', action_nodes_path %> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>--> | |||
| </h1> | |||
| <p>说明:该界面适用于action 节点参数配置</p> | |||
| <table border="1"> | |||
| <thead> | |||
| <tr> | |||
| <th>ID</th> | |||
| <th width="20%">参数名称</th> | |||
| <th width="25%">参数输入类型</th> | |||
| <th width="20%">参数描述</th> | |||
| <th>是否必填项</th> | |||
| <th>排序号</th> | |||
| <th>更新时间</th> | |||
| <th colspan="2">操作</th> | |||
| </tr> | |||
| </thead> | |||
| <!-- :id, :name, :input_type, :description, :sort_no,--> | |||
| <tbody> | |||
| <% @node_inputs.each do |info| %> | |||
| <tr> | |||
| <td><%= info.id %></td> | |||
| <td><%= info.name %></td> | |||
| <td><%= info.input_type %> | |||
| <% if info.input_type == "select" %> | |||
| <%= select_tag(:version, options_for_select(@node.action_node_selects.map(&:value)), class: 'form-control') %> | |||
| <%= link_to '修改选择项', edit_action_node_node_input_path(@node.id, info) %> | |||
| <% end %> | |||
| </td> | |||
| <td><%= info.description %></td> | |||
| <td><%= info.is_required %></td> | |||
| <td><%= info.sort_no %></td> | |||
| <td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td> | |||
| <td><%= link_to '编辑', edit_action_node_node_input_path(@node.id, info) %></td> | |||
| <td><%= link_to 'Destroy', action_node_node_input_path(@node, info), method: :delete, data: { confirm: 'Are you sure?' } %></td> | |||
| </tr> | |||
| <% end %> | |||
| </tbody> | |||
| </table> | |||
| <br> | |||
| <%= link_to '新增', new_action_node_node_input_path(@node) %> | |||
| @@ -0,0 +1,20 @@ | |||
| json.types @node_types.each do |node_type| | |||
| if node_type.name.to_s == "未分类" | |||
| json.extract! node_type, :id, :name | |||
| json.nodes @no_type_nodes do |node| | |||
| json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count | |||
| json.inputs node.action_node_inputs do |node_input| | |||
| json.partial! "node_input", locals: { node_input: node_input, node: node } | |||
| end | |||
| end | |||
| else | |||
| json.extract! node_type, :id, :name | |||
| json.nodes node_type.action_nodes do |node| | |||
| json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count | |||
| json.inputs node.action_node_inputs do |node_input| | |||
| json.partial! "node_input", locals: { node_input: node_input, node: node } | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| <h1>新增</h1> | |||
| <%= render 'form', node_input: @node_input %> | |||
| <%= link_to 'Back', action_node_node_inputs_path(@node) %> | |||
| @@ -0,0 +1,7 @@ | |||
| json.status 0 | |||
| json.message "success" | |||
| json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count | |||
| json.inputs @node.action_node_inputs do |node_input| | |||
| json.partial! "node_input", locals: { node_input: node_input, node: @node } | |||
| end | |||
| @@ -0,0 +1,39 @@ | |||
| <%= form_with(model: node_select, url: action_node_node_selects_path(@node), local: true) do |form| %> | |||
| <% if node_select.errors.any? %> | |||
| <div id="error_explanation"> | |||
| <h2><%= pluralize(node_select.errors.count, "error") %> prohibited this node select from being saved:</h2> | |||
| <ul> | |||
| <% node_select.errors.full_messages.each do |message| %> | |||
| <li><%= message %></li> | |||
| <% end %> | |||
| </ul> | |||
| </div> | |||
| <% end %> | |||
| <div class="field"> | |||
| <%= form.label :name, "选择项名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :val, "选择项值" %> | |||
| <%= form.text_field :val %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :val_ext, "选择项值扩展" %> | |||
| <%= form.text_field :val_ext %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存") %> | |||
| </div> | |||
| <% end %> | |||
| @@ -0,0 +1,46 @@ | |||
| <h1>编辑 | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>--> | |||
| </h1> | |||
| <%= form_with(model: @node_select, url: action_node_node_select_path(@node,@node_select), local: true) do |form| %> | |||
| <% if @node_select.errors.any? %> | |||
| <div id="error_explanation"> | |||
| <h2><%= pluralize(@node_select.errors.count, "error") %> prohibited this node select from being saved:</h2> | |||
| <ul> | |||
| <% @node_select.errors.full_messages.each do |message| %> | |||
| <li><%= message %></li> | |||
| <% end %> | |||
| </ul> | |||
| </div> | |||
| <% end %> | |||
| <div class="field"> | |||
| <%= form.label :name, "选择项名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :val, "选择项值" %> | |||
| <%= form.text_field :val %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :val_ext, "选择项值扩展" %> | |||
| <%= form.text_field :val_ext %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存") %> | |||
| </div> | |||
| <% end %> | |||
| <%= link_to 'Back', action_node_node_inputs_path(@node) %> | |||
| @@ -0,0 +1,43 @@ | |||
| <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> | |||
| <h1>action 节点参数配置<%= link_to '>>>Back action节点首页', action_nodes_path %> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>--> | |||
| </h1> | |||
| <p>说明:该界面适用于action 节点参数配置</p> | |||
| <table border="1"> | |||
| <thead> | |||
| <tr> | |||
| <th>ID</th> | |||
| <th width="10%">选择项名称</th> | |||
| <th width="10%">选择项值</th> | |||
| <th width="10%">选择项值扩展</th> | |||
| <th width="15%">描述</th> | |||
| <th width="20%">下载地址</th> | |||
| <th>排序号</th> | |||
| <th>更新时间</th> | |||
| <th colspan="2">操作</th> | |||
| </tr> | |||
| </thead> | |||
| <!-- :id, :name, :input_type, :description, :sort_no,--> | |||
| <tbody> | |||
| <% @node_selects.each do |info| %> | |||
| <tr> | |||
| <td><%= info.id %></td> | |||
| <td><%= info.name %></td> | |||
| <td><%= info.val %></td> | |||
| <td><%= info.val_ext %></td> | |||
| <td><%= info.description %></td> | |||
| <td><%= info.download_url %></td> | |||
| <td><%= info.sort_no %></td> | |||
| <td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td> | |||
| <td><%= link_to '编辑', edit_action_node_node_select_path(@node.id, info) %></td> | |||
| <td><%= link_to 'Destroy', action_node_node_select_path(@node, info), method: :delete, data: { confirm: 'Are you sure?' } %></td> | |||
| </tr> | |||
| <% end %> | |||
| </tbody> | |||
| </table> | |||
| <br> | |||
| <%= link_to '新增', new_action_node_node_input_path(@node) %> | |||
| @@ -0,0 +1,5 @@ | |||
| <h1>新增</h1> | |||
| <%= render 'form', node_select: @node_select %> | |||
| <%= link_to 'Back', action_node_node_selects_path(@node) %> | |||
| @@ -0,0 +1,31 @@ | |||
| <%= form_with(model: node_type, local: true) do |form| %> | |||
| <% if node_type.errors.any? %> | |||
| <div id="error_explanation"> | |||
| <h2><%= pluralize(node_type.errors.count, "error") %> prohibited this node type from being saved:</h2> | |||
| <ul> | |||
| <% node_type.errors.full_messages.each do |message| %> | |||
| <li><%= message %></li> | |||
| <% end %> | |||
| </ul> | |||
| </div> | |||
| <% end %> | |||
| <div class="field"> | |||
| <%= form.label :name, "分类名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存") %> | |||
| </div> | |||
| <% end %> | |||
| @@ -0,0 +1,7 @@ | |||
| <h1>编辑 | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>--> | |||
| </h1> | |||
| <%= render 'form', node_type: @node_type %> | |||
| <%= link_to 'Back', action_node_types_path %> | |||
| @@ -0,0 +1,37 @@ | |||
| <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> | |||
| <h1>action 节点分类配置<%= link_to '>>>Back action节点首页', action_nodes_path %> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>--> | |||
| </h1> | |||
| <p>说明:该界面适用于action 节点分类配置</p> | |||
| <table border="1" width="100%"> | |||
| <thead> | |||
| <tr> | |||
| <th>ID</th> | |||
| <th width="20%">分类名称</th> | |||
| <th width="25%">描述</th> | |||
| <th>排序号</th> | |||
| <th>更新时间</th> | |||
| <th colspan="2">操作</th> | |||
| </tr> | |||
| </thead> | |||
| <!-- :id, :name, :input_type, :description, :sort_no,--> | |||
| <tbody> | |||
| <% @node_types.each do |info| %> | |||
| <tr> | |||
| <td><%= info.id %></td> | |||
| <td><%= info.name %></td> | |||
| <td><%= info.description %></td> | |||
| <td><%= info.sort_no %></td> | |||
| <td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td> | |||
| <td><%= link_to '编辑', edit_action_node_type_path(info) %></td> | |||
| <td><%= link_to 'Destroy', action_node_type_path(info), method: :delete, data: { confirm: 'Are you sure?' } %></td> | |||
| </tr> | |||
| <% end %> | |||
| </tbody> | |||
| </table> | |||
| <br> | |||
| <%= link_to '新增', new_action_node_type_path %> | |||
| @@ -0,0 +1,5 @@ | |||
| <h1>新增</h1> | |||
| <%= render 'form', node_type: @node_type %> | |||
| <%= link_to 'Back', action_node_types_path %> | |||
| @@ -0,0 +1,63 @@ | |||
| <%= form_with(model: node, local: true) do |form| %> | |||
| <%# if node.errors.any? %> | |||
| <!-- <div id="error_explanation">--> | |||
| <!-- <h2><%#= pluralize(node.errors.count, "error") %> prohibited this node from being saved:</h2>--> | |||
| <!-- <ul>--> | |||
| <%# node.errors.full_messages.each do |message| %> | |||
| <!-- <li><%#= message %></li>--> | |||
| <%# end %> | |||
| <!-- </ul>--> | |||
| <!-- </div>--> | |||
| <%# end %> | |||
| <div class="form-group "> | |||
| <label for="status">类型:</label> | |||
| <%= form.select :action_node_types_id, options_for_select(Action::NodeType.all.map { |key| [key.name, key.id]}, node.action_node_types_id), {}, class: "form-control" %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :name, "节点名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :full_name, "节点全称" %> | |||
| <%= form.text_field :full_name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :icon, "Icon图标" %> | |||
| <%= form.text_field :icon %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :is_local, "是否本地化" %> | |||
| <%= form.check_box("is_local", {}, "true", "false") %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :local_url, "本地化地址" %> | |||
| <%= form.text_field :local_url, :style => 'width:1200px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :yaml, "yaml语法代码" %> | |||
| <%= form.text_area :yaml, rows: 5, :style => 'width:1200px;' %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存") %> | |||
| </div> | |||
| <% end %> | |||
| @@ -0,0 +1,6 @@ | |||
| json.extract! node_input, :id, :name, :input_type, :description, :is_required | |||
| if node_input.input_type.to_s == "select" | |||
| json.select node.action_node_selects do |node_select| | |||
| json.partial! "node_select", locals: { node_select: node_select, node: node } | |||
| end | |||
| end | |||
| @@ -0,0 +1,4 @@ | |||
| json.extract! node_select, :id, :val | |||
| if node.is_local? | |||
| json.local_url node.local_url | |||
| end | |||
| @@ -0,0 +1,7 @@ | |||
| <h1>编辑 | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>--> | |||
| </h1> | |||
| <%= render 'form', node: @node %> | |||
| <%= link_to 'Back', action_nodes_path %> | |||
| @@ -0,0 +1,49 @@ | |||
| <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> | |||
| <h1>action 节点配置</h1> | |||
| <p><a href="<%= action_node_types_path %>" style="font-size: 14px;">>>前往节点分类配置</a></p> | |||
| <p><a href="<%= action_templates_path %>" style="font-size: 14px;">>>前往模板配置</a></p> | |||
| <p>说明:该界面适用于action 节点配置参数配置</p> | |||
| <table border="1" width="100%"> | |||
| <thead> | |||
| <tr> | |||
| <th>ID</th> | |||
| <th width="15%">节点名称</th> | |||
| <th width="20%">节点全称</th> | |||
| <th width="20%">节点描述</th> | |||
| <th width="10%">分类</th> | |||
| <!-- <th>是否本地化</th>--> | |||
| <!-- <th>本地化地址</th>--> | |||
| <!-- <th>yaml语法代码</th>--> | |||
| <th>排序号</th> | |||
| <th>更新时间</th> | |||
| <th colspan="3">操作</th> | |||
| </tr> | |||
| </thead> | |||
| <!-- :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no,--> | |||
| <tbody> | |||
| <% @nodes.each do |info| %> | |||
| <tr> | |||
| <td><%= info.id %></td> | |||
| <td><%= info.name %></td> | |||
| <td><%= info.full_name %></td> | |||
| <td><%= info.description %></td> | |||
| <td><%= info.action_node_type&.name %></td> | |||
| <!-- <td><%#= info.is_local? %></td>--> | |||
| <!-- <td><%#= info.local_url %></td>--> | |||
| <!-- <td><%#= info.yaml %></td>--> | |||
| <td><%= info.sort_no %></td> | |||
| <td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td> | |||
| <td><%= link_to '编辑', edit_action_node_path(info) %></td> | |||
| <td><%= link_to '参数列表', action_node_node_inputs_path(info) %></td> | |||
| <td><%= link_to 'Destroy', info, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |||
| </tr> | |||
| <% end %> | |||
| </tbody> | |||
| </table> | |||
| <br> | |||
| <%= link_to '新增', new_action_node_path %> | |||
| @@ -0,0 +1,20 @@ | |||
| json.types @node_types.each do |node_type| | |||
| if node_type.name.to_s == "未分类" | |||
| json.extract! node_type, :id, :name | |||
| json.nodes @no_type_nodes do |node| | |||
| json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count | |||
| json.inputs node.action_node_inputs do |node_input| | |||
| json.partial! "node_input", locals: { node_input: node_input, node: node } | |||
| end | |||
| end | |||
| else | |||
| json.extract! node_type, :id, :name | |||
| json.nodes node_type.action_nodes do |node| | |||
| json.extract! node, :id, :name, :full_name, :description, :action_node_types_id, :yaml, :sort_no, :use_count | |||
| json.inputs node.action_node_inputs do |node_input| | |||
| json.partial! "node_input", locals: { node_input: node_input, node: node } | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| <h1>新增</h1> | |||
| <%= render 'form', node: @node %> | |||
| <%= link_to 'Back', action_nodes_path %> | |||
| @@ -0,0 +1,7 @@ | |||
| json.status 0 | |||
| json.message "success" | |||
| json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count | |||
| json.inputs @node.action_node_inputs do |node_input| | |||
| json.partial! "node_input", locals: { node_input: node_input, node: @node } | |||
| end | |||
| @@ -0,0 +1,43 @@ | |||
| <%= form_with(model: template, local: true) do |form| %> | |||
| <% if template.errors.any? %> | |||
| <div id="error_explanation"> | |||
| <h2><%= pluralize(template.errors.count, "error") %> prohibited this node type from being saved:</h2> | |||
| <ul> | |||
| <% template.errors.full_messages.each do |message| %> | |||
| <li><%= message %></li> | |||
| <% end %> | |||
| </ul> | |||
| </div> | |||
| <% end %> | |||
| <div class="field"> | |||
| <%= form.label :name, "模板名称" %> | |||
| <%= form.text_field :name %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :description, "描述" %> | |||
| <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :img, "配图" %> | |||
| <%= form.text_field :img %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :sort_no, "排序号" %> | |||
| <%= form.text_field :sort_no %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :yaml, "yaml语法代码" %> | |||
| <%= form.text_area :yaml, rows: 5, :style => 'width:1200px;' %> | |||
| </div> | |||
| <div class="field"> | |||
| <%= form.label :json, "json语法代码" %> | |||
| <%= form.text_area :json, rows: 5, :style => 'width:1200px;' %> | |||
| </div> | |||
| <div class="actions" style="margin-top:10px;"> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点管理页面</a>--> | |||
| <%= form.submit("保存") %> | |||
| </div> | |||
| <% end %> | |||
| @@ -0,0 +1,6 @@ | |||
| <h1>编辑 | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往定制竞赛管理页面</a>--> | |||
| </h1> | |||
| <%= render 'form', template: @template %> | |||
| <%= link_to 'Back', action_templates_path %> | |||
| @@ -0,0 +1,37 @@ | |||
| <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> | |||
| <h1>action 模板配置<%= link_to '>>>Back action节点首页', action_nodes_path %> | |||
| <!-- <a href="/managements/competition/customize" style="font-size: 28px;">>>前往节点配置</a>--> | |||
| </h1> | |||
| <p>说明:该界面适用于action 模板配置</p> | |||
| <table border="1" width="100%"> | |||
| <thead> | |||
| <tr> | |||
| <th>ID</th> | |||
| <th width="20%">模板名称</th> | |||
| <th width="25%">描述</th> | |||
| <th>排序号</th> | |||
| <th>更新时间</th> | |||
| <th colspan="2">操作</th> | |||
| </tr> | |||
| </thead> | |||
| <!-- :id, :name, :input_type, :description, :sort_no,--> | |||
| <tbody> | |||
| <% @templates.each do |info| %> | |||
| <tr> | |||
| <td><%= info.id %></td> | |||
| <td><%= info.name %></td> | |||
| <td><%= info.description %></td> | |||
| <td><%= info.sort_no %></td> | |||
| <td><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %></td> | |||
| <td><%= link_to '编辑', edit_action_template_path(info) %></td> | |||
| <td><%= link_to 'Destroy', action_template_path(info), method: :delete, data: { confirm: 'Are you sure?' } %></td> | |||
| </tr> | |||
| <% end %> | |||
| </tbody> | |||
| </table> | |||
| <br> | |||
| <%= link_to '新增', new_action_template_path %> | |||
| @@ -0,0 +1,3 @@ | |||
| json.templates @templates.each do |tpl| | |||
| json.extract! tpl, :id, :name, :description, :img, :sort_no, :json, :yaml | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| <h1>新增</h1> | |||
| <%= render 'form', template: @template %> | |||
| <%= link_to 'Back', action_templates_path %> | |||
| @@ -0,0 +1 @@ | |||
| json.extract! @template, :id, :name, :description, :img, :sort_no, :json, :yaml | |||
| @@ -0,0 +1,12 @@ | |||
| json.total_count @group_sync_repository_branch.count | |||
| json.sync_repository_branches @group_sync_repository_branch.each do |item| | |||
| json.gitlink_branch_name item.gitlink_branch_name | |||
| json.external_branch_name item.external_branch_name | |||
| branches = @sync_repository_branches.joins(:sync_repository).where(sync_repositories: {type: item.type}, 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.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) | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| json.gitlink_repo_address "#{EduSetting.get("gitlink_repo_domain")}/#{@project.owner&.login}/#{@project.identifier}.git" | |||
| json.external_repo_address @sync_repository1.external_repo_address | |||
| json.sync_granularity @sync_repository1.sync_granularity | |||
| json.gitlink_branch_name @sync_repository_branch1&.gitlink_branch_name | |||
| json.external_branch_name @sync_repository_branch1&.external_branch_name | |||
| @@ -0,0 +1,12 @@ | |||
| json.total_count @total_count | |||
| json.gitlink_branch_name @branch&.gitlink_branch_name | |||
| json.external_type @branch&.sync_repository&.type | |||
| json.external_branch_name @branch&.external_branch_name | |||
| json.logs @reposync_branch_logs.each do |log| | |||
| type = log['repo_name'].start_with?('gitee') ? 'gitee' : 'github' | |||
| json.change_from log['sync_direct'] == "to_inter" ? type : 'gitlink' | |||
| json.commit_id log['commit_id'] | |||
| json.sync_time log['update_at'] | |||
| json.log log['log'] | |||
| json.sync_status log['log'].include?("************ 分支同步完成 ************") ? 'success' : "failure" | |||
| end | |||
| @@ -0,0 +1,8 @@ | |||
| json.total_count @group_sync_repository.keys.count | |||
| json.sync_repositories @group_sync_repository.each do |key| | |||
| json.type key[0][0] | |||
| json.external_repo_address key[0][1] | |||
| json.sync_granularity key[0][2] | |||
| json.external_token key[0][3] | |||
| json.sync_repository_ids @sync_repositories.where(type: key[0][0], external_repo_address: key[0][1], sync_granularity: key[0][2]).pluck(:id) | |||
| end | |||
| @@ -510,6 +510,19 @@ Rails.application.routes.draw do | |||
| end | |||
| end | |||
| # scope module: :action do | |||
| # | |||
| # end | |||
| namespace :action do | |||
| resources :nodes do | |||
| resources :node_inputs | |||
| resources :node_selects | |||
| end | |||
| resources :node_types | |||
| resources :templates | |||
| end | |||
| # Project Area START | |||
| scope "/:owner/:repo",constraints: { repo: /[^\/]+/ } do | |||
| scope do | |||
| @@ -1095,15 +1108,15 @@ Rails.application.routes.draw do | |||
| resources :sub_repertoires, only: [:index, :create, :edit, :update, :destroy] | |||
| resources :tag_repertoires, only: [:index, :create, :edit, :update, :destroy] | |||
| resources :salesmans, only: [:index, :create, :edit, :update, :destroy] do | |||
| post :batch_add, on: :collection | |||
| end | |||
| resources :salesman_channels, only: [:index, :create, :edit, :update, :destroy] do | |||
| post :batch_add, on: :collection | |||
| end | |||
| resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy] do | |||
| post :batch_add, on: :collection | |||
| end | |||
| # resources :salesmans, only: [:index, :create, :edit, :update, :destroy] do | |||
| # post :batch_add, on: :collection | |||
| # end | |||
| # resources :salesman_channels, only: [:index, :create, :edit, :update, :destroy] do | |||
| # post :batch_add, on: :collection | |||
| # end | |||
| # resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy] do | |||
| # post :batch_add, on: :collection | |||
| # end | |||
| end | |||
| @@ -108,6 +108,17 @@ defaults format: :json do | |||
| # projects文件夹下的 | |||
| scope module: :projects do | |||
| resources :sync_repositories, only: [:create, :index] do | |||
| collection do | |||
| post :update_info | |||
| post :sync | |||
| get :branches | |||
| post :change_enable | |||
| post :unbind | |||
| get :history | |||
| post :create_branch | |||
| end | |||
| end | |||
| resource :dataset, only: [:create, :update, :show] | |||
| resources :actions, module: 'actions' do | |||
| collection do | |||
| @@ -0,0 +1,10 @@ | |||
| class CreateActionNodeTypes < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :action_node_types do |t| | |||
| t.string :name | |||
| t.string :description | |||
| t.integer :sort_no, default: 0 | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,18 @@ | |||
| class CreateActionNodes < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :action_nodes do |t| | |||
| t.string :name | |||
| t.string :full_name | |||
| t.string :description | |||
| t.string :icon | |||
| t.references :action_node_types | |||
| t.boolean :is_local, default: false | |||
| t.string :local_url | |||
| t.text :yaml | |||
| t.integer :sort_no, default: 0 | |||
| t.integer :use_count, default: 0 | |||
| t.references :user | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,17 @@ | |||
| class CreateActionNodeSelects < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :action_node_selects do |t| | |||
| t.references :action_nodes | |||
| t.string :name | |||
| t.string :val | |||
| t.string :val_ext | |||
| t.string :description | |||
| t.string :download_url | |||
| t.integer :sort_no, default: 0 | |||
| t.integer :use_count, default: 0 | |||
| t.references :user | |||
| t.timestamps | |||
| t.index :name, length: 191 | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,14 @@ | |||
| class CreateActionNodeInputs < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :action_node_inputs do |t| | |||
| t.references :action_nodes | |||
| t.string :name | |||
| t.string :input_type | |||
| t.string :description | |||
| t.boolean :is_required, default: false | |||
| t.string :sort_no, default: 0 | |||
| t.references :user | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,13 @@ | |||
| class CreateActionTemplates < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :action_templates do |t| | |||
| t.string :name | |||
| t.string :description | |||
| t.string :img | |||
| t.string :sort_no, default: 0 | |||
| t.text :json | |||
| t.text :yaml | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,14 @@ | |||
| class CreateSyncRepositories < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :sync_repositories do |t| | |||
| t.references :project | |||
| t.string :type | |||
| t.string :repo_name | |||
| t.string :external_repo_address | |||
| t.integer :sync_granularity | |||
| t.integer :sync_direction, comment: "1表示从gitlink到外部2表示从外部到gitlink" | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,14 @@ | |||
| class CreateSyncRepositoryBranches < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :sync_repository_branches do |t| | |||
| t.references :sync_repository | |||
| t.string :gitlink_branch_name, comment: 'gitlink分支' | |||
| t.string :external_branch_name, comment: '外部仓库分支' | |||
| t.datetime :sync_time | |||
| t.integer :sync_status, default: 0 | |||
| t.integer :reposync_branch_id | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| class AddEnableToSyncRepositoryBranch < ActiveRecord::Migration[5.2] | |||
| def change | |||
| add_column :sync_repository_branches, :enable, :boolean, default: true | |||
| end | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| class AddExternalTokenToSyncRepository < ActiveRecord::Migration[5.2] | |||
| def change | |||
| add_column :sync_repositories, :external_token, :string | |||
| end | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| class AddWebhookGidToSyncRepository < ActiveRecord::Migration[5.2] | |||
| def change | |||
| add_column :sync_repositories, :webhook_gid, :integer | |||
| end | |||
| end | |||
| @@ -0,0 +1,82 @@ | |||
| # actions 下载包 | |||
| # node go java | |||
| namespace :actions_download do | |||
| task go: :environment do | |||
| # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' | |||
| # api_url = "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json" | |||
| api_url = "https://testgitea2.trustie.net/actions/go-versions/raw/branch/main/versions-manifest.json" | |||
| uri = URI.parse(api_url) | |||
| response = Net::HTTP.get_response(uri) | |||
| puts "gitee api response.code ===== #{response.code}" | |||
| lists = JSON.parse(response.body) | |||
| puts "lists.size =====#{lists.size}" | |||
| lists.each do |data| | |||
| version_arr = data['version'].to_s.split(".") | |||
| if version_arr[0].to_i == 1 && version_arr[1].to_i >= 18 | |||
| action_node_select = Action::NodeSelect.find_or_initialize_by(name: "go-version", val: data["version"]) | |||
| puts data["version"] | |||
| data['files'].each do |file| | |||
| if file['platform'] == "linux" | |||
| puts "download_url==#{file['download_url']}" | |||
| action_node_select.download_url = file['download_url'] | |||
| end | |||
| end | |||
| action_node_select.action_nodes_id=1 | |||
| action_node_select.save | |||
| end | |||
| end | |||
| end | |||
| task node: :environment do | |||
| # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' | |||
| # api_url = "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json" | |||
| api_url = "https://testgitea2.trustie.net/actions/node-versions/raw/branch/main/versions-manifest.json" | |||
| uri = URI.parse(api_url) | |||
| response = Net::HTTP.get_response(uri) | |||
| puts "gitee api response.code ===== #{response.code}" | |||
| lists = JSON.parse(response.body) | |||
| puts "lists.size =====#{lists.size}" | |||
| lists.each do |data| | |||
| version_arr = data['version'].to_s.split(".") | |||
| if version_arr[0].to_i >= 16 | |||
| puts data["version"] | |||
| action_node_select = Action::NodeSelect.find_or_initialize_by(name: "node-version", val: data["version"]) | |||
| data['files'].each do |file| | |||
| if file['platform'] == "linux" | |||
| puts "download_url==#{file['download_url']}" | |||
| action_node_select.download_url = file['download_url'] | |||
| end | |||
| end | |||
| action_node_select.action_nodes_id=2 | |||
| action_node_select.save | |||
| end | |||
| end | |||
| end | |||
| task java: :environment do | |||
| # curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/mindspore/mindspore/issues?access_token=5ccebd935915fb6cfcae634b161047a2&state=open&sort=created&direction=desc&page=1&per_page=10' | |||
| # api_url = "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json" | |||
| [0, 1, 2].each do |page| | |||
| api_url = "https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&os=linux&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=#{page}" | |||
| uri = URI.parse(api_url) | |||
| response = Net::HTTP.get_response(uri) | |||
| puts "gitee api response.code ===== #{response.code}" | |||
| lists = JSON.parse(response.body) | |||
| puts "lists.size =====#{lists.size}" | |||
| lists.each do |data| | |||
| puts data["release_name"] | |||
| puts "#{data['version_data']['major']}@#{data['version_data']['openjdk_version']}" | |||
| action_node_select = Action::NodeSelect.find_or_initialize_by(name: "java-version", val: "#{data['version_data']['major']}", val_ext: "#{data['version_data']['openjdk_version']}") | |||
| data['binaries'].each do |file| | |||
| puts "download_url==#{file['package']['link']}" | |||
| action_node_select.download_url = file['package']['link'] | |||
| end | |||
| action_node_select.action_nodes_id=5 | |||
| action_node_select.save | |||
| end | |||
| end | |||
| end | |||
| end | |||