fix: use configured branch names in user notification

Remove near-duplicate to string implementations.
This commit is contained in:
Paul Campbell 2024-09-01 08:38:08 +01:00
parent 853b862f10
commit 4160b6d6ee
2 changed files with 33 additions and 29 deletions

View file

@ -30,34 +30,8 @@ impl Actor for AlertsActor {
} }
fn short_message(user_notification: &UserNotification) -> String { fn short_message(user_notification: &UserNotification) -> String {
let tail = match user_notification { let (forge_alias, repo_alias) = user_notification.aliases();
UserNotification::CICheckFailed { format!("[git-next] {forge_alias}/{repo_alias}: {user_notification}")
forge_alias,
repo_alias,
commit,
log: _,
} => format!("{forge_alias}/{repo_alias}: CI Check Failed: {commit}"),
UserNotification::RepoConfigLoadFailure {
forge_alias,
repo_alias,
reason: _,
} => format!("{forge_alias}/{repo_alias}: Invalid Repo Config"),
UserNotification::WebhookRegistration {
forge_alias,
repo_alias,
reason: _,
} => format!("{forge_alias}/{repo_alias}: Failed Webhook Registration"),
UserNotification::DevNotBasedOnMain {
forge_alias,
repo_alias,
dev_branch: _,
main_branch: _,
dev_commit: _,
main_commit: _,
log: _,
} => format!("{forge_alias}/{repo_alias}: Dev not based on Main"),
};
format!("[git-next] {tail}")
} }
fn full_message(user_notification: &UserNotification) -> String { fn full_message(user_notification: &UserNotification) -> String {

View file

@ -116,6 +116,32 @@ impl UserNotification {
}), }),
} }
} }
#[must_use]
pub fn aliases(&self) -> (ForgeAlias, RepoAlias) {
match self {
Self::CICheckFailed {
forge_alias,
repo_alias,
..
}
| Self::RepoConfigLoadFailure {
forge_alias,
repo_alias,
..
}
| Self::WebhookRegistration {
forge_alias,
repo_alias,
..
}
| Self::DevNotBasedOnMain {
forge_alias,
repo_alias,
..
} => (forge_alias.clone(), repo_alias.clone()),
}
}
} }
impl Display for UserNotification { impl Display for UserNotification {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@ -127,7 +153,11 @@ impl Display for UserNotification {
Self::WebhookRegistration { reason, .. } => { Self::WebhookRegistration { reason, .. } => {
format!("Failed to register webhook: {reason}") format!("Failed to register webhook: {reason}")
} }
Self::DevNotBasedOnMain { .. } => "Dev not based on main".to_string(), Self::DevNotBasedOnMain {
dev_branch,
main_branch,
..
} => format!("{dev_branch} not based on {main_branch}"),
}; };
write!(f, "{message}") write!(f, "{message}")
} }