diff --git a/app/services/gitea/organization/get_service.rb b/app/services/gitea/organization/get_service.rb index 0b58239f9..c193bafb1 100644 --- a/app/services/gitea/organization/get_service.rb +++ b/app/services/gitea/organization/get_service.rb @@ -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 \ No newline at end of file diff --git a/lib/tasks/sync_org_mirror_repo.rake b/lib/tasks/sync_org_mirror_repo.rake index a62230369..547b09d8b 100644 --- a/lib/tasks/sync_org_mirror_repo.rake +++ b/lib/tasks/sync_org_mirror_repo.rake @@ -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)