This commit is contained in:
Jasder 2020-03-19 17:18:17 +08:00
parent 172093efe9
commit 70de2ae571
1 changed files with 21 additions and 0 deletions

View File

@ -79,4 +79,25 @@ class Project < ApplicationRecord
end
end
def self.init_bluck_repository
Project.includes(:repository).find_each do |project|
puts project.id
next if project.owner.blank?
if project.repository.blank?
Repository.create!(project_id: project.id, identifier: Project.generate_identifier, user_id: project&.owner&.id)
end
end
end
def self.generate_identifier
str_arr = (("a".."z").to_a + ("A".."Z").to_a)
str = str_arr.shuffle[0..8].join
while Repository.exists?(identifier: str)
str = str_arr.shuffle[0..8].join
end
str
end
end