Commit b64cb29b authored by gm's avatar gm

添加本地缓存,记录该版本是否已经发过邮件

parent e06cc23e
# HappyKit
因为launchctl的运行环境所能找到的ruby为/usr/bin/ruby ruby命令必须如下方式执行
/usr/bin/ruby /Users/gm/LaunchAgentScript/HappyKit/notify_release_date_by_email.rb
#!/usr/bin/ruby
# encoding: UTF-8
require 'httparty'
require "ostruct"
require 'mail'
......@@ -43,6 +44,7 @@ def login
end
def today
# 打开下面注释,改成某个版本开始时间,就可以调试这个版本的发邮件服务了
# return Date.parse("2019-06-20")
return Date.today
end
......@@ -90,14 +92,30 @@ end
def should_send_email_today
response = get_dev_events_response
obj = JSON.parse(response.body, object_class: OpenStruct)
# 读取历史记录,如果以前发送过,则不需要再次发送
filePath = File.dirname(__FILE__) + '/sprintEmailHistory.log'
file = File.open(filePath, "a+", external_encoding: Encoding::UTF_8, internal_encoding: Encoding::UTF_8)
history = file.read()
puts "history #{history}"
for event in obj.events
puts "#{event.title} #{event.start}"
start = Date.parse(event.start)
if start == today
if history == event.title
puts "#{event.title} 版本已经发过邮件"
return false
else
file.truncate(0)
count = file.write(event.title)
file.close
puts "可以发送邮件"
return true
end
end
end
puts "今天不是发送邮件的日子"
return false
end
......@@ -119,10 +137,19 @@ def send_email(deliver_info)
mail = Mail.deliver do
# 其实下面都是方法调用,不要被迷惑了
to ['hualu@igengmei.com', 'wangjun@igengmei.com', 'sunwenhui@igengmei.com', 'tanchenshuai@igengmei.com', 'zhucuicui@igengmei.com', 'huchunhe@igengmei.com', 'dongqiang@igengmei.com', 'SJ-liuxiao@igengmei.com', 'client-rd@igengmei.com']
#to ['jaguar@igengmei.com']
from 'jaguar@igengmei.com'
# to ['jaguar@igengmei.com']
bcc 'jaguar@igengmei.com' # 抄送
from 'jaguar@igengmei.com' # 发件人
subject "更美app#{deliver_info.title}商店物料信息"
body "Hi,All,#{deliver_info.title}时间为#{deliver_info.date.to_s},请准备商店相关的物料信息(是否更换APP icon和商店海报),谢谢~"
text_part do
content_type "text/plain; charset=utf-8"
body <<-EOF
Hi,All
#{deliver_info.title}时间为#{deliver_info.date.to_s},请准备商店相关的物料信息(是否更换APP icon和商店海报),谢谢~
EOF
end
end
end
......@@ -145,6 +172,4 @@ if should_send_email_today
)
DingBot.send_msg(message)
end
else
puts "今天不是发邮件日期"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment