Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "repos"
version = "0.0.2"
version = "0.0.3"
edition = "2024"

[dependencies]
Expand Down
34 changes: 34 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -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";
}
4 changes: 2 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ pub fn get_default_branch(repo_path: &str) -> Result<String> {
}
}

// Final fallback to "main"
Ok("main".to_string())
// Final fallback to default branch
Ok(crate::constants::git::FALLBACK_BRANCH.to_string())
}
5 changes: 1 addition & 4 deletions src/github/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
4 changes: 2 additions & 2 deletions src/github/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod commands;
pub mod config;
pub mod constants;
pub mod git;
pub mod github;
pub mod runner;
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -20,7 +20,7 @@ enum Commands {
repos: Vec<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
Expand All @@ -41,11 +41,11 @@ enum Commands {
repos: Vec<String>,

/// 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
Expand Down Expand Up @@ -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
Expand All @@ -113,7 +113,7 @@ enum Commands {
repos: Vec<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
Expand All @@ -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
Expand Down
Loading