Skip to content

Commit

Permalink
A 发布结果通知添加主机信息
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Apr 20, 2020
1 parent 1951b45 commit 8e15ea8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spug_api/apps/deploy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def __init__(self, rds, token, r_id):
@staticmethod
def send_deploy_notify(req):
rst_notify = json.loads(req.deploy.rst_notify)
host_ids = json.loads(req.host_ids)
if rst_notify['mode'] != '0' and rst_notify.get('value'):
extra = json.loads(req.extra)
if req.deploy.extend == '1':
Expand All @@ -203,13 +204,15 @@ def send_deploy_notify(req):
version = extra1
else:
version = extra[0]
hosts = [{'id': x.id, 'name': x.name} for x in Host.objects.filter(id__in=host_ids)]
if rst_notify['mode'] == '1':
color, text = ('#8ece60', '成功') if req.status == '3' else ('#f90202', '失败')
texts = [
'## %s ## ' % '发布结果通知',
f'**应用名称:** {req.deploy.app.name} ',
f'**发布环境:** {req.deploy.env.name} ',
f'**应用版本:** {version} ',
f'**发布环境:** {req.deploy.env.name} ',
f'**发布主机:** {",".join(x["name"] for x in hosts)} ',
f'**发布结果:** <font color="{color}">{text}</font>',
f'**发布时间:** {human_datetime()} ',
'> 来自 Spug运维平台'
Expand All @@ -230,6 +233,7 @@ def send_deploy_notify(req):
'env_id': req.deploy.env_id,
'env_name': req.deploy.env.name,
'version': version,
'targets': hosts,
'is_success': req.status == '3',
'deploy_at': human_datetime()
}
Expand Down

0 comments on commit 8e15ea8

Please sign in to comment.