fix(workspace): 工作空间树挂载项目关联仓库——apps/modules数据源增加sd_project_repos(按实际目录归类),根治元景项目无spec.json时看不到模块/应用仓库

This commit is contained in:
ymq 2026-09-01 14:14:53 +08:00
parent 8993a10106
commit 493732e062

View File

@ -345,16 +345,21 @@ async def get_project_dir_pl(sor, uid, session_id='', pipeline_id=''):
async def get_project_apps_modules(sor, uid, session_id=''): async def get_project_apps_modules(sor, uid, session_id=''):
"""读项目目录下 {应用名}_spec.json,返回 (apps, modules)。 """返回项目用到的 (apps, modules)。
apps = 各 spec.json 的 app 字段;modules = referenced_modules + generated_modules 去重。 数据源(并集去重):
1. 项目目录下各 *_spec.json 的 app / referenced_modules / generated_modules 字段
2. sd_project_repos 关联仓库——按仓库在机构空间的实际位置归类({space}/apps/ 或
{space}/modules/);两个目录都不存在则不挂载(仓库可能尚未克隆)。
(2026-09-01 修复:元景项目无 spec.json 但有 7 个关联仓库,工作空间树
因此看不到任何模块/应用仓库——仓库表是项目用哪些仓库的权威来源之一)
""" """
import json as _json import json as _json
project_dir, _ = await get_project_dir(sor, uid, session_id) project_dir, _ = await get_project_dir(sor, uid, session_id)
if not project_dir or not os.path.isdir(project_dir): space_dir, _ = await get_space_dir(sor, uid, session_id)
return [], []
apps = [] apps = []
modules = set() modules = set()
if project_dir and os.path.isdir(project_dir):
try: try:
for f in sorted(os.listdir(project_dir)): for f in sorted(os.listdir(project_dir)):
if not f.endswith('_spec.json'): if not f.endswith('_spec.json'):
@ -375,6 +380,24 @@ async def get_project_apps_modules(sor, uid, session_id=''):
modules.add(m.strip()) modules.add(m.strip())
except Exception: except Exception:
pass pass
# 关联仓库:按机构空间实际目录归类(仓库表是项目用哪些仓库的权威来源)
try:
pid = await get_session_project_id(sor, uid, session_id)
if pid and space_dir:
recs = await sor.sqlExe(
"SELECT repo_name FROM sd_project_repos WHERE project_id=${pid}$",
{"pid": pid})
await sor.sqlExe("COMMIT", {})
for r in (recs or []):
rn = (getattr(r, 'repo_name', '') or '').strip()
if not rn or '/' in rn:
continue
if os.path.isdir(os.path.join(space_dir, 'apps', rn)):
apps.append(rn)
elif os.path.isdir(os.path.join(space_dir, 'modules', rn)):
modules.add(rn)
except Exception:
pass
return sorted(set(apps)), sorted(modules) return sorted(set(apps)), sorted(modules)