Skip to content

refactor(command_executor): extract resolve_command_str helper - #2476

Merged
max-sixty merged 1 commit into
mainfrom
command-executor-dedup
Apr 29, 2026
Merged

max-sixty merged 1 commit into
mainfrom
command-executor-dedup

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

Lazy-template expansion was duplicated between run_one_command and run_concurrent_group in src/commands/command_executor.rs — both decoded context_json, looked up lazy_template, and called expand_shell_template with cmd.label. Extract a single helper:

fn resolve_command_str(cmd: &PreparedCommand, repo: &Repository) -> Result<String> {
    match &cmd.lazy_template {
        Some(template) => {
            let context: HashMap<String, String> = serde_json::from_str(&cmd.context_json)
                .context("failed to deserialize context_json")?;
            expand_shell_template(template, &context, repo, &cmd.label)
        }
        None => Ok(cmd.expanded.clone()),
    }
}

Returning String removes the lazy_expanded placeholder binding and avoids a Cow-vs-borrow split. The eager-path clone is cheap.

Lazy-template expansion now exists in exactly one place.

Test plan

  • cargo run -- hook pre-merge --yes (3395 tests pass, all lints green)

🤖 Generated with Claude Code

Lazy-template expansion was duplicated between `run_one_command` and
`run_concurrent_group` — both decoded `context_json`, looked up
`lazy_template`, and called `expand_shell_template` with `cmd.label`.
Collapse into a single helper that returns `String` (eager-path clone is
cheap; avoids a Cow split).

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 8d7d048 into main Apr 29, 2026
25 checks passed
@max-sixty
max-sixty deleted the command-executor-dedup branch April 29, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants