git list refactor
This commit is contained in:
@@ -302,12 +302,62 @@ class GitService:
|
||||
except (ValueError, Exception):
|
||||
has_commits = False
|
||||
|
||||
current_branch = repo.active_branch.name
|
||||
tracking_branch = None
|
||||
has_upstream = False
|
||||
ahead_count = 0
|
||||
behind_count = 0
|
||||
|
||||
try:
|
||||
tracking_branch = repo.active_branch.tracking_branch()
|
||||
has_upstream = tracking_branch is not None
|
||||
except Exception:
|
||||
tracking_branch = None
|
||||
has_upstream = False
|
||||
|
||||
if has_upstream and tracking_branch is not None:
|
||||
try:
|
||||
# Commits present locally but not in upstream.
|
||||
ahead_count = sum(
|
||||
1 for _ in repo.iter_commits(f"{tracking_branch.name}..{current_branch}")
|
||||
)
|
||||
# Commits present in upstream but not local.
|
||||
behind_count = sum(
|
||||
1 for _ in repo.iter_commits(f"{current_branch}..{tracking_branch.name}")
|
||||
)
|
||||
except Exception:
|
||||
ahead_count = 0
|
||||
behind_count = 0
|
||||
|
||||
is_dirty = repo.is_dirty(untracked_files=True)
|
||||
untracked_files = repo.untracked_files
|
||||
modified_files = [item.a_path for item in repo.index.diff(None)]
|
||||
staged_files = [item.a_path for item in repo.index.diff("HEAD")] if has_commits else []
|
||||
is_diverged = ahead_count > 0 and behind_count > 0
|
||||
|
||||
if is_diverged:
|
||||
sync_state = "DIVERGED"
|
||||
elif behind_count > 0:
|
||||
sync_state = "BEHIND_REMOTE"
|
||||
elif ahead_count > 0:
|
||||
sync_state = "AHEAD_REMOTE"
|
||||
elif is_dirty or modified_files or staged_files or untracked_files:
|
||||
sync_state = "CHANGES"
|
||||
else:
|
||||
sync_state = "SYNCED"
|
||||
|
||||
return {
|
||||
"is_dirty": repo.is_dirty(untracked_files=True),
|
||||
"untracked_files": repo.untracked_files,
|
||||
"modified_files": [item.a_path for item in repo.index.diff(None)],
|
||||
"staged_files": [item.a_path for item in repo.index.diff("HEAD")] if has_commits else [],
|
||||
"current_branch": repo.active_branch.name
|
||||
"is_dirty": is_dirty,
|
||||
"untracked_files": untracked_files,
|
||||
"modified_files": modified_files,
|
||||
"staged_files": staged_files,
|
||||
"current_branch": current_branch,
|
||||
"upstream_branch": tracking_branch.name if tracking_branch is not None else None,
|
||||
"has_upstream": has_upstream,
|
||||
"ahead_count": ahead_count,
|
||||
"behind_count": behind_count,
|
||||
"is_diverged": is_diverged,
|
||||
"sync_state": sync_state,
|
||||
}
|
||||
# [/DEF:get_status:Function]
|
||||
|
||||
@@ -411,4 +461,4 @@ class GitService:
|
||||
# [/DEF:test_connection:Function]
|
||||
|
||||
# [/DEF:GitService:Class]
|
||||
# [/DEF:backend.src.services.git_service:Module]
|
||||
# [/DEF:backend.src.services.git_service:Module]
|
||||
|
||||
@@ -79,6 +79,67 @@ class ResourceService:
|
||||
return result
|
||||
# [/DEF:get_dashboards_with_status:Function]
|
||||
|
||||
# [DEF:get_dashboards_page_with_status:Function]
|
||||
# @PURPOSE: Fetch one dashboard page from environment and enrich only that page with status metadata.
|
||||
# @PRE: env is valid; page >= 1; page_size > 0.
|
||||
# @POST: Returns page items plus total counters without scanning all pages locally.
|
||||
# @PARAM: env (Environment) - Source environment.
|
||||
# @PARAM: tasks (Optional[List[Task]]) - Tasks for latest LLM status.
|
||||
# @PARAM: page (int) - 1-based page number.
|
||||
# @PARAM: page_size (int) - Page size.
|
||||
# @RETURN: Dict[str, Any] - {"dashboards": List[Dict], "total": int, "total_pages": int}
|
||||
async def get_dashboards_page_with_status(
|
||||
self,
|
||||
env: Any,
|
||||
tasks: Optional[List[Task]] = None,
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
search: Optional[str] = None,
|
||||
include_git_status: bool = True,
|
||||
) -> Dict[str, Any]:
|
||||
with belief_scope(
|
||||
"get_dashboards_page_with_status",
|
||||
f"env={env.id}, page={page}, page_size={page_size}, search={search}",
|
||||
):
|
||||
client = SupersetClient(env)
|
||||
total, dashboards_page = client.get_dashboards_summary_page(
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
search=search,
|
||||
)
|
||||
|
||||
result = []
|
||||
for dashboard in dashboards_page:
|
||||
dashboard_dict = dashboard
|
||||
dashboard_id = dashboard_dict.get("id")
|
||||
|
||||
if include_git_status:
|
||||
dashboard_dict["git_status"] = self._get_git_status_for_dashboard(dashboard_id)
|
||||
else:
|
||||
dashboard_dict["git_status"] = None
|
||||
|
||||
dashboard_dict["last_task"] = self._get_last_llm_task_for_dashboard(
|
||||
dashboard_id,
|
||||
env.id,
|
||||
tasks,
|
||||
)
|
||||
result.append(dashboard_dict)
|
||||
|
||||
total_pages = (total + page_size - 1) // page_size if total > 0 else 1
|
||||
logger.info(
|
||||
"[ResourceService][Coherence:OK] Fetched dashboards page %s/%s (%s items, total=%s)",
|
||||
page,
|
||||
total_pages,
|
||||
len(result),
|
||||
total,
|
||||
)
|
||||
return {
|
||||
"dashboards": result,
|
||||
"total": total,
|
||||
"total_pages": total_pages,
|
||||
}
|
||||
# [/DEF:get_dashboards_page_with_status:Function]
|
||||
|
||||
# [DEF:_get_last_llm_task_for_dashboard:Function]
|
||||
# @PURPOSE: Get most recent LLM validation task for a dashboard in an environment
|
||||
# @PRE: dashboard_id is a valid integer identifier
|
||||
|
||||
Reference in New Issue
Block a user