forked from jasder/forgeplus
修改bug
This commit is contained in:
parent
9eb94e6344
commit
a879069c0a
|
@ -88,7 +88,11 @@ class SyncForgeJob < ApplicationJob
|
||||||
end
|
end
|
||||||
if new_user.gitea_uid.present?
|
if new_user.gitea_uid.present?
|
||||||
result = Gitea::User::GenerateTokenService.new(owner_params["login"], user_password).call
|
result = Gitea::User::GenerateTokenService.new(owner_params["login"], user_password).call
|
||||||
new_user.gitea_token = result['sha1']
|
if result != 401
|
||||||
|
new_user.gitea_token = result.result['sha1']
|
||||||
|
else
|
||||||
|
new_user.gitea_token = ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if new_user.save(:validate => false)
|
if new_user.save(:validate => false)
|
||||||
|
@ -106,7 +110,7 @@ class SyncForgeJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def random_password
|
def random_password
|
||||||
[*('a'..'z'),*(0..9),*('A'..'Z')].shuffle[0..8].join
|
[*('a'..'z'),*(0..9),*('A'..'Z')].shuffle[0..12].join
|
||||||
end
|
end
|
||||||
|
|
||||||
#同步项目
|
#同步项目
|
||||||
|
@ -135,23 +139,28 @@ class SyncForgeJob < ApplicationJob
|
||||||
project_identifier = repo_params["identifier"]
|
project_identifier = repo_params["identifier"]
|
||||||
end
|
end
|
||||||
|
|
||||||
project_exists = false
|
# project_exists = false
|
||||||
if project_identifier.present?
|
# if project_identifier.present?
|
||||||
project_exists = Project.exists?(user_id: new_user.id, identifier:project_identifier)
|
# project_exists = Project.exists?(user_id: new_user.id, identifier:project_identifier)
|
||||||
end
|
# end
|
||||||
unless project_exists
|
|
||||||
new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id))
|
new_project = Project.new(project&.except!(*keys_to_delete).merge(user_id: new_user.id))
|
||||||
if new_project.save!(:validate => false)
|
if new_project.save!(:validate => false)
|
||||||
if project_identifier.present?
|
if project_identifier.present?
|
||||||
unless Repository.exists?(project_id: new_project.id, user_id: new_user.id, identifier: project_identifier)
|
|
||||||
repository_params = {
|
repository_params = {
|
||||||
hidden: project["is_public"],
|
hidden: project["is_public"],
|
||||||
user_id: new_user.id,
|
user_id: new_user.id,
|
||||||
identifier: project_identifier
|
identifier: project_identifier
|
||||||
}
|
}
|
||||||
Repositories::CreateService.new(new_user, new_project, repository_params).call
|
Repositories::CreateService.new(new_user, new_project, repository_params).call
|
||||||
# SyncRepositoryJob.perform_later(new_user.login, project["identifier"]) #暂时不迁移版本库
|
# unless Repository.exists?(project_id: new_project.id, user_id: new_user.id, identifier: project_identifier)
|
||||||
end
|
# repository_params = {
|
||||||
|
# hidden: project["is_public"],
|
||||||
|
# user_id: new_user.id,
|
||||||
|
# identifier: project_identifier
|
||||||
|
# }
|
||||||
|
# Repositories::CreateService.new(new_user, new_project, repository_params).call
|
||||||
|
# # SyncRepositoryJob.perform_later(new_user.login, project["identifier"]) #暂时不迁移版本库
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
if project_score.present?
|
if project_score.present?
|
||||||
|
@ -169,7 +178,6 @@ class SyncForgeJob < ApplicationJob
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.info("#######_______projects_sync__failed__#########{e}")
|
Rails.logger.info("#######_______projects_sync__failed__#########{e}")
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
|
|
|
@ -7,11 +7,15 @@ class Gitea::User::GenerateTokenService < Gitea::ClientService
|
||||||
@password = password
|
@password = password
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def call
|
def call
|
||||||
params = {}
|
params = {}
|
||||||
url = "/users/#{username}/tokens".freeze
|
url = "/users/#{username}/tokens".freeze
|
||||||
params = params.merge(token: token_params, data: request_params)
|
params = params.merge(token: token_params, data: request_params)
|
||||||
post(url, params)
|
response = post_token(url, params)
|
||||||
|
|
||||||
|
render_status(response)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -25,4 +29,27 @@ class Gitea::User::GenerateTokenService < Gitea::ClientService
|
||||||
def request_params
|
def request_params
|
||||||
{ name: username }
|
{ name: username }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_token(url, params={})
|
||||||
|
puts "[gitea] request params: #{params}"
|
||||||
|
request_url = [api_url, url].join('').freeze
|
||||||
|
auth_token = authen_params(params[:token])
|
||||||
|
conn(auth_token).post do |req|
|
||||||
|
req.url "#{request_url}"
|
||||||
|
req.body = params[:data].to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_status(response)
|
||||||
|
case response.status
|
||||||
|
when 200
|
||||||
|
if response.body.size > 0
|
||||||
|
JSON.parse(response&.body)
|
||||||
|
else
|
||||||
|
401
|
||||||
|
end
|
||||||
|
else
|
||||||
|
401
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue