From ba3934bc4759b53964db8e86fbce96043a9a9a42 Mon Sep 17 00:00:00 2001 From: nicos_backbase Date: Sat, 18 Oct 2025 07:11:03 +0200 Subject: [PATCH] refactor: consolidate github api --- src/commands/pr.rs | 4 ++-- src/github/api.rs | 9 +++++++-- src/github/mod.rs | 2 +- tests/github_api_tests.rs | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/commands/pr.rs b/src/commands/pr.rs index 636d609..c555a3b 100644 --- a/src/commands/pr.rs +++ b/src/commands/pr.rs @@ -70,7 +70,7 @@ impl Command for PrCommand { async move { ( repo.name.clone(), - github::create_pull_request(&repo, &pr_options).await, + github::create_pr_from_workspace(&repo, &pr_options).await, ) } }) @@ -88,7 +88,7 @@ impl Command for PrCommand { } } else { for repo in repositories { - match github::create_pull_request(&repo, &pr_options).await { + match github::create_pr_from_workspace(&repo, &pr_options).await { Ok(_) => successful += 1, Err(e) => { eprintln!( diff --git a/src/github/api.rs b/src/github/api.rs index 9febbb1..9eb6c28 100644 --- a/src/github/api.rs +++ b/src/github/api.rs @@ -9,8 +9,13 @@ use anyhow::Result; use colored::*; use uuid::Uuid; -/// Create a pull request for a repository -pub async fn create_pull_request(repo: &Repository, options: &PrOptions) -> Result<()> { +/// High-level function to create a PR from local changes +/// +/// This function encapsulates the entire pull request creation flow: +/// 1. Check for changes in the workspace +/// 2. Create branch, add, commit, and push changes +/// 3. Create GitHub PR via API +pub async fn create_pr_from_workspace(repo: &Repository, options: &PrOptions) -> Result<()> { let repo_path = repo.get_target_dir(); // Check if repository has changes diff --git a/src/github/mod.rs b/src/github/mod.rs index 9cffbe8..8e04970 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -6,7 +6,7 @@ pub mod client; pub mod types; // Re-export commonly used items for convenience -pub use api::create_pull_request; +pub use api::create_pr_from_workspace; pub use auth::GitHubAuth; pub use client::GitHubClient; pub use types::{PrOptions, PullRequestParams}; diff --git a/tests/github_api_tests.rs b/tests/github_api_tests.rs index ab57304..6cc75f1 100644 --- a/tests/github_api_tests.rs +++ b/tests/github_api_tests.rs @@ -1,7 +1,7 @@ //! GitHub API tests focusing on PR creation functionality use repos::config::Repository; -use repos::github::api::create_pull_request; +use repos::github::api::create_pr_from_workspace; use repos::github::types::PrOptions; use std::fs; use std::path::PathBuf; @@ -54,7 +54,7 @@ async fn test_create_pull_request_no_changes() { ); // Should succeed with no changes (just prints a message and returns Ok) - let result = create_pull_request(&repo, &options).await; + let result = create_pr_from_workspace(&repo, &options).await; assert!(result.is_ok()); }