Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: flatten part of config struct #1154

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 21 additions & 50 deletions crates/release_plz/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ pub struct Workspace {
/// These options also affect the `release-plz release-pr` command.
#[serde(flatten)]
pub update: UpdateConfig,
#[serde(flatten)]
pub release_pr: ReleasePrConfig,
/// # PR Draft
/// If `true`, the created release PR will be marked as a draft.
#[serde(default)]
pub pr_draft: bool,
/// # PR Labels
/// Labels to add to the release PR.
#[serde(default)]
pub pr_labels: Vec<String>,
#[serde(flatten)]
pub common: CommonCmdConfig,
/// Configuration applied to all packages by default.
Expand Down Expand Up @@ -138,20 +144,6 @@ pub struct UpdateConfig {
pub allow_dirty: Option<bool>,
}

/// Configuration for the `release-pr` command.
/// Generical for the whole workspace. Cannot be customized on a per-package basic.
#[derive(Serialize, Deserialize, Default, PartialEq, Eq, Debug, JsonSchema)]
pub struct ReleasePrConfig {
/// # PR Draft
/// If `true`, the created release PR will be marked as a draft.
#[serde(default)]
pub pr_draft: bool,
/// # PR Labels
/// Labels to add to the release PR.
#[serde(default)]
pub pr_labels: Vec<String>,
}

/// Config at the `[[package]]` level.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, JsonSchema)]
pub struct PackageSpecificConfig {
Expand Down Expand Up @@ -208,7 +200,7 @@ impl From<PackageReleaseConfig> for release_plz_core::ReleaseConfig {
let is_publish_enabled = value.release.publish != Some(false);
let is_git_release_enabled = value.git_release.enable != Some(false);
let is_git_release_draft = value.git_release.draft == Some(true);
let is_git_tag_enabled = value.git_tag.enable != Some(false);
let is_git_tag_enabled = value.git_tag_enable != Some(false);
let mut cfg = Self::default()
.with_publish(release_plz_core::PublishConfig::enabled(is_publish_enabled))
.with_git_release(
Expand Down Expand Up @@ -285,8 +277,10 @@ pub struct PackageReleaseConfig {
/// Configuration for the GitHub/Gitea/GitLab release.
#[serde(flatten, default)]
pub git_release: GitReleaseConfig,
#[serde(flatten, default)]
pub git_tag: GitTagConfig,
/// # Git Tag Enable
/// Publish the git tag for the new package version.
/// Enabled by default.
pub git_tag_enable: Option<bool>,
#[serde(flatten, default)]
pub release: ReleaseConfig,
}
Expand All @@ -297,7 +291,7 @@ impl PackageReleaseConfig {
Self {
git_release: self.git_release.merge(default.git_release),
release: self.release.merge(default.release),
git_tag: self.git_tag.merge(default.git_tag),
git_tag_enable: self.git_tag_enable.or(default.git_tag_enable),
}
}
}
Expand Down Expand Up @@ -340,23 +334,6 @@ pub enum SemverCheck {
No,
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Default, JsonSchema)]
pub struct GitTagConfig {
/// # Git Tag Enable
/// Publish the git tag for the new package version.
/// Enabled by default.
#[serde(rename = "git_tag_enable")]
enable: Option<bool>,
}

impl GitTagConfig {
pub fn merge(self, default: GitTagConfig) -> Self {
Self {
enable: self.enable.or(default.enable),
}
}
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Default, JsonSchema)]
pub struct GitReleaseConfig {
/// # Git Release Enable
Expand Down Expand Up @@ -444,10 +421,8 @@ mod tests {
..Default::default()
},
},
release_pr: ReleasePrConfig {
pr_draft: false,
pr_labels: vec![],
},
pr_draft: false,
pr_labels: vec![],
publish_timeout: Some("10m".to_string()),
},
package: [].into(),
Expand Down Expand Up @@ -482,10 +457,8 @@ mod tests {
common: CommonCmdConfig {
repo_url: Some("https://github.com/MarcoIeni/release-plz".parse().unwrap()),
},
release_pr: ReleasePrConfig {
pr_draft: false,
pr_labels: vec![],
},
pr_draft: false,
pr_labels: vec![],
packages_defaults: PackageConfig {
update: PackageUpdateConfig {
semver_check: None,
Expand All @@ -497,7 +470,7 @@ mod tests {
release_type: Some(ReleaseType::Prod),
draft: Some(false),
},
git_tag: GitTagConfig { enable: None },
git_tag_enable: None,
release: ReleaseConfig {
publish: None,
allow_dirty: None,
Expand Down Expand Up @@ -526,10 +499,8 @@ mod tests {
common: CommonCmdConfig {
repo_url: Some("https://github.com/MarcoIeni/release-plz".parse().unwrap()),
},
release_pr: ReleasePrConfig {
pr_draft: false,
pr_labels: vec!["label1".to_string()],
},
pr_draft: false,
pr_labels: vec!["label1".to_string()],
packages_defaults: PackageConfig {
update: PackageUpdateConfig {
semver_check: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/release_plz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ async fn run(args: CliArgs) -> anyhow::Result<()> {
}
Command::ReleasePr(cmd_args) => {
let config = cmd_args.update.config()?;
let pr_labels = config.workspace.release_pr.pr_labels.clone();
let pr_draft = config.workspace.release_pr.pr_draft;
let pr_labels = config.workspace.pr_labels.clone();
let pr_draft = config.workspace.pr_draft;
let update_request = cmd_args.update.update_request(config)?;
let repo_url = update_request
.repo_url()
Expand Down