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

Prompt user to "config migrate" during init process #1409

Merged
merged 6 commits into from
Feb 19, 2025
Merged
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
42 changes: 41 additions & 1 deletion qlty-cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use dialoguer::Confirm;
use duct::cmd;
use itertools::Itertools;
use num_format::{Locale, ToFormattedString};
use qlty_config::Workspace;
use qlty_config::{MigrateConfig, MigrationSettings, Workspace};
use std::io::Write;
use tabwriter::TabWriter;

const CLASSIC_CONFIG_NAME: &str = ".codeclimate.yml";

#[derive(Args, Debug)]
pub struct Init {
/// Answer yes to all prompts
Expand Down Expand Up @@ -106,6 +108,11 @@ impl Init {
self.print_enabled_plugins(&initializer)?;
}

// For now, this feature does not work for dry runs
if !self.dry_run {
self.maybe_migrate_config()?;
}

if !self.skip_plugins {
self.plugins_post_init(&initializer)?;
}
Expand Down Expand Up @@ -269,4 +276,37 @@ impl Init {
let current_exe = std::env::current_exe()?;
Ok(current_exe)
}

fn maybe_migrate_config(&self) -> Result<()> {
let workspace = Workspace::new()?;
let classic_config_path = workspace.root.join(CLASSIC_CONFIG_NAME);

if classic_config_path.exists()
&& !self.no
&& (self.yes
|| self.prompt_yes_no(
"Would you like to migrate your .codeclimate.yml configuration?",
)?)
{
let migration_settings = MigrationSettings::new(
&workspace.root,
workspace.config()?,
&workspace.config_path()?,
&classic_config_path,
self.dry_run,
)?;

MigrateConfig::new(migration_settings)?.migrate()?;
self.print_check("Migrated .codeclimate.yml configuration");
}
Ok(())
}

fn prompt_yes_no(&self, prompt: &str) -> Result<bool> {
Ok(Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(prompt)
.default(true)
.show_default(true)
.interact()?)
}
}
Loading