jj_ryu/submit/
progress.rs1use crate::error::Error;
7use crate::types::PullRequest;
8use async_trait::async_trait;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum Phase {
13 Analyzing,
15 Planning,
17 Executing,
19 AddingComments,
21 Complete,
23}
24
25impl std::fmt::Display for Phase {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::Analyzing => write!(f, "Analyzing"),
29 Self::Planning => write!(f, "Planning"),
30 Self::Executing => write!(f, "Executing"),
31 Self::AddingComments => write!(f, "Updating stack comments"),
32 Self::Complete => write!(f, "Done"),
33 }
34 }
35}
36
37#[derive(Debug, Clone, PartialEq, Eq)]
39pub enum PushStatus {
40 Started,
42 Success,
44 AlreadySynced,
46 Failed(String),
48}
49
50impl std::fmt::Display for PushStatus {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 match self {
53 Self::Started => write!(f, "started"),
54 Self::Success => write!(f, "success"),
55 Self::AlreadySynced => write!(f, "already synced"),
56 Self::Failed(msg) => write!(f, "failed: {msg}"),
57 }
58 }
59}
60
61#[async_trait]
67pub trait ProgressCallback: Send + Sync {
68 async fn on_phase(&self, phase: Phase);
70
71 async fn on_bookmark_push(&self, bookmark: &str, status: PushStatus);
73
74 async fn on_pr_created(&self, bookmark: &str, pr: &PullRequest);
76
77 async fn on_pr_updated(&self, bookmark: &str, pr: &PullRequest);
79
80 async fn on_error(&self, error: &Error);
82
83 async fn on_message(&self, message: &str);
85}
86
87pub struct NoopProgress;
89
90#[async_trait]
91impl ProgressCallback for NoopProgress {
92 async fn on_phase(&self, _phase: Phase) {}
93 async fn on_bookmark_push(&self, _bookmark: &str, _status: PushStatus) {}
94 async fn on_pr_created(&self, _bookmark: &str, _pr: &PullRequest) {}
95 async fn on_pr_updated(&self, _bookmark: &str, _pr: &PullRequest) {}
96 async fn on_error(&self, _error: &Error) {}
97 async fn on_message(&self, _message: &str) {}
98}