Skip to content

Commit 772561a

Browse files
committed
docs: add comprehensive documentation to public types
Add detailed doc comments with examples for: - CodeownersEntry: Parsed ownership rule structure - InlineCodeownersEntry: File-embedded ownership declarations - Owner: Owner representation with type classification - OwnerType: Classification enum for owner types - Tag: Metadata tag for categorization - OutputFormat: CLI output format enum - FileEntry: File with resolved ownership - CodeownersCache: Pre-computed cache structure
1 parent c42a912 commit 772561a

File tree

1 file changed

+92
-8
lines changed

1 file changed

+92
-8
lines changed

codeinput/src/core/types.rs

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,25 @@ fn normalize_codeowners_pattern(pattern: &str) -> String {
2020
}
2121
}
2222

23-
/// CODEOWNERS entry with source tracking
23+
/// A parsed CODEOWNERS entry representing a single ownership rule.
24+
///
25+
/// Each entry corresponds to a line in a CODEOWNERS file that defines
26+
/// which teams or individuals own files matching a specific pattern.
27+
///
28+
/// # Fields
29+
///
30+
/// * `source_file` - Path to the CODEOWNERS file containing this entry
31+
/// * `line_number` - Line number (0-indexed) where this entry appears
32+
/// * `pattern` - The glob pattern for matching files (e.g., `*.rs`, `/docs/`)
33+
/// * `owners` - List of owners assigned to files matching this pattern
34+
/// * `tags` - Optional metadata tags (e.g., `#backend`, `#critical`)
35+
///
36+
/// # Example
37+
///
38+
/// A CODEOWNERS line like `*.rs @rust-team #backend` would produce:
39+
/// - `pattern`: `"*.rs"`
40+
/// - `owners`: `[Owner { identifier: "@rust-team", owner_type: Team }]`
41+
/// - `tags`: `[Tag("backend")]`
2442
#[derive(Debug, Serialize, Deserialize)]
2543
pub struct CodeownersEntry {
2644
pub source_file: PathBuf,
@@ -30,7 +48,19 @@ pub struct CodeownersEntry {
3048
pub tags: Vec<Tag>,
3149
}
3250

33-
/// Inline CODEOWNERS entry for file-specific ownership
51+
/// An inline CODEOWNERS declaration embedded within a source file.
52+
///
53+
/// Inline declarations allow files to specify their own ownership using
54+
/// a special marker comment: `!!!CODEOWNERS @owner1 @owner2 #tag1`
55+
///
56+
/// This is useful when a specific file requires different ownership
57+
/// than what the main CODEOWNERS file would assign.
58+
///
59+
/// # Example
60+
///
61+
/// A Rust file containing `// !!!CODEOWNERS @security-team #critical` would
62+
/// produce an entry with the security team as owner regardless of the
63+
/// patterns in the root CODEOWNERS file.
3464
#[derive(Debug, Clone, Serialize, Deserialize)]
3565
pub struct InlineCodeownersEntry {
3666
pub file_path: PathBuf,
@@ -121,20 +151,39 @@ pub fn codeowners_entry_to_matcher(
121151
})
122152
}
123153

124-
/// Detailed owner representation
154+
/// Represents an owner of code files.
155+
///
156+
/// Owners can be GitHub users, teams, email addresses, or special markers
157+
/// indicating unowned files.
158+
///
159+
/// # Examples
160+
///
161+
/// * `@username` - A GitHub user (OwnerType::User)
162+
/// * `@org/team-name` - A GitHub team (OwnerType::Team)
163+
/// * `user@example.com` - An email address (OwnerType::Email)
164+
/// * `NOOWNER` - Explicitly unowned (OwnerType::Unowned)
125165
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
126166
pub struct Owner {
167+
/// The raw identifier string (e.g., "@rust-team", "dev@example.com")
127168
pub identifier: String,
169+
/// The classified type of this owner
128170
pub owner_type: OwnerType,
129171
}
130172

131-
/// Owner type classification
173+
/// Classification of owner types in CODEOWNERS files.
174+
///
175+
/// Used to distinguish between different forms of ownership identifiers.
132176
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
133177
pub enum OwnerType {
178+
/// A GitHub user (e.g., `@username`)
134179
User,
180+
/// A GitHub team (e.g., `@org/team-name`)
135181
Team,
182+
/// An email address (e.g., `user@example.com`)
136183
Email,
184+
/// Explicitly marked as unowned (NOOWNER keyword)
137185
Unowned,
186+
/// Could not determine the owner type
138187
Unknown,
139188
}
140189

@@ -150,14 +199,27 @@ impl std::fmt::Display for OwnerType {
150199
}
151200
}
152201

153-
/// Tag representation
202+
/// A metadata tag for categorizing code ownership rules.
203+
///
204+
/// Tags are optional annotations in CODEOWNERS entries prefixed with `#`.
205+
/// They can be used to categorize files by domain, criticality, or other attributes.
206+
///
207+
/// # Examples
208+
///
209+
/// * `#backend` - Backend service code
210+
/// * `#critical` - Security-critical files
211+
/// * `#frontend` - Frontend components
154212
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
155213
pub struct Tag(pub String);
156214

215+
/// Output format for CLI commands.
157216
#[derive(Clone, Debug, Eq, PartialEq)]
158217
pub enum OutputFormat {
218+
/// Human-readable text output (default)
159219
Text,
220+
/// JSON format for programmatic consumption
160221
Json,
222+
/// Binary format for efficient serialization
161223
Bincode,
162224
}
163225

@@ -172,22 +234,44 @@ impl std::fmt::Display for OutputFormat {
172234
}
173235

174236
// Cache related types
175-
/// File entry in the ownership cache
237+
238+
/// A file with its resolved ownership information.
239+
///
240+
/// This represents the final computed ownership for a specific file,
241+
/// combining rules from CODEOWNERS files and inline declarations.
176242
#[derive(Debug, Clone, Serialize, Deserialize)]
177243
pub struct FileEntry {
244+
/// Path to the file (relative to repository root)
178245
pub path: PathBuf,
246+
/// All owners assigned to this file
179247
pub owners: Vec<Owner>,
248+
/// All tags associated with this file
180249
pub tags: Vec<Tag>,
181250
}
182251

183-
/// Cache for storing parsed CODEOWNERS information
252+
/// Pre-computed cache of CODEOWNERS information for fast lookups.
253+
///
254+
/// The cache stores parsed CODEOWNERS rules, file ownership mappings,
255+
/// and reverse lookup indexes for efficient querying.
256+
///
257+
/// # Cache Invalidation
258+
///
259+
/// The cache is invalidated when the repository state changes, detected
260+
/// via the `hash` field which combines:
261+
/// - HEAD commit hash
262+
/// - Index/staging area state
263+
/// - Unstaged file changes (excluding cache files themselves)
184264
#[derive(Debug)]
185265
pub struct CodeownersCache {
266+
/// SHA-256 hash of the repository state for cache invalidation
186267
pub hash: [u8; 32],
268+
/// All parsed CODEOWNERS entries
187269
pub entries: Vec<CodeownersEntry>,
270+
/// All files with their resolved ownership
188271
pub files: Vec<FileEntry>,
189-
// Derived data for lookups
272+
/// Reverse lookup: owner → list of owned files
190273
pub owners_map: std::collections::HashMap<Owner, Vec<PathBuf>>,
274+
/// Reverse lookup: tag → list of tagged files
191275
pub tags_map: std::collections::HashMap<Tag, Vec<PathBuf>>,
192276
}
193277

0 commit comments

Comments
 (0)