git_workspace/providers/
mod.rs

1mod gitea;
2mod github;
3mod gitlab;
4
5use crate::repository::Repository;
6use anyhow::Context;
7pub use gitea::GiteaProvider;
8pub use github::GithubProvider;
9pub use gitlab::GitlabProvider;
10use std::fmt;
11
12pub static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
13
14pub trait Provider: fmt::Display {
15    /// Returns true if the provider should work, otherwise prints an error and return false
16    fn correctly_configured(&self) -> bool;
17    fn fetch_repositories(&self) -> anyhow::Result<Vec<Repository>>;
18}
19
20pub fn create_exclude_regex_set(items: &Vec<String>) -> anyhow::Result<regex::RegexSet> {
21    if items.is_empty() {
22        Ok(regex::RegexSet::empty())
23    } else {
24        Ok(regex::RegexSet::new(items).context("Error parsing exclude regular expressions")?)
25    }
26}
27
28pub fn create_include_regex_set(items: &Vec<String>) -> anyhow::Result<regex::RegexSet> {
29    if items.is_empty() {
30        let all = vec![".*"];
31        Ok(regex::RegexSet::new(all).context("Error parsing include regular expressions")?)
32    } else {
33        Ok(regex::RegexSet::new(items).context("Error parsing include regular expressions")?)
34    }
35}