pub mod github;
pub mod gitlab;
pub mod gitea;
pub mod phabricator;
pub mod custom;
use std::collections::HashMap;
use color_eyre::Result;
use crate::core::config::Config;
use crate::core::stack::PatchEntry;
use crate::git::ops::Repo;
pub trait Forge {
fn submit(
&self, repo: &Repo, hash: &str, subject: &str,
base: &str, body: &str,
) -> Result<String>;
fn update(
&self, repo: &Repo, hash: &str, subject: &str, base: &str,
) -> Result<String>;
fn list_open(&self, repo: &Repo) -> (HashMap<String, u32>, bool);
fn edit_base(&self, repo: &Repo, branch: &str, base: &str) -> bool;
fn mark_submitted(&self, repo: &Repo, patches: &mut [PatchEntry]);
fn sync(
&self, repo: &Repo, patches: &[PatchEntry],
on_progress: &dyn Fn(&str),
) -> Result<Vec<String>>;
fn needs_description_editor(&self) -> bool { true }
fn get_trailers(&self, _body: &str) -> Vec<String> { Vec::new() }
fn fix_dependencies(&self, _repo: &Repo) -> Result<()> { Ok(()) }
fn find_landed_branches(&self, _repo: &Repo, _branches: &[String]) -> Vec<String> {
Vec::new()
}
fn name(&self) -> &str;
}
pub fn create_forge(config: &Config) -> Box<dyn Forge> {
match config.forge.forge_type.as_str() {
"github" => Box::new(github::GitHub),
"gitlab" => Box::new(gitlab::GitLab),
"gitea" => Box::new(gitea::Gitea),
"phabricator" => Box::new(phabricator::Phabricator),
"custom" => Box::new(custom::Custom::new(
config.forge.submit_cmd.clone().unwrap_or_default(),
)),
_ => Box::new(github::GitHub),
}
}