aptu_core/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2
3#![warn(missing_docs)]
4
5//! # Aptu Core
6//!
7//! Core library for the Aptu CLI - AI-powered OSS issue triage.
8//!
9//! This crate provides reusable components for:
10//! - GitHub API integration (authentication, issues, GraphQL)
11//! - AI-assisted issue triage via `OpenRouter`
12//! - Configuration management
13//! - Contribution history tracking
14//! - Curated repository discovery
15//!
16//! ## Quick Start
17//!
18//! ```rust,no_run
19//! use aptu_core::{load_config, AiClient, IssueDetails, ai::AiProvider};
20//! use anyhow::Result;
21//!
22//! # async fn example() -> Result<()> {
23//! // Load configuration
24//! let config = load_config()?;
25//!
26//! // Create AI client (reuse for multiple requests)
27//! let client = AiClient::new(&config.ai.provider, &config.ai)?;
28//!
29//! // Create issue details
30//! let issue = IssueDetails::builder()
31//! .owner("block".to_string())
32//! .repo("goose".to_string())
33//! .number(123)
34//! .title("Example issue".to_string())
35//! .body("Issue description...".to_string())
36//! .labels(vec![])
37//! .comments(vec![])
38//! .url("https://github.com/block/goose/issues/123".to_string())
39//! .build();
40//!
41//! // Analyze with AI
42//! let ai_response = client.analyze_issue(&issue).await?;
43//! println!("Summary: {}", ai_response.triage.summary);
44//! # Ok(())
45//! # }
46//! ```
47//!
48//! ## Modules
49//!
50//! - [`ai`] - AI integration (`OpenRouter` API, triage analysis)
51//! - [`config`] - Configuration loading and paths
52//! - [`error`] - Error types
53//! - [`github`] - GitHub API (auth, issues, GraphQL)
54//! - [`history`] - Contribution history tracking
55//! - [`repos`] - Curated repository list
56
57// ============================================================================
58// Authentication
59// ============================================================================
60
61pub use auth::TokenProvider;
62
63// ============================================================================
64// Error Handling
65// ============================================================================
66
67pub use error::AptuError;
68
69/// Convenience Result type for Aptu operations.
70///
71/// This is equivalent to `std::result::Result<T, AptuError>`.
72pub type Result<T> = std::result::Result<T, AptuError>;
73
74// ============================================================================
75// Configuration
76// ============================================================================
77
78pub use config::{
79 AiConfig, AppConfig, CacheConfig, GitHubConfig, UiConfig, UserConfig, config_dir,
80 config_file_path, data_dir, load_config,
81};
82
83// ============================================================================
84// Caching
85// ============================================================================
86
87pub use cache::CacheEntry;
88
89// ============================================================================
90// AI Triage
91// ============================================================================
92
93pub use ai::types::{
94 IssueComment, IssueDetails, PrDetails, PrFile, PrReviewResponse, ReviewEvent, TriageResponse,
95};
96pub use ai::{
97 AiClient, AiModel, ModelInfo, ModelProvider, ProviderConfig, all_providers, get_provider,
98};
99
100// ============================================================================
101// GitHub Integration
102// ============================================================================
103
104pub use github::auth::TokenSource;
105pub use github::graphql::IssueNode;
106pub use github::ratelimit::{RateLimitStatus, check_rate_limit};
107pub use octocrab::params::State;
108
109// ============================================================================
110// AI Integration
111// ============================================================================
112
113pub use ai::types::CreditsStatus;
114
115// ============================================================================
116// History Tracking
117// ============================================================================
118
119pub use history::{Contribution, ContributionStatus, HistoryData};
120
121// ============================================================================
122// Repository Discovery
123// ============================================================================
124
125pub use repos::{CuratedRepo, RepoFilter};
126
127// ============================================================================
128// Triage Detection
129// ============================================================================
130
131pub use triage::{APTU_SIGNATURE, TriageStatus, check_already_triaged};
132
133// ============================================================================
134// Retry Logic
135// ============================================================================
136
137pub use retry::{is_retryable_anyhow, is_retryable_http, retry_backoff};
138
139// ============================================================================
140// Utilities
141// ============================================================================
142
143pub use utils::{
144 format_relative_time, parse_and_format_relative_time, truncate, truncate_with_suffix,
145};
146
147// ============================================================================
148// Platform-Agnostic Facade
149// ============================================================================
150
151pub use facade::{
152 add_custom_repo, analyze_issue, fetch_issues, label_pr, list_curated_repos, list_repos,
153 post_pr_review, remove_custom_repo, review_pr,
154};
155
156// ============================================================================
157// Modules
158// ============================================================================
159
160pub mod ai;
161pub mod auth;
162pub mod cache;
163pub mod config;
164pub mod error;
165pub mod facade;
166pub mod github;
167pub mod history;
168pub mod repos;
169pub mod retry;
170pub mod triage;
171pub mod utils;