新增:初始化项目搜索标签脚本

This commit is contained in:
yystopf 2023-04-13 17:07:41 +08:00
parent dfd4ff55a5
commit c01c3de2fd
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# 执行示例 bundle exec rake init_project_topic:project
# RAILS_ENV=production bundle exec rake init_project_topic:project
namespace :init_project_topic do
desc "Init Project Topic for Project"
task project: :environment do
Project.find_each do |p|
next if p.project_topics.size >= 3
languages = $gitea_client.get_repos_languages_by_owner_repo(p.owner.login, p.identifier)
topic_count = p.project_topics.size
languages.each do |k, _|
next if topic_count >= 3
project_topic = ProjectTopic.find_or_create_by!(name: k.downcase)
project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: p.id)
if project_topic.present? && project_topic_ralate.present?
topic_count +=1
end
end
end
end
end