WIP: migrate to full featured filter list

I don't like the fact that ordering is significant, given that we would
be processing this filter list in multiple places...
This commit is contained in:
Bruno BELANYI 2021-04-18 13:36:42 +00:00
parent d942dc1098
commit efbfc3f4a0
3 changed files with 39 additions and 15 deletions

View file

@ -96,8 +96,8 @@ default_remotes:
additional_remotes: additional_remotes:
- "git@git.sr.ht:~user" - "git@git.sr.ht:~user"
blacklist: filters:
- "private-.*" - FIXME:
``` ```
- `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,12 +34,15 @@ fn gitea_webhook(
config: State<GlobalSettings>, config: State<GlobalSettings>,
) -> Status { ) -> Status {
if config if config
.blacklist .filters
.iter() .iter()
.any(|re| re.is_match(&payload.repository.full_name)) // Find first filter that matches the given destination
.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 blacklisted", "Ignoring webhook for repo {} which is marked as not mirrored",
payload.repository.full_name payload.repository.full_name
); );
return Status::Ok; return Status::Ok;

View file

@ -10,8 +10,29 @@ 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 regexes, if a repository's name matches any of the, it is not mirrored by `lohr` /// List of filters to blacklist repositories, or modify push options on specific remotes.
/// even if it contains a `.lorh` file. /// Only the first matching filter is applied, so order is important.
#[serde(with = "serde_regex", default)] #[serde(default)]
pub blacklist: Vec<regex::Regex>, pub filters: Vec<FilterSettings>,
}
#[derive(Clone, Default, Deserialize)]
pub(crate) struct FilterSettings {
/// Match on the source remote
#[serde(with = "serde_regex", default)]
pub source: Option<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
} }