Skip to content

Commit 85fb84a

Browse files
Merge pull request #1205 from vadi2/claude/investigate-fhir-issue-1204-01BMNm1rEKZXAeLPD6yD3Ghv
Fix support for SSH-style Git URLs (fixes #1204)
2 parents 9c3eb94 + 580084d commit 85fb84a

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/GitUtilities.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,20 @@ public static String getGitSource(File gitDir) {
7171
* <p/>
7272
* This will also send log info to console that reports user information removal, as well as a malformed URL
7373
* resulting in a null return.
74+
* <p/>
75+
* SSH-style Git URLs (e.g., git@github.com:org/repo.git) are supported and returned as-is since they
76+
* don't contain embedded credentials.
7477
*
7578
* @param url The URL
7679
* @param urlSource A string representing the source of the URL to be output (CLI param, git remote, etc.)
7780
* @return A valid URL that does not contain user information or null if the url param was malformed.
7881
*/
7982
protected static String getURLWithNoUserInfo(final String url, final String urlSource) {
83+
// Handle SSH-style Git URLs (e.g., git@github.com:org/repo.git)
84+
// These don't contain embedded passwords (they use SSH keys) so are safe to return as-is
85+
if (url != null && url.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+:.*$")) {
86+
return url;
87+
}
8088
try {
8189
URL newUrl = URI.create(url).toURL();
8290
if (newUrl.getUserInfo() != null) {

org.hl7.fhir.publisher.core/src/test/java/org/hl7/fhir/igtools/publisher/GitUtilitiesTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class GitUtilitiesTests {
2525

2626
public static final String VALID_URL = "https://github.com/FHIR/fhir-core-examples.git";
2727
public static final String USERNAME_AND_TOKEN_URL = "https://username:token@github.com/FHIR/fhir-core-examples.git";
28+
public static final String SSH_URL = "git@github.com:FHIR/fhir-core-examples.git";
2829
public static final String NORMAL_BRANCH = "normal-branch";
2930
public static final String WORKTREE_BRANCH = "branch-a";
3031

@@ -98,7 +99,8 @@ public void testGitStatusWhenNotGitDirectory() throws IOException {
9899
@CsvSource(value= {
99100
VALID_URL+","+VALID_URL,
100101
"whwehwhasdlksdjsdf,''",
101-
USERNAME_AND_TOKEN_URL+","+ VALID_URL})
102+
USERNAME_AND_TOKEN_URL+","+ VALID_URL,
103+
SSH_URL+","+SSH_URL})
102104
void testGetGitSource(String url, String expected) throws IOException, InterruptedException {
103105
File gitRoot = initiateGitDirectory();
104106
createOriginURL(gitRoot, url);
@@ -110,7 +112,9 @@ void testGetGitSource(String url, String expected) throws IOException, Interrupt
110112
@CsvSource(value= {
111113
VALID_URL+","+VALID_URL,
112114
"whwehwhasdlksdjsdf,NULL",
113-
USERNAME_AND_TOKEN_URL+","+VALID_URL}, nullValues={"NULL"})
115+
USERNAME_AND_TOKEN_URL+","+VALID_URL,
116+
SSH_URL+","+SSH_URL,
117+
"deploy@gitlab.example.com:org/repo.git,deploy@gitlab.example.com:org/repo.git"}, nullValues={"NULL"})
114118
public void testGetURLWithNoUserInfo(String url, String expected) {
115119
String result = GitUtilities.getURLWithNoUserInfo(url, "test");
116120
assertThat(result).isEqualTo(expected);

0 commit comments

Comments
 (0)