Skip to content

fix: support custom port in SSH URL for private repo check#41822

Open
YoussefMansour9 wants to merge 2 commits into
appsmithorg:releasefrom
YoussefMansour9:fix/ssh-url-custom-port
Open

fix: support custom port in SSH URL for private repo check#41822
YoussefMansour9 wants to merge 2 commits into
appsmithorg:releasefrom
YoussefMansour9:fix/ssh-url-custom-port

Conversation

@YoussefMansour9
Copy link
Copy Markdown

@YoussefMansour9 YoussefMansour9 commented May 17, 2026

Description

The SSH URL pattern for private repo check did not accommodate custom ports. When connecting to a git repo on a custom port (e.g., git@host:2222/user/repo.git), the port was being included as part of the path, resulting in incorrect HTTPS URL like https://host/2222/user/repo instead of https://host:2222/user/repo.

Changes

  • Updated URL_PATTERN_WITHOUT_SCHEME regex to capture custom port number
  • Added fallback pattern for URLs without port (backward compatible)
  • Updated convertSshUrlToBrowserSupportedUrl() to include port in HTTPS URL when present

Testing

  • git@host:2222/user/repo.githttps://host:2222/user/repo.git (new - custom port)
  • git@host:user/repo.githttps://host/user/repo.git (existing - no port)

Fixes #32862

Summary by CodeRabbit

  • Bug Fixes
    • Improved Git SSH URL handling to support repositories that specify explicit SSH ports (e.g., user@host:port/path). Users can now open and navigate to browser links for repos hosted on non-standard ports without errors, improving compatibility with custom or enterprise Git server setups.

Review Change Stack

@YoussefMansour9 YoussefMansour9 requested a review from a team as a code owner May 17, 2026 08:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 01d78ea4-7398-4b42-b7bd-dc40e6468db1

📥 Commits

Reviewing files that changed from the base of the PR and between 329660b and 6929d4e.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java

Walkthrough

Extended the SSH URL regex to capture custom ports in SCP-like URLs (user@host:port/path) and updated the HTTPS conversion to include the captured port when present, falling back to the previous path capture when no port is matched.

Changes

SSH URL Pattern Extension

Layer / File(s) Summary
SSH URL pattern with custom port support
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java
URL_PATTERN_WITHOUT_SCHEME regex adds an alternate that captures port for SCP-like SSH URLs; convertSshUrlToBrowserSupportedUrl uses the port capture to include :<port> in the generated https:// URL when present, otherwise falls back to the original path capture (pathOnly).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

Ports and paths fall into line,
SSH strings now parse just fine.
A colon, number, then a slash —
Browser links rebuilt in a rush.
🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding support for custom ports in SSH URLs for the private repo check.
Description check ✅ Passed The description covers the problem, changes made, testing examples, and links to issue #32862, though it lacks the structured template format with automation sections.
Linked Issues check ✅ Passed The PR successfully addresses issue #32862 by updating the SSH URL regex pattern to capture custom ports and modifying the URL conversion logic accordingly.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the SSH URL port handling in GitUtils.java, directly addressing the linked issue with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ 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 and usage tips.

Copy link
Copy Markdown
Contributor

@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: 2

🤖 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.

Inline comments:
In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java`:
- Around line 75-77: The httpsUrl construction in GitUtils.java currently
appends ":" + port whenever port != null, but port can be an empty string
(pattern uses \\d*), producing "https://host:/..."; update the conditional used
when building httpsUrl (the expression assigning httpsUrl) to treat an empty
port as absent by checking that port is not null AND not empty (or matches
"\\d+"), and only append ":" + port when that check passes; keep the existing
use of match.group("host") and path unchanged.
- Line 43: The regex in the Pattern.compile call inside GitUtils declares the
named group "host" in both alternation branches which causes
PatternSyntaxException on class load; fix it by rewriting the pattern so "host"
is defined only once (e.g., pull the host subpattern out of the alternation or
convert one or both occurrences to non-named groups and then reference by group
index), update any code that reads the group to use the single "host" name or
the appropriate group index, and re-run tests to ensure other named groups like
"path" / "pathOnly" still resolve correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0c19ede1-ebcf-4042-b4ef-663f089c135e

📥 Commits

Reviewing files that changed from the base of the PR and between 6c8fab7 and d2a130c.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java

@YoussefMansour9 YoussefMansour9 force-pushed the fix/ssh-url-custom-port branch from d2a130c to f6e0961 Compare May 17, 2026 08:27
Copy link
Copy Markdown
Contributor

@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

🤖 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.

Inline comments:
In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java`:
- Line 43: The current regex in GitUtils that builds the Pattern.compile(...)
treats a numeric first path segment as a port; update the parsing to
disambiguate numeric-first segments by either (A) swapping the alternation in
the Pattern.compile(...) so the path-only branch is attempted before the port
branch, or (B) implement a dual-attempt conversion inside GitUtils that first
tries parsing with port capture and, if the result yields an unlikely port/path
interpretation, falls back to treating the numeric segment as part of the path;
then add regression tests covering both forms like "git@host:1234/repo.git" (as
path) and "git@host:1234/actual/repo.git" (as host+port) to ensure both
interpretations behave as expected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ba0ed825-183c-425a-b456-9bb4af0bf343

📥 Commits

Reviewing files that changed from the base of the PR and between d2a130c and f6e0961.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java

- Updated URL_PATTERN_WITHOUT_SCHEME to capture custom port number
- Fixed duplicate named group 'host' by using non-capturing group alternation
- Added empty port check to prevent malformed URLs like https://host:/...
- Updated convertSshUrlToBrowserSupportedUrl to include port in HTTPS URL when present
- Added documentation for known limitation with numeric path segments

Fixes appsmithorg#32862
@YoussefMansour9 YoussefMansour9 force-pushed the fix/ssh-url-custom-port branch from f6e0961 to 329660b Compare May 17, 2026 08:39
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.

[Bug]: SSH URL pattern for private repo check does not accommodate custom port in the check

1 participant