Skip to content

Commit

Permalink
feat: query the latest eval with package filters
Browse files Browse the repository at this point in the history
  • Loading branch information
bryango committed Nov 22, 2024
1 parent 11bdc18 commit 9bd144a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ impl HydraCheckCli {
let args = args.guess_jobset();
let queries = match (args.queries.is_empty(), args.eval) {
(true, false) => Queries::Jobset,
(true, true) => Queries::Evals(vec![]), // this would resolve to the latest eval of a jobset
// this would resolve to the latest eval of a jobset:
(true, true) => Queries::Evals(vec![Evaluation::guess_from_spec("")]),
(false, true) => Queries::Evals(args.guess_evals()),
(false, false) => Queries::Packages(args.guess_packages()),
};
Expand Down
17 changes: 10 additions & 7 deletions src/queries/evals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl ResolvedArgs {
evals: &Vec<Evaluation>,
) -> anyhow::Result<bool> {
let mut indexmap = IndexMap::new();
let evals = match &evals.is_empty() {
let evals = match evals.iter().any(|eval| eval.id == 0) {
false => evals.clone(),
true => {
info!(
Expand All @@ -398,12 +398,15 @@ impl ResolvedArgs {
)
};
eprintln!("");
let id = self
.fetch_and_print_jobset(true)?
.ok_or_else(err)?
.to_string();
eprintln!("");
vec![Evaluation::guess_from_spec(&id)]
let id = self.fetch_and_print_jobset(false)?.ok_or_else(err)?;
println!("");
evals
.iter()
.map(|eval| match &eval.id {
0 => Evaluation { id, ..eval.clone() },
_ => eval.clone(),
})
.collect()
}
};
for (idx, eval) in evals.iter().enumerate() {
Expand Down
58 changes: 35 additions & 23 deletions src/structs/eval.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{error, info};
use log::info;
use serde::Serialize;

use crate::constants;
Expand All @@ -18,33 +18,39 @@ pub(crate) struct Evaluation {
impl Evaluation {
/// Parses an evaluation from a plain text specification.
pub(crate) fn guess_from_spec(spec: &str) -> Self {
let mut spec = spec.splitn(2, "/");
let id = spec.next().unwrap();
let id = match id.parse() {
Ok(id) => id,
Err(err) => {
error!(
"evaluations must be identified by a number {} {} '{}': {}",
"(slash an optional filter), e.g. '1809585/coreutils'.",
"Instead we get",
id,
err
);
std::process::exit(1);
}
let spec = spec.trim();

let mut split_spec = spec.splitn(2, "/");
let id = split_spec.next().unwrap().trim();
let filter = split_spec.next();

let (id, filter) = match id.parse() {
Ok(x) => (x, filter),
Err(_) => (
0u64, // for the latest eval
match id.is_empty() {
true => filter,
false => Some(spec),
},
),
};
let filter = match spec.next() {
let filter = match filter {
None => {
let default = constants::DEFAULT_EVALUATION_FILTER.to_string();
info!(
"{}, so the default filter '/{default}' is used {}",
"no package filter has been specified", "for better performance"
);
info!(
"specify another filter with --eval '{}', {}: '{}'\n",
format!("{id}/<filter>"),
"or force an empty filter with a trailing slash",
format!("{id}/")
"specify another filter with --eval '{}', {}\n",
format!(
"{}/<filter>",
match id {
0 => "<id>".into(),
x => x.to_string(),
}
),
"or force an empty filter with a trailing slash '/'",
);
Some(default)
}
Expand All @@ -67,13 +73,19 @@ impl Evaluation {

#[test]
fn guess_eval_from_spec() {
let default_filter = constants::DEFAULT_EVALUATION_FILTER.into();
let default_filter = constants::DEFAULT_EVALUATION_FILTER;
for (spec, id, filter) in [
("123456", 123456, Some(default_filter)),
("123456", 123456, Some(default_filter.into())),
("123456/", 123456, None),
("123456/rustc", 123456, Some("rustc".into())),
("", 0, Some(default_filter.into())),
("/", 0, None),
("/rustc", 0, Some("rustc".into())),
("rustc", 0, Some("rustc".into())),
("weird/filter", 0, Some("weird/filter".into())),
] {
let eval = Evaluation::guess_from_spec(&spec);
debug_assert!(eval.id == id && eval.filter == filter);
println!("{:?}", eval);
assert!(eval.id == id && eval.filter == filter);
}
}

0 comments on commit 9bd144a

Please sign in to comment.