Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HappyKit
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile
HappyKit
Commits
4cef2763
Commit
4cef2763
authored
Jul 09, 2019
by
gm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正:存储文件的时间不对
parent
b64cb29b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
22 deletions
+39
-22
notify_release_date_by_email.rb
notify_release_date_by_email.rb
+39
-22
No files found.
notify_release_date_by_email.rb
View file @
4cef2763
...
...
@@ -63,14 +63,14 @@ def get_dev_events_response
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
$event_headers
)
end
class
Deliver
attr_accessor
:title
attr_accessor
:date
def
initialize
(
title
,
date
)
@title
=
title
@date
=
date
end
end
# 类似于“7.11开发”这样的事件名,用于对比记录邮件是否已经发送
$dev_title
=
""
# 类似于“7.11客户端提交”这样的事件名,用于稍后发邮件
$title
=
""
# 类似于“7.11客户端提交”这样的事件的时间,用于稍后发邮件
$date
=
""
# 用来存储全局变量$dev_title的文件名
STORE_KEY
=
"sprintEmailHistory.log"
# 返回值:Deliver
def
get_deliver_info
...
...
@@ -84,18 +84,33 @@ def get_deliver_info
for
event
in
obj
.
events
deploy_date
=
Date
.
parse
(
event
.
start
)
if
deploy_date
>
today
return
Deliver
.
new
(
event
.
title
,
deploy_date
)
$title
=
event
.
title
$date
=
deploy_date
end
end
end
def
get_store_value
(
key
)
# sprintEmailHistory.log
filePath
=
File
.
dirname
(
__FILE__
)
+
'/'
+
key
file
=
File
.
open
(
filePath
,
"a+"
,
external_encoding:
Encoding
::
UTF_8
,
internal_encoding:
Encoding
::
UTF_8
)
return
file
.
read
()
end
def
set_store_value
(
key
,
value
)
filePath
=
File
.
dirname
(
__FILE__
)
+
'/'
+
key
file
=
File
.
open
(
filePath
,
"a+"
,
external_encoding:
Encoding
::
UTF_8
,
internal_encoding:
Encoding
::
UTF_8
)
file
.
truncate
(
0
)
count
=
file
.
write
(
value
)
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
()
history
=
get_store_value
(
STORE_KEY
)
puts
"history
#{
history
}
"
for
event
in
obj
.
events
...
...
@@ -107,9 +122,7 @@ def should_send_email_today
puts
"
#{
event
.
title
}
版本已经发过邮件"
return
false
else
file
.
truncate
(
0
)
count
=
file
.
write
(
event
.
title
)
file
.
close
$dev_title
=
event
.
title
puts
"可以发送邮件"
return
true
end
...
...
@@ -120,7 +133,7 @@ def should_send_email_today
end
def
send_email
(
deliver_info
)
def
send_email
()
mail
=
Mail
.
defaults
do
delivery_method
:smtp
,
{
:port
=>
465
,
...
...
@@ -136,18 +149,18 @@ 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
[
'hualu@igengmei.com'
,
'wangjun@igengmei.com'
,
'sunwenhui@igengmei.com'
,
'zhucuicui@igengmei.com'
,
'huchunhe@igengmei.com'
,
'dongqiang@igengmei.com'
,
'SJ-liuxiao@igengmei.com'
,
'client-rd@igengmei.com'
]
# to ['jaguar@igengmei.com']
bcc
'jaguar@igengmei.com'
# 抄送
from
'jaguar@igengmei.com'
# 发件人
subject
"更美app
#{
deliver_info
.
title
}
商店物料信息"
subject
"更美app
#{
$
title
}
商店物料信息"
text_part
do
content_type
"text/plain; charset=utf-8"
body
<<-
EOF
Hi,All
#{
deliver_info
.
title
}
时间为
#{
deliver_info
.
date
.
to_s
}
,请准备商店相关的物料信息(是否更换APP icon和商店海报),谢谢~
#{
$title
}
时间为
#{
$
date
.
to_s
}
,请准备商店相关的物料信息(是否更换APP icon和商店海报),谢谢~
EOF
end
end
...
...
@@ -156,17 +169,21 @@ end
login
if
should_send_email_today
deliver
=
get_deliver_info
get_deliver_info
begin
send_email
deliver
# 邮件发送成功后,再存储数据
send_email
set_store_value
(
STORE_KEY
,
$dev_title
)
puts
"邮件已发送"
rescue
Exception
=>
e
puts
"邮件发送失败"
puts
e
.
message
DingBot
.
endpoint
=
'https://oapi.dingtalk.com/robot/send'
DingBot
.
access_token
=
'8142e051fe21d101b7e619c179741b0502f99b66ede221e164c2c1643122378d'
message
=
DingBot
::
Message
::
Text
.
new
(
'sprintEmail 迭代发版时间邮件发送失败'
,
"sprintEmail 迭代发版时间邮件发送失败.
\n
#{
e
.
message
}
"
,
[
'15811315780'
],
false
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment