forked from Gitlink/forgeplus
更改:创建项目强关联
This commit is contained in:
parent
389a72b0a1
commit
b0ec4d7e9e
|
@ -16,7 +16,7 @@ class Projects::CreateForm < BaseForm
|
||||||
check_project_language(project_language_id)
|
check_project_language(project_language_id)
|
||||||
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?
|
||||||
check_gitea_repository_name(user_id, repository_name) unless repository_name.blank?
|
# check_gitea_repository_name(user_id, repository_name) unless repository_name.blank?
|
||||||
check_blockchain_token_all(blockchain_token_all) unless blockchain_token_all.blank?
|
check_blockchain_token_all(blockchain_token_all) unless blockchain_token_all.blank?
|
||||||
check_blockchain_init_token(blockchain_init_token) unless blockchain_init_token.blank?
|
check_blockchain_init_token(blockchain_init_token) unless blockchain_init_token.blank?
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Projects::MigrateForm < BaseForm
|
||||||
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?
|
||||||
check_gitea_repository_name(user_id, repository_name) unless repository_name.blank?
|
# check_gitea_repository_name(user_id, repository_name) unless repository_name.blank?
|
||||||
check_project_category(project_category_id)
|
check_project_category(project_category_id)
|
||||||
check_project_language(project_language_id)
|
check_project_language(project_language_id)
|
||||||
check_owner
|
check_owner
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Projects::UpdateForm < BaseForm
|
||||||
check_project_language(project_language_id)
|
check_project_language(project_language_id)
|
||||||
|
|
||||||
check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier
|
check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier
|
||||||
check_gitea_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier
|
# check_gitea_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier
|
||||||
check_project_name(user_id, name) unless name.blank? || name == project_name
|
check_project_name(user_id, name) unless name.blank? || name == project_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,18 +38,27 @@ class Repositories::CreateService < ApplicationService
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_gitea_repository
|
def create_gitea_repository
|
||||||
if project.owner.is_a?(User)
|
begin
|
||||||
# @gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
@gitea_repository = $gitea_client.get_repos_by_owner_repo(project.owner.login, params[:identifier])
|
||||||
@gitea_repository = $gitea_client.post_user_repos({query: {token: user.gitea_token}, body: gitea_repository_params.to_json})
|
rescue Gitea::Api::ServerError => e
|
||||||
elsif project.owner.is_a?(Organization)
|
if e.http_code.to_i == 404
|
||||||
# @gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params)
|
if project.owner.is_a?(User)
|
||||||
@gitea_repository = $gitea_client.post_orgs_repos_by_org(project.owner.login, {query: {token: user.gitea_token}, body: gitea_repository_params.to_json})
|
# @gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
||||||
|
@gitea_repository = $gitea_client.post_user_repos({query: {token: user.gitea_token}, body: gitea_repository_params.to_json})
|
||||||
|
elsif project.owner.is_a?(Organization)
|
||||||
|
# @gitea_repository = Gitea::Organization::Repository::CreateService.call(user.gitea_token, project.owner.login, gitea_repository_params)
|
||||||
|
@gitea_repository = $gitea_client.post_orgs_repos_by_org(project.owner.login, {query: {token: user.gitea_token}, body: gitea_repository_params.to_json})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise "服务器错误,请联系系统管理员!"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_project
|
def sync_project
|
||||||
if gitea_repository
|
if gitea_repository
|
||||||
project.update_columns(
|
project.update_columns(
|
||||||
|
is_public: !gitea_repository["private"],
|
||||||
gpid: gitea_repository["id"],
|
gpid: gitea_repository["id"],
|
||||||
identifier: repository.identifier,
|
identifier: repository.identifier,
|
||||||
default_branch: gitea_repository["default_branch"],
|
default_branch: gitea_repository["default_branch"],
|
||||||
|
@ -58,7 +67,7 @@ class Repositories::CreateService < ApplicationService
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_repository
|
def sync_repository
|
||||||
repository.update_columns(url: remote_repository_url,) if gitea_repository
|
repository.update_columns(url: remote_repository_url, hidden: gitea_repository["private"]) if gitea_repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_repository_url
|
def remote_repository_url
|
||||||
|
|
Loading…
Reference in New Issue