pipeline-sdlc/wwwroot/api/cockpit_context.dspy

38 lines
1.3 KiB
Plaintext

# cockpit_context.dspy — 返回当前上下文(项目/迭代),供前端 context_bar 显示
import json
dbname = get_module_dbname('pipeline-sdlc')
async with DBPools().sqlorContext(dbname) as sor:
recs = await sor.sqlExe(
"SELECT current_project_id, current_iteration_id FROM pipeline_agent_settings WHERE user_id=${uid}$",
{"uid": uid})
pid = ''
iid = ''
if recs and len(recs) > 0:
pid = getattr(recs[0], 'current_project_id', '') or ''
iid = getattr(recs[0], 'current_iteration_id', '') or ''
# 拿到项目名和迭代名
pname = ''
iname = ''
ws_dir = ''
if pid:
precs = await sor.sqlExe(
"SELECT name, workspace_dir FROM sd_projects WHERE id=${pid}$", {"pid": pid})
if precs and len(precs) > 0:
pname = getattr(precs[0], 'name', '') or ''
ws_dir = getattr(precs[0], 'workspace_dir', '') or ''
if iid:
irecs = await sor.sqlExe(
"SELECT iteration_name FROM sd_iterations WHERE id=${iid}$", {"iid": iid})
if irecs and len(irecs) > 0:
iname = getattr(irecs[0], 'iteration_name', '') or ''
return json.dumps({
"project_name": pname,
"iteration_name": iname,
"project_id": pid,
"iteration_id": iid,
"workspace_dir": ws_dir,
}, ensure_ascii=False)