Расширил registry настройками проекта
Этот коммит содержится в:
@@ -16,16 +16,60 @@ def load_projects():
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def save_project(project: dict):
|
def save_projects(projects: list[dict]) -> list[dict]:
|
||||||
projects = load_projects()
|
|
||||||
|
|
||||||
existing = [p for p in projects if p.get('repo_url') != project.get('repo_url')]
|
|
||||||
existing.append(project)
|
|
||||||
|
|
||||||
REGISTRY_FILE.parent.mkdir(parents=True, exist_ok=True)
|
REGISTRY_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||||
REGISTRY_FILE.write_text(
|
REGISTRY_FILE.write_text(
|
||||||
json.dumps(existing, ensure_ascii=False, indent=2),
|
json.dumps(projects, ensure_ascii=False, indent=2),
|
||||||
encoding='utf-8'
|
encoding='utf-8'
|
||||||
)
|
)
|
||||||
|
return projects
|
||||||
|
|
||||||
return existing
|
|
||||||
|
def save_project(project: dict):
|
||||||
|
projects = load_projects()
|
||||||
|
existing_project = None
|
||||||
|
|
||||||
|
for item in projects:
|
||||||
|
if item.get('repo_url') == project.get('repo_url') or item.get('workspace') == project.get('workspace'):
|
||||||
|
existing_project = item
|
||||||
|
break
|
||||||
|
|
||||||
|
if existing_project:
|
||||||
|
merged = {**existing_project, **project}
|
||||||
|
projects = [merged if p is existing_project else p for p in projects]
|
||||||
|
else:
|
||||||
|
projects.append(project)
|
||||||
|
|
||||||
|
return save_projects(projects)
|
||||||
|
|
||||||
|
|
||||||
|
def find_project_by_workspace(workspace: str) -> dict | None:
|
||||||
|
for project in load_projects():
|
||||||
|
if project.get('workspace') == workspace:
|
||||||
|
return project
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def find_project_by_repo(repo_url: str) -> dict | None:
|
||||||
|
for project in load_projects():
|
||||||
|
if project.get('repo_url') == repo_url:
|
||||||
|
return project
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def update_project_settings(workspace: str, settings: dict) -> dict | None:
|
||||||
|
projects = load_projects()
|
||||||
|
updated = None
|
||||||
|
|
||||||
|
for index, project in enumerate(projects):
|
||||||
|
if project.get('workspace') == workspace:
|
||||||
|
merged = {**project, **settings}
|
||||||
|
projects[index] = merged
|
||||||
|
updated = merged
|
||||||
|
break
|
||||||
|
|
||||||
|
if updated is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
save_projects(projects)
|
||||||
|
return updated
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user