Skip to content

Commit 07b2671

Browse files
committed
ContextPath
1 parent fc34b32 commit 07b2671

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/bencher_context/src/client/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ mod platform;
77
pub use platform::Fingerprint;
88
use platform::OperatingSystem;
99

10-
use crate::{ContextKey, ReportContext};
10+
use crate::{ContextPath, ReportContext};
1111

12+
const BENCHER_DEV: &str = "bencher.dev";
1213
const ROOT: &str = "root";
1314

1415
impl ReportContext {
@@ -17,7 +18,7 @@ impl ReportContext {
1718
}
1819

1920
fn insert(&mut self, path: &str, value: String) -> Option<String> {
20-
let key = format!("bencher.dev{path}");
21+
let key = format!("{BENCHER_DEV}{path}");
2122
self.0.insert(key, value)
2223
}
2324
}
@@ -42,31 +43,31 @@ fn git_context(context: &mut ReportContext) {
4243
};
4344

4445
if let Some(repo_name) = repo_name(&repo) {
45-
context.insert(ContextKey::REPO_NAME, repo_name);
46+
context.insert(ContextPath::REPO_NAME, repo_name);
4647
}
4748

4849
if let Some(root_commit) = repo_hash(&repo) {
49-
context.insert(ContextKey::REPO_HASH, root_commit);
50+
context.insert(ContextPath::REPO_HASH, root_commit);
5051
}
5152

5253
if let Some((branch_ref, branch_ref_name)) = branch_ref(&repo) {
53-
context.insert(ContextKey::BRANCH_REF, branch_ref);
54-
context.insert(ContextKey::BRANCH_REF_NAME, branch_ref_name);
54+
context.insert(ContextPath::BRANCH_REF, branch_ref);
55+
context.insert(ContextPath::BRANCH_REF_NAME, branch_ref_name);
5556
}
5657

5758
if let Some(hash) = branch_hash(&repo) {
58-
context.insert(ContextKey::BRANCH_HASH, hash);
59+
context.insert(ContextPath::BRANCH_HASH, hash);
5960
}
6061
}
6162

6263
fn platform_context(context: &mut ReportContext) {
6364
context.insert(
64-
ContextKey::TESTBED_OS,
65+
ContextPath::TESTBED_OS,
6566
OperatingSystem::current().to_string(),
6667
);
6768

6869
if let Some(fingerprint) = Fingerprint::current() {
69-
context.insert(ContextKey::TESTBED_FINGERPRINT, fingerprint.to_string());
70+
context.insert(ContextPath::TESTBED_FINGERPRINT, fingerprint.to_string());
7071
}
7172
}
7273

lib/bencher_context/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,39 @@ pub struct ReportContext(pub HashMap<String, String>);
1818
#[allow(clippy::multiple_inherent_impl)]
1919
impl ReportContext {
2020
pub fn repo_name(&self) -> Option<&str> {
21-
self.0.get(ContextKey::REPO_NAME).map(String::as_str)
21+
self.0.get(ContextPath::REPO_NAME).map(String::as_str)
2222
}
2323

2424
pub fn repo_hash(&self) -> Option<&str> {
25-
self.0.get(ContextKey::REPO_HASH).map(String::as_str)
25+
self.0.get(ContextPath::REPO_HASH).map(String::as_str)
2626
}
2727

2828
pub fn branch_ref(&self) -> Option<&str> {
29-
self.0.get(ContextKey::BRANCH_REF).map(String::as_str)
29+
self.0.get(ContextPath::BRANCH_REF).map(String::as_str)
3030
}
3131

3232
pub fn branch_ref_name(&self) -> Option<&str> {
33-
self.0.get(ContextKey::BRANCH_REF_NAME).map(String::as_str)
33+
self.0.get(ContextPath::BRANCH_REF_NAME).map(String::as_str)
3434
}
3535

3636
pub fn branch_hash(&self) -> Option<&str> {
37-
self.0.get(ContextKey::BRANCH_HASH).map(String::as_str)
37+
self.0.get(ContextPath::BRANCH_HASH).map(String::as_str)
3838
}
3939

4040
pub fn testbed_os(&self) -> Option<&str> {
41-
self.0.get(ContextKey::TESTBED_OS).map(String::as_str)
41+
self.0.get(ContextPath::TESTBED_OS).map(String::as_str)
4242
}
4343

4444
pub fn testbed_fingerprint(&self) -> Option<&str> {
4545
self.0
46-
.get(ContextKey::TESTBED_FINGERPRINT)
46+
.get(ContextPath::TESTBED_FINGERPRINT)
4747
.map(String::as_str)
4848
}
4949
}
5050

51-
struct ContextKey;
51+
struct ContextPath;
5252

53-
impl ContextKey {
53+
impl ContextPath {
5454
pub const REPO_NAME: &str = "/repo/name";
5555
pub const REPO_HASH: &str = "/repo/hash";
5656
pub const BRANCH_REF: &str = "/branch/ref";

0 commit comments

Comments
 (0)