SendApplyAccountEmail send uuid email build email message send email send error email build error email message send error email
Signed-off-by: Luan Shengde shdluan@163.com --- .../mail-robot/send-apply-account-email.rb | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 container/mail-robot/send-apply-account-email.rb
diff --git a/container/mail-robot/send-apply-account-email.rb b/container/mail-robot/send-apply-account-email.rb new file mode 100755 index 0000000..f29ff1e --- /dev/null +++ b/container/mail-robot/send-apply-account-email.rb @@ -0,0 +1,72 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +# build mail data and send mail +class SendApplyAccountEmail + def initialize(send_mail_info) + @send_mail_host = %x(/sbin/ip route |awk '/default/ {print $3}').chomp + @send_mail_info = send_mail_info + end + + def send_uuid_email + email_msg = <<~EMAIL_MESSAGE + To: #{@send_mail_info['my_email']} + Subject: [compass-ci] Account Ready + + Dear #{@send_mail_info['my_name']}, + + Thank you for joining us. + You can use the following info to submit jobs: + + 1) setup default config + run the following command to add the below setup to default config file + mkdir -p ~/.config/compass-ci/defaults/ + cat >> ~/.config/compass-ci/defaults/\${USER}.yaml <<-EOF + my_email: #{@send_mail_info['my_email']} + my_name: #{@send_mail_info['my_name']} + my_uuid: #{@send_mail_info['my_uuid']} + EOF + + 2) download lkp-tests and dependencies + run the following command to install the lkp-test and effect the configuration + git clone https://gitee.com/wu_fengguang/lkp-tests.git + cd lkp-tests + make install + source ${HOME}/.bashrc && source ${HOME}/.bash_profile + + 3) submit job + reference: https://gitee.com/wu_fengguang/compass-ci/blob/master/doc/tutorial.md + find how to write job yaml + submit jobs/netperf.yaml + + regards + compass-ci + EMAIL_MESSAGE + + send_mail(email_msg) + end + + def send_error_email + email_msg = <<~EMAIL_MESSAGE + To: #{@send_mail_info['my_email']} + Subject: apply account failed + + Dear #{@send_mail_info['my_name']} + + Your application for account failed with following errors + + #{@send_mail_info['error_message']} + + regards + compass-ci + EMAIL_MESSAGE + + send_mail(email_msg) + end + + def send_mail(email_msg) + %x(curl -XPOST "#{@send_mail_host}:#{ENV['SEND_MAIL_PORT']}/send_mail_text" -d "#{email_msg}") + end +end