[FIX]

[FIX]
This commit is contained in:
vilet.yy 2021-02-22 10:29:39 +08:00
parent ef0c44f29c
commit 93fa02bd7b
2 changed files with 11 additions and 8 deletions

View File

@ -1,9 +1,8 @@
class Gitea::Organization::GetService < Gitea::ClientService
attr_reader :user, :org_name
attr_reader :org
def initialize(user, org_name)
@user = user
@org_name = org_name
def initialize(org)
@org = org
end
def call
@ -13,10 +12,10 @@ class Gitea::Organization::GetService < Gitea::ClientService
private
def params
Hash.new.merge(token: user.gitea_token)
Hash.new.merge(token: org.gitea_token)
end
def url
"/orgs/#{org_name}".freeze
"/orgs/#{org.login}".freeze
end
end

View File

@ -10,8 +10,11 @@ namespace :sync_org_mirror_repo do
puts "=========need init count is [#{need_init_orgs.size}]=========="
need_init_orgs.find_each do |org|
puts "=== fix org name is [#{org.name}] ==="
user = User.first
gitea_org = Gitea::Organization::GetService.call(user, org.name)
gitea_org = Gitea::Organization::GetService.call(org)
if gitea_org[:status] == 404
org.destroy
next
end
org.update(gitea_uid: gitea_org["id"])
end
puts "========end to init organization gitea_uid==========="
@ -24,6 +27,7 @@ namespace :sync_org_mirror_repo do
.where.not(mirrors: {id: nil})
.where(users: {type: 'Organization'})
need_fix_repos.find_each do |repo|
next if repo.user_id == repo.project&.user_id
puts "=== fix repository owner is [#{repo&.project&.owner&.login}] ==="
puts "=== fix repository identifier is [#{repo.identifier}] ==="
Gitea::Repository::DeleteService.call(repo.project.owner, repo.identifier)