mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
fixed reposyncer 分支组合已配置,不能重复
This commit is contained in:
@@ -13,7 +13,8 @@ class ObRepositorySyncsController < ApplicationController
|
||||
tip_exception "参数错误" if params[:github_address].blank? && params[:gitee_address].blank?
|
||||
project_name ="#{@project.owner.name}:#{@project.identifier}"
|
||||
service = ObRepositorySync::ApiService.new(project_name)
|
||||
project_params = params.merge({ "gitlink_address": @project.repository.url })
|
||||
domain = GiteaService.gitea_config[:domain]
|
||||
project_params = params.merge({ "gitlink_address": "#{domain}/#{@project.owner&.login}/#{@project.identifier}.git" })
|
||||
res = service.create_projects(project_params)
|
||||
tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200"
|
||||
sync_id = res["data"]["id"]
|
||||
@@ -23,7 +24,6 @@ class ObRepositorySyncsController < ApplicationController
|
||||
ob_repository_sync.name = project_name
|
||||
ob_repository_sync.github_address = "#{params[:github_address]}"
|
||||
ob_repository_sync.gitee_address = "#{params[:gitee_address]}"
|
||||
ob_repository_sync.gitlink_address = @project.repository.url
|
||||
ob_repository_sync.github_token = "#{params[:github_token]}"
|
||||
ob_repository_sync.gitee_token = "#{params[:gitee_token]}"
|
||||
ob_repository_sync.sync_id = sync_id
|
||||
@@ -38,16 +38,30 @@ class ObRepositorySyncsController < ApplicationController
|
||||
if res["code"].to_s == "200"
|
||||
@ob_repository_sync.destroy!
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def jobs
|
||||
tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank?
|
||||
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
|
||||
res = service.get_projects_jobs
|
||||
render_ok(count: res["data"]["total"], data: res["data"]["list"])
|
||||
data = res["data"]["list"]
|
||||
if params[:type] && params[:type].to_s.downcase == "github"
|
||||
data = data.select { |row| row["github_branch"].present? }
|
||||
elsif params[:type] && params[:type].to_s.downcase == "gitee"
|
||||
data = data.select { |row| row["gitee_branch"].present? }
|
||||
end
|
||||
render_ok(count: res["data"]["total"], data: data)
|
||||
end
|
||||
|
||||
def create_jobs
|
||||
tip_exception "必须配置一个分支" if params[:github_branch].blank? && params[:gitee_branch].blank? && params[:gitlink_branch].blank?
|
||||
ob_jobs = ObRepositorySyncJob.where(ob_repository_sync_id: @ob_repository_sync.id)
|
||||
ob_jobs = ob_jobs.where(job_type: params[:job_type]) if params[:job_type].present?
|
||||
ob_jobs = ob_jobs.where(github_branch: params[:github_branch]) if params[:github_branch].present?
|
||||
ob_jobs = ob_jobs.where(gitee_branch: params[:gitee_branch]) if params[:gitee_branch].present?
|
||||
ob_jobs = ob_jobs.where(gitlink_branch: params[:gitlink_branch]) if params[:gitlink_branch].present?
|
||||
tip_exception "该分支组合已配置,不能重复!" if ob_jobs.count > 0
|
||||
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
|
||||
res = service.create_projects_jobs(params)
|
||||
tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200"
|
||||
@@ -57,7 +71,7 @@ class ObRepositorySyncsController < ApplicationController
|
||||
job.github_branch = "#{params[:github_branch]}"
|
||||
job.gitee_branch = "#{params[:gitee_branch]}"
|
||||
job.gitlink_branch = "#{params[:gitlink_branch]}"
|
||||
job.job_type = "#{params[:type]}"
|
||||
job.job_type = "#{params[:job_type]}"
|
||||
job.base = "#{params[:base]}"
|
||||
job.job_id = job_id
|
||||
job.save
|
||||
@@ -70,7 +84,8 @@ class ObRepositorySyncsController < ApplicationController
|
||||
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
|
||||
res = service.delete_job params[:job_id]
|
||||
tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200"
|
||||
@ob_repository_sync.destroy!
|
||||
job = ObRepositorySyncJob.find_by(ob_repository_sync_id: @ob_repository_sync.id, job_id: params[:job_id])
|
||||
job.destroy! if job.present?
|
||||
render_ok
|
||||
end
|
||||
|
||||
@@ -94,7 +109,7 @@ class ObRepositorySyncsController < ApplicationController
|
||||
tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank?
|
||||
tip_exception "缺少参数job_id" if params[:job_id].blank?
|
||||
service = ObRepositorySync::ApiService.new(@ob_repository_sync.name)
|
||||
@data = service.job_logs params[:job_id]
|
||||
res = service.job_logs params[:job_id]
|
||||
tip_exception "请求错误: #{res["msg"]}" if res["code"].to_s != "200"
|
||||
render_ok(count: res["data"]["total"], data: res["data"]["list"])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user