1mod handle;
2mod runner;
3mod state;
4pub mod types;
5
6use crate::history;
7use crate::history::HistoryEntry;
8use crate::runtime;
9use crate::ui::types::UiEvent;
10use anyhow::{Context, Result};
11use std::collections::HashMap;
12use std::env;
13use std::path::Path;
14use tokio::sync::mpsc;
15
16pub use handle::{UiBridge, UiHandle};
17pub use types::{UiCommand, UiJobInfo, UiJobResources, UiJobStatus};
18
19pub fn view_history(history: Vec<HistoryEntry>, current_run_id: String) -> Result<()> {
21 let (tx, rx) = mpsc::unbounded_channel();
22 let (cmd_tx, _cmd_rx) = mpsc::unbounded_channel();
23 let workdir = env::current_dir().unwrap_or_else(|_| Path::new(".").to_path_buf());
24 let pipeline_path = workdir.join(".gitlab-ci.yml");
25 let runner = runner::UiRunner::new(
26 Vec::new(),
27 history,
28 current_run_id,
29 HashMap::new(),
30 String::new(),
31 workdir,
32 pipeline_path,
33 tx.clone(),
34 rx,
35 cmd_tx,
36 )?;
37 let _ = tx.send(UiEvent::PipelineFinished);
38 runner.run()
39}
40
41pub fn view_pipeline_logs(_root: &Path) -> Result<()> {
42 let history_path = runtime::history_path();
43 let history = history::load(&history_path)
44 .with_context(|| format!("failed to load history at {}", history_path.display()))?;
45 if history.is_empty() {
46 anyhow::bail!("no history entries found at {}", history_path.display());
47 }
48 let current_run_id = history
49 .last()
50 .map(|entry| entry.run_id.clone())
51 .unwrap_or_else(|| "history-view".to_string());
52 let (tx, rx) = mpsc::unbounded_channel();
53 let (cmd_tx, _cmd_rx) = mpsc::unbounded_channel();
54 let workdir = env::current_dir().unwrap_or_else(|_| Path::new(".").to_path_buf());
55 let pipeline_path = workdir.join(".gitlab-ci.yml");
56 let runner = runner::UiRunner::new(
57 Vec::new(),
58 history,
59 current_run_id,
60 HashMap::new(),
61 String::new(),
62 workdir,
63 pipeline_path,
64 tx.clone(),
65 rx,
66 cmd_tx,
67 )?;
68 let _ = tx.send(UiEvent::PipelineFinished);
69 runner.run()
70}
71
72pub fn page_text_with_pager(content: &str) -> Result<()> {
73 state::page_text_with_pager(content)
74}