新增:解绑和更改状态接口

This commit is contained in:
yystopf 2024-04-18 15:20:19 +08:00
parent eeb0994961
commit 6f458e0e79
4 changed files with 36 additions and 5 deletions

View File

@ -11,8 +11,9 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
end
def sync
@sync_repositories = SyncRepository.where(project: @project)
@sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories)
return render_error("请输入正确的同步方向!") if params[:sync_direction].blank?
@sync_repositories = SyncRepository.where(project: @project, sync_direction: params[:sync_direction])
@sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories, enable: true)
@sync_repositories.each do |item|
TouchSyncJob.perform_later(item)
end
@ -21,6 +22,34 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
end
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)
repo.destroy
end
render_ok
end
def change_enable
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.where(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|
if branch&.sync_repository&.sync_direction.to_i == 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
end
render_ok
else
render_error("更新失败!")
end
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(","))

View File

@ -75,7 +75,7 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
active: true,
branch_filter: '*',
http_method: 'POST',
url: "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync",
url: "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync?sync_direction=1",
content_type: 'json',
type: 'reposync',
events: ["push"]

View File

@ -2,8 +2,8 @@ json.total_count @group_sync_repository_branch.keys.count
json.sync_repository_branches @group_sync_repository_branch.each do |key|
json.gitlink_branch_name key[0][0]
json.external_branch_name key[0][1]
branches = @sync_repository_branches.where(gitlink_branch_name: key[0][0], external_branch_name: key[0][1])
branch = branches.last
branches = @sync_repository_branches.where(gitlink_branch_name: key[0][0], external_branch_name: key[0][1]).order(updated_at: :desc)
branch = branches.first
json.sync_time branch.sync_time
json.sync_status branch.sync_status
json.enable branch.enable

View File

@ -82,6 +82,8 @@ defaults format: :json do
collection do
post :sync
get :branches
post :change_enable
post :unbind
end
end
resource :dataset, only: [:create, :update, :show]