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
7275144c
Commit
7275144c
authored
Sep 22, 2019
by
汪洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加可行通知
parent
fbab8f2f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
174 additions
and
72 deletions
+174
-72
Confluence.rb
Confluence.rb
+48
-0
README.md
README.md
+19
-0
kexing_notify.rb
kexing_notify.rb
+90
-0
notify_release_date_by_email.rb
notify_release_date_by_email.rb
+15
-71
sprintEmail.sh
sprintEmail.sh
+2
-1
No files found.
Confluence.rb
0 → 100644
View file @
7275144c
#!/Users/wangyang/.rvm/rubies/ruby-2.3.1/bin/ruby
require
'httparty'
require
"ostruct"
def
login
# 登录
options
=
{
:body
=>
{
:os_username
=>
" jaguar"
,
:os_password
=>
'jaguar@GM123'
,
:login
=>
'%E7%99%BB%E5%BD%95'
},
:headers
=>
{
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
}
}
login
=
HTTParty
.
post
(
"http://wiki.wanmeizhensuo.com/dologin.action"
,
options
)
# puts login.to_s
cookie
=
login
.
headers
[
'set-cookie'
]
$event_headers
=
{
:headers
=>
{
'Cookie'
=>
cookie
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
},
}
end
def
today
# 打开下面注释,改成某个版本开始时间,就可以调试这个版本的发邮件服务了
# return Date.parse("2019-09-17")
return
Date
.
today
end
def
a_month_ago
return
today
<<
1
end
def
a_month_later
return
today
>>
1
end
# event_id: confluence 日历事件id,比如“可行会”、“细审会”等待。在浏览器中抓包中取得
# 返回此日历事件的前一个月至后一个月该事件的集合。
def
get_events
(
event_id
)
event_query
=
"subCalendarId=
#{
event_id
}
&userTimeZoneId=Asia%2FShanghai&start=
#{
a_month_ago
}
T00%3A00%3A00Z&end=
#{
a_month_later
}
T00%3A00%3A00Z&_=1552802345400"
response
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
$event_headers
)
obj
=
JSON
.
parse
(
response
.
body
,
object_class:
OpenStruct
)
return
obj
.
events
end
\ No newline at end of file
README.md
View file @
7275144c
# HappyKit
因为launchctl的运行环境所能找到的ruby为/usr/bin/ruby ruby命令必须如下方式执行
/usr/bin/ruby /Users/gm/LaunchAgentScript/HappyKit/notify_release_date_by_email.rb
## 知识点
### 网络请求库 HTTParty
gem HTTParty 一个现成的网络请求,用法简单到有些奇怪。当然也可以用ruby原生的请求方法,只是很繁琐
### JSON解析
gem json 提供了JSON解析
类如:JSON.parse(json_string),就可以将这段string转为相应的模型
### JSON转模型,ostruct
gem ostruct 提供了一行代码将json string转模型的能力
例如:obj = JSON.parse(json_string, object_class: OpenStruct)
就直接得到了模型。注意OpenStruct为固定写法,不需要改变。也不需要像Objective-C 或者 Java 那样要先写一个对象模型,OpenStruct这一行代码直接就可以生成一个对象,其对象结构就和 json_string 一模一样。
### 发送邮件
gem mail 提供了邮件能力。具体见send_email方法的实现
\ No newline at end of file
kexing_notify.rb
0 → 100644
View file @
7275144c
#! /Users/wangyang/.rvm/rubies/ruby-2.3.1/bin/ruby
require
'httparty'
require
"ostruct"
require
'mail'
require
'dingbot'
require
File
.
dirname
(
__FILE__
)
+
'/Confluence'
# 提前通知要过可行;当天也会提示
def
ke_xing_notify
()
ke_xing_event_id
=
"2c8733f7-938d-41e4-9706-ea01bf88ba91"
events
=
get_events
(
ke_xing_event_id
)
for
event
in
events
start
=
Date
.
parse
(
event
.
start
)
puts
event
.
title
days_left
=
(
start
-
today
).
to_i
cweek_offset
=
start
.
cweek
-
today
.
cweek
# 只提前一天提示,要考虑跨周末的情况
if
cweek_offset
==
1
if
days_left
==
3
# 下周X
msg
=
"
#{
event
.
title
}
时间为下周一"
ding_msg
(
msg
)
end
elsif
cweek_offset
==
0
if
days_left
==
1
msg
=
"明天
#{
event
.
title
}
"
ding_msg
(
msg
)
end
end
if
days_left
==
0
ding_msg
(
"今天可行"
)
end
end
end
# 提交审核那一天,通知迭代负责人预订会议室
def
notify_to_book_ke_xing_meeting_room
()
submit_event_id
=
"b065a064-5851-4722-931b-7e932257ef54"
events
=
get_events
(
submit_event_id
)
for
event
in
events
start
=
Date
.
parse
(
event
.
start
)
days_left
=
(
start
-
today
).
to_i
cweek_offset
=
start
.
cweek
-
today
.
cweek
if
start
==
today
ding_meeting_book
end
end
end
PM_BOT
=
"7f105786f654bac5491b5ad808d24521e6fec5d8da8f8b6b7590c16a91a1c4fd"
KEXING_BOT
=
"6565866a84fe1e879c06273d434152bfd7669d93153780ca34ec2792e0386c1c"
TEST_BOT
=
"0e53adfed496676b49931ab73092ce6dc206ced89fb66852be0906b5e3dcfa75"
def
ding_msg
(
msg
)
# ding(PM_BOT, msg)
# ding(KEXING_BOT, msg)
ding
(
TEST_BOT
,
msg
)
end
def
ding
(
bot_id
,
msg
)
puts
msg
DingBot
.
endpoint
=
'https://oapi.dingtalk.com/robot/send'
DingBot
.
access_token
=
bot_id
message
=
DingBot
::
Message
::
Text
.
new
(
"
#{
msg
}
"
,
[],
false
)
DingBot
.
send_msg
(
message
)
end
def
ding_meeting_book
DingBot
.
endpoint
=
'https://oapi.dingtalk.com/robot/send'
DingBot
.
access_token
=
KEXING_BOT
message
=
DingBot
::
Message
::
Text
.
new
(
"预订下一个迭代可行的会议室"
,
[
"15811315780"
],
false
)
DingBot
.
send_msg
(
message
)
end
login
ke_xing_notify
notify_to_book_ke_xing_meeting_room
notify_release_date_by_email.rb
View file @
7275144c
...
...
@@ -4,64 +4,7 @@ require 'httparty'
require
"ostruct"
require
'mail'
require
'dingbot'
=begin
知识点:网络请求库 HTTParty
gem HTTParty 一个现成的网络请求,用法简单到有些奇怪。当然也可以用ruby原生的请求方法,只是很繁琐
知识点:JSON转模型,ostruct
gem ostruct 提供了一行代码将json string转模型的能力
例如:obj = JSON.parse(json_string, object_class: OpenStruct)
就直接得到了模型。注意OpenStruct为固定写法,不需要改变
知识点:JSON解析
gem json 提供了JSON解析
类如:JSON.parse(json_string),就可以将这段string转为相应的模型
知识点:发送邮件
gem mail 提供了邮件能力。具体见send_email方法的实现
=end
# TODO: 将登录帐号及邮箱换成只在内网使用的,比如jaguar
def
login
# 登录
options
=
{
:body
=>
{
:os_username
=>
" jaguar"
,
:os_password
=>
'jaguar@GM123'
,
:login
=>
'%E7%99%BB%E5%BD%95'
},
:headers
=>
{
'Content-Type'
=>
'application/x-www-form-urlencoded'
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
}
}
login
=
HTTParty
.
post
(
"http://wiki.wanmeizhensuo.com/dologin.action"
,
options
)
# puts login.to_s
cookie
=
login
.
headers
[
'set-cookie'
]
$event_headers
=
{
:headers
=>
{
'Cookie'
=>
cookie
,
'Accept'
=>
'application/json, text/javascript, */*; q=0.01'
},
}
end
def
today
# 打开下面注释,改成某个版本开始时间,就可以调试这个版本的发邮件服务了
# return Date.parse("2019-06-20")
return
Date
.
today
end
def
dev_start_time
return
today
<<
1
end
def
dev_end_time
return
today
>>
1
end
def
get_dev_events_response
dev_event_id
=
"3bcd7d25-37d0-4624-83d2-691c456a76a8"
event_query
=
"subCalendarId=
#{
dev_event_id
}
&userTimeZoneId=Asia%2FShanghai&start=
#{
dev_start_time
}
T00%3A00%3A00Z&end=
#{
dev_end_time
}
T00%3A00%3A00Z&_=1552802345400"
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
$event_headers
)
end
require
File
.
dirname
(
__FILE__
)
+
'/Confluence'
# 类似于“7.11开发”这样的事件名,用于对比记录邮件是否已经发送
$dev_title
=
""
...
...
@@ -74,14 +17,11 @@ STORE_KEY = "sprintEmailHistory.log"
# 返回值:Deliver
def
get_submit_info
# 以后端上线时间为准,保证程序员不被其它工作量压到下一个迭代的开发周
dev_event_id
=
"e1c8aef8-130e-40bf-8f6c-fe0e5c5dbd9c"
# 提交时间
# backend_deploy_event_id = "8389fda3-a06c-49b5-af85-788c4af12071" # 后端上线时间
event_query
=
"subCalendarId=
#{
dev_event_id
}
&userTimeZoneId=Asia%2FShanghai&start=
#{
dev_start_time
}
T00%3A00%3A00Z&end=
#{
dev_end_time
}
T00%3A00%3A00Z&_=1552802345400"
events
=
HTTParty
.
get
(
"http://wiki.wanmeizhensuo.com/rest/calendar-services/1.0/calendar/events.json?
#{
event_query
}
"
,
$event_headers
)
obj
=
JSON
.
parse
(
events
.
body
,
object_class:
OpenStruct
)
# 客户端提交时间
submit_event_id
=
"e1c8aef8-130e-40bf-8f6c-fe0e5c5dbd9c"
events
=
get_events
(
submit_event_id
)
# 发版时间大于今天,则是这个版本的发版时间
for
event
in
obj
.
events
for
event
in
events
deploy_date
=
Date
.
parse
(
event
.
start
)
if
deploy_date
>
today
$submit_title
=
event
.
title
...
...
@@ -105,16 +45,16 @@ def set_store_value(key, value)
count
=
file
.
write
(
value
)
end
# 如果今天是开发第一天,并且之前没有发送过,则允许发送邮件;
# 如果今天是开发第一天,并且之前没有发送过,则允许发送邮件
def
should_send_email_today
response
=
get_dev_events_response
obj
=
JSON
.
parse
(
response
.
body
,
object_class:
OpenStruct
)
# 开始开发的时间
dev_event_id
=
"3bcd7d25-37d0-4624-83d2-691c456a76a8"
events
=
get_events
(
dev_event_id
)
# 读取历史记录,如果以前发送过,则不需要再次发送
history
=
get_store_value
(
STORE_KEY
)
puts
"history
#{
history
}
"
for
event
in
obj
.
events
for
event
in
events
start
=
Date
.
parse
(
event
.
start
)
if
start
==
today
...
...
@@ -168,6 +108,7 @@ Hi,All
end
# 测试 email_body 是否符合预期
def
test_email_body
()
puts
<<-
EOF
Hi,All
...
...
@@ -180,9 +121,12 @@ login
if
should_send_email_today
get_submit_info
begin
send_email
# 可以注释掉上面的 send_email方法,打开下面的test_email_body方法,单独测试
# test_email_body
# 邮件发送成功后,再存储数据
send_email
set_store_value
(
STORE_KEY
,
$dev_title
)
puts
"邮件已发送"
...
...
sprintEmail.sh
View file @
7275144c
#! /bin/bash
/usr/bin/ruby /Users/gm/LaunchAgentScript/HappyKit/notify_release_date_by_email.rb
/usr/bin/ruby
$(
pwd
)
/notify_release_date_by_email.rb
/usr/bin/ruby
$(
pwd
)
/kexing_notify.rb
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