use crate::error::Error;
use crate::types::PullRequest;
use async_trait::async_trait;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Phase {
Analyzing,
Planning,
Executing,
AddingComments,
Complete,
}
impl std::fmt::Display for Phase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Analyzing => write!(f, "Analyzing"),
Self::Planning => write!(f, "Planning"),
Self::Executing => write!(f, "Executing"),
Self::AddingComments => write!(f, "Updating stack comments"),
Self::Complete => write!(f, "Done"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PushStatus {
Started,
Success,
AlreadySynced,
Failed(String),
}
impl std::fmt::Display for PushStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Started => write!(f, "started"),
Self::Success => write!(f, "success"),
Self::AlreadySynced => write!(f, "already synced"),
Self::Failed(msg) => write!(f, "failed: {msg}"),
}
}
}
#[async_trait]
pub trait ProgressCallback: Send + Sync {
async fn on_phase(&self, phase: Phase);
async fn on_bookmark_push(&self, bookmark: &str, status: PushStatus);
async fn on_pr_created(&self, bookmark: &str, pr: &PullRequest);
async fn on_pr_updated(&self, bookmark: &str, pr: &PullRequest);
async fn on_error(&self, error: &Error);
async fn on_message(&self, message: &str);
}
pub struct NoopProgress;
#[async_trait]
impl ProgressCallback for NoopProgress {
async fn on_phase(&self, _phase: Phase) {}
async fn on_bookmark_push(&self, _bookmark: &str, _status: PushStatus) {}
async fn on_pr_created(&self, _bookmark: &str, _pr: &PullRequest) {}
async fn on_pr_updated(&self, _bookmark: &str, _pr: &PullRequest) {}
async fn on_error(&self, _error: &Error) {}
async fn on_message(&self, _message: &str) {}
}