fix: handle trailing slash in UrlRepoLoader.get_repo_name#36
Conversation
|
Warning Review limit reached
Next review available in: 45 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesRepository name parsing
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
repo2readme/loaders/loader.py (1)
92-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider
removesuffixinstead ofreplacefor.gitstripping.
name.replace(".git", "")replaces all occurrences of.gitanywhere in the name, not just the suffix. A repo namedgit-tools.gitwould incorrectly become-tools. If the project targets Python 3.9+,str.removesuffix(".git")is a safer, more precise alternative. This is pre-existing behavior, not introduced by this PR, so it's an optional improvement.♻️ Optional refactor
name = self.clone_url.rstrip("/").split("/")[-1] - return name.replace(".git", "") + return name.removesuffix(".git")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@repo2readme/loaders/loader.py` around lines 92 - 93, Update the repository name extraction in the surrounding loader method to remove ".git" only when it is the trailing suffix, using str.removesuffix(".git") for Python 3.9+ rather than replacing every occurrence. Preserve names containing ".git" elsewhere unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@repo2readme/loaders/loader.py`:
- Around line 92-93: Update the repository name extraction in the surrounding
loader method to remove ".git" only when it is the trailing suffix, using
str.removesuffix(".git") for Python 3.9+ rather than replacing every occurrence.
Preserve names containing ".git" elsewhere unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 818fb201-b5fe-42d5-a705-2530d7682052
📒 Files selected for processing (2)
repo2readme/loaders/loader.pytests/test_loader.py
There was a problem hiding this comment.
Pull request overview
This PR updates UrlRepoLoader.get_repo_name() to correctly extract repository names from GitHub clone URLs that end with one or more trailing slashes, and adds regression tests to prevent the issue from recurring.
Changes:
- Strip trailing
/characters before splitting the URL to extract the repo name. - Add unit tests covering plain URLs,
.gitURLs, and trailing-slash variants.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| repo2readme/loaders/loader.py | Adjusts repo-name extraction to handle trailing slashes. |
| tests/test_loader.py | Adds regression tests for repo-name parsing across URL variants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def get_repo_name(self): | ||
| name = self.clone_url.split("/")[-1] | ||
| name = self.clone_url.rstrip("/").split("/")[-1] | ||
| return name.replace(".git", "") |
|
|
||
| def get_repo_name(self): | ||
| name = self.clone_url.split("/")[-1] | ||
| name = self.clone_url.rstrip("/").split("/")[-1] |
70fa4e7 to
35eb5f0
Compare
Fixes #35
Summary
This PR fixes an issue where
UrlRepoLoader.get_repo_name()returned an empty string for repository URLs ending with a trailing slash.Root Cause
get_repo_name()extracted the repository name using:For URLs ending with a trailing slash (for example,
https://github.com/user/repo/),split("/")[-1]returns an empty string.As a result,
load()resolves:to the system temporary directory itself instead of a repository-specific subdirectory. The subsequent cleanup step then invokes:
on that resolved path.
Changes
rstrip("/")..gitrepository URLs.gitURLs ending with a trailing slashTesting
Verified the fix with the following commands:
Result:
Impact
This change ensures that repository URLs ending with one or more trailing slashes are handled correctly while preserving existing behavior for all previously supported URL formats. The added regression tests help prevent this issue from recurring in future changes.
Summary by CodeRabbit
Bug Fixes
.git/variants and multiple trailing slashes.Tests