Compare commits

..

No commits in common. "add-full-featured-filters" and "main" have entirely different histories.

3 changed files with 14 additions and 38 deletions

View file

@ -96,8 +96,8 @@ default_remotes:
additional_remotes: additional_remotes:
- "git@git.sr.ht:~user" - "git@git.sr.ht:~user"
filters: blacklist:
- FIXME: - "private-.*"
``` ```
- `default_remotes` is a list of remotes to use if no `.lohr` file is found in a - `default_remotes` is a list of remotes to use if no `.lohr` file is found in a

View file

@ -34,15 +34,12 @@ fn gitea_webhook(
config: State<GlobalSettings>, config: State<GlobalSettings>,
) -> Status { ) -> Status {
if config if config
.filters .blacklist
.iter() .iter()
// Find first filter that matches the given destination .any(|re| re.is_match(&payload.repository.full_name))
.find(|filter| filter.destination.as_ref().map_or(false, |re| re.is_match(&payload.repository.full_name)))
// Default to mirroring, unless told not to
.map_or(true, |filter| filter.mirror)
{ {
info!( info!(
"Ignoring webhook for repo {} which is marked as not mirrored", "Ignoring webhook for repo {} which is blacklisted",
payload.repository.full_name payload.repository.full_name
); );
return Status::Ok; return Status::Ok;

View file

@ -10,29 +10,8 @@ pub(crate) struct GlobalSettings {
/// List of remote stems to use for every repository /// List of remote stems to use for every repository
#[serde(default)] #[serde(default)]
pub additional_remotes: Vec<RepoUrl>, pub additional_remotes: Vec<RepoUrl>,
/// List of filters to blacklist repositories, or modify push options on specific remotes. /// List of regexes, if a repository's name matches any of the, it is not mirrored by `lohr`
/// Only the first matching filter is applied, so order is important. /// even if it contains a `.lorh` file.
#[serde(default)]
pub filters: Vec<FilterSettings>,
}
#[derive(Clone, Default, Deserialize)]
pub(crate) struct FilterSettings {
/// Match on the source remote
#[serde(with = "serde_regex", default)] #[serde(with = "serde_regex", default)]
pub source: Option<regex::Regex>, pub blacklist: Vec<regex::Regex>,
/// Match on the destination remote
#[serde(with = "serde_regex", default)]
pub destination: Option<regex::Regex>,
/// Whether to mirror the repository or not
#[serde(default = "default_true")]
pub mirror: bool,
/// Push options to be used for the matched remote
#[serde(default)]
pub push_options: Vec<String>,
}
// Workaround for https://github.com/serde-rs/serde/issues/368
fn default_true() -> bool {
true
} }