From e9981fa1a1d38c4088ba8072182526f37e6586c0 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 9 Sep 2024 19:07:22 -0400 Subject: [PATCH] locate: switch to yamlpath::QueryBuilder --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/finding/locate.rs | 24 ++++++++---------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89155840..f9329609 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1687,9 +1687,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "yamlpath" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d386792df4f4a1e19f4951bca7b396fdabc2ea4c0a84f516b2a935d3ad51b9a" +checksum = "5d55fd88d0f8a01d2507db53a06129114b2786a36336afd31e291e3a58333736" dependencies = [ "thiserror", "tree-sitter", diff --git a/Cargo.toml b/Cargo.toml index ae9f729b..c659ad9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,4 +18,4 @@ serde = { version = "1.0.208", features = ["derive"] } serde-sarif = "0.6.5" serde_json = "1.0.125" serde_yaml = "0.9.34" -yamlpath = "0.3.0" +yamlpath = "0.4.0" diff --git a/src/finding/locate.rs b/src/finding/locate.rs index 7acfc8a2..a6c14d7a 100644 --- a/src/finding/locate.rs +++ b/src/finding/locate.rs @@ -18,34 +18,26 @@ impl Locator { workflow: &'w Workflow, location: &WorkflowLocation, ) -> Result> { - let mut path = vec![]; + let mut builder = yamlpath::QueryBuilder::new(); if let Some(job) = &location.job { - path.extend([ - yamlpath::Component::Key("jobs".into()), - yamlpath::Component::Key(job.id.into()), - ]); + builder = builder.key("jobs").key(job.id); if let Some(step) = &job.step { - path.extend([ - yamlpath::Component::Key("steps".into()), - yamlpath::Component::Index(step.index), - ]); + builder = builder.key("steps").index(step.index); } else if let Some(key) = &job.key { - path.push(yamlpath::Component::Key(key.to_string())); + builder = builder.key(*key); } } else { // Non-job top-level key. - path.push(yamlpath::Component::Key( + builder = builder.key( location .key - .expect("API misuse: must provide key if job is not specified") - .to_string(), - )); + .expect("API misuse: must provide key if job is not specified"), + ); } - // Infallible: we always have at least one path component above. - let query = yamlpath::Query::new(path).unwrap(); + let query = builder.build(); let feature = workflow.document.query(&query)?; Ok(Feature {