use async_trait::async_trait;
use std::any::Any;
use url::Url;
#[cfg(test)]
use mockall::automock;
use crate::{
config::Config,
forge::request::{
Commit, CreateCommitRequest, CreatePrRequest,
CreateReleaseBranchRequest, ForgeCommit, GetFileContentRequest,
GetPrRequest, PrLabelsRequest, PullRequest, ReleaseByTagResponse, Tag,
UpdatePrRequest,
},
result::Result,
};
#[cfg_attr(test, automock)]
#[async_trait]
pub trait Forge: Any + Send + Sync {
fn repo_name(&self) -> String;
fn release_link_base_url(&self) -> Url;
fn compare_link_base_url(&self) -> Url;
fn default_branch(&self) -> String;
fn set_commit_search_depth(&mut self, depth: usize);
fn set_tag_search_depth(&mut self, depth: usize);
async fn load_config(&self, branch: Option<String>) -> Result<Config>;
async fn get_file_content(
&self,
req: GetFileContentRequest,
) -> Result<Option<String>>;
async fn get_release_by_tag(
&self,
tag: &str,
) -> Result<ReleaseByTagResponse>;
async fn create_release_branch(
&self,
req: CreateReleaseBranchRequest,
) -> Result<Commit>;
async fn create_commit(&self, req: CreateCommitRequest) -> Result<Commit>;
async fn tag_commit(&self, tag_name: &str, sha: &str) -> Result<()>;
async fn get_latest_tags_for_prefix(
&self,
prefix: &str,
branch: &str,
) -> Result<Vec<Tag>>;
async fn get_commits(
&self,
branch: Option<String>,
sha: Option<String>,
) -> Result<Vec<ForgeCommit>>;
async fn get_open_release_pr(
&self,
req: GetPrRequest,
) -> Result<Option<PullRequest>>;
async fn get_merged_release_pr(
&self,
req: GetPrRequest,
) -> Result<Option<PullRequest>>;
async fn create_pr(&self, req: CreatePrRequest) -> Result<PullRequest>;
async fn update_pr(&self, req: UpdatePrRequest) -> Result<()>;
async fn replace_pr_labels(&self, req: PrLabelsRequest) -> Result<()>;
async fn create_release(
&self,
tag: &str,
sha: &str,
notes: &str,
) -> Result<()>;
}
#[async_trait]
pub trait FileLoader: Send + Sync {
async fn load_file(
&self,
branch: Option<String>,
path: String,
) -> Result<Option<String>>;
}