From 8afd4b4132c2bbab511cb3afa2759096b1735e77 Mon Sep 17 00:00:00 2001 From: Ching Date: Thu, 21 Mar 2024 16:24:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=B0=E5=BB=BA=20?= =?UTF-8?q?issue=20=E7=9A=84=E9=80=9A=E7=9F=A5=20TUN-31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) 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