Skip to content

fix: make sidebar path detection work in both repos#875

Merged
petercrocker merged 1 commit intostablefrom
fix/sidebar-cross-repo-paths
Mar 19, 2026
Merged

fix: make sidebar path detection work in both repos#875
petercrocker merged 1 commit intostablefrom
fix/sidebar-cross-repo-paths

Conversation

@petercrocker
Copy link
Contributor

@petercrocker petercrocker commented Mar 18, 2026

Summary by CodeRabbit

  • Refactor
    • Improved documentation directory path resolution with centralized base directory detection, providing more flexible and reliable doc location handling across sidebar configurations.
  • Adds getDocsBaseDir() to sidebar-utils.ts that detects which repo the sidebar files are running in (infrahub-sdk-python vs infrahub-docs) by probing for the SDK-repo directory layout
  • Updates sidebars-python-sdk.ts and sidebars-infrahubctl.ts to use getDocsBaseDir() instead of hardcoded __dirname-relative paths

Problem

The sync workflow (sync-docs.yml) copies sidebar files from docs/sidebars/ in this repo to docs/ in infrahub-docs. This changes __dirname, breaking all hardcoded relative paths:

Repo __dirname Resolved path
infrahub-sdk-python docs/sidebars/ docs/sidebars/../docs/python-sdk = docs/docs/python-sdk
infrahub-docs docs/ docs/../docs/python-sdk = docs/python-sdk ✗ (content is at docs/docs-python-sdk/python-sdk)

Test plan

  • Verify Docusaurus builds successfully in this repo (docs/)
  • Verify the sync workflow runs cleanly and the Docusaurus build succeeds in infrahub-docs after merge

… 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.
@github-actions github-actions bot added the type/documentation Improvements or additions to documentation label Mar 18, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

Walkthrough

A new helper function getDocsBaseDir() was introduced in sidebar-utils.ts that detects the base docs directory by checking if a python-sdk path exists in an inferred sdk repo docs location, falling back to a docs-python-sdk path if not found. The sidebars-infrahubctl.ts and sidebars-python-sdk.ts files were updated to use this centralized helper function instead of __dirname-based path resolution for computing their respective docs directory paths.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making sidebar path detection work across both the infrahub-sdk-python and infrahub-docs repositories.
Description check ✅ Passed The description includes key sections (Summary, Problem, Test plan) and provides clear context about the issue and solution, though some optional template sections are not filled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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 readdirSync with 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

📥 Commits

Reviewing files that changed from the base of the PR and between ca47d40 and 1564076.

📒 Files selected for processing (3)
  • docs/sidebars/sidebar-utils.ts
  • docs/sidebars/sidebars-infrahubctl.ts
  • docs/sidebars/sidebars-python-sdk.ts

@petercrocker petercrocker merged commit 4305d22 into stable Mar 19, 2026
15 checks passed
@petercrocker petercrocker deleted the fix/sidebar-cross-repo-paths branch March 19, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants