use async_trait::async_trait;
use crate::ci::error::Result;
use crate::ci::model::{
Capabilities, CiRun, JobId, LogChunk, PrComment, PullRequest, RunDetail, RunExtras, RunId,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProviderKind {
GitHub,
GitLab,
Forgejo,
}
#[async_trait]
pub trait ForgeProvider: Send {
fn kind(&self) -> ProviderKind;
fn capabilities(&self) -> Capabilities;
async fn list_runs(&self, limit: usize) -> Result<Vec<CiRun>>;
async fn run_detail(&self, run: &RunId) -> Result<RunDetail>;
async fn job_log(&self, run: &RunId, job: &JobId, offset: u64) -> Result<LogChunk>;
async fn run_extras(&self, run: &RunId) -> Result<RunExtras>;
async fn current_pr(&self) -> Result<Option<PullRequest>>;
async fn list_prs(&self) -> Result<Vec<PullRequest>>;
async fn pr_comments(&self, number: u64) -> Result<Vec<PrComment>>;
async fn post_pr_comment(&self, new: &NewPrComment) -> Result<PrComment>;
async fn reply_pr_comment(&self, number: u64, remote_id: &str, body: &str)
-> Result<PrComment>;
async fn submit_pr_review(&self, review: &NewPrReview) -> Result<()>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewPrReview {
pub number: u64,
pub head_oid: String,
pub comments: Vec<NewPrComment>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewPrComment {
pub number: u64,
pub head_oid: String,
pub path: String,
pub line: u32,
pub new_side: bool,
pub body: String,
}