Skip to content

🐛 Fix GitHub repo tree to show file contents instead of empty#4063

Merged
clubanderson merged 1 commit intomainfrom
fix/github-repo-tree-contents
Apr 1, 2026
Merged

🐛 Fix GitHub repo tree to show file contents instead of empty#4063
clubanderson merged 1 commit intomainfrom
fix/github-repo-tree-contents

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

Summary

Root cause fix for "Empty" showing when expanding watched GitHub repos in the Mission Explorer.

toggleNode for github source nodes was always calling /api/github/repos?hasMissionsDir=true — this lists the user's repos, which is correct for the root "My Repositories" node but wrong for a child repo like sample-runbooks. Now distinguishes by node ID:

  • Root (id=github): lists user repos
  • Child repo: calls /api/github/repos/{owner}/{repo}/contents via the GitHub Contents API proxy, filtered to mission file extensions

Test plan

  • Add clubanderson/sample-runbooks → expand → should show 9 files (YAML + MD)
  • Files should appear as tree children, not "Empty"

toggleNode for github source nodes was always calling
/api/github/repos?hasMissionsDir=true regardless of whether the node
is the root "My Repositories" or a child repo. Now distinguishes:
- Root node (id=github): lists user's repos
- Child repo node: lists repo contents via GitHub Contents API

This was the root cause of "Empty" for watched GitHub repos.

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Copilot AI review requested due to automatic review settings April 1, 2026 02:08
@clubanderson clubanderson merged commit 41e64df into main Apr 1, 2026
@kubestellar-prow kubestellar-prow bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Apr 1, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow bot deleted the fix/github-repo-tree-contents branch April 1, 2026 02:08
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 1, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit 7f71380
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69cc7e311a2f2f0008e6504e
😎 Deploy Preview https://deploy-preview-4063.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the Mission Explorer GitHub repo tree expansion so watched repository nodes fetch and display repository contents (mission-relevant files/directories) instead of listing repos again and showing “Empty”.

Changes:

  • Updated toggleNode to distinguish the GitHub root node (id=github) from child repo nodes.
  • For child repo nodes, fetches repo contents via the GitHub Contents API proxy and filters to mission file extensions + directories.

Comment on lines +612 to +614
const repoPath = node.path
const { data: ghEntries } = await api.get<Array<{ name: string; path: string; type: string; size?: number }>>(
`/api/github/repos/${repoPath}/contents`
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repoPath is taken from node.path and interpolated into /api/github/repos/${repoPath}/contents. Once a repo has been expanded, directory nodes will have node.path like owner/repo/someDir, which produces a proxy call to /repos/owner/repo/someDir/contents (not a valid GitHub Contents API route). Parse node.path into owner, repo, and an optional subPath, and call the Contents endpoint as /api/github/repos/${owner}/${repo}/contents/${subPath} (root should use an empty subPath with a trailing slash). Also consider applying the same fix to the similar GitHub directory listing code in selectNode.

Suggested change
const repoPath = node.path
const { data: ghEntries } = await api.get<Array<{ name: string; path: string; type: string; size?: number }>>(
`/api/github/repos/${repoPath}/contents`
const pathParts = node.path.split('/')
const [owner, repo, ...subPathParts] = pathParts
const subPath = subPathParts.join('/')
const repoPath = `${owner}/${repo}`
const contentsUrl = subPath
? `/api/github/repos/${owner}/${repo}/contents/${subPath}`
: `/api/github/repos/${owner}/${repo}/contents/`
const { data: ghEntries } = await api.get<Array<{ name: string; path: string; type: string; size?: number }>>(
contentsUrl

Copilot uses AI. Check for mistakes.
if (nodeId === 'github') {
// Root "My Repositories" — list user's repos
const { data: repos } = await api.get<Array<{ name: string; full_name: string }>>(
'/api/github/repos?hasMissionsDir=true'
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root branch uses /api/github/repos?hasMissionsDir=true, but the backend GitHub proxy only allows /repos/, /rate_limit, /user, and /notifications (see pkg/api/handlers/github_proxy.go), so /api/github/repos (no trailing slash / no owner+repo) will be rejected with 403. Also, the root github node is initialized with loaded: true, so this fetch path is currently unreachable. Either remove this branch, or change the root node loading strategy and use a valid GitHub API endpoint (e.g. /api/github/user/repos) with client-side filtering.

Suggested change
'/api/github/repos?hasMissionsDir=true'
'/api/github/user/repos?hasMissionsDir=true'

Copilot uses AI. Check for mistakes.
Comment on lines +616 to +626
children = (ghEntries || [])
.filter(e => e.type === 'dir' || isMissionFile(e.name))
.map(e => ({
id: `${nodeId}/${e.name}`,
name: e.name,
path: `${repoPath.split('/').slice(0, 2).join('/')}/${e.path}`,
type: (e.type === 'dir' ? 'directory' : 'file') as TreeNode['type'],
source: 'github' as const,
loaded: e.type !== 'dir',
description: e.size ? `${e.size} bytes` : undefined,
}))
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MissionBrowser has unit tests, but the new GitHub tree expansion behavior isn’t covered. Add a test that triggers toggleNode on a watched GitHub repo node, verifies the correct contents API URL is requested, and asserts children are filtered to directories + isMissionFile matches (and that non-mission files are excluded).

Copilot uses AI. Check for mistakes.
@clubanderson
Copy link
Copy Markdown
Collaborator Author

🔄 Auto-Applying Copilot Code Review

Copilot code review found 2 code suggestion(s) and 1 general comment(s).

@copilot Please apply all of the following code review suggestions:

  • web/src/components/missions/MissionBrowser.tsx (line 614): const pathParts = node.path.split('/') const [owner, repo, ...subPat...
  • web/src/components/missions/MissionBrowser.tsx (line 599): '/api/github/user/repos?hasMissionsDir=true'

Also address these general comments:

  • web/src/components/missions/MissionBrowser.tsx (line 626): MissionBrowser has unit tests, but the new GitHub tree expansion behavior isn’t covered. Add a test that triggers `toggl

Push all fixes in a single commit. Run cd web && npm run build && npm run lint before committing.


Auto-generated by copilot-review-apply workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants