fix: make sidebar path detection work in both repos#875
Conversation
… infrahub-docs The sync workflow copies sidebar files from docs/sidebars/ (source) to docs/ (target), changing __dirname and breaking all hardcoded relative paths to doc content directories. Add getDocsBaseDir() to sidebar-utils.ts which probes for the SDK-repo directory layout and returns the correct base path regardless of which repo the file is executing in. Both sidebar files now use getDocsBaseDir() instead of hardcoded __dirname-relative paths.
WalkthroughA new helper function 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can generate a title for your PR based on the changes.Add |
Deploying infrahub-sdk-python with
|
| Latest commit: |
1564076
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3d23b1ba.infrahub-sdk-python.pages.dev |
| Branch Preview URL: | https://fix-sidebar-cross-repo-paths.infrahub-sdk-python.pages.dev |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/sidebars/sidebar-utils.ts (1)
18-19: Consider explicit validation when neither layout matches.If neither repo layout exists, the current fallback can defer failure to a later
readdirSyncwith a less clear error. Returning an explicit error here would make misconfigured builds easier to diagnose.Proposed refactor
export function getDocsBaseDir(): string { const sdkRepoDocsDir = join(__dirname, '..', 'docs'); if (existsSync(join(sdkRepoDocsDir, 'python-sdk'))) { return sdkRepoDocsDir; } - return join(__dirname, 'docs-python-sdk'); + const docsRepoDocsDir = join(__dirname, 'docs-python-sdk'); + if (existsSync(join(docsRepoDocsDir, 'python-sdk'))) { + return docsRepoDocsDir; + } + + throw new Error( + `Unable to resolve docs base directory. Checked: ${sdkRepoDocsDir} and ${docsRepoDocsDir}`, + ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/sidebars/sidebar-utils.ts` around lines 18 - 19, The function currently falls back to returning join(__dirname, 'docs-python-sdk') without validating that either expected repo layout exists, which delays a clear failure until a later readdirSync; update the logic around the return of join(__dirname, 'docs-python-sdk') to explicitly check for the presence of the expected layout directories (the two repo layouts your earlier checks look for) and, if neither exists, throw a descriptive Error (e.g., "No docs layout found: expected X or Y") so builds fail fast and show a clear message rather than producing a later readdirSync error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/sidebars/sidebar-utils.ts`:
- Around line 18-19: The function currently falls back to returning
join(__dirname, 'docs-python-sdk') without validating that either expected repo
layout exists, which delays a clear failure until a later readdirSync; update
the logic around the return of join(__dirname, 'docs-python-sdk') to explicitly
check for the presence of the expected layout directories (the two repo layouts
your earlier checks look for) and, if neither exists, throw a descriptive Error
(e.g., "No docs layout found: expected X or Y") so builds fail fast and show a
clear message rather than producing a later readdirSync error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4eddeb6c-3a4f-441f-8a89-48affff7f746
📒 Files selected for processing (3)
docs/sidebars/sidebar-utils.tsdocs/sidebars/sidebars-infrahubctl.tsdocs/sidebars/sidebars-python-sdk.ts
Summary by CodeRabbit
getDocsBaseDir()tosidebar-utils.tsthat detects which repo the sidebar files are running in (infrahub-sdk-python vs infrahub-docs) by probing for the SDK-repo directory layoutsidebars-python-sdk.tsandsidebars-infrahubctl.tsto usegetDocsBaseDir()instead of hardcoded__dirname-relative pathsProblem
The sync workflow (sync-docs.yml) copies sidebar files from
docs/sidebars/in this repo todocs/ininfrahub-docs. This changes__dirname, breaking all hardcoded relative paths:__dirnamedocs/sidebars/docs/sidebars/../docs/python-sdk=docs/docs/python-sdk✓docs/docs/../docs/python-sdk=docs/python-sdk✗ (content is atdocs/docs-python-sdk/python-sdk)Test plan
docs/)