diff --git a/app.py b/app.py index b07367d..8974f32 100644 --- a/app.py +++ b/app.py @@ -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