From 025ce562e454fa175137a60027617c0f601d404b Mon Sep 17 00:00:00 2001 From: Ching Date: Thu, 21 Mar 2024 15:43:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=86=20commit=20gitea=20=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=B7=BB=E5=8A=A0=E5=88=B0=20issue=20=E9=87=8C=20TUN-?= =?UTF-8?q?26=20TUN-25=20TUN-27?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app.py b/app.py index e05e8a3..1155783 100644 --- a/app.py +++ b/app.py @@ -89,6 +89,17 @@ def gitea_push(): logger.error('Failed to get completed state') return jsonify({'message': 'Failed to get completed state'}), 500 + def _attach_url_to_issue(issue_id, url, title=None): + data = {'query': 'mutation { attachmentLinkURL (title: "%s" url: "%s" issueId: "%s") { success } }' % (title, url, issue_id)} + resp = requests.post(LINEAR_API_URL, json=data, headers=headers) + if resp.status_code != 200: + logger.error('Failed to attach url to issue: %s' % resp.text) + return False + if not resp.json().get('data', {}).get('attachmentLinkURL', {}).get('success'): + logger.error('Failed to attach url to issue: %s' % resp.text) + return False + return True + # check if the commit message contains a linear issue id like 'TUN-21' # if yes, update the issue state to completed for commit in data['commits']: @@ -104,6 +115,7 @@ def gitea_push(): if not issue_data: logger.error('Issue not found: %s' % issue_id) continue + _attach_url_to_issue(issue_id, commit['url'], f'Gitea Commit: {commit["id"][:7]}') issue_data = issue_data['issue'] if issue_data['state']['type'] == 'completed': continue