032: T045 — git services async (run_blocking for all blocking ops)

_merge.py partially done. Tests still pending.
This commit is contained in:
2026-06-04 20:36:33 +03:00
parent 5ca1131ba3
commit 27bbf057ec
9 changed files with 70 additions and 64 deletions

View File

@@ -55,9 +55,9 @@ def _handle_unexpected_git_route_error(route_name: str, error: Exception) -> Non
# @BRIEF Resolve repository status for one dashboard with graceful NO_REPO semantics.
# @PRE `dashboard_id` is a valid integer.
# @POST Returns standard status payload or `NO_REPO` payload when repository path is absent.
def _resolve_repository_status(dashboard_id: int) -> dict:
async def _resolve_repository_status(dashboard_id: int) -> dict:
git_service = get_git_service()
repo_path = git_service._get_repo_path(dashboard_id)
repo_path = await git_service._get_repo_path(dashboard_id)
if not os.path.exists(repo_path):
logger.reason(
f"Repository is not initialized for dashboard {dashboard_id}",
@@ -310,7 +310,7 @@ def _resolve_current_user_git_identity(
# #region _apply_git_identity_from_profile [C:2] [TYPE Function]
# @BRIEF Apply user-scoped Git identity to repository-local config before write/pull operations.
def _apply_git_identity_from_profile(
async def _apply_git_identity_from_profile(
dashboard_id: int,
db: Session,
current_user: User | None,
@@ -320,11 +320,11 @@ def _apply_git_identity_from_profile(
return
git_service = get_git_service()
configure_identity = getattr(git_service, "configure_identity", None)
if not callable(configure_identity):
configure_identity_fn = getattr(git_service, "configure_identity", None)
if not callable(configure_identity_fn):
return
git_username, git_email = identity
configure_identity(dashboard_id, git_username, git_email)
await configure_identity_fn(dashboard_id, git_username, git_email)
# #endregion _apply_git_identity_from_profile
# #endregion GitHelpers

View File

@@ -118,7 +118,7 @@ async def promote_dashboard(
to_branch,
reason,
)
_apply_git_identity_from_profile(dashboard_id, db, current_user)
await _apply_git_identity_from_profile(dashboard_id, db, current_user)
result = _gs.promote_direct_merge(
dashboard_id=dashboard_id,
from_branch=from_branch,

View File

@@ -48,7 +48,7 @@ async def commit_changes(
dashboard_id = await _resolve_dashboard_id_from_ref(
dashboard_ref, config_manager, env_id
)
_apply_git_identity_from_profile(dashboard_id, db, current_user)
await _apply_git_identity_from_profile(dashboard_id, db, current_user)
_gs.commit_changes(
dashboard_id, commit_data.message, commit_data.files
)
@@ -138,7 +138,7 @@ async def pull_changes(
f"config_provider={config_provider} config_url={config_url}",
extra={"src": "pull_changes"},
)
_apply_git_identity_from_profile(dashboard_id, db, current_user)
await _apply_git_identity_from_profile(dashboard_id, db, current_user)
_gs.pull_changes(dashboard_id)
return {"status": "success"}
except HTTPException:
@@ -164,7 +164,7 @@ async def get_repository_status(
dashboard_id = await _resolve_dashboard_id_from_ref(
dashboard_ref, config_manager, env_id
)
return _resolve_repository_status(dashboard_id)
return await _resolve_repository_status(dashboard_id)
except HTTPException:
raise
except Exception as e:
@@ -191,7 +191,7 @@ async def get_repository_status_batch(
statuses = {}
for dashboard_id in dashboard_ids:
try:
statuses[str(dashboard_id)] = _resolve_repository_status(dashboard_id)
statuses[str(dashboard_id)] = await _resolve_repository_status(dashboard_id)
except HTTPException:
statuses[str(dashboard_id)] = {
**_build_no_repo_status_payload(),

View File

@@ -63,7 +63,7 @@ async def init_repository(
f"Initializing repo for dashboard {dashboard_id}",
extra={"src": "init_repository"},
)
_gs.init_repo(
await _gs.init_repo(
dashboard_id,
init_data.remote_url,
config.pat,
@@ -71,7 +71,7 @@ async def init_repository(
default_branch=config.default_branch,
)
repo_path = _gs._get_repo_path(dashboard_id, repo_key=repo_key)
repo_path = await _gs._get_repo_path(dashboard_id, repo_key=repo_key)
db_repo = (
db.query(GitRepository)
.filter(GitRepository.dashboard_id == dashboard_id)
@@ -166,7 +166,7 @@ async def delete_repository(
dashboard_id = await _resolve_dashboard_id_from_ref(
dashboard_ref, config_manager, env_id
)
_gs.delete_repo(dashboard_id)
await _gs.delete_repo(dashboard_id)
return {"status": "success"}
except HTTPException:
raise
@@ -220,7 +220,7 @@ async def create_branch(
dashboard_id = await _resolve_dashboard_id_from_ref(
dashboard_ref, config_manager, env_id
)
_apply_git_identity_from_profile(dashboard_id, db, current_user)
await _apply_git_identity_from_profile(dashboard_id, db, current_user)
_gs.create_branch(
dashboard_id, branch_data.name, branch_data.from_branch
)