Skip to content

Commit 009209b

Browse files
author
nicos_backbase
committed
chore: extract constants
1 parent 5c754cc commit 009209b

File tree

8 files changed

+51
-16
lines changed

8 files changed

+51
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "repos"
3-
version = "0.0.2"
3+
version = "0.0.3"
44
edition = "2024"
55

66
[dependencies]

src/constants.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Central constants for the repos application
2+
3+
/// Default values for Git operations
4+
pub mod git {
5+
/// Default fallback branch name when unable to determine repository default branch
6+
pub const FALLBACK_BRANCH: &str = "main";
7+
8+
/// Default commit message when none is provided
9+
pub const DEFAULT_COMMIT_MSG: &str = "Automated changes";
10+
}
11+
12+
/// Default values for GitHub operations
13+
pub mod github {
14+
/// Default prefix for automated branch names
15+
pub const DEFAULT_BRANCH_PREFIX: &str = "automated-changes";
16+
17+
/// Length of UUID suffix used in branch names
18+
pub const UUID_LENGTH: usize = 6;
19+
20+
/// GitHub API base URL
21+
pub const API_BASE: &str = "https://api.github.com";
22+
23+
/// Default User-Agent header for API requests
24+
pub const DEFAULT_USER_AGENT: &str = concat!("repos/", env!("CARGO_PKG_VERSION"));
25+
}
26+
27+
/// Default values for configuration
28+
pub mod config {
29+
/// Default configuration file name
30+
pub const DEFAULT_CONFIG_FILE: &str = "config.yaml";
31+
32+
/// Default logs directory
33+
pub const DEFAULT_LOGS_DIR: &str = "logs";
34+
}

src/git.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,6 @@ pub fn get_default_branch(repo_path: &str) -> Result<String> {
211211
}
212212
}
213213

214-
// Final fallback to "main"
215-
Ok("main".to_string())
214+
// Final fallback to default branch
215+
Ok(crate::constants::git::FALLBACK_BRANCH.to_string())
216216
}

src/github/api.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
use super::client::GitHubClient;
44
use super::types::{PrOptions, PullRequestParams};
55
use crate::config::Repository;
6+
use crate::constants::github::{DEFAULT_BRANCH_PREFIX, UUID_LENGTH};
67
use crate::git;
78
use anyhow::Result;
89
use colored::*;
910
use uuid::Uuid;
1011

11-
// Constants for maintainability
12-
const DEFAULT_BRANCH_PREFIX: &str = "automated-changes";
13-
const UUID_LENGTH: usize = 6;
14-
1512
/// Create a pull request for a repository
1613
pub async fn create_pull_request(repo: &Repository, options: &PrOptions) -> Result<()> {
1714
let repo_path = repo.get_target_dir();

src/github/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ pub use api::create_pull_request;
1010
pub use auth::GitHubAuth;
1111
pub use client::GitHubClient;
1212
pub use types::{PrOptions, PullRequestParams};
13+
14+
// Re-export constants for easy access
15+
pub use crate::constants::github::{DEFAULT_BRANCH_PREFIX, DEFAULT_USER_AGENT};

src/github/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ pub struct PullRequest {
146146

147147
/// Constants for GitHub API
148148
pub mod constants {
149-
pub const GITHUB_API_BASE: &str = "https://api.github.com";
150-
pub const DEFAULT_USER_AGENT: &str = "repos/0.1.0";
149+
// Re-export from centralized constants
150+
pub use crate::constants::github::{API_BASE as GITHUB_API_BASE, DEFAULT_USER_AGENT};
151151
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub mod commands;
44
pub mod config;
5+
pub mod constants;
56
pub mod git;
67
pub mod github;
78
pub mod runner;

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use clap::{Parser, Subcommand};
3-
use repos::{commands::*, config::Config};
3+
use repos::{commands::*, config::Config, constants};
44
use std::env;
55

66
#[derive(Parser)]
@@ -20,7 +20,7 @@ enum Commands {
2020
repos: Vec<String>,
2121

2222
/// Configuration file path
23-
#[arg(short, long, default_value = "config.yaml")]
23+
#[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())]
2424
config: String,
2525

2626
/// Filter repositories by tag
@@ -41,11 +41,11 @@ enum Commands {
4141
repos: Vec<String>,
4242

4343
/// Directory to store log files
44-
#[arg(short, long, default_value = "logs")]
44+
#[arg(short, long, default_value_t = constants::config::DEFAULT_LOGS_DIR.to_string())]
4545
logs: String,
4646

4747
/// Configuration file path
48-
#[arg(short, long, default_value = "config.yaml")]
48+
#[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())]
4949
config: String,
5050

5151
/// Filter repositories by tag
@@ -95,7 +95,7 @@ enum Commands {
9595
create_only: bool,
9696

9797
/// Configuration file path
98-
#[arg(short, long, default_value = "config.yaml")]
98+
#[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())]
9999
config: String,
100100

101101
/// Filter repositories by tag
@@ -113,7 +113,7 @@ enum Commands {
113113
repos: Vec<String>,
114114

115115
/// Configuration file path
116-
#[arg(short, long, default_value = "config.yaml")]
116+
#[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())]
117117
config: String,
118118

119119
/// Filter repositories by tag
@@ -128,7 +128,7 @@ enum Commands {
128128
/// Create a config.yaml file from discovered Git repositories
129129
Init {
130130
/// Output file name
131-
#[arg(short, long, default_value = "config.yaml")]
131+
#[arg(short, long, default_value_t = constants::config::DEFAULT_CONFIG_FILE.to_string())]
132132
output: String,
133133

134134
/// Overwrite existing file if it exists

0 commit comments

Comments
 (0)