pipeline-sdlc/wwwroot/api/submit_bug.dspy

47 lines
2.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

user_id = await get_user()
if not user_id:
return json.dumps({'status': 'error', 'message': '未登录'}, ensure_ascii=False)
reporter_type = params_kw.get('reporter_type', '')
if not reporter_type:
reporter_type = 'agent' if params_kw.get('is_agent', '') else 'human'
data = {
'id': getID(),
'iteration_id': params_kw.get('iteration_id', ''),
'case_id': params_kw.get('case_id', ''),
'step_name': params_kw.get('step_name', ''),
'title': params_kw.get('title', ''),
'description': params_kw.get('description', ''),
'severity': params_kw.get('severity', 'medium'),
'priority': params_kw.get('priority', 'medium'),
'status': 'new',
'reporter_type': reporter_type,
'reporter_id': user_id,
'assignee_id': params_kw.get('assignee_id', ''),
'created_at': curDateString(),
}
try:
async with get_sor_context(request._run_ns, 'pipeline') as sor:
# 同机构校验:人类报告的 bug 须与项目同机构agent 报告跳过)
if reporter_type == 'human' and data.get('iteration_id'):
it = await sor.sqlExe(
"SELECT project_id FROM sd_iterations WHERE id=${iid}$",
{"iid": data['iteration_id']})
await sor.sqlExe("COMMIT", {})
pid = getattr(it[0], 'project_id', '') if it else ''
if pid:
p = await sor.sqlExe("SELECT org_id FROM sd_projects WHERE id=${pid}$", {"pid": pid})
await sor.sqlExe("COMMIT", {})
proj_org = getattr(p[0], 'org_id', '') if p else ''
u = await sor.sqlExe("SELECT orgid FROM users WHERE id=${u}$", {"u": user_id})
await sor.sqlExe("COMMIT", {})
user_org = getattr(u[0], 'orgid', '') if u else ''
if proj_org and user_org != proj_org:
return json.dumps({'status': 'error', 'message': '仅同机构用户可报告 Bug'}, ensure_ascii=False)
await sor.C('sd_bugs', data)
return json.dumps({'status': 'ok', 'id': data['id']}, ensure_ascii=False)
except Exception as e:
return json.dumps({'status': 'error', 'message': str(e)}, ensure_ascii=False)