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