Skip to content

fix(git): support git@ SSH URLs with regression-safe repo detection (#317)#385

Merged
MaojiaSheng merged 1 commit intovolcengine:mainfrom
r266-tech:fix/git-ssh-url-317
Mar 2, 2026
Merged

fix(git): support git@ SSH URLs with regression-safe repo detection (#317)#385
MaojiaSheng merged 1 commit intovolcengine:mainfrom
r266-tech:fix/git-ssh-url-317

Conversation

@r266-tech
Copy link
Contributor

Description

Fix CLI's inability to recognize git@domain:repo.git format URLs (Issue #317).

This PR takes a different approach from #375 by introducing a strict is_git_repo_url() function that prevents the regression identified by @qin-ctx — HTTPS URLs like https://github.com/org/repo/issues/123 are correctly not routed to CodeRepositoryParser.

Related Issue

Fixes #317

Key Design Decisions

Regression-safe routing via is_git_repo_url()

  • git@, ssh://, git:// protocols → always treated as git repos (if domain matches)
  • https:// URLs → only treated as repos when path has exactly 2 segments (/owner/repo)
  • URLs with sub-paths like /issues/, /pull/, /blob/ are not routed to git clone

Addresses all review comments from PR #375

  1. Regression risk (media_processor routing): Fixed with is_git_repo_url() strict path check
  2. Error message command info lost (_run_git): Preserved with Command: git {args}. Details: {error}
  3. No tests: Added 20 comprehensive pytest tests
  4. SSH/HTTP path inconsistency: Both branches now take only first 2 path segments
  5. Unnecessary try/except: Removed, uses explicit return False

Changes Made

File Change
code_hosting_utils.py Added git@ support to parse_code_hosting_url, is_code_hosting_url; new validate_git_ssh_uri, is_git_repo_url
__init__.py Export new functions
media_processor.py Recognize git URLs in _is_url(); route to CodeRepositoryParser in _process_url()
resources.py CLI recognizes git@/ssh://git:// as URLs
code.py Handle git@ in parse(); enhanced error messages with command info
test_code_hosting_utils.py 20 tests covering all new functions

Testing

$ python3 -m pytest tests/test_code_hosting_utils.py -v
20 passed in 0.27s

Test coverage includes:

  • git@github.com:org/repo.git → correctly parsed as org/repo
  • git@unknown.com:org/repo.git → rejected (unknown domain)
  • git@github.com:repo → rejected (single segment)
  • https://github.com/org/repo → recognized as repo
  • https://github.com/org/repo/issues/123NOT a repo (regression test)
  • https://github.com/org/repo/pull/456NOT a repo (regression test)
  • https://github.com/org/repo/blob/main/file.pyNOT a repo (regression test)
  • Validation: empty path, missing colon, non-git URI → ValueError

…317)

- Add git@ SSH URL parsing to parse_code_hosting_url()
- Add git@ support to is_code_hosting_url() (clean, no try/except)
- Add validate_git_ssh_uri() for early format validation
- Add is_git_repo_url() for strict cloneable-repo detection:
  * git@/ssh://git:// protocols: always repo if domain matches
  * https URLs: require exactly /owner/repo path (2 segments)
  * Prevents regression: /issues/, /pull/, /blob/ etc. are NOT repos
- Update media_processor routing to use CodeRepositoryParser for git repos
- Update CLI resource handler to recognize git@ URLs
- Update CodeRepositoryParser.parse() to handle git@ directly
- Enhance _run_git() errors: keep command info, add friendly messages
- Add 20 comprehensive tests covering all new functions

Fixes #317
Addresses review comments from PR #375 (regression risk, test coverage,
error message preservation, SSH/HTTP path consistency)
@MaojiaSheng MaojiaSheng merged commit 6aa8e7d into volcengine:main Mar 2, 2026
4 of 5 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 2, 2026
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: cli 不能识别 git@domain:repo.git 格式的资源

3 participants