huskies: merge 879

This commit is contained in:
dave
2026-04-30 00:21:31 +00:00
parent 8fc581ad6b
commit a796bd933f
4 changed files with 98 additions and 129 deletions
-53
View File
@@ -94,25 +94,6 @@ pub fn write_review_hold(path: &Path) -> Result<(), String> {
Ok(())
}
/// Write or update `depends_on:` field in the YAML front matter of a story file.
///
/// Serialises `deps` as an inline YAML sequence, e.g. `[477, 478]`.
/// If `deps` is empty the field is removed.
/// If no front matter is present, this is a no-op (returns Ok).
pub fn write_depends_on(path: &Path, deps: &[u32]) -> Result<(), String> {
let contents =
fs::read_to_string(path).map_err(|e| format!("Failed to read story file: {e}"))?;
let updated = if deps.is_empty() {
remove_front_matter_field(&contents, "depends_on")
} else {
let nums: Vec<String> = deps.iter().map(|n| n.to_string()).collect();
let yaml_value = format!("[{}]", nums.join(", "));
set_front_matter_field(&contents, "depends_on", &yaml_value)
};
fs::write(path, &updated).map_err(|e| format!("Failed to write story file: {e}"))?;
Ok(())
}
/// Remove a key from the YAML front matter of a markdown string (pure function).
///
/// Returns the updated content. If no front matter or key is not found,
@@ -152,20 +133,6 @@ pub fn write_mergemaster_attempted_in_content(contents: &str) -> String {
set_front_matter_field(contents, "mergemaster_attempted", "true")
}
/// Write or update `depends_on` in story content (pure function).
///
/// Serialises `deps` as an inline YAML sequence, e.g. `[477, 478]`.
/// If `deps` is empty the field is removed.
pub fn write_depends_on_in_content(contents: &str, deps: &[u32]) -> String {
if deps.is_empty() {
remove_front_matter_field(contents, "depends_on")
} else {
let nums: Vec<String> = deps.iter().map(|n| n.to_string()).collect();
let yaml_value = format!("[{}]", nums.join(", "));
set_front_matter_field(contents, "depends_on", &yaml_value)
}
}
#[cfg(test)]
mod tests {
use super::*;
@@ -242,24 +209,4 @@ mod tests {
assert!(contents.contains("review_hold: true"));
assert!(contents.contains("name: My Spike"));
}
#[test]
fn write_depends_on_sets_field() {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("story.md");
std::fs::write(&path, "---\nname: Test\n---\n# Story\n").unwrap();
write_depends_on(&path, &[477, 478]).unwrap();
let contents = std::fs::read_to_string(&path).unwrap();
assert!(contents.contains("depends_on: [477, 478]"), "{contents}");
}
#[test]
fn write_depends_on_removes_field_when_empty() {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("story.md");
std::fs::write(&path, "---\nname: Test\ndepends_on: [477]\n---\n# Story\n").unwrap();
write_depends_on(&path, &[]).unwrap();
let contents = std::fs::read_to_string(&path).unwrap();
assert!(!contents.contains("depends_on"), "{contents}");
}
}
+2 -3
View File
@@ -14,9 +14,8 @@ mod types;
pub use deps::{check_archived_deps, check_archived_deps_from_list, check_unmet_deps};
pub use fields::{
clear_front_matter_field, clear_front_matter_field_in_content, set_front_matter_field,
write_depends_on, write_depends_on_in_content, write_merge_failure_in_content,
write_mergemaster_attempted_in_content, write_rejection_notes_to_content, write_review_hold,
write_review_hold_in_content,
write_merge_failure_in_content, write_mergemaster_attempted_in_content,
write_rejection_notes_to_content, write_review_hold, write_review_hold_in_content,
};
pub use parser::{
is_story_frozen_in_store, parse_front_matter, parse_unchecked_todos, resolve_qa_mode,