gitlink-forgeplus/app/models/glcc_medium_term_examine_ma...

86 lines
2.3 KiB
Ruby

# == Schema Information
#
# Table name: ignores
#
# student_reg_id
# task_id
# defence_video_url
# code_or_pr_url
# PPT_attachment_id
# term
# created_on
# updated_on
# is_delete
# round
class GlccMediumTermExamineMaterial < ActiveRecord::Base
self.table_name = "glcc_medium_term_examine_material"
belongs_to :glcc_student, :class_name => :GlccRegistrationStudent, :foreign_key => "student_reg_id"
def check_pr_url
state = []
# code_or_pr_url = "https://www.gitlink.org.cn/Gitlink/forgeplus/pulls/337"
url_array = code_or_pr_url.split("/")
gitlink_index = url_array.index("www.gitlink.org.cn") || url_array.index("gitlink.org.cn")
pull_index = url_array.index("pulls")
#发送没有在gitlink上提交PR的邮件
unless gitlink_index.present?
state << 1
end
# 输入的地址有问题邮件内容
unless pull_index == 5
state << 2
end
project = Project.find_by(identifier: url_array[4])
pr = PullRequest.where(project:project, gitea_number:url_array[6])
unless pr.present?
state << 3
end
state
end
def send_mail
gcs = glcc_student
mail = gcs.mail
return if mail.nil? || code_or_pr_url.nil?
state = check_pr_url
return unless state.present?
title = "2023年GitLink确实开源GLCC开源夏令营#{term == 1 ? "中期考核" : "结项考核"}提醒"
content = ""
state.map{|e|
content = content + number_to_content(e)
}
puts content
UserMailer.glcc_pr_check_email(mail,title, gcs.student_name, content).deliver_now
end
def state_to_html
gcs = glcc_student
mail = gcs.mail
return "数据异常PR连接为空" if mail.nil? || code_or_pr_url.nil?
state = check_pr_url
content = ""
state.map{|e|
content = content + number_to_content(e)
}
content
end
def number_to_content(num)
case num
when 1
"<p> PR链接为非GitLink平台链接 </p>"
when 2
"<p> PR链接为GitLink平台非PR链接 </p>"
when 3
"<p> PR链接中的PR不存在 </p>"
end
end
end