diff --git a/app.py b/app.py index 66426a8..e05e8a3 100644 --- a/app.py +++ b/app.py @@ -89,32 +89,32 @@ def gitea_push(): logger.error('Failed to get completed state') return jsonify({'message': 'Failed to get completed state'}), 500 - # check if the commit message contains a linear issue id + # 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']: - issue = re.search(r'TUN-\d+', commit['message']) - if issue: - issue_id = issue.group() - data_ = {'query': '{ issue(id: "%s") { title state { name type }}}' % issue_id} - resp = requests.post(LINEAR_API_URL, json=data_, headers=headers) - if resp.status_code != 200: - logger.error('Failed to get issue: %s' % resp.text) - return jsonify({'message': 'Failed to get issue'}), 500 - issue_data = resp.json().get('data') - if not issue_data: - logger.error('Issue not found: %s' % issue_id) - return jsonify({'message': 'Issue not found'}), 400 - issue_data = issue_data['issue'] - if issue_data['state']['type'] == 'completed': - return jsonify({'message': 'Issue already completed'}), 200 - update_data = {'query': 'mutation { issueUpdate(input: { stateId: "%s" } id: "%s") { success } }' % (completed_state, issue_id)} - update_resp = requests.post(LINEAR_API_URL, json=update_data, headers=headers) - if update_resp.status_code != 200: - logger.error('Failed to update issue: %s' % update_resp.text) - return jsonify({'message': 'Failed to update issue'}), 500 - if not update_resp.json().get('data', {}).get('issueUpdate', {}).get('success'): - logger.error('Failed to update issue: %s' % update_resp.text) - return jsonify({'message': 'Failed to update issue'}), 500 + issues = re.findall(r'TUN-\d+', commit['message']) + if issues: + for issue_id in issues: + data_ = {'query': '{ issue(id: "%s") { title state { name type }}}' % issue_id} + resp = requests.post(LINEAR_API_URL, json=data_, headers=headers) + if resp.status_code != 200: + logger.error('Failed to get issue: %s' % resp.text) + continue + issue_data = resp.json().get('data') + if not issue_data: + logger.error('Issue not found: %s' % issue_id) + continue + issue_data = issue_data['issue'] + if issue_data['state']['type'] == 'completed': + continue + update_data = {'query': 'mutation { issueUpdate(input: { stateId: "%s" } id: "%s") { success } }' % (completed_state, issue_id)} + update_resp = requests.post(LINEAR_API_URL, json=update_data, headers=headers) + if update_resp.status_code != 200: + logger.error('Failed to update issue: %s' % update_resp.text) + continue + if not update_resp.json().get('data', {}).get('issueUpdate', {}).get('success'): + logger.error('Failed to update issue: %s' % update_resp.text) + continue return jsonify({'message': 'Ok'}), 200