mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-02 19:30:48 +08:00
Merge branch 'standalone_develop' into pm_project_develop
This commit is contained in:
75
app/controllers/action/node_inputs_controller.rb
Normal file
75
app/controllers/action/node_inputs_controller.rb
Normal file
@@ -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
|
||||
76
app/controllers/action/node_selects_controller.rb
Normal file
76
app/controllers/action/node_selects_controller.rb
Normal file
@@ -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
|
||||
64
app/controllers/action/node_types_controller.rb
Normal file
64
app/controllers/action/node_types_controller.rb
Normal file
@@ -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
|
||||
69
app/controllers/action/nodes_controller.rb
Normal file
69
app/controllers/action/nodes_controller.rb
Normal file
@@ -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
|
||||
68
app/controllers/action/templates_controller.rb
Normal file
68
app/controllers/action/templates_controller.rb
Normal file
@@ -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
|
||||
148
app/controllers/api/v1/projects/sync_repositories_controller.rb
Normal file
148
app/controllers/api/v1/projects/sync_repositories_controller.rb
Normal file
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user