diff --git a/demo-hytradboi/src/adapter.rs b/demo-hytradboi/src/adapter.rs index 435b10c5..24ba4c84 100644 --- a/demo-hytradboi/src/adapter.rs +++ b/demo-hytradboi/src/adapter.rs @@ -1,11 +1,11 @@ #![allow(dead_code)] -use std::{rc::Rc, sync::Arc, fs}; +use std::{fs, rc::Rc, sync::Arc}; use git_url_parse::GitUrl; use hn_api::{types::Item, HnClient}; use lazy_static::__Deref; -use octorust::types::{FullRepository, ContentFile}; +use octorust::types::{ContentFile, FullRepository}; use tokio::runtime::Runtime; use trustfall_core::{ interpreter::{Adapter, DataContext, InterpretedQuery}, @@ -13,9 +13,10 @@ use trustfall_core::{ }; use crate::{ + actions_parser::{get_env_for_run_step, get_jobs_in_workflow_file, get_steps_in_job}, pagers::{CratesPager, WorkflowsPager}, - token::{Token, Repository}, - util::{Pager, get_owner_and_repo}, actions_parser::{get_jobs_in_workflow_file, get_steps_in_job, get_env_for_run_step}, + token::{Repository, Token}, + util::{get_owner_and_repo, Pager}, }; const USER_AGENT: &str = "demo-hytradboi (github.com/obi1kenobi/trustfall)"; @@ -35,7 +36,8 @@ lazy_static! { )), ) .unwrap(); - static ref REPOS_CLIENT: octorust::repos::Repos = octorust::repos::Repos::new(GITHUB_CLIENT.clone()); + static ref REPOS_CLIENT: octorust::repos::Repos = + octorust::repos::Repos::new(GITHUB_CLIENT.clone()); static ref RUNTIME: Runtime = tokio::runtime::Builder::new_current_thread() .enable_all() .build() @@ -329,27 +331,40 @@ impl Adapter<'static> for DemoAdapter { }), // properties on GitHubActionsJob - ("GitHubActionsJob", "name") => impl_property!(data_contexts, as_github_actions_job, name), - ("GitHubActionsJob", "runsOn") => impl_property!(data_contexts, as_github_actions_job, runs_on), + ("GitHubActionsJob", "name") => { + impl_property!(data_contexts, as_github_actions_job, name) + } + ("GitHubActionsJob", "runsOn") => { + impl_property!(data_contexts, as_github_actions_job, runs_on) + } // properties on GitHubActionsStep and its implementers - ("GitHubActionsStep" | "GitHubActionsImportedStep" | "GitHubActionsRunStep", "name") => impl_property!(data_contexts, as_github_actions_step, step_name, { + ( + "GitHubActionsStep" | "GitHubActionsImportedStep" | "GitHubActionsRunStep", + "name", + ) => impl_property!(data_contexts, as_github_actions_step, step_name, { step_name.map(|x| x.to_string()).into() }), // properties on GitHubActionsImportedStep - ("GitHubActionsImportedStep", "uses") => impl_property!(data_contexts, as_github_actions_imported_step, uses), + ("GitHubActionsImportedStep", "uses") => { + impl_property!(data_contexts, as_github_actions_imported_step, uses) + } // properties on GitHubActionsRunStep - ("GitHubActionsRunStep", "run") => impl_property!(data_contexts, as_github_actions_run_step, run), + ("GitHubActionsRunStep", "run") => { + impl_property!(data_contexts, as_github_actions_run_step, run) + } // properties on NameValuePair ("NameValuePair", "name") => impl_property!(data_contexts, as_name_value_pair, pair, { pair.0.clone().into() }), - ("NameValuePair", "value") => impl_property!(data_contexts, as_name_value_pair, pair, { - pair.1.clone().into() - }), + ("NameValuePair", "value") => { + impl_property!(data_contexts, as_name_value_pair, pair, { + pair.1.clone().into() + }) + } _ => unreachable!(), } } @@ -531,13 +546,13 @@ impl Adapter<'static> for DemoAdapter { Item::Comment(c) => { comment_id = c.id; parent_id = c.parent; - }, + } Item::Poll(..) | Item::Pollopt(..) => { // Not supported, because HackerNews doesn't really // run polls anymore, even though the API still supports them. break Box::new(std::iter::empty()); } - } + }, Err(e) => { eprintln!( "API error while fetching comment {} parent {}: {}", @@ -635,7 +650,8 @@ impl Adapter<'static> for DemoAdapter { None => Box::new(std::iter::empty()), Some(token) => Box::new( WorkflowsPager::new(GITHUB_CLIENT.clone(), token, RUNTIME.deref()) - .into_iter().map(|x| x.into()) + .into_iter() + .map(|x| x.into()), ), }; @@ -711,8 +727,12 @@ impl Adapter<'static> for DemoAdapter { ("Webpage", "Repository") => token.as_repository().is_some(), ("Webpage", "GitHubRepository") => token.as_github_repository().is_some(), ("Repository", "GitHubRepository") => token.as_github_repository().is_some(), - ("GitHubActionsStep", "GitHubActionsImportedStep") => token.as_github_actions_imported_step().is_some(), - ("GitHubActionsStep", "GitHubActionsRunStep") => token.as_github_actions_run_step().is_some(), + ("GitHubActionsStep", "GitHubActionsImportedStep") => { + token.as_github_actions_imported_step().is_some() + } + ("GitHubActionsStep", "GitHubActionsRunStep") => { + token.as_github_actions_run_step().is_some() + } unhandled => unreachable!("{:?}", unhandled), }; @@ -775,6 +795,6 @@ fn get_repo_file_content(repo: &FullRepository, path: &str) -> Option>() ); diff --git a/demo-hytradboi/src/pagers.rs b/demo-hytradboi/src/pagers.rs index 71abe7ef..8bc429a3 100644 --- a/demo-hytradboi/src/pagers.rs +++ b/demo-hytradboi/src/pagers.rs @@ -5,7 +5,7 @@ use tokio::runtime::Runtime; use crate::{ token::{RepoWorkflow, Token}, - util::{Pager, PagerOutput, get_owner_and_repo}, + util::{get_owner_and_repo, Pager, PagerOutput}, }; pub(crate) struct CratesPager<'a> { @@ -86,13 +86,23 @@ impl<'a> Pager for WorkflowsPager<'a> { if response.workflows.is_empty() { PagerOutput::None } else if response.workflows.len() == per_page as usize { - PagerOutput::Page(response.workflows.into_iter().map(|w| { - RepoWorkflow::new(repo_clone.repo.clone(), Rc::new(w)) - }).collect::>().into_iter()) + PagerOutput::Page( + response + .workflows + .into_iter() + .map(|w| RepoWorkflow::new(repo_clone.repo.clone(), Rc::new(w))) + .collect::>() + .into_iter(), + ) } else { - PagerOutput::KnownFinalPage(response.workflows.into_iter().map(|w| { - RepoWorkflow::new(repo_clone.repo.clone(), Rc::new(w)) - }).collect::>().into_iter()) + PagerOutput::KnownFinalPage( + response + .workflows + .into_iter() + .map(|w| RepoWorkflow::new(repo_clone.repo.clone(), Rc::new(w))) + .collect::>() + .into_iter(), + ) } } Err(e) => { diff --git a/demo-hytradboi/src/token.rs b/demo-hytradboi/src/token.rs index 0435b7d7..d9b9eff3 100644 --- a/demo-hytradboi/src/token.rs +++ b/demo-hytradboi/src/token.rs @@ -57,7 +57,11 @@ pub struct ActionsJob { impl ActionsJob { pub(crate) fn new(yaml: Yaml, name: String, runs_on: Option) -> Self { - Self { yaml, name, runs_on } + Self { + yaml, + name, + runs_on, + } } } diff --git a/demo-hytradboi/src/util.rs b/demo-hytradboi/src/util.rs index 241d2af0..172a0464 100644 --- a/demo-hytradboi/src/util.rs +++ b/demo-hytradboi/src/util.rs @@ -11,19 +11,22 @@ pub(crate) trait Pager { fn get_page(&mut self, page: usize) -> PagerOutput; - fn into_iter(self) -> PaginationIterator where Self : Sized { + fn into_iter(self) -> PaginationIterator + where + Self: Sized, + { PaginationIterator::new(self) } } -pub(crate) struct PaginationIterator> { +pub(crate) struct PaginationIterator> { pager: P, next_page: usize, batch: Option>, final_page_seen: bool, } -impl> PaginationIterator { +impl> PaginationIterator { pub(crate) fn new(pager: P) -> Self { Self { pager, @@ -34,7 +37,7 @@ impl> PaginationIterator { } } -impl> Iterator for PaginationIterator { +impl> Iterator for PaginationIterator { type Item = T; fn next(&mut self) -> Option { @@ -49,9 +52,7 @@ impl> Iterator for PaginationIterator { true } } - None => { - true - } + None => true, }; if needs_next_page { if self.final_page_seen { @@ -65,10 +66,10 @@ impl> Iterator for PaginationIterator { PagerOutput::KnownFinalPage(batch) => { self.final_page_seen = true; self.batch = Some(batch); - }, + } PagerOutput::Page(batch) => { self.batch = Some(batch); - }, + } } } } diff --git a/trustfall_core/src/ir/mod.rs b/trustfall_core/src/ir/mod.rs index 82cb9699..25d5ec75 100644 --- a/trustfall_core/src/ir/mod.rs +++ b/trustfall_core/src/ir/mod.rs @@ -83,7 +83,9 @@ impl From for TransparentValue { FieldValue::Boolean(x) => TransparentValue::Boolean(x), FieldValue::DateTimeUtc(x) => TransparentValue::DateTimeUtc(x), FieldValue::Enum(x) => TransparentValue::Enum(x), - FieldValue::List(x) => TransparentValue::List(x.into_iter().map(|v| v.into()).collect()), + FieldValue::List(x) => { + TransparentValue::List(x.into_iter().map(|v| v.into()).collect()) + } } } } diff --git a/trustfall_core/src/schema/mod.rs b/trustfall_core/src/schema/mod.rs index 85a1487f..74d82636 100644 --- a/trustfall_core/src/schema/mod.rs +++ b/trustfall_core/src/schema/mod.rs @@ -345,7 +345,8 @@ fn check_property_and_edge_invariants( // and this field is neither an edge nor a property. unreachable!( "field {} (type {}) appears to represent neither an edge nor a property", - field_defn.name.node.as_ref(), field_type.to_string(), + field_defn.name.node.as_ref(), + field_type.to_string(), ) } }