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_name(user_id, name) unless 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_init_token(blockchain_init_token) unless blockchain_init_token.blank?
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class Projects::MigrateForm < BaseForm
|
|||
validate do
|
||||
check_project_name(user_id, name) unless 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_language(project_language_id)
|
||||
check_owner
|
||||
|
|
|
@ -10,7 +10,7 @@ class Projects::UpdateForm < BaseForm
|
|||
check_project_language(project_language_id)
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
@ -38,18 +38,27 @@ class Repositories::CreateService < ApplicationService
|
|||
private
|
||||
|
||||
def create_gitea_repository
|
||||
if project.owner.is_a?(User)
|
||||
# @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})
|
||||
begin
|
||||
@gitea_repository = $gitea_client.get_repos_by_owner_repo(project.owner.login, params[:identifier])
|
||||
rescue Gitea::Api::ServerError => e
|
||||
if e.http_code.to_i == 404
|
||||
if project.owner.is_a?(User)
|
||||
# @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
|
||||
|
||||
def sync_project
|
||||
if gitea_repository
|
||||
project.update_columns(
|
||||
is_public: !gitea_repository["private"],
|
||||
gpid: gitea_repository["id"],
|
||||
identifier: repository.identifier,
|
||||
default_branch: gitea_repository["default_branch"],
|
||||
|
@ -58,7 +67,7 @@ class Repositories::CreateService < ApplicationService
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def remote_repository_url
|
||||
|
|
Loading…
Reference in New Issue