修改bug

This commit is contained in:
sylor_huang@126.com 2020-03-16 18:33:09 +08:00
parent 9eb94e6344
commit a879069c0a
2 changed files with 69 additions and 34 deletions

View File

@ -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,38 +139,42 @@ 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? repository_params = {
unless Repository.exists?(project_id: new_project.id, user_id: new_user.id, identifier: project_identifier) hidden: project["is_public"],
repository_params = { user_id: new_user.id,
hidden: project["is_public"], identifier: project_identifier
user_id: new_user.id, }
identifier: project_identifier Repositories::CreateService.new(new_user, new_project, repository_params).call
} # unless Repository.exists?(project_id: new_project.id, user_id: new_user.id, identifier: project_identifier)
Repositories::CreateService.new(new_user, new_project, repository_params).call # repository_params = {
# SyncRepositoryJob.perform_later(new_user.login, project["identifier"]) #暂时不迁移版本库 # hidden: project["is_public"],
end # user_id: new_user.id,
end # identifier: project_identifier
# }
if project_score.present? # Repositories::CreateService.new(new_user, new_project, repository_params).call
project_score = project_score["project_score"] if old_version_source.include?(platform) #trustie上需要 # # SyncRepositoryJob.perform_later(new_user.login, project["identifier"]) #暂时不迁移版本库
ProjectScore.create!(project_score&.except!(*score_to_delete).merge(project_id: new_project.id)) # end
end
sync_user_issues(new_project.id, new_user.id,old_user_id,issue_params, platform)
sync_members(new_project.id, member_params,platform)
sync_commits(new_project.id,new_project.gpid, commit_params,platform)
sync_pull_requests(new_project.id,new_user.id, pr_params,platform)
sync_versions(new_project.id, new_user.id, version_params,platform)
sync_watchers(new_project.id, watchers_params, platform)
sync_praises(new_project.id,praise_trends_params,platform)
end end
if project_score.present?
project_score = project_score["project_score"] if old_version_source.include?(platform) #trustie上需要
ProjectScore.create!(project_score&.except!(*score_to_delete).merge(project_id: new_project.id))
end
sync_user_issues(new_project.id, new_user.id,old_user_id,issue_params, platform)
sync_members(new_project.id, member_params,platform)
sync_commits(new_project.id,new_project.gpid, commit_params,platform)
sync_pull_requests(new_project.id,new_user.id, pr_params,platform)
sync_versions(new_project.id, new_user.id, version_params,platform)
sync_watchers(new_project.id, watchers_params, platform)
sync_praises(new_project.id,praise_trends_params,platform)
end end
end end
end end

View File

@ -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