Skip to content

Conversation

@ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Aug 15, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages when JSON decoding fails by ensuring the URL is properly formatted in exceptions and logs.
  • Refactor

    • Standardized repository initialization to use an explicit, string-based root directory parameter for consistency.
    • No user-facing behavior changes or workflow impacts are expected.

@coderabbitai
Copy link

coderabbitai bot commented Aug 15, 2025

Walkthrough

Updates to utils adjust type handling: stringify response.url in JSON decode errors and instantiate GitRepoManager with a root_directory keyword argument using a string. Repository API changes rename the GitRepoManager constructor parameter from directory to root_directory.

Changes

Cohort / File(s) Summary
Utils adjustments
infrahub_sdk/utils.py
decode_json now passes str(response.url) to JsonDecodeError; get_branch now constructs GitRepoManager(root_directory=str(directory)) instead of positional arg.
Repository API change
infrahub_sdk/repository.py
GitRepoManager.init signature updated from (directory: str) to (root_directory: str).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pog-correct-parameter-types

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 90802de
Status: ✅  Deploy successful!
Preview URL: https://653a41aa.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-correct-parameter-types.infrahub-sdk-python.pages.dev

View logs

@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/utils.py 50.00% 1 Missing ⚠️
@@             Coverage Diff             @@
##           develop     #499      +/-   ##
===========================================
- Coverage    76.25%   75.74%   -0.52%     
===========================================
  Files          100      100              
  Lines         9036     8846     -190     
  Branches      1732     1732              
===========================================
- Hits          6890     6700     -190     
  Misses        1670     1670              
  Partials       476      476              
Flag Coverage Δ
integration-tests 34.65% <0.00%> (-1.39%) ⬇️
python-3.10 48.19% <50.00%> (-1.12%) ⬇️
python-3.11 48.21% <50.00%> (-1.07%) ⬇️
python-3.12 48.19% <50.00%> (+0.02%) ⬆️
python-3.13 48.19% <50.00%> (-1.09%) ⬇️
python-3.9 46.86% <0.00%> (-1.14%) ⬇️
python-filler-3.12 25.09% <0.00%> (+0.52%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/utils.py 85.38% <50.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3269a41 and 90802de.

📒 Files selected for processing (1)
  • infrahub_sdk/utils.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
infrahub_sdk/utils.py (2)
infrahub_sdk/exceptions.py (1)
  • JsonDecodeError (13-20)
infrahub_sdk/repository.py (1)
  • GitRepoManager (9-33)
🔇 Additional comments (1)
infrahub_sdk/utils.py (1)

95-99: Good fix: ensure JsonDecodeError.url is a string as expected by the exception type

JsonDecodeError.url is annotated as str | None (see infrahub_sdk/exceptions.py), so passing str(response.url) is correct and avoids leaking an httpx.URL instance.

Comment on lines +235 to 236
repo = GitRepoManager(root_directory=str(directory))
return str(repo.active_branch)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Bug: returning "None" string when no active branch is present

repo.active_branch is annotated as str | None (see infrahub_sdk/repository.py). Casting it with str(...) will convert None to the literal string "None", which is misleading and violates the function’s contract to return the actual branch name. Handle the None case explicitly.

Apply this diff to avoid returning "None" and fail fast with a clear error:

-    repo = GitRepoManager(root_directory=str(directory))
-    return str(repo.active_branch)
+    repo = GitRepoManager(root_directory=str(directory))
+    active_branch = repo.active_branch
+    if active_branch is None:
+        raise ValueError(f"Could not determine active branch for repository at {directory!s}")
+    return active_branch

Run this to find other call sites that may still use the old GitRepoManager constructor or rely on get_branch returning a non-empty string:


🏁 Script executed:

#!/bin/bash
# Find GitRepoManager instantiations and check argument usage
rg -n -C2 '\bGitRepoManager\s*\('

# Look for any usage expecting get_branch() to never be empty/None
rg -n -C2 '\bget_branch\s*\('

Length of output: 5976


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- infrahub_sdk/utils.py (1-400) ----"
sed -n '1,400p' infrahub_sdk/utils.py || true

echo
echo "---- infrahub_sdk/repository.py (1-240) ----"
sed -n '1,240p' infrahub_sdk/repository.py || true

echo
echo "---- infrahub_sdk/operation.py (1-160) ----"
sed -n '1,160p' infrahub_sdk/operation.py || true

echo
echo "---- infrahub_sdk/checks.py (1-240) ----"
sed -n '1,240p' infrahub_sdk/checks.py || true

echo
echo "---- infrahub_sdk/node/node.py (1-140) ----"
sed -n '1,140p' infrahub_sdk/node/node.py || true

echo
echo "---- infrahub_sdk/store.py (1-320) ----"
sed -n '1,320p' infrahub_sdk/store.py || true

echo
echo "---- Grep for active_branch usages ----"
rg -n --hidden -S 'active_branch' || true

echo
echo "---- Grep for str(...active_branch...) usages ----"
rg -n --hidden -S "str\([^)]+active_branch[^\)]*\)" || true

Length of output: 39725


Fail fast on missing git active branch — avoid returning the literal "None"

Casting repo.active_branch with str(...) will convert None to the string "None". repository.active_branch is annotated as str | None (infrahub_sdk/repository.py), and I found three call sites that currently do this conversion — they must explicitly handle None and fail fast with a clear error.

Files to change:

  • infrahub_sdk/utils.py — get_branch (around lines 230–236)
  • infrahub_sdk/operation.py — branch_name property (around line 42)
  • infrahub_sdk/checks.py — branch_name property (around line 143)

Suggested diffs:

infrahub_sdk/utils.py

-    repo = GitRepoManager(root_directory=str(directory))
-    return str(repo.active_branch)
+    repo = GitRepoManager(root_directory=str(directory))
+    active_branch = repo.active_branch
+    if active_branch is None:
+        raise ValueError(f"Could not determine active branch for repository at {directory!s}")
+    return active_branch

infrahub_sdk/operation.py

-        if not hasattr(self, "git") or not self.git:
-            self.git = GitRepoManager(self.root_directory)
-
-        self.branch = str(self.git.active_branch)
+        if not hasattr(self, "git") or not self.git:
+            self.git = GitRepoManager(self.root_directory)
+
+        active_branch = self.git.active_branch
+        if active_branch is None:
+            raise ValueError(f"Could not determine active branch for repository at {self.root_directory!s}")
+        self.branch = active_branch

infrahub_sdk/checks.py

-        if not self.git:
-            self.git = GitRepoManager(self.root_directory)
-
-        self.branch = str(self.git.active_branch)
-        return self.branch
+        if not self.git:
+            self.git = GitRepoManager(self.root_directory)
+
+        active_branch = self.git.active_branch
+        if active_branch is None:
+            raise ValueError(f"Could not determine active branch for repository at {self.root_directory!s}")
+        self.branch = active_branch
+        return self.branch

Reasoning: explicit None checks avoid returning the misleading string "None" and produce a clear, early error when the active branch cannot be determined. After these changes, update any callers that expect get_branch()/branch_name to always succeed or handle the ValueError appropriately.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
repo = GitRepoManager(root_directory=str(directory))
return str(repo.active_branch)
repo = GitRepoManager(root_directory=str(directory))
active_branch = repo.active_branch
if active_branch is None:
raise ValueError(f"Could not determine active branch for repository at {directory!s}")
return active_branch
🤖 Prompt for AI Agents
infrahub_sdk/utils.py around lines 230–236, infrahub_sdk/operation.py around
line 42, and infrahub_sdk/checks.py around line 143: currently code casts
repository.active_branch to str which turns None into the literal "None";
instead, check if repo.active_branch is None and if so raise a clear ValueError
(e.g. "cannot determine active git branch") so callers fail fast, otherwise
return the branch string; update the three locations to perform this explicit
None check and raise the ValueError rather than returning str(None).

@ogenstad ogenstad requested a review from a team August 15, 2025 12:59
@ogenstad ogenstad merged commit 7905287 into develop Aug 15, 2025
20 checks passed
@ogenstad ogenstad deleted the pog-correct-parameter-types branch August 15, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants