[FIX]sync mirror project

This commit is contained in:
vilet.yy 2021-02-21 17:14:51 +08:00
parent f7b7122d60
commit 9681a1a491
3 changed files with 15 additions and 3 deletions

View File

@ -2,7 +2,7 @@ class Projects::MigrateForm < BaseForm
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id, :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id, :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
validates :user_id, :name, :description,:repository_name, :project_category_id, :project_language_id, presence: true
validates :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
@ -12,6 +12,18 @@ class Projects::MigrateForm < BaseForm
check_repository_name(user_id, repository_name) unless repository_name.blank?
check_project_category(project_category_id)
check_project_language(project_language_id)
check_owner
check_max_repo_creation
end
def check_owner
@owner = Owner.find_by(id: user_id)
raise "user_id值无效." if user_id && owner.blank?
end
def check_max_repo_creation
return unless owner.is_a?(Organization)
return if owner.max_repo_creation <= -1
raise "已超过组织设置最大仓库数" if owner.max_repo_creation == owner.num_projects
end
end

View File

@ -44,7 +44,7 @@ class Projects::MigrateService < ApplicationService
hidden: project_secretion[:hidden],
identifier: params[:repository_name],
mirror_url: params[:clone_addr],
user_id: user.id,
user_id: params[:user_id],
login: params[:auth_username],
password: params[:auth_password],
is_mirror: params[:is_mirror]

View File

@ -28,7 +28,7 @@ class Repositories::MigrateService < ApplicationService
{
clone_addr: params[:mirror_url],
repo_name: params[:identifier],
uid: user.gitea_uid,
uid: project&.owner&.gitea_uid,
private: params[:hidden],
mirror: wrapper_mirror || false,
auth_username: params[:login],