Skip to content

fix: handle trailing slash in UrlRepoLoader.get_repo_name#36

Merged
agsaru merged 1 commit into
agsaru:mainfrom
deepmhatre13:investigate-temp-dir-deletion
Jul 11, 2026
Merged

fix: handle trailing slash in UrlRepoLoader.get_repo_name#36
agsaru merged 1 commit into
agsaru:mainfrom
deepmhatre13:investigate-temp-dir-deletion

Conversation

@deepmhatre13

@deepmhatre13 deepmhatre13 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

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:

self.clone_url.split("/")[-1]

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:

self.temp_dir = os.path.join(tempfile.gettempdir(), repo_name)

to the system temporary directory itself instead of a repository-specific subdirectory. The subsequent cleanup step then invokes:

shutil.rmtree(self.temp_dir, onerror=force_remove)

on that resolved path.

Changes

  • Strip trailing slashes before extracting the repository name using rstrip("/").
  • Preserve existing behavior for repository URLs without trailing slashes.
  • Add regression tests covering:
    • Standard repository URLs
    • .git repository URLs
    • Repository URLs ending with a trailing slash
    • .git URLs ending with a trailing slash
    • Multiple trailing slashes

Testing

Verified the fix with the following commands:

python -m pytest tests/test_loader.py -v
python -m pytest tests -v

Result:

24 passed

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

    • Improved repository name detection for URLs with trailing slashes, including .git/ variants and multiple trailing slashes.
  • Tests

    • Added coverage for extracting repository names from common GitHub-style URL formats.

Copilot AI review requested due to automatic review settings July 11, 2026 13:52
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@deepmhatre13, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f94ee027-7a5b-43ac-aee6-50d31bbc50ba

📥 Commits

Reviewing files that changed from the base of the PR and between 70fa4e7 and 35eb5f0.

📒 Files selected for processing (2)
  • repo2readme/loaders/loader.py
  • tests/test_loader.py
📝 Walkthrough

Walkthrough

UrlRepoLoader.get_repo_name now handles trailing slashes in repository URLs. New pytest cases verify plain URLs, .git suffixes, and single or multiple trailing slashes.

Changes

Repository name parsing

Layer / File(s) Summary
Parsing and validation
repo2readme/loaders/loader.py, tests/test_loader.py
Trailing slashes are removed before extracting the repository name, with tests covering multiple GitHub-style URL variants.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR does not address issue #34's requested docs/ folder creation or README update. Add the requested docs/ folder and user documentation, and update the README to satisfy issue #34.
Out of Scope Changes check ⚠️ Warning The loader fix and regression tests are unrelated to the linked docs/README request in issue #34. Move the loader bug fix and tests to a separate PR, or update the linked issue scope to include them.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making UrlRepoLoader.get_repo_name handle trailing slashes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
repo2readme/loaders/loader.py (1)

92-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider removesuffix instead of replace for .git stripping.

name.replace(".git", "") replaces all occurrences of .git anywhere in the name, not just the suffix. A repo named git-tools.git would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7cd3542 and 70fa4e7.

📒 Files selected for processing (2)
  • repo2readme/loaders/loader.py
  • tests/test_loader.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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, .git URLs, 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.

Comment thread repo2readme/loaders/loader.py Outdated
Comment on lines 91 to 93
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]

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@agsaru agsaru merged commit 52a783c into agsaru:main Jul 11, 2026
4 checks passed
@agsaru agsaru added the ECSoC26 label Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Trailing slash in repository URL resolves temporary clone path to the system temp directory

3 participants