fixed 新建项目初始化项目标签
This commit is contained in:
parent
68be385af0
commit
289e024253
|
@ -56,6 +56,7 @@ class ProjectsController < ApplicationController
|
|||
Projects::CreateForm.new(project_params).validate!
|
||||
@project = Projects::CreateService.new(current_user, project_params).call
|
||||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id)
|
||||
UpdateProjectTopicJob.set(wait: 5.seconds).perform_later(@project.id) if @project.id.present?
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
|
|
@ -16,6 +16,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob
|
|||
project_id = repo&.project&.id
|
||||
puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############"
|
||||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present?
|
||||
UpdateProjectTopicJob.set(wait: 5.seconds).perform_later(project_id) if project_id.present?
|
||||
puts "############ mirror status: #{repo.mirror.status} ############"
|
||||
else
|
||||
repo&.mirror&.failed!
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
class UpdateProjectTopicJob < ApplicationJob
|
||||
include ProjectsHelper
|
||||
|
||||
queue_as :message
|
||||
|
||||
def perform(project_id)
|
||||
project = Project.find_by(id: project_id)
|
||||
return if project.blank?
|
||||
begin
|
||||
languages = $gitea_client.get_repos_languages_by_owner_repo(project.owner.login, project.identifier)
|
||||
topic_count = 0
|
||||
if project.project_category_id.present?
|
||||
project_topic = ProjectTopic.find_or_create_by!(name: project.project_category.name.downcase)
|
||||
project_topic_ralate = project_topic.project_topic_ralates.find_or_create_by!(project_id: project.id)
|
||||
if project_topic.present? && project_topic_ralate.present?
|
||||
topic_count +=1
|
||||
end
|
||||
end
|
||||
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: project.id)
|
||||
if project_topic.present? && project_topic_ralate.present?
|
||||
topic_count +=1
|
||||
end
|
||||
end
|
||||
rescue
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -4,7 +4,7 @@
|
|||
namespace :init_project_topic do
|
||||
desc "Init Project Topic for Project"
|
||||
task project: :environment do
|
||||
Project.order(created_at: :desc).find_each do |p|
|
||||
Project.where(platform: 'forge').order(created_at: :desc).find_each do |p|
|
||||
next unless p.owner.present?
|
||||
next if p.project_topics.size >= 3
|
||||
begin
|
||||
|
|
Loading…
Reference in New Issue