diff --git a/app/controllers/action/node_inputs_controller.rb b/app/controllers/action/node_inputs_controller.rb new file mode 100644 index 00000000..65227c65 --- /dev/null +++ b/app/controllers/action/node_inputs_controller.rb @@ -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 diff --git a/app/controllers/action/node_selects_controller.rb b/app/controllers/action/node_selects_controller.rb new file mode 100644 index 00000000..9acd6fc5 --- /dev/null +++ b/app/controllers/action/node_selects_controller.rb @@ -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 diff --git a/app/controllers/action/node_types_controller.rb b/app/controllers/action/node_types_controller.rb new file mode 100644 index 00000000..32508d94 --- /dev/null +++ b/app/controllers/action/node_types_controller.rb @@ -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 diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb new file mode 100644 index 00000000..e1e7799f --- /dev/null +++ b/app/controllers/action/nodes_controller.rb @@ -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 diff --git a/app/controllers/action/templates_controller.rb b/app/controllers/action/templates_controller.rb new file mode 100644 index 00000000..092d38d6 --- /dev/null +++ b/app/controllers/action/templates_controller.rb @@ -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 diff --git a/app/controllers/api/v1/projects/sync_repositories_controller.rb b/app/controllers/api/v1/projects/sync_repositories_controller.rb new file mode 100644 index 00000000..04780041 --- /dev/null +++ b/app/controllers/api/v1/projects/sync_repositories_controller.rb @@ -0,0 +1,147 @@ +class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController + before_action :require_public_and_member_above + + 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[:ref].split("refs/heads/")[-1] + 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 \ No newline at end of file diff --git a/app/helpers/action/node_helper.rb b/app/helpers/action/node_helper.rb new file mode 100644 index 00000000..05d08da2 --- /dev/null +++ b/app/helpers/action/node_helper.rb @@ -0,0 +1,2 @@ +module Action::NodeHelper +end diff --git a/app/jobs/touch_sync_job.rb b/app/jobs/touch_sync_job.rb new file mode 100644 index 00000000..3beaf52e --- /dev/null +++ b/app/jobs/touch_sync_job.rb @@ -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 \ No newline at end of file diff --git a/app/models/action/node.rb b/app/models/action/node.rb new file mode 100644 index 00000000..69e45b3a --- /dev/null +++ b/app/models/action/node.rb @@ -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 diff --git a/app/models/action/node_input.rb b/app/models/action/node_input.rb new file mode 100644 index 00000000..4f382517 --- /dev/null +++ b/app/models/action/node_input.rb @@ -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 diff --git a/app/models/action/node_select.rb b/app/models/action/node_select.rb new file mode 100644 index 00000000..25be51f9 --- /dev/null +++ b/app/models/action/node_select.rb @@ -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 diff --git a/app/models/action/node_type.rb b/app/models/action/node_type.rb new file mode 100644 index 00000000..7ce78b0f --- /dev/null +++ b/app/models/action/node_type.rb @@ -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 diff --git a/app/models/action/template.rb b/app/models/action/template.rb new file mode 100644 index 00000000..34b669f6 --- /dev/null +++ b/app/models/action/template.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index f3ec5f9b..2231320d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/project_unit.rb b/app/models/project_unit.rb index 8cf4ed6a..d2b6d208 100644 --- a/app/models/project_unit.rb +++ b/app/models/project_unit.rb @@ -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 diff --git a/app/models/sync_repositories/gitee.rb b/app/models/sync_repositories/gitee.rb new file mode 100644 index 00000000..0a51b21c --- /dev/null +++ b/app/models/sync_repositories/gitee.rb @@ -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 diff --git a/app/models/sync_repositories/github.rb b/app/models/sync_repositories/github.rb new file mode 100644 index 00000000..1ef413a5 --- /dev/null +++ b/app/models/sync_repositories/github.rb @@ -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 diff --git a/app/models/sync_repository.rb b/app/models/sync_repository.rb new file mode 100644 index 00000000..94f7c663 --- /dev/null +++ b/app/models/sync_repository.rb @@ -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 diff --git a/app/models/sync_repository_branch.rb b/app/models/sync_repository_branch.rb new file mode 100644 index 00000000..1940fd11 --- /dev/null +++ b/app/models/sync_repository_branch.rb @@ -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 diff --git a/app/services/api/v1/projects/sync_repositories/create_service.rb b/app/services/api/v1/projects/sync_repositories/create_service.rb new file mode 100644 index 00000000..6b64efab --- /dev/null +++ b/app/services/api/v1/projects/sync_repositories/create_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/api/v1/projects/sync_repositories/update_service.rb b/app/services/api/v1/projects/sync_repositories/update_service.rb new file mode 100644 index 00000000..9b4fec3e --- /dev/null +++ b/app/services/api/v1/projects/sync_repositories/update_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/api/v1/projects/webhooks/create_service.rb b/app/services/api/v1/projects/webhooks/create_service.rb index 303f3b39..829710cb 100644 --- a/app/services/api/v1/projects/webhooks/create_service.rb +++ b/app/services/api/v1/projects/webhooks/create_service.rb @@ -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 diff --git a/app/services/reposync/client_service.rb b/app/services/reposync/client_service.rb new file mode 100644 index 00000000..a8ddc18b --- /dev/null +++ b/app/services/reposync/client_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/create_sync_branch_service.rb b/app/services/reposync/create_sync_branch_service.rb new file mode 100644 index 00000000..2b417a7e --- /dev/null +++ b/app/services/reposync/create_sync_branch_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/create_sync_repo_service.rb b/app/services/reposync/create_sync_repo_service.rb new file mode 100644 index 00000000..0f0cc43e --- /dev/null +++ b/app/services/reposync/create_sync_repo_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/delete_branch_service.rb b/app/services/reposync/delete_branch_service.rb new file mode 100644 index 00000000..6d3d7c32 --- /dev/null +++ b/app/services/reposync/delete_branch_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/delete_repo_service.rb b/app/services/reposync/delete_repo_service.rb new file mode 100644 index 00000000..420a2d60 --- /dev/null +++ b/app/services/reposync/delete_repo_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/get_logs_service.rb b/app/services/reposync/get_logs_service.rb new file mode 100644 index 00000000..1288de6b --- /dev/null +++ b/app/services/reposync/get_logs_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/get_sync_branches_service.rb b/app/services/reposync/get_sync_branches_service.rb new file mode 100644 index 00000000..92c9d856 --- /dev/null +++ b/app/services/reposync/get_sync_branches_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/get_sync_repos_service.rb b/app/services/reposync/get_sync_repos_service.rb new file mode 100644 index 00000000..3fc39d89 --- /dev/null +++ b/app/services/reposync/get_sync_repos_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/sync_branch_service.rb b/app/services/reposync/sync_branch_service.rb new file mode 100644 index 00000000..9ca71b3f --- /dev/null +++ b/app/services/reposync/sync_branch_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/sync_repo_service.rb b/app/services/reposync/sync_repo_service.rb new file mode 100644 index 00000000..8b9e6c24 --- /dev/null +++ b/app/services/reposync/sync_repo_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/update_branch_status_service.rb b/app/services/reposync/update_branch_status_service.rb new file mode 100644 index 00000000..98ebcd5b --- /dev/null +++ b/app/services/reposync/update_branch_status_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/update_repo_addr_service.rb b/app/services/reposync/update_repo_addr_service.rb new file mode 100644 index 00000000..aa34f4fb --- /dev/null +++ b/app/services/reposync/update_repo_addr_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/reposync/update_repo_status_service.rb b/app/services/reposync/update_repo_status_service.rb new file mode 100644 index 00000000..db7065d8 --- /dev/null +++ b/app/services/reposync/update_repo_status_service.rb @@ -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 \ No newline at end of file diff --git a/app/views/action/node_inputs/_form.html.erb b/app/views/action/node_inputs/_form.html.erb new file mode 100644 index 00000000..deccfa69 --- /dev/null +++ b/app/views/action/node_inputs/_form.html.erb @@ -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? %> +
+

<%= pluralize(node_input.errors.count, "error") %> prohibited this node_input from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, "参数名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :input_type, "参数类型" %> + <%= form.text_field :input_type %> +
+
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+
+ <%= form.label :is_required, "是否必填项" %> + <%= form.check_box("is_required", {}, "true", "false") %> +
+
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+ +
+ + <%= form.submit("保存") %> +
+<% end %> diff --git a/app/views/action/node_inputs/_node_input.json.jbuilder b/app/views/action/node_inputs/_node_input.json.jbuilder new file mode 100644 index 00000000..9f0a6074 --- /dev/null +++ b/app/views/action/node_inputs/_node_input.json.jbuilder @@ -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 diff --git a/app/views/action/node_inputs/_node_select.json.jbuilder b/app/views/action/node_inputs/_node_select.json.jbuilder new file mode 100644 index 00000000..4e90508e --- /dev/null +++ b/app/views/action/node_inputs/_node_select.json.jbuilder @@ -0,0 +1,4 @@ +json.extract! node_select, :id, :version +if node.is_local? + json.local_url node.local_url +end diff --git a/app/views/action/node_inputs/edit.html.erb b/app/views/action/node_inputs/edit.html.erb new file mode 100644 index 00000000..6ae9f8a7 --- /dev/null +++ b/app/views/action/node_inputs/edit.html.erb @@ -0,0 +1,47 @@ +

编辑 + +

+ +<%= form_with(model: @node_input, url: action_node_node_input_path(@node,@node_input), local: true) do |form| %> + <% if @node_input.errors.any? %> +
+

<%= pluralize(@node_input.errors.count, "error") %> prohibited this node_input from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, "参数名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :input_type, "参数类型" %> + <%= form.text_field :input_type %> +
+
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+
+ <%= form.label :is_required, "是否必填项" %> + <%= form.check_box("is_required", {}, "true", "false") %> +
+ +
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+ +
+ + <%= form.submit("保存赛事") %> +
+<% end %> + + +<%= link_to 'Back', action_node_node_inputs_path(@node) %> diff --git a/app/views/action/node_inputs/index.html.erb b/app/views/action/node_inputs/index.html.erb new file mode 100644 index 00000000..f070b3dd --- /dev/null +++ b/app/views/action/node_inputs/index.html.erb @@ -0,0 +1,46 @@ +<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +

action 节点参数配置<%= link_to '>>>Back action节点首页', action_nodes_path %> + +

+

说明:该界面适用于action 节点参数配置

+ + + + + + + + + + + + + + + + + <% @node_inputs.each do |info| %> + + + + + + + + + + + + <% end %> + +
ID参数名称参数输入类型参数描述是否必填项排序号更新时间操作
<%= info.id %><%= info.name %><%= 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 %> + <%= info.description %><%= info.is_required %><%= info.sort_no %><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %><%= link_to '编辑', edit_action_node_node_input_path(@node.id, info) %><%= link_to 'Destroy', action_node_node_input_path(@node, info), method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to '新增', new_action_node_node_input_path(@node) %> diff --git a/app/views/action/node_inputs/index.json.jbuilder b/app/views/action/node_inputs/index.json.jbuilder new file mode 100644 index 00000000..3909639c --- /dev/null +++ b/app/views/action/node_inputs/index.json.jbuilder @@ -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 diff --git a/app/views/action/node_inputs/new.html.erb b/app/views/action/node_inputs/new.html.erb new file mode 100644 index 00000000..965ae937 --- /dev/null +++ b/app/views/action/node_inputs/new.html.erb @@ -0,0 +1,5 @@ +

新增

+ +<%= render 'form', node_input: @node_input %> + +<%= link_to 'Back', action_node_node_inputs_path(@node) %> \ No newline at end of file diff --git a/app/views/action/node_inputs/show.json.jbuilder b/app/views/action/node_inputs/show.json.jbuilder new file mode 100644 index 00000000..64548544 --- /dev/null +++ b/app/views/action/node_inputs/show.json.jbuilder @@ -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 \ No newline at end of file diff --git a/app/views/action/node_selects/_form.html.erb b/app/views/action/node_selects/_form.html.erb new file mode 100644 index 00000000..7dd4a663 --- /dev/null +++ b/app/views/action/node_selects/_form.html.erb @@ -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? %> +
+

<%= pluralize(node_select.errors.count, "error") %> prohibited this node select from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, "选择项名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :val, "选择项值" %> + <%= form.text_field :val %> +
+
+ <%= form.label :val_ext, "选择项值扩展" %> + <%= form.text_field :val_ext %> +
+
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+ +
+ + <%= form.submit("保存") %> +
+<% end %> diff --git a/app/views/action/node_selects/edit.html.erb b/app/views/action/node_selects/edit.html.erb new file mode 100644 index 00000000..fca5b3ce --- /dev/null +++ b/app/views/action/node_selects/edit.html.erb @@ -0,0 +1,46 @@ +

编辑 + +

+ +<%= form_with(model: @node_select, url: action_node_node_select_path(@node,@node_select), local: true) do |form| %> + <% if @node_select.errors.any? %> +
+

<%= pluralize(@node_select.errors.count, "error") %> prohibited this node select from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, "选择项名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :val, "选择项值" %> + <%= form.text_field :val %> +
+
+ <%= form.label :val_ext, "选择项值扩展" %> + <%= form.text_field :val_ext %> +
+
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+ +
+ + <%= form.submit("保存") %> +
+<% end %> + + +<%= link_to 'Back', action_node_node_inputs_path(@node) %> diff --git a/app/views/action/node_selects/index.html.erb b/app/views/action/node_selects/index.html.erb new file mode 100644 index 00000000..09d427d9 --- /dev/null +++ b/app/views/action/node_selects/index.html.erb @@ -0,0 +1,43 @@ +<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +

action 节点参数配置<%= link_to '>>>Back action节点首页', action_nodes_path %> + +

+

说明:该界面适用于action 节点参数配置

+ + + + + + + + + + + + + + + + + + <% @node_selects.each do |info| %> + + + + + + + + + + + + + <% end %> + +
ID选择项名称选择项值选择项值扩展描述下载地址排序号更新时间操作
<%= info.id %><%= info.name %><%= info.val %><%= info.val_ext %><%= info.description %><%= info.download_url %><%= info.sort_no %><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %><%= link_to '编辑', edit_action_node_node_select_path(@node.id, info) %><%= link_to 'Destroy', action_node_node_select_path(@node, info), method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to '新增', new_action_node_node_input_path(@node) %> diff --git a/app/views/action/node_selects/new.html.erb b/app/views/action/node_selects/new.html.erb new file mode 100644 index 00000000..c2fcaf12 --- /dev/null +++ b/app/views/action/node_selects/new.html.erb @@ -0,0 +1,5 @@ +

新增

+ +<%= render 'form', node_select: @node_select %> + +<%= link_to 'Back', action_node_node_selects_path(@node) %> \ No newline at end of file diff --git a/app/views/action/node_types/_form.html.erb b/app/views/action/node_types/_form.html.erb new file mode 100644 index 00000000..9a6a5d69 --- /dev/null +++ b/app/views/action/node_types/_form.html.erb @@ -0,0 +1,31 @@ +<%= form_with(model: node_type, local: true) do |form| %> + <% if node_type.errors.any? %> +
+

<%= pluralize(node_type.errors.count, "error") %> prohibited this node type from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, "分类名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+ +
+ + <%= form.submit("保存") %> +
+<% end %> diff --git a/app/views/action/node_types/edit.html.erb b/app/views/action/node_types/edit.html.erb new file mode 100644 index 00000000..9a44930a --- /dev/null +++ b/app/views/action/node_types/edit.html.erb @@ -0,0 +1,7 @@ +

编辑 + +

+<%= render 'form', node_type: @node_type %> + + +<%= link_to 'Back', action_node_types_path %> diff --git a/app/views/action/node_types/index.html.erb b/app/views/action/node_types/index.html.erb new file mode 100644 index 00000000..812d06a2 --- /dev/null +++ b/app/views/action/node_types/index.html.erb @@ -0,0 +1,37 @@ +<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +

action 节点分类配置<%= link_to '>>>Back action节点首页', action_nodes_path %> + +

+

说明:该界面适用于action 节点分类配置

+ + + + + + + + + + + + + + + <% @node_types.each do |info| %> + + + + + + + + + + <% end %> + +
ID分类名称描述排序号更新时间操作
<%= info.id %><%= info.name %><%= info.description %><%= info.sort_no %><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %><%= link_to '编辑', edit_action_node_type_path(info) %><%= link_to 'Destroy', action_node_type_path(info), method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to '新增', new_action_node_type_path %> diff --git a/app/views/action/node_types/new.html.erb b/app/views/action/node_types/new.html.erb new file mode 100644 index 00000000..1e053b9d --- /dev/null +++ b/app/views/action/node_types/new.html.erb @@ -0,0 +1,5 @@ +

新增

+ +<%= render 'form', node_type: @node_type %> + +<%= link_to 'Back', action_node_types_path %> \ No newline at end of file diff --git a/app/views/action/nodes/_form.html.erb b/app/views/action/nodes/_form.html.erb new file mode 100644 index 00000000..4e40f0ff --- /dev/null +++ b/app/views/action/nodes/_form.html.erb @@ -0,0 +1,63 @@ +<%= form_with(model: node, local: true) do |form| %> + <%# if node.errors.any? %> + + + + + <%# node.errors.full_messages.each do |message| %> + + <%# end %> + + + <%# end %> +
+ + <%= 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" %> +
+ +
+ <%= form.label :name, "节点名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :full_name, "节点全称" %> + <%= form.text_field :full_name %> +
+ +
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+ +
+ <%= form.label :icon, "Icon图标" %> + <%= form.text_field :icon %> +
+ +
+ <%= form.label :is_local, "是否本地化" %> + <%= form.check_box("is_local", {}, "true", "false") %> +
+ +
+ <%= form.label :local_url, "本地化地址" %> + <%= form.text_field :local_url, :style => 'width:1200px;' %> +
+ + + +
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+ +
+ <%= form.label :yaml, "yaml语法代码" %> + <%= form.text_area :yaml, rows: 5, :style => 'width:1200px;' %> +
+ +
+ + <%= form.submit("保存") %> +
+<% end %> diff --git a/app/views/action/nodes/_node_input.json.jbuilder b/app/views/action/nodes/_node_input.json.jbuilder new file mode 100644 index 00000000..c41f93c7 --- /dev/null +++ b/app/views/action/nodes/_node_input.json.jbuilder @@ -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 diff --git a/app/views/action/nodes/_node_select.json.jbuilder b/app/views/action/nodes/_node_select.json.jbuilder new file mode 100644 index 00000000..897e3f8e --- /dev/null +++ b/app/views/action/nodes/_node_select.json.jbuilder @@ -0,0 +1,4 @@ +json.extract! node_select, :id, :val +if node.is_local? + json.local_url node.local_url +end diff --git a/app/views/action/nodes/edit.html.erb b/app/views/action/nodes/edit.html.erb new file mode 100644 index 00000000..ee9cb094 --- /dev/null +++ b/app/views/action/nodes/edit.html.erb @@ -0,0 +1,7 @@ +

编辑 + +

+ +<%= render 'form', node: @node %> + +<%= link_to 'Back', action_nodes_path %> diff --git a/app/views/action/nodes/index.html.erb b/app/views/action/nodes/index.html.erb new file mode 100644 index 00000000..763a8e46 --- /dev/null +++ b/app/views/action/nodes/index.html.erb @@ -0,0 +1,49 @@ +<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +

action 节点配置

+

>>前往节点分类配置

+

>>前往模板配置

+

说明:该界面适用于action 节点配置参数配置

+ + + + + + + + + + + + + + + + + + + + + <% @nodes.each do |info| %> + + + + + + + + + + + + + + + + <% end %> + +
ID节点名称节点全称节点描述分类排序号更新时间操作
<%= info.id %><%= info.name %><%= info.full_name %><%= info.description %><%= info.action_node_type&.name %><%= info.sort_no %><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %><%= link_to '编辑', edit_action_node_path(info) %><%= link_to '参数列表', action_node_node_inputs_path(info) %><%= link_to 'Destroy', info, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to '新增', new_action_node_path %> diff --git a/app/views/action/nodes/index.json.jbuilder b/app/views/action/nodes/index.json.jbuilder new file mode 100644 index 00000000..3909639c --- /dev/null +++ b/app/views/action/nodes/index.json.jbuilder @@ -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 diff --git a/app/views/action/nodes/new.html.erb b/app/views/action/nodes/new.html.erb new file mode 100644 index 00000000..4a5d2fae --- /dev/null +++ b/app/views/action/nodes/new.html.erb @@ -0,0 +1,5 @@ +

新增

+ +<%= render 'form', node: @node %> + +<%= link_to 'Back', action_nodes_path %> \ No newline at end of file diff --git a/app/views/action/nodes/show.json.jbuilder b/app/views/action/nodes/show.json.jbuilder new file mode 100644 index 00000000..64548544 --- /dev/null +++ b/app/views/action/nodes/show.json.jbuilder @@ -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 \ No newline at end of file diff --git a/app/views/action/templates/_form.html.erb b/app/views/action/templates/_form.html.erb new file mode 100644 index 00000000..7d93cb76 --- /dev/null +++ b/app/views/action/templates/_form.html.erb @@ -0,0 +1,43 @@ +<%= form_with(model: template, local: true) do |form| %> + <% if template.errors.any? %> +
+

<%= pluralize(template.errors.count, "error") %> prohibited this node type from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, "模板名称" %> + <%= form.text_field :name %> +
+
+ <%= form.label :description, "描述" %> + <%= form.text_area :description, rows: 5, :style => 'width:800px;' %> +
+
+ <%= form.label :img, "配图" %> + <%= form.text_field :img %> +
+
+ <%= form.label :sort_no, "排序号" %> + <%= form.text_field :sort_no %> +
+
+ <%= form.label :yaml, "yaml语法代码" %> + <%= form.text_area :yaml, rows: 5, :style => 'width:1200px;' %> +
+
+ <%= form.label :json, "json语法代码" %> + <%= form.text_area :json, rows: 5, :style => 'width:1200px;' %> +
+ +
+ + <%= form.submit("保存") %> +
+<% end %> diff --git a/app/views/action/templates/edit.html.erb b/app/views/action/templates/edit.html.erb new file mode 100644 index 00000000..f9c1effc --- /dev/null +++ b/app/views/action/templates/edit.html.erb @@ -0,0 +1,6 @@ +

编辑 + +

+<%= render 'form', template: @template %> + +<%= link_to 'Back', action_templates_path %> diff --git a/app/views/action/templates/index.html.erb b/app/views/action/templates/index.html.erb new file mode 100644 index 00000000..b71aaede --- /dev/null +++ b/app/views/action/templates/index.html.erb @@ -0,0 +1,37 @@ +<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + +

action 模板配置<%= link_to '>>>Back action节点首页', action_nodes_path %> + +

+

说明:该界面适用于action 模板配置

+ + + + + + + + + + + + + + + <% @templates.each do |info| %> + + + + + + + + + + <% end %> + +
ID模板名称描述排序号更新时间操作
<%= info.id %><%= info.name %><%= info.description %><%= info.sort_no %><%= info.updated_at&.strftime('%Y-%m-%d %H:%M') %><%= link_to '编辑', edit_action_template_path(info) %><%= link_to 'Destroy', action_template_path(info), method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to '新增', new_action_template_path %> diff --git a/app/views/action/templates/index.json.jbuilder b/app/views/action/templates/index.json.jbuilder new file mode 100644 index 00000000..da534c84 --- /dev/null +++ b/app/views/action/templates/index.json.jbuilder @@ -0,0 +1,3 @@ +json.templates @templates.each do |tpl| + json.extract! tpl, :id, :name, :description, :img, :sort_no, :json, :yaml +end diff --git a/app/views/action/templates/new.html.erb b/app/views/action/templates/new.html.erb new file mode 100644 index 00000000..e67c6a67 --- /dev/null +++ b/app/views/action/templates/new.html.erb @@ -0,0 +1,5 @@ +

新增

+ +<%= render 'form', template: @template %> + +<%= link_to 'Back', action_templates_path %> \ No newline at end of file diff --git a/app/views/action/templates/show.json.jbuilder b/app/views/action/templates/show.json.jbuilder new file mode 100644 index 00000000..5db67424 --- /dev/null +++ b/app/views/action/templates/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @template, :id, :name, :description, :img, :sort_no, :json, :yaml \ No newline at end of file diff --git a/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder b/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder new file mode 100644 index 00000000..f040c647 --- /dev/null +++ b/app/views/api/v1/projects/sync_repositories/branches.json.jbuilder @@ -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 \ No newline at end of file diff --git a/app/views/api/v1/projects/sync_repositories/create.json.jbuilder b/app/views/api/v1/projects/sync_repositories/create.json.jbuilder new file mode 100644 index 00000000..20bb70c6 --- /dev/null +++ b/app/views/api/v1/projects/sync_repositories/create.json.jbuilder @@ -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 \ No newline at end of file diff --git a/app/views/api/v1/projects/sync_repositories/history.json.jbuilder b/app/views/api/v1/projects/sync_repositories/history.json.jbuilder new file mode 100644 index 00000000..01546b29 --- /dev/null +++ b/app/views/api/v1/projects/sync_repositories/history.json.jbuilder @@ -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 \ No newline at end of file diff --git a/app/views/api/v1/projects/sync_repositories/index.json.jbuilder b/app/views/api/v1/projects/sync_repositories/index.json.jbuilder new file mode 100644 index 00000000..84bbdde5 --- /dev/null +++ b/app/views/api/v1/projects/sync_repositories/index.json.jbuilder @@ -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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 347ed29b..a2544764 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -511,6 +511,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 @@ -1096,15 +1109,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 diff --git a/config/routes/api.rb b/config/routes/api.rb index 3f18235c..e42afba5 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -78,6 +78,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 diff --git a/db/migrate/20240408010101_create_action_node_types.rb b/db/migrate/20240408010101_create_action_node_types.rb new file mode 100644 index 00000000..b9c53078 --- /dev/null +++ b/db/migrate/20240408010101_create_action_node_types.rb @@ -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 diff --git a/db/migrate/20240408010102_create_action_nodes.rb b/db/migrate/20240408010102_create_action_nodes.rb new file mode 100644 index 00000000..67331e4d --- /dev/null +++ b/db/migrate/20240408010102_create_action_nodes.rb @@ -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 diff --git a/db/migrate/20240408010213_create_action_node_selects.rb b/db/migrate/20240408010213_create_action_node_selects.rb new file mode 100644 index 00000000..5f49bcd8 --- /dev/null +++ b/db/migrate/20240408010213_create_action_node_selects.rb @@ -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 + end + end +end diff --git a/db/migrate/20240408010227_create_action_node_inputs.rb b/db/migrate/20240408010227_create_action_node_inputs.rb new file mode 100644 index 00000000..501844e2 --- /dev/null +++ b/db/migrate/20240408010227_create_action_node_inputs.rb @@ -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 diff --git a/db/migrate/20240408010233_create_action_templates.rb b/db/migrate/20240408010233_create_action_templates.rb new file mode 100644 index 00000000..47d33509 --- /dev/null +++ b/db/migrate/20240408010233_create_action_templates.rb @@ -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 diff --git a/db/migrate/20240415014011_create_sync_repositories.rb b/db/migrate/20240415014011_create_sync_repositories.rb new file mode 100644 index 00000000..d2908bfe --- /dev/null +++ b/db/migrate/20240415014011_create_sync_repositories.rb @@ -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 diff --git a/db/migrate/20240415015216_create_sync_repository_branches.rb b/db/migrate/20240415015216_create_sync_repository_branches.rb new file mode 100644 index 00000000..b44a6f39 --- /dev/null +++ b/db/migrate/20240415015216_create_sync_repository_branches.rb @@ -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 diff --git a/db/migrate/20240417025003_add_enable_to_sync_repository_branch.rb b/db/migrate/20240417025003_add_enable_to_sync_repository_branch.rb new file mode 100644 index 00000000..fdbd7b7e --- /dev/null +++ b/db/migrate/20240417025003_add_enable_to_sync_repository_branch.rb @@ -0,0 +1,5 @@ +class AddEnableToSyncRepositoryBranch < ActiveRecord::Migration[5.2] + def change + add_column :sync_repository_branches, :enable, :boolean, default: true + end +end diff --git a/db/migrate/20240424085125_add_external_token_to_sync_repository.rb b/db/migrate/20240424085125_add_external_token_to_sync_repository.rb new file mode 100644 index 00000000..fde46cab --- /dev/null +++ b/db/migrate/20240424085125_add_external_token_to_sync_repository.rb @@ -0,0 +1,5 @@ +class AddExternalTokenToSyncRepository < ActiveRecord::Migration[5.2] + def change + add_column :sync_repositories, :external_token, :string + end +end diff --git a/db/migrate/20240429070012_add_webhook_gid_to_sync_repository.rb b/db/migrate/20240429070012_add_webhook_gid_to_sync_repository.rb new file mode 100644 index 00000000..dfd3e6c7 --- /dev/null +++ b/db/migrate/20240429070012_add_webhook_gid_to_sync_repository.rb @@ -0,0 +1,5 @@ +class AddWebhookGidToSyncRepository < ActiveRecord::Migration[5.2] + def change + add_column :sync_repositories, :webhook_gid, :integer + end +end diff --git a/lib/tasks/actions_download.rake b/lib/tasks/actions_download.rake new file mode 100644 index 00000000..bad2d535 --- /dev/null +++ b/lib/tasks/actions_download.rake @@ -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 \ No newline at end of file