mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-10-18 19:30:29 +08:00
feat: make Tag event filter take a regular expression
Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
+1
-1
@@ -943,7 +943,7 @@ adapters:
|
||||
triggers:
|
||||
- adapter: default
|
||||
filters:
|
||||
- !Tag "v1.0"
|
||||
- !Tag "v\\d+(\\.\\d+)"
|
||||
~~~
|
||||
|
||||
## Filter predicate `Branch`
|
||||
|
||||
+22
-8
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user