Skip to content

Commit

Permalink
Make all Group keys optional.
Browse files Browse the repository at this point in the history
Also test and validate all action templates.
  • Loading branch information
joaander committed May 13, 2024
1 parent e811a20 commit 801e616
Show file tree
Hide file tree
Showing 4 changed files with 466 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/cli/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn submit<W: Write>(
let status = project.separate_by_status(action, matching_directories)?;
let groups = project.separate_into_groups(action, status.eligible)?;

if action.group.submit_whole {
if action.group.submit_whole() {
let whole_groups =
project.separate_into_groups(action, project.state().list_directories())?;
for group in &groups {
Expand Down
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,27 @@ pub enum Error {
#[error("Cannot compare {0} and {1} while checking directory '{2}'.")]
CannotCompareInclude(Value, Value, PathBuf),

#[error("Action at index {0} is missing name.")]
#[error("Action at index {0} is missing `name`.")]
ActionMissingName(usize),

#[error("Action '{0}' is missing command.")]
#[error("Action '{0}' is missing `command`.")]
ActionMissingCommand(String),

#[error("Default action must not set `from`.")]
DefaultActionSetsFrom(),

#[error("Action '{0}' set in `from` not found.")]
FromActionNotFound(String),

#[error("Cannot resolve recursive `from={0}`.")]
RecursiveFrom(String),

#[error("Duplicate actions '{0}' must have the same `products`.")]
DuplicateActionsDifferentProducts(String),

#[error("Duplicate actions '{0}' must have the same `previous_actions`.")]
DuplicateActionsDifferentPreviousActions(String),

// submission errors
#[error("Error encountered while executing action '{0}': {1}.")]
ExecuteAction(String, String),
Expand Down
26 changes: 12 additions & 14 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Project {

'outer: for name in directories {
if let Some(value) = self.state.values().get(&name) {
for (include, comparison, expected) in &action.group.include {
for (include, comparison, expected) in action.group.include() {
let actual = value
.pointer(include)
.ok_or_else(|| Error::JSONPointerNotFound(name.clone(), include.clone()))?;
Expand Down Expand Up @@ -302,7 +302,7 @@ impl Project {
.ok_or_else(|| Error::DirectoryNotFound(directory_name.clone()))?;

let mut sort_key = Vec::new();
for pointer in &action.group.sort_by {
for pointer in action.group.sort_by() {
let element = value.pointer(pointer).ok_or_else(|| {
Error::JSONPointerNotFound(directory_name.clone(), pointer.clone())
})?;
Expand All @@ -313,8 +313,8 @@ impl Project {

// Sort by key when there are keys to sort by.
let mut result = Vec::new();
if action.group.sort_by.is_empty() {
if action.group.reverse_sort {
if action.group.sort_by().is_empty() {
if action.group.reverse_sort() {
directories.reverse();
}
result.push(directories);
Expand All @@ -324,13 +324,13 @@ impl Project {
.expect("Valid JSON comparison")
});

if action.group.reverse_sort {
if action.group.reverse_sort() {
directories.reverse();
}

// Split by the sort key when requested.
#[allow(clippy::redundant_closure_for_method_calls)]
if action.group.split_by_sort_key {
if action.group.split_by_sort_key() {
result.extend(
directories
.chunk_by(|a, b| {
Expand Down Expand Up @@ -465,10 +465,8 @@ previous_actions = ["two"]
);

let mut action = project.workflow.action[1].clone();
action
.group
.include
.push(("/i".into(), Comparison::GreaterThan, Value::from(4)));
let include = &mut action.group.include.as_mut().unwrap();
include.push(("/i".into(), Comparison::GreaterThan, Value::from(4)));
assert_eq!(
project
.find_matching_directories(&action, all_directories.clone())
Expand Down Expand Up @@ -539,7 +537,7 @@ previous_actions = ["two"]
reversed.reverse();

let mut action = project.workflow.action[0].clone();
action.group.reverse_sort = true;
action.group.reverse_sort = Some(true);
let groups = project
.separate_into_groups(&action, all_directories.clone())
.unwrap();
Expand Down Expand Up @@ -578,7 +576,7 @@ previous_actions = ["two"]
all_directories.sort_unstable();

let mut action = project.workflow.action[0].clone();
action.group.sort_by = vec!["/j".to_string()];
action.group.sort_by = Some(vec!["/j".to_string()]);
let groups = project
.separate_into_groups(&action, all_directories.clone())
.unwrap();
Expand Down Expand Up @@ -606,8 +604,8 @@ previous_actions = ["two"]
all_directories.sort_unstable();

let mut action = project.workflow.action[0].clone();
action.group.sort_by = vec!["/j".to_string()];
action.group.split_by_sort_key = true;
action.group.sort_by = Some(vec!["/j".to_string()]);
action.group.split_by_sort_key = Some(true);
let groups = project
.separate_into_groups(&action, all_directories.clone())
.unwrap();
Expand Down
Loading

0 comments on commit 801e616

Please sign in to comment.