forked from Gitlink/forgeplus
FIX delete some mandatory field with migrate repo api
This commit is contained in:
parent
67d4544d6b
commit
e38539445d
|
@ -374,9 +374,7 @@ curl -X POST \
|
|||
-d "user_id=36408" \
|
||||
-d "clone_addr=https://gitea.com/mx8090alex/golden.git" \
|
||||
-d "name=golden_mirror1" \
|
||||
-d "description=golden_mirror" \
|
||||
-d "project_category_id=1" \
|
||||
-d "project_language_id=2" \
|
||||
-d "repository_name=golden_mirror1" \
|
||||
http://localhost:3000/api/projects/migrate.json | jq
|
||||
```
|
||||
*请求参数说明:*
|
||||
|
|
|
@ -56,7 +56,6 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def migrate
|
||||
tip_exception("无法使用以下关键词:#{mirror_params[:repository_name]},请重新命名") if ReversedKeyword.is_reversed(mirror_params[:repository_name]).present?
|
||||
Projects::MigrateForm.new(mirror_params).validate!
|
||||
|
||||
@project =
|
||||
|
|
|
@ -19,7 +19,7 @@ class BaseForm
|
|||
end
|
||||
|
||||
def check_reversed_keyword(repository_name)
|
||||
raise "仓库名称已被使用." if ReversedKeyword.is_reversed(repository_name).exists?
|
||||
raise "仓库名称已被占用." if ReversedKeyword.is_reversed(repository_name).exists?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
class Projects::CreateForm < BaseForm
|
||||
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id,
|
||||
:project_language_id, :ignore_id, :license_id, :private, :owner
|
||||
|
||||
validates :user_id, :name, :repository_name, presence: true
|
||||
validates :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
|
||||
validates :name, length: { maximum: 50 }
|
||||
validates :repository_name, length: { maximum: 100 }
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
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, :repository_name, :project_category_id, :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :owner
|
||||
|
||||
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: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :clone_addr, format: { with: URL_REGEX, multiline: true, message: "地址格式不正确" }
|
||||
validates :user_id, :name, :repository_name, :clone_addr, presence: true
|
||||
validates :repository_name, format: { with: CustomRegexp::REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :clone_addr, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" }
|
||||
validate do
|
||||
check_project_name(user_id, name) unless name.blank?
|
||||
check_repository_name(user_id, repository_name) unless repository_name.blank?
|
||||
|
|
|
@ -6,4 +6,8 @@ module CustomRegexp
|
|||
PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{8,16}\z/
|
||||
URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/
|
||||
IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
|
||||
|
||||
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
|
||||
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class Repositories::MigrateService < ApplicationService
|
|||
private: params[:hidden],
|
||||
mirror: wrapper_mirror || false,
|
||||
auth_username: params[:login],
|
||||
auth_password: Base64.decode64(params[:password])
|
||||
auth_password: Base64.decode64(params[:password] || "")
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue