feat: 增加新建 issue 的通知 TUN-31
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ching 2024-03-21 16:24:36 +08:00
parent 129c550d09
commit 8afd4b4132

30
app.py
View File

@ -41,24 +41,34 @@ def linear_issue():
if not 'action' in data:
logger.error('Invalid issue data: %s' % data)
return jsonify({'message': 'Invalid issue data'}), 400
if data['action'] != 'update':
if data['action'] not in ['update', 'create']:
logger.warning('Ignoring issue action: %s' % data['action'])
return jsonify({'message': 'Ignoring issue action'}), 200
# Send Discord message
if not data['updatedFrom'].get('stateId'):
logger.warning('Ignoring issue changes')
return jsonify({'message': 'Ignoring issue changes'}), 200
apobj = apprise.Apprise()
apobj.add(f'discord://{DISCORD_WEBHOOK_ID}/{DISCORD_WEBHOOK_TOKEN}/?avatar=No&format=markdown&url={data["data"]["url"]}')
apobj.asset.app_id = None
title = data['data']['identifier'] + ' - ' + data['data']['title']
if data['action'] == 'update':
if not data['updatedFrom'].get('stateId'):
logger.warning('Ignoring issue changes')
return jsonify({'message': 'Ignoring issue changes'}), 200
title = data['data']['identifier'] + ' - ' + data['data']['title']
body = f"状态变更。\n#Status\n{data['data']['state']['name']}"
notify_type = apprise.NotifyType.INFO
if data['data']['state']['type'] == 'completed':
notify_type = apprise.NotifyType.SUCCESS
apobj.notify(body=body, title=title, notify_type=notify_type)
elif data['action'] == 'create':
title = data['data']['identifier'] + ' - ' + data['data']['title']
body = f"创建 issue。\n#Status\n{data['data']['state']['name']}"
notify_type = apprise.NotifyType.INFO
for label in data['data']['labels']:
if label['name'] == 'Bug':
notify_type = apprise.NotifyType.FAILURE
break
apobj.notify(body=body, title=title, notify_type=notify_type)
body = f"状态变更。\n#Status\n{data['data']['state']['name']}"
notify_type = apprise.NotifyType.INFO
if data['data']['state']['type'] == 'completed':
notify_type = apprise.NotifyType.SUCCESS
apobj.notify(body=body, title=title, notify_type=notify_type)
return jsonify({'message': 'Ok'}), 200