Skip to main content

diffler_ci/
provider.rs

1//! The provider seam. One async trait every forge adapter implements; the host
2//! holds a `Box<dyn CiProvider + Send>` chosen at runtime by detection.
3
4use async_trait::async_trait;
5
6use crate::error::Result;
7use crate::model::{
8    Capabilities, CiRun, JobId, LogChunk, PullRequest, RunDetail, RunExtras, RunId,
9};
10
11/// Which forge an adapter talks to.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum ProviderKind {
14    GitHub,
15    GitLab,
16}
17
18#[async_trait]
19pub trait CiProvider: Send {
20    fn kind(&self) -> ProviderKind;
21
22    /// What this provider can do, so the UI degrades honestly.
23    fn capabilities(&self) -> Capabilities;
24
25    /// The most recent runs, newest first, capped at `limit`.
26    async fn list_runs(&self, limit: usize) -> Result<Vec<CiRun>>;
27
28    /// A run's jobs and dependency edges.
29    async fn run_detail(&self, run: &RunId) -> Result<RunDetail>;
30
31    /// A slice of a job's log starting at `offset`. For `LogMode::Dump`
32    /// providers the whole log returns once the job completes.
33    async fn job_log(&self, run: &RunId, job: &JobId, offset: u64) -> Result<LogChunk>;
34
35    /// A run's artifacts and annotations, for the graph page's extras panel.
36    /// A provider that exposes neither returns the empty default.
37    async fn run_extras(&self, run: &RunId) -> Result<RunExtras>;
38
39    /// The pull/merge request for the checked-out branch, if one is open.
40    /// `None` when there's no PR or the provider can't resolve one.
41    async fn current_pr(&self) -> Result<Option<PullRequest>>;
42}