convert hand-written enum as_str matches to strum derives workspace-wide

This commit is contained in:
damocles 2026-09-11 21:06:54 +02:00
commit 299add158f
14 changed files with 70 additions and 113 deletions

View file

@ -74,6 +74,7 @@ hive-types.workspace = true
reqwest = { workspace = true, features = ["blocking"] }
serde.workspace = true
serde_json.workspace = true
strum.workspace = true
swarm-authelia-bridge-sock.workspace = true
# The queue connect (token mint + auth callback + reconnect) is shared with
# every other participant - a hive publishing its own status runs the same

View file

@ -167,11 +167,13 @@ fn hex_decode(s: &str) -> Option<Vec<u8>> {
/// registration we made* instead of by a field the sender chooses. Each
/// registered hook gets its own `target_url`, exactly as the per-hive hooks
/// do today.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, strum::IntoStaticStr, strum::EnumString)]
pub(super) enum DeliveryKind {
/// Push events on the hive-wide knowledge repo.
#[strum(serialize = "knowledge")]
Knowledge,
/// `pull_request` events on the agent-config repos.
#[strum(serialize = "config-pr")]
ConfigPr,
/// `push` events on every repo in the instance — see
/// `crate::vcs_metrics`'s doc comment for why this exists as its own
@ -179,6 +181,7 @@ pub(super) enum DeliveryKind {
/// hook: that one is repo-scoped to the knowledge repo alone, and this
/// one is instance-wide (registered via `admin_create_hook`, not
/// `repo_create_hook`) — different scope, same event name.
#[strum(serialize = "vcs-activity")]
VcsActivity,
}
@ -219,14 +222,12 @@ impl DeliveryKind {
/// Parse the `{kind}` path segment. Unknown values are rejected rather
/// than accepted-and-ignored: a typo in a registered `target_url` must
/// be *observable*, and a 200 for an unrecognised path is exactly the
/// silence this issue exists to remove.
/// silence this issue exists to remove. Derived (`strum::EnumString`,
/// the same per-variant `#[strum(serialize = "...")]` spellings
/// `as_str` uses) rather than a hand-written match kept in sync with
/// that one by hand.
fn parse(segment: &str) -> Option<Self> {
match segment {
"knowledge" => Some(Self::Knowledge),
"config-pr" => Some(Self::ConfigPr),
"vcs-activity" => Some(Self::VcsActivity),
_ => None,
}
segment.parse().ok()
}
/// Stable string form, used for logging. Deliberately the same spelling
@ -238,11 +239,7 @@ impl DeliveryKind {
/// addressed to the hives that need it; which hook a delivery arrived on
/// is an input to deriving it, not the thing sent.
fn as_str(self) -> &'static str {
match self {
Self::Knowledge => "knowledge",
Self::ConfigPr => "config-pr",
Self::VcsActivity => "vcs-activity",
}
self.into()
}
}