Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize git remote urls for anonymized telemetry #1279

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sputnik/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ publish = false

[dependencies]
ci_info = { version = "0.14", features = ["serde-1"] }
git2 = "0.14"
reqwest = { version = "0.11", default-features = false, features = ["blocking", "socks"] }
rover-client = { path = "../rover-client" }
saucer = { git = "https://github.com/EverlastingBugstopper/awc.git", branch = "main" }
# saucer = { path = "../../../awc/saucer" }
semver = { version = "1", features = ["serde"] }
Expand Down
19 changes: 6 additions & 13 deletions crates/sputnik/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ci_info::types::Vendor as CiVendor;
use git2::Repository;
use reqwest::blocking::Client;
use reqwest::Url;
use rover_client::shared::GitContext;
use saucer::Utf8PathBuf;
use semver::Version;
use serde::Serialize;
Expand Down Expand Up @@ -97,7 +97,7 @@ impl Session {
let current_dir = Utf8PathBuf::try_from(env::current_dir()?)?;
let session_id = Uuid::new_v4();
let cwd_hash = get_cwd_hash(&current_dir);
let remote_url_hash = get_repo_hash(&current_dir);
let remote_url_hash = get_repo_hash();

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

/// returns sha256 digest of the repository the tool was executed from.
fn get_repo_hash(current_dir: &Utf8PathBuf) -> Option<String> {
let repo = Repository::discover(current_dir);
if let Ok(repo) = repo {
if let Ok(remote) = repo.find_remote("origin") {
if let Some(remote_url) = remote.url() {
return Some(format!("{:x}", Sha256::digest(remote_url.as_bytes())));
}
}
}

None
fn get_repo_hash() -> Option<String> {
GitContext::default()
.remote_url
.map(|remote_url| format!("{:x}", Sha256::digest(remote_url.as_bytes())))
}