Skip to content

Commit 8c649ef

Browse files
normalize git remote urls for anonymized telemetry (#1279)
this PR adds normalization logic to the remote URLs reported to apollo's telemetry service. CI providers like GitLab include username and passwords in their remote URLs, which makes their hashes non-unique. we now use the same normalization techniques used to provide `GitContext` to the Apollo Studio GraphQL API which should give us stronger insights into the number of unique projects using rover.
1 parent 5c2808b commit 8c649ef

File tree

3 files changed

+8
-31
lines changed

3 files changed

+8
-31
lines changed

Cargo.lock

+1-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sputnik/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ publish = false
88

99
[dependencies]
1010
ci_info = { version = "0.14", features = ["serde-1"] }
11-
git2 = "0.14"
1211
reqwest = { version = "0.11", default-features = false, features = ["blocking", "socks"] }
12+
rover-client = { path = "../rover-client" }
1313
saucer = { git = "https://github.com/EverlastingBugstopper/awc.git", branch = "main" }
1414
# saucer = { path = "../../../awc/saucer" }
1515
semver = { version = "1", features = ["serde"] }

crates/sputnik/src/session.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ci_info::types::Vendor as CiVendor;
2-
use git2::Repository;
32
use reqwest::blocking::Client;
43
use reqwest::Url;
4+
use rover_client::shared::GitContext;
55
use saucer::Utf8PathBuf;
66
use semver::Version;
77
use serde::Serialize;
@@ -97,7 +97,7 @@ impl Session {
9797
let current_dir = Utf8PathBuf::try_from(env::current_dir()?)?;
9898
let session_id = Uuid::new_v4();
9999
let cwd_hash = get_cwd_hash(&current_dir);
100-
let remote_url_hash = get_repo_hash(&current_dir);
100+
let remote_url_hash = get_repo_hash();
101101

102102
let continuous_integration = if ci_info::is_ci() {
103103
ci_info::get().vendor
@@ -157,15 +157,8 @@ fn get_cwd_hash(current_dir: &Utf8PathBuf) -> String {
157157
}
158158

159159
/// returns sha256 digest of the repository the tool was executed from.
160-
fn get_repo_hash(current_dir: &Utf8PathBuf) -> Option<String> {
161-
let repo = Repository::discover(current_dir);
162-
if let Ok(repo) = repo {
163-
if let Ok(remote) = repo.find_remote("origin") {
164-
if let Some(remote_url) = remote.url() {
165-
return Some(format!("{:x}", Sha256::digest(remote_url.as_bytes())));
166-
}
167-
}
168-
}
169-
170-
None
160+
fn get_repo_hash() -> Option<String> {
161+
GitContext::default()
162+
.remote_url
163+
.map(|remote_url| format!("{:x}", Sha256::digest(remote_url.as_bytes())))
171164
}

0 commit comments

Comments
 (0)