FIX 根据gitea接口更新创建镜像项目api
This commit is contained in:
parent
e8ac921aa9
commit
d464ab3891
|
@ -88,7 +88,7 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def mirror_params
|
def mirror_params
|
||||||
params.permit(:user_id, :name, :description, :repository_name,
|
params.permit(:user_id, :name, :description, :repository_name, :is_mirror, :auth_username,
|
||||||
:project_category_id, :project_language_id, :clone_addr, :private)
|
:auth_password, :project_category_id, :project_language_id, :clone_addr, :private)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ class Projects::MigrateForm < BaseForm
|
||||||
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
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
|
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
|
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id, :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password
|
||||||
|
|
||||||
validates :user_id, :name, :description,:repository_name, :project_category_id, :project_language_id, presence: true
|
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 :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
class MigrateRemoteRepositoryJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(repo, token, params)
|
||||||
|
gitea_repository = Gitea::Repository::MigrateService.new(token, params).call
|
||||||
|
sync_project(repo, gitea_repository)
|
||||||
|
sync_repository(repo, gitea_repository)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def sync_project(repo, gitea_repository)
|
||||||
|
repo&.project.update_columns(gpid: gitea_repository["id"], identifier: gitea_repository["name"]) if gitea_repository
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_repository(repository, gitea_repository)
|
||||||
|
repository.mirror.update_columns(statuses: Mirror.statuses[:succeeded]) if gitea_repository
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,7 +4,11 @@ class Project < ApplicationRecord
|
||||||
include Watchable
|
include Watchable
|
||||||
include ProjectOperable
|
include ProjectOperable
|
||||||
|
|
||||||
enum project_type: { mirror: 1, common: 0 } # common:开源托管项目, mirror:开源镜像项目
|
# common:开源托管项目
|
||||||
|
# mirror:普通镜像项目,没有定时同步功能
|
||||||
|
# sync_mirror:同步镜像项目,有系统定时同步功能,且用户可手动同步操作
|
||||||
|
#
|
||||||
|
enum project_type: { sync_mirror: 2, mirror: 1, common: 0 }
|
||||||
|
|
||||||
belongs_to :ignore, optional: true
|
belongs_to :ignore, optional: true
|
||||||
belongs_to :license, optional: true
|
belongs_to :license, optional: true
|
||||||
|
|
|
@ -2,6 +2,7 @@ class Repository < ApplicationRecord
|
||||||
self.inheritance_column = nil # FIX The single-table inheritance mechanism failed
|
self.inheritance_column = nil # FIX The single-table inheritance mechanism failed
|
||||||
belongs_to :project, :touch => true
|
belongs_to :project, :touch => true
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
has_one :mirror, foreign_key: :repo_id
|
||||||
has_many :version_releases, dependent: :destroy
|
has_many :version_releases, dependent: :destroy
|
||||||
|
|
||||||
validates :identifier, presence: true
|
validates :identifier, presence: true
|
||||||
|
@ -9,4 +10,9 @@ class Repository < ApplicationRecord
|
||||||
def to_param
|
def to_param
|
||||||
self.identifier.parameterize
|
self.identifier.parameterize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# with repository is mirror
|
||||||
|
def set_mirror!
|
||||||
|
self.build_mirror(status: Mirror.statuses[:waiting]).save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,17 +31,23 @@ class Projects::MigrateService < ApplicationService
|
||||||
project_category_id: params[:project_category_id],
|
project_category_id: params[:project_category_id],
|
||||||
project_language_id: params[:project_language_id],
|
project_language_id: params[:project_language_id],
|
||||||
is_public: project_secretion[:public],
|
is_public: project_secretion[:public],
|
||||||
project_type: Project.project_types[:mirror]
|
project_type: set_project_type
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_project_type
|
||||||
|
ActiveModel::Type::Boolean.new.cast(params[:is_mirror]) == true ? Project.project_types[:sync_mirror] : Project.project_types[:mirror]
|
||||||
|
end
|
||||||
|
|
||||||
def repository_params
|
def repository_params
|
||||||
{
|
{
|
||||||
hidden: project_secretion[:hidden],
|
hidden: project_secretion[:hidden],
|
||||||
identifier: params[:repository_name],
|
identifier: params[:repository_name],
|
||||||
mirror_url: params[:clone_addr],
|
mirror_url: params[:clone_addr],
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
login: user.login
|
login: params[:auth_username],
|
||||||
|
password: params[:auth_password],
|
||||||
|
is_mirror: params[:is_mirror]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue