Skip to main content

ralph_workflow/reducer/event/
rebase.rs

1//! Rebase operation events.
2//!
3//! Events related to git rebase operations including conflict detection
4//! and resolution.
5
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9/// Rebase phase (initial or post-review).
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11pub enum RebasePhase {
12    /// Initial rebase before development starts.
13    Initial,
14    /// Post-review rebase after review fixes.
15    PostReview,
16}
17
18/// Conflict resolution strategy.
19///
20/// Determines how the pipeline should handle merge conflicts during rebase operations.
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
22pub enum ConflictStrategy {
23    /// Abort the rebase and restore original state.
24    Abort,
25    /// Continue rebase after conflict resolution.
26    Continue,
27    /// Skip the conflicting commit.
28    Skip,
29}
30
31/// Rebase operation events.
32///
33/// Events related to git rebase operations including conflict detection
34/// and resolution. Rebase operations can occur at multiple points in the
35/// pipeline (initial and post-review).
36///
37/// # State Machine
38///
39/// ```text
40/// NotStarted -> InProgress -> Conflicted -> InProgress -> Completed
41///                    |                           |
42///                    +---------> Skipped <-------+
43///                    |
44///                    +---------> Failed (resets to NotStarted)
45/// ```
46///
47/// # Emitted By
48///
49/// - Rebase handlers in `handler/rebase.rs`
50/// - Git integration layer
51#[derive(Clone, Serialize, Deserialize, Debug)]
52pub enum RebaseEvent {
53    /// Rebase operation started.
54    ///
55    /// Emitted when a rebase begins. The reducer uses this to:
56    /// - Track which rebase phase is active (initial or post-review)
57    /// - Record the target branch for observability
58    Started {
59        /// The rebase phase (initial or post-review).
60        phase: RebasePhase,
61        /// The target branch to rebase onto.
62        target_branch: String,
63    },
64    /// Merge conflict detected during rebase.
65    ///
66    /// Emitted when git detects merge conflicts. The handler will attempt
67    /// automated resolution; the reducer tracks which files are conflicted.
68    ConflictDetected {
69        /// The files with conflicts.
70        files: Vec<PathBuf>,
71    },
72    /// Merge conflicts were resolved.
73    ///
74    /// Emitted after successful conflict resolution. The reducer uses this
75    /// to clear the conflict state and allow rebase to continue.
76    ConflictResolved {
77        /// The files that were resolved.
78        files: Vec<PathBuf>,
79    },
80    /// Rebase completed successfully.
81    ///
82    /// Emitted when rebase finishes without errors. The reducer uses this to:
83    /// - Mark rebase as complete
84    /// - Record the new HEAD commit
85    /// - Transition to the next pipeline phase
86    Succeeded {
87        /// The rebase phase that completed.
88        phase: RebasePhase,
89        /// The new HEAD after rebase.
90        new_head: String,
91    },
92    /// Rebase failed and was reset.
93    ///
94    /// Emitted when rebase encounters an unrecoverable error. The reducer
95    /// uses this to decide whether to retry or abort the pipeline.
96    Failed {
97        /// The rebase phase that failed.
98        phase: RebasePhase,
99        /// The reason for failure.
100        reason: String,
101    },
102    /// Rebase was aborted and state restored.
103    ///
104    /// Emitted when rebase is explicitly aborted (e.g., user interrupt).
105    /// The reducer marks rebase as not attempted.
106    Aborted {
107        /// The rebase phase that was aborted.
108        phase: RebasePhase,
109        /// The commit that was restored.
110        restored_to: String,
111    },
112    /// Rebase was skipped (e.g., already up to date).
113    ///
114    /// Emitted when rebase is unnecessary. The reducer marks rebase as
115    /// complete without actually performing the operation.
116    Skipped {
117        /// The rebase phase that was skipped.
118        phase: RebasePhase,
119        /// The reason for skipping.
120        reason: String,
121    },
122}