Skip to content

Consolidate GitHub API logic #21

@codcod

Description

@codcod

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorA code change (src or test) that neither fixes a bug nor adds a feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions