posthog_cli/experimental/tasks/
mod.rs

1mod list;
2mod progress;
3mod update_stage;
4mod utils;
5
6use anyhow::Result;
7use chrono::{DateTime, Utc};
8use clap::Subcommand;
9use serde::{Deserialize, Serialize};
10use serde_json::Value;
11use uuid::Uuid;
12
13use self::list::list_tasks;
14use self::progress::show_progress;
15use self::update_stage::update_stage;
16
17#[derive(Debug, Serialize, Deserialize)]
18pub struct Task {
19    pub id: Uuid,
20    pub title: String,
21    pub description: Option<String>,
22    pub origin_product: String,
23    pub position: i32,
24    pub workflow: Option<Uuid>,
25    pub current_stage: Option<Uuid>,
26    pub github_integration: Option<i64>,
27    pub repository_config: Option<Value>,
28    pub repository_list: Option<Vec<Value>>,
29    pub primary_repository: Option<Value>,
30    pub github_branch: Option<String>,
31    pub github_pr_url: Option<String>,
32    pub created_at: DateTime<Utc>,
33    pub updated_at: DateTime<Utc>,
34}
35
36#[derive(Debug, Serialize, Deserialize)]
37pub struct WorkflowStage {
38    pub id: Uuid,
39    pub workflow: Uuid,
40    pub name: String,
41    pub key: String,
42    pub position: i32,
43    pub color: String,
44    pub agent: Option<Uuid>,
45    pub agent_name: Option<String>,
46    pub is_manual_only: bool,
47    pub is_archived: bool,
48    pub fallback_stage: Option<Uuid>,
49    pub task_count: Option<i32>,
50}
51
52#[derive(Debug, Serialize, Deserialize)]
53pub struct AgentDefinition {
54    pub id: Uuid,
55    pub name: String,
56    pub agent_type: String,
57    pub description: Option<String>,
58    pub config: Value, // JSON object
59    pub is_active: bool,
60    pub created_at: DateTime<Utc>,
61    pub updated_at: DateTime<Utc>,
62}
63
64#[derive(Debug, Serialize, Deserialize)]
65pub struct TaskWorkflow {
66    pub id: Uuid,
67    pub name: String,
68    pub description: Option<String>,
69    pub color: String,
70    pub is_default: bool,
71    pub is_active: bool,
72    pub version: i32,
73    pub stages: Vec<WorkflowStage>,
74    pub task_count: Option<i32>,
75    pub can_delete: Option<CanDeleteResponse>,
76    pub created_at: DateTime<Utc>,
77    pub updated_at: DateTime<Utc>,
78}
79
80#[derive(Debug, Serialize, Deserialize)]
81pub struct CanDeleteResponse {
82    pub can_delete: bool,
83    pub reason: String,
84}
85
86#[derive(Debug, Serialize, Deserialize)]
87pub struct TaskListResponse {
88    pub results: Vec<Task>,
89    pub count: usize,
90    pub next: Option<String>,
91    pub previous: Option<String>,
92}
93
94#[derive(Debug, Serialize, Deserialize)]
95pub struct RepositoryConfig {
96    pub integration_id: Option<i64>,
97    pub organization: String,
98    pub repository: String,
99}
100
101#[derive(Debug, Serialize, Deserialize)]
102pub struct WorkflowConfiguration {
103    pub workflow: TaskWorkflow,
104    pub stages: Vec<WorkflowStage>,
105}
106
107#[derive(Subcommand)]
108pub enum TaskCommand {
109    /// List all tasks
110    List {
111        /// Maximum number of tasks to display
112        #[arg(long)]
113        limit: Option<usize>,
114
115        /// Page offset for pagination
116        #[arg(long)]
117        offset: Option<usize>,
118    },
119
120    /// View task progress
121    Progress {
122        /// Task ID (will prompt for selection if not provided)
123        task_id: Option<Uuid>,
124    },
125
126    /// Update task stage
127    UpdateStage {
128        /// Task ID (will prompt for selection if not provided)
129        task_id: Option<Uuid>,
130    },
131}
132
133impl TaskCommand {
134    pub fn run(&self) -> Result<()> {
135        match self {
136            TaskCommand::List { limit, offset } => list_tasks(limit.as_ref(), offset.as_ref()),
137            TaskCommand::Progress { task_id } => show_progress(task_id.as_ref()),
138            TaskCommand::UpdateStage { task_id } => update_stage(task_id.as_ref()),
139        }
140    }
141}