use clap::{Args, Subcommand};
#[derive(Args, Debug)]
#[command(
about = "Retroactive maintenance operations on existing commit rows.",
long_about = "Re-run extraction or scoring steps on commits already in the database.\n\n\
These operations update existing rows in-place rather than ingesting new data.\n\
Each subcommand supports --dry-run to preview changes without writing.\n\n\
NOTE: --branch is collect-only. Commits in the DB do not carry branch\n\
attribution after the walk, so there is no branch filter on backfill operations.\n\
If you need to re-walk specific branches, use `tga collect --branch <name>`.\n\n\
TIPS:\n\
- Use --repos to limit scope to one service at a time on large corpora.\n\
- Use --since/--until or --weeks to limit the date window for fast iteration.",
after_help = "EXAMPLES:\n\
# Re-extract ticket IDs for all commits (after pattern change)\n\
tga backfill ticket-ids\n\n\
# Re-score effort for the last 4 weeks of one repo\n\
tga backfill effort --repos my-service --weeks 4 --force\n\n\
# Re-run reachability scan after adding release-branch patterns\n\
tga backfill reachability --repos core-api"
)]
pub struct BackfillArgs {
#[command(subcommand)]
pub subcommand: BackfillSubcommand,
#[arg(long, default_value_t = false, global = true)]
pub dry_run: bool,
#[arg(long, value_delimiter = ',', global = true)]
pub repos: Vec<String>,
#[arg(long, value_name = "N", global = true, conflicts_with_all = ["since", "until"])]
pub weeks: Option<u32>,
#[arg(long, value_name = "DATE", global = true, conflicts_with = "weeks")]
pub since: Option<String>,
#[arg(long, value_name = "DATE", global = true, conflicts_with = "weeks")]
pub until: Option<String>,
}
#[derive(Subcommand, Debug)]
pub enum BackfillSubcommand {
AiDetection,
RevertFlags,
TicketIds,
Reachability,
Effort(EffortBackfillArgs),
Complexity(ComplexityBackfillArgs),
Ticketed,
AiDetectionCommits,
TopLevel,
EffortTshirt,
Quality,
}
#[derive(Args, Debug)]
pub struct ComplexityBackfillArgs {
#[arg(long, default_value_t = false)]
pub use_llm: bool,
}
#[derive(Args, Debug)]
pub struct EffortBackfillArgs {
#[arg(long, value_name = "RANGE")]
pub range: Option<String>,
#[arg(long, default_value_t = false)]
pub force: bool,
#[arg(long, default_value_t = false)]
pub notes: bool,
#[arg(long, value_name = "N")]
pub limit: Option<usize>,
}
pub(super) struct EffortRow {
pub sha: String,
pub repository: String,
pub size: String,
pub score: f64,
pub loc: u32,
pub files: u32,
pub test_loc: u32,
pub tests_factor: f64,
pub formula_version: String,
pub computed_at: i64,
#[allow(dead_code)]
pub effort_tshirt: i64,
}