Skip to content

Commit dcd81cc

Browse files
committed
update for type safety, from PR review
Signed-off-by: sallyom <[email protected]>
1 parent 9c7d528 commit dcd81cc

File tree

2 files changed

+30
-8
lines changed
  • components
    • backend/handlers
    • frontend/src/app/api/projects/[name]/agentic-sessions/[sessionName]/repos/status

2 files changed

+30
-8
lines changed

components/backend/handlers/sessions.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,27 +1471,42 @@ func RemoveRepo(c *gin.Context) {
14711471
}
14721472

14731473
// Also check status.reconciledRepos for repos added directly to runner
1474-
status, _ := item.Object["status"].(map[string]interface{})
1475-
reconciledRepos, _ := status["reconciledRepos"].([]interface{})
1474+
status, found, err := unstructured.NestedMap(item.Object, "status")
1475+
if !found || err != nil {
1476+
log.Printf("Failed to get status: %v", err)
1477+
status = make(map[string]interface{})
1478+
}
1479+
1480+
reconciledRepos, found, err := unstructured.NestedSlice(status, "reconciledRepos")
1481+
if !found || err != nil {
1482+
log.Printf("Failed to get reconciledRepos: %v", err)
1483+
reconciledRepos = []interface{}{}
1484+
}
1485+
14761486
foundInReconciled := false
14771487
for _, r := range reconciledRepos {
1478-
rm, _ := r.(map[string]interface{})
1479-
name, _ := rm["name"].(string)
1480-
if name == repoName {
1488+
rm, ok := r.(map[string]interface{})
1489+
if !ok {
1490+
continue
1491+
}
1492+
1493+
name, found, err := unstructured.NestedString(rm, "name")
1494+
if found && err == nil && name == repoName {
14811495
foundInReconciled = true
14821496
break
14831497
}
1498+
14841499
// Also try matching by URL
1485-
url, _ := rm["url"].(string)
1486-
if DeriveRepoFolderFromURL(url) == repoName {
1500+
url, found, err := unstructured.NestedString(rm, "url")
1501+
if found && err == nil && DeriveRepoFolderFromURL(url) == repoName {
14871502
foundInReconciled = true
14881503
break
14891504
}
14901505
}
14911506

14921507
// Always call runner to remove from filesystem (if session is running)
14931508
// Do this BEFORE checking if repo exists in CR, because it might only be on filesystem
1494-
phase, _ := status["phase"].(string)
1509+
phase, _, _ := unstructured.NestedString(status, "phase")
14951510
runnerRemoved := false
14961511
if phase == "Running" {
14971512
runnerURL := fmt.Sprintf("http://session-%s.%s.svc.cluster.local:8001/repos/remove", sessionName, project)

components/frontend/src/app/api/projects/[name]/agentic-sessions/[sessionName]/repos/status/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export async function GET(
1616
}
1717
);
1818

19+
if (!resp.ok) {
20+
return new Response(
21+
JSON.stringify({ error: 'Failed to fetch repos status', repos: [] }),
22+
{ status: 200, headers: { 'Content-Type': 'application/json' } }
23+
);
24+
}
25+
1926
const data = await resp.text();
2027
return new Response(data, {
2128
status: resp.status,

0 commit comments

Comments
 (0)