feat: 处理一条 message 中多个 issue id 的情况 TUN-28
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c7d4fe3c58
commit
f2cd178d42
48
app.py
48
app.py
@ -89,32 +89,32 @@ def gitea_push():
|
|||||||
logger.error('Failed to get completed state')
|
logger.error('Failed to get completed state')
|
||||||
return jsonify({'message': 'Failed to get completed state'}), 500
|
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
|
# if yes, update the issue state to completed
|
||||||
for commit in data['commits']:
|
for commit in data['commits']:
|
||||||
issue = re.search(r'TUN-\d+', commit['message'])
|
issues = re.findall(r'TUN-\d+', commit['message'])
|
||||||
if issue:
|
if issues:
|
||||||
issue_id = issue.group()
|
for issue_id in issues:
|
||||||
data_ = {'query': '{ issue(id: "%s") { title state { name type }}}' % issue_id}
|
data_ = {'query': '{ issue(id: "%s") { title state { name type }}}' % issue_id}
|
||||||
resp = requests.post(LINEAR_API_URL, json=data_, headers=headers)
|
resp = requests.post(LINEAR_API_URL, json=data_, headers=headers)
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
logger.error('Failed to get issue: %s' % resp.text)
|
logger.error('Failed to get issue: %s' % resp.text)
|
||||||
return jsonify({'message': 'Failed to get issue'}), 500
|
continue
|
||||||
issue_data = resp.json().get('data')
|
issue_data = resp.json().get('data')
|
||||||
if not issue_data:
|
if not issue_data:
|
||||||
logger.error('Issue not found: %s' % issue_id)
|
logger.error('Issue not found: %s' % issue_id)
|
||||||
return jsonify({'message': 'Issue not found'}), 400
|
continue
|
||||||
issue_data = issue_data['issue']
|
issue_data = issue_data['issue']
|
||||||
if issue_data['state']['type'] == 'completed':
|
if issue_data['state']['type'] == 'completed':
|
||||||
return jsonify({'message': 'Issue already completed'}), 200
|
continue
|
||||||
update_data = {'query': 'mutation { issueUpdate(input: { stateId: "%s" } id: "%s") { success } }' % (completed_state, issue_id)}
|
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)
|
update_resp = requests.post(LINEAR_API_URL, json=update_data, headers=headers)
|
||||||
if update_resp.status_code != 200:
|
if update_resp.status_code != 200:
|
||||||
logger.error('Failed to update issue: %s' % update_resp.text)
|
logger.error('Failed to update issue: %s' % update_resp.text)
|
||||||
return jsonify({'message': 'Failed to update issue'}), 500
|
continue
|
||||||
if not update_resp.json().get('data', {}).get('issueUpdate', {}).get('success'):
|
if not update_resp.json().get('data', {}).get('issueUpdate', {}).get('success'):
|
||||||
logger.error('Failed to update issue: %s' % update_resp.text)
|
logger.error('Failed to update issue: %s' % update_resp.text)
|
||||||
return jsonify({'message': 'Failed to update issue'}), 500
|
continue
|
||||||
|
|
||||||
return jsonify({'message': 'Ok'}), 200
|
return jsonify({'message': 'Ok'}), 200
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user