Skip to content

Commit

Permalink
Add serde deny_unknown_fields to Config
Browse files Browse the repository at this point in the history
This adds deny_unknown_fields to Config so that any typo mistakes
will be caught by the config validation.
  • Loading branch information
ehuss committed Jan 22, 2024
1 parent 11aecef commit 522cfb1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lazy_static::lazy_static! {

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(deny_unknown_fields)]
pub(crate) struct Config {
pub(crate) relabel: Option<RelabelConfig>,
pub(crate) assign: Option<AssignConfig>,
Expand All @@ -38,6 +39,7 @@ pub(crate) struct Config {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct NominateConfig {
// team name -> label
pub(crate) teams: HashMap<String, String>,
Expand Down Expand Up @@ -68,6 +70,7 @@ impl PingConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct PingTeamConfig {
pub(crate) message: String,
#[serde(default)]
Expand All @@ -76,6 +79,7 @@ pub(crate) struct PingTeamConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct AssignConfig {
/// If `true`, then posts a warning comment if the PR is opened against a
/// different branch than the default (usually master or main).
Expand Down Expand Up @@ -105,6 +109,7 @@ impl AssignConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct NoMergesConfig {
/// No action will be taken on PRs with these substrings in the title.
#[serde(default)]
Expand All @@ -121,6 +126,7 @@ pub(crate) struct NoMergesConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct NoteConfig {
#[serde(default)]
_empty: (),
Expand All @@ -133,6 +139,7 @@ pub(crate) struct MentionsConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct MentionsPathConfig {
pub(crate) message: Option<String>,
#[serde(default)]
Expand All @@ -141,18 +148,21 @@ pub(crate) struct MentionsPathConfig {

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(deny_unknown_fields)]
pub(crate) struct RelabelConfig {
#[serde(default)]
pub(crate) allow_unauthenticated: Vec<String>,
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct ShortcutConfig {
#[serde(default)]
_empty: (),
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct PrioritizeConfig {
pub(crate) label: String,
}
Expand All @@ -176,6 +186,7 @@ impl AutolabelConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct AutolabelLabelConfig {
#[serde(default)]
pub(crate) trigger_labels: Vec<String>,
Expand All @@ -196,6 +207,7 @@ pub(crate) struct NotifyZulipConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct NotifyZulipLabelConfig {
pub(crate) zulip_stream: u64,
pub(crate) topic: String,
Expand All @@ -208,6 +220,7 @@ pub(crate) struct NotifyZulipLabelConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct MajorChangeConfig {
/// A username (typically a group, e.g. T-lang) to ping on Zulip for newly
/// opened proposals.
Expand Down Expand Up @@ -243,18 +256,22 @@ impl MajorChangeConfig {
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct GlacierConfig {}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct CloseConfig {}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct ReviewSubmittedConfig {
pub(crate) review_labels: Vec<String>,
pub(crate) reviewed_label: String,
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct ReviewRequestedConfig {
pub(crate) remove_labels: Vec<String>,
pub(crate) add_labels: Vec<String>,
Expand All @@ -280,6 +297,7 @@ pub(crate) async fn get(

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(deny_unknown_fields)]
pub(crate) struct GitHubReleasesConfig {
pub(crate) format: ChangelogFormat,
pub(crate) project_name: String,
Expand Down

0 comments on commit 522cfb1

Please sign in to comment.