feat: make Tag event filter take a regular expression

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2025-04-04 11:42:11 +03:00
parent b783ef65d7
commit a7d02c18c4
3 changed files with 32 additions and 9 deletions
+1 -1
View File
@@ -943,7 +943,7 @@ adapters:
triggers:
- adapter: default
filters:
- !Tag "v1.0"
- !Tag "v\\d+(\\.\\d+)"
~~~
## Filter predicate `Branch`
+22 -8
View File
@@ -1,10 +1,11 @@
use std::path::{Path, PathBuf};
use regex::Regex;
use serde::{Deserialize, Serialize};
use radicle::{
cob::patch::PatchId,
git::{raw::ObjectType, BranchName, Oid, RefString},
git::{raw::ObjectType, BranchName, Oid},
node::NodeId,
prelude::{Profile, RepoId},
storage::git::Repository,
@@ -55,8 +56,8 @@ pub enum EventFilter {
/// Event is for a specific branch.
Branch(BranchName),
/// Event is for a specific tag.
Tag(RefString),
/// Event is for a tag whose name matches a regular expression.
Tag(String),
/// Event if for the default branch for the repository.
DefaultBranch,
@@ -155,11 +156,24 @@ impl EventFilter {
format!("wanted={wanted} actual={actual:?}"),
)
}
Self::Tag(wanted) => {
let actual = event.tag();
let allowed = Some(wanted) == actual;
Decision::string("Tag", allowed, format!("wanted={wanted} actual={actual:?}"))
}
Self::Tag(wanted) => match Regex::new(wanted) {
Ok(re) => {
let actual = event.tag();
let allowed = match &actual {
Some(actual) => re.is_match_at(actual.as_str(), 0),
_ => false,
};
Decision::string(
"Tag",
allowed,
format!("wanted={wanted:?} actual={actual:?}"),
)
}
Err(err) => {
logger::queueproc_filter_regex_error(wanted, err);
Decision::new("Tag", false, "regex syntax error")
}
},
Self::DefaultBranch => {
let repo = event.repository();
let actual = event.branch();
+9
View File
@@ -444,6 +444,15 @@ pub fn queueproc_queue_length(len: usize) {
);
}
pub fn queueproc_filter_regex_error(pattern: &str, err: regex::Error) {
warn!(
msg_id = ?Id::QueueProcFilterDecision,
kind = %Kind::FilterDecision,
?pattern,
?err,
"regular expression syntax error");
}
pub fn queueproc_filter_decision(event: &CiEvent, filter: &EventFilter, allowed: bool) {
info!(
msg_id = ?Id::QueueProcFilterDecision,