From b0ec4d7e9ee1b528ca48190bebf212096464b6c0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 4 Jul 2024 16:47:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=BC=BA=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/projects/create_form.rb | 2 +- app/forms/projects/migrate_form.rb | 2 +- app/forms/projects/update_form.rb | 2 +- app/services/repositories/create_service.rb | 23 ++++++++++++++------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/forms/projects/create_form.rb b/app/forms/projects/create_form.rb index cd2b9ffb5..d2d83bce9 100644 --- a/app/forms/projects/create_form.rb +++ b/app/forms/projects/create_form.rb @@ -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 diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index 649fcbb92..8c1d04968 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -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 diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index e75858c5a..e8d59ac7a 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -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 diff --git a/app/services/repositories/create_service.rb b/app/services/repositories/create_service.rb index 800d5f420..38b2e2cd9 100644 --- a/app/services/repositories/create_service.rb +++ b/app/services/repositories/create_service.rb @@ -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