From c01c3de2fddaea2f2ab486db3418ac4f799b8ad7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 13 Apr 2023 17:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=A1=B9=E7=9B=AE=E6=90=9C=E7=B4=A2=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/init_project_topic.rake | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/tasks/init_project_topic.rake diff --git a/lib/tasks/init_project_topic.rake b/lib/tasks/init_project_topic.rake new file mode 100644 index 000000000..9d96a473f --- /dev/null +++ b/lib/tasks/init_project_topic.rake @@ -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 \ No newline at end of file