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