Skip to main content

chronicle/read/
mod.rs

1pub mod contracts;
2pub mod decisions;
3pub mod deps;
4pub mod history;
5pub mod lookup;
6pub(crate) mod matching;
7pub mod retrieve;
8pub mod sentiments;
9pub mod staleness;
10pub mod summary;
11
12use crate::error::{ChronicleError, Result};
13use crate::git::GitOps;
14use crate::schema::common::LineRange;
15use crate::schema::v3;
16
17/// Query parameters for reading annotations.
18#[derive(Debug, Clone)]
19pub struct ReadQuery {
20    pub file: String,
21    pub anchor: Option<String>,
22    pub lines: Option<LineRange>,
23}
24
25/// Result of a read query.
26#[derive(Debug, Clone, serde::Serialize)]
27pub struct ReadResult {
28    pub file: String,
29    pub annotations: Vec<MatchedAnnotation>,
30}
31
32/// A v3-native annotation matched to a specific commit.
33#[derive(Debug, Clone, serde::Serialize)]
34pub struct MatchedAnnotation {
35    pub commit: String,
36    pub timestamp: String,
37    pub summary: String,
38    #[serde(default, skip_serializing_if = "Vec::is_empty")]
39    pub wisdom: Vec<v3::WisdomEntry>,
40    pub provenance: String,
41}
42
43/// Execute a read query against the repository.
44pub fn execute(git: &dyn GitOps, query: &ReadQuery) -> Result<ReadResult> {
45    let annotations =
46        retrieve::retrieve_annotations(git, query).map_err(|e| ChronicleError::Git {
47            source: e,
48            location: snafu::Location::default(),
49        })?;
50
51    Ok(ReadResult {
52        file: query.file.clone(),
53        annotations,
54    })
55}