Skip to content

Commit 4c70555

Browse files
runningcodeclaudeszokeasaurusrex
authored
feat: Normalize VCS provider names to match backend (#2770)
## Summary Backend does not accept github.com, it only accepts github Normalize VCS provider names. Closes EME-303 ## Examples | Hostname | Before | After | |----------|--------|-------| | `github.com` | `github.com` | `github` | | `gitlab.com` | `gitlab.com` | `gitlab` | | `dev.azure.com` | `dev.azure.com` | `azure` | | `git.mycompany.com` | `git.mycompany.com` | `mycompany` | 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
1 parent a81510b commit 4c70555

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

src/utils/vcs.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ impl VcsUrl {
207207
}
208208
}
209209

210+
fn extract_provider_name(host: &str) -> &str {
211+
let trimmed = host.trim_end_matches('.');
212+
trimmed.rsplit('.').nth(1).unwrap_or(trimmed)
213+
}
214+
210215
fn is_matching_url(a: &str, b: &str) -> bool {
211216
VcsUrl::parse(a) == VcsUrl::parse(b)
212217
}
@@ -218,7 +223,7 @@ pub fn get_repo_from_remote(repo: &str) -> String {
218223

219224
pub fn get_provider_from_remote(remote: &str) -> String {
220225
let obj = VcsUrl::parse(remote);
221-
obj.provider
226+
extract_provider_name(&obj.provider).to_owned()
222227
}
223228

224229
pub fn git_repo_remote_url(
@@ -922,6 +927,63 @@ mod tests {
922927
);
923928
}
924929

930+
#[test]
931+
fn test_extract_provider_name() {
932+
// Test basic provider name extraction
933+
assert_eq!(extract_provider_name("github.com"), "github");
934+
assert_eq!(extract_provider_name("gitlab.com"), "gitlab");
935+
assert_eq!(extract_provider_name("bitbucket.org"), "bitbucket");
936+
937+
// Test edge case with trailing dots
938+
assert_eq!(extract_provider_name("github.com."), "github");
939+
940+
// Test subdomain cases - we want the part before TLD, not the subdomain
941+
assert_eq!(extract_provider_name("api.github.com"), "github");
942+
assert_eq!(extract_provider_name("ssh.dev.azure.com"), "azure");
943+
assert_eq!(extract_provider_name("dev.azure.com"), "azure");
944+
945+
// Test single component (no dots)
946+
assert_eq!(extract_provider_name("localhost"), "localhost");
947+
assert_eq!(extract_provider_name("myserver"), "myserver");
948+
949+
// Test empty string
950+
assert_eq!(extract_provider_name(""), "");
951+
}
952+
953+
#[test]
954+
fn test_get_provider_from_remote() {
955+
// Test that get_provider_from_remote normalizes provider names
956+
assert_eq!(
957+
get_provider_from_remote("https://github.com/user/repo"),
958+
"github"
959+
);
960+
assert_eq!(
961+
get_provider_from_remote("git@gitlab.com:user/repo.git"),
962+
"gitlab"
963+
);
964+
assert_eq!(
965+
get_provider_from_remote("https://bitbucket.org/user/repo"),
966+
"bitbucket"
967+
);
968+
assert_eq!(
969+
get_provider_from_remote("https://dev.azure.com/user/repo"),
970+
"azure"
971+
);
972+
assert_eq!(
973+
get_provider_from_remote("https://github.mycompany.com/user/repo"),
974+
"mycompany"
975+
);
976+
assert_eq!(
977+
get_provider_from_remote("https://source.developers.google.com/p/project/r/repo"),
978+
"google"
979+
);
980+
// Test edge case with trailing dot in hostname
981+
assert_eq!(
982+
get_provider_from_remote("https://github.com./user/repo"),
983+
"github"
984+
);
985+
}
986+
925987
#[test]
926988
fn test_url_normalization() {
927989
assert!(!is_matching_url(

0 commit comments

Comments
 (0)