huskies: merge 867
This commit is contained in:
@@ -97,3 +97,28 @@ pub fn apply_transition_str(
|
||||
) -> Result<TransitionFired, String> {
|
||||
apply_transition(story_id, event, content_transform).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Freeze a story at its current stage.
|
||||
///
|
||||
/// Transitions the story to `Stage::Frozen { resume_to: current_stage }` and
|
||||
/// writes `resume_to_stage` into the front matter so the projection layer can
|
||||
/// reconstruct the full typed stage on subsequent reads.
|
||||
pub fn transition_to_frozen(story_id: &str) -> Result<TransitionFired, ApplyError> {
|
||||
let item = read_typed(story_id)?.ok_or_else(|| ApplyError::NotFound(story_id.to_string()))?;
|
||||
let resume_dir = item.stage.dir_name().to_string();
|
||||
let transform = move |content: &str| -> String {
|
||||
crate::io::story_metadata::set_front_matter_field(content, "resume_to_stage", &resume_dir)
|
||||
};
|
||||
apply_transition(story_id, PipelineEvent::Freeze, Some(&transform))
|
||||
}
|
||||
|
||||
/// Unfreeze a story, restoring it to the stage it was in before freezing.
|
||||
///
|
||||
/// Transitions `Stage::Frozen { resume_to }` back to `resume_to` and removes
|
||||
/// the `resume_to_stage` field from the front matter.
|
||||
pub fn transition_to_unfrozen(story_id: &str) -> Result<TransitionFired, ApplyError> {
|
||||
let transform = |content: &str| -> String {
|
||||
crate::io::story_metadata::clear_front_matter_field_in_content(content, "resume_to_stage")
|
||||
};
|
||||
apply_transition(story_id, PipelineEvent::Unfreeze, Some(&transform))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user