diff --git a/Cargo.toml b/Cargo.toml index c6badcc..2f60b4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "repos" -version = "0.0.2" +version = "0.0.3" edition = "2024" [dependencies] diff --git a/src/constants.rs b/src/constants.rs new file mode 100644 index 0000000..a4fc2c2 --- /dev/null +++ b/src/constants.rs @@ -0,0 +1,34 @@ +//! Central constants for the repos application + +/// Default values for Git operations +pub mod git { + /// Default fallback branch name when unable to determine repository default branch + pub const FALLBACK_BRANCH: &str = "main"; + + /// Default commit message when none is provided + pub const DEFAULT_COMMIT_MSG: &str = "Automated changes"; +} + +/// Default values for GitHub operations +pub mod github { + /// Default prefix for automated branch names + pub const DEFAULT_BRANCH_PREFIX: &str = "automated-changes"; + + /// Length of UUID suffix used in branch names + pub const UUID_LENGTH: usize = 6; + + /// GitHub API base URL + pub const API_BASE: &str = "https://api.github.com"; + + /// Default User-Agent header for API requests + pub const DEFAULT_USER_AGENT: &str = concat!("repos/", env!("CARGO_PKG_VERSION")); +} + +/// Default values for configuration +pub mod config { + /// Default configuration file name + pub const DEFAULT_CONFIG_FILE: &str = "config.yaml"; + + /// Default logs directory + pub const DEFAULT_LOGS_DIR: &str = "logs"; +} diff --git a/src/git.rs b/src/git.rs index aaf0133..8441f19 100644 --- a/src/git.rs +++ b/src/git.rs @@ -211,6 +211,6 @@ pub fn get_default_branch(repo_path: &str) -> Result { } } - // Final fallback to "main" - Ok("main".to_string()) + // Final fallback to default branch + Ok(crate::constants::git::FALLBACK_BRANCH.to_string()) } diff --git a/src/github/api.rs b/src/github/api.rs index 378a6ab..41d55ae 100644 --- a/src/github/api.rs +++ b/src/github/api.rs @@ -3,15 +3,12 @@ use super::client::GitHubClient; use super::types::{PrOptions, PullRequestParams}; use crate::config::Repository; +use crate::constants::github::{DEFAULT_BRANCH_PREFIX, UUID_LENGTH}; use crate::git; use anyhow::Result; use colored::*; use uuid::Uuid; -// Constants for maintainability -const DEFAULT_BRANCH_PREFIX: &str = "automated-changes"; -const UUID_LENGTH: usize = 6; - /// Create a pull request for a repository pub async fn create_pull_request(repo: &Repository, options: &PrOptions) -> Result<()> { let repo_path = repo.get_target_dir(); diff --git a/src/github/mod.rs b/src/github/mod.rs index a9c488b..9cffbe8 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -10,3 +10,6 @@ pub use api::create_pull_request; pub use auth::GitHubAuth; pub use client::GitHubClient; pub use types::{PrOptions, PullRequestParams}; + +// Re-export constants for easy access +pub use crate::constants::github::{DEFAULT_BRANCH_PREFIX, DEFAULT_USER_AGENT}; diff --git a/src/github/types.rs b/src/github/types.rs index b83d7f0..59e5489 100644 --- a/src/github/types.rs +++ b/src/github/types.rs @@ -146,6 +146,6 @@ pub struct PullRequest { /// Constants for GitHub API pub mod constants { - pub const GITHUB_API_BASE: &str = "https://api.github.com"; - pub const DEFAULT_USER_AGENT: &str = "repos/0.1.0"; + // Re-export from centralized constants + pub use crate::constants::github::{API_BASE as GITHUB_API_BASE, DEFAULT_USER_AGENT}; } diff --git a/src/lib.rs b/src/lib.rs index 9734eb6..c1a1b25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ pub mod commands; pub mod config; +pub mod constants; pub mod git; pub mod github; pub mod runner; diff --git a/src/main.rs b/src/main.rs index 910c5b8..2218f38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::{Parser, Subcommand}; -use repos::{commands::*, config::Config}; +use repos::{commands::*, config::Config, constants}; use std::env; #[derive(Parser)] @@ -20,7 +20,7 @@ enum Commands { repos: Vec, /// Configuration file path - #[arg(short, long, default_value = "config.yaml")] + #[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())] config: String, /// Filter repositories by tag @@ -41,11 +41,11 @@ enum Commands { repos: Vec, /// Directory to store log files - #[arg(short, long, default_value = "logs")] + #[arg(short, long, default_value_t = constants::config::DEFAULT_LOGS_DIR.to_string())] logs: String, /// Configuration file path - #[arg(short, long, default_value = "config.yaml")] + #[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())] config: String, /// Filter repositories by tag @@ -95,7 +95,7 @@ enum Commands { create_only: bool, /// Configuration file path - #[arg(short, long, default_value = "config.yaml")] + #[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())] config: String, /// Filter repositories by tag @@ -113,7 +113,7 @@ enum Commands { repos: Vec, /// Configuration file path - #[arg(short, long, default_value = "config.yaml")] + #[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())] config: String, /// Filter repositories by tag @@ -128,7 +128,7 @@ enum Commands { /// Create a config.yaml file from discovered Git repositories Init { /// Output file name - #[arg(short, long, default_value = "config.yaml")] + #[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())] output: String, /// Overwrite existing file if it exists