Problem: The logic for interacting with the GitHub API is split between api.rs and the PrCommand in pr.rs. The command orchestrates git operations and then calls the API.
Suggestion: Encapsulate the entire "create a pull request" flow (including git operations like branch creation, commit, and push) into a single high-level function within the github module, for example, github::create_pr_from_workspace().
Minimal Change Example:
Create a new high-level function in api.rs:
// ...existing code...
/// High-level function to create a PR from local changes
pub async fn create_pr_from_workspace(repo: &Repository, options: &PrOptions) -> Result<()> {
// 1. Check for changes
if !git::has_changes(&repo.get_target_dir())? {
// ... print no changes and return
return Ok(());
}
// 2. Create branch, add, commit, push (move logic from PrCommand::execute)
// ...
// 3. Create GitHub PR
create_github_pr(repo, &branch_name, options).await?;
Ok(())
}
// ...existing code...
The PrCommand::execute method would then become much simpler, primarily responsible for iterating through repositories and calling this new function.
Problem: The logic for interacting with the GitHub API is split between
api.rsand thePrCommandinpr.rs. The command orchestrates git operations and then calls the API.Suggestion: Encapsulate the entire "create a pull request" flow (including git operations like branch creation, commit, and push) into a single high-level function within the
githubmodule, for example,github::create_pr_from_workspace().Minimal Change Example:
Create a new high-level function in
api.rs:The
PrCommand::executemethod would then become much simpler, primarily responsible for iterating through repositories and calling this new function.