Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 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 apps/native/src-tauri/src/commands/summarize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn finalize_restore(

/// Generates a commit message from the current semantic change map via the pipeline.
#[tauri::command]
pub async fn generate_commit_message(app: AppHandle) -> Result<String, String> {
pub async fn generate_commit_message(app: AppHandle) -> Result<Option<String>, String> {
crate::summarize::pipelines::commit_message::generate(&app)
.await
.map_err(|e| capture_err("generate_commit_message", e))
Expand Down
50 changes: 48 additions & 2 deletions apps/native/src-tauri/src/summarize/pipelines/commit_message.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
//! Commit message pipeline — returns the stored whole-diff summary when available.

use crate::summarize::find_existing::FoundSetForCurrent;
use anyhow::Result;
use tauri::{AppHandle, Runtime};

pub async fn generate<R: Runtime>(app: &AppHandle<R>) -> Result<String> {
pub async fn generate<R: Runtime>(app: &AppHandle<R>) -> Result<Option<String>> {
let base_ref = crate::summarize::active_summary_base_ref(app);
let change_sets = crate::summarize::found_change_sets_since(app, &base_ref)?;

Ok(stored_generated_commit_message(&change_sets))
}

fn stored_generated_commit_message(change_sets: &[FoundSetForCurrent]) -> Option<String> {
change_sets
.iter()
.find_map(|entry| {
Expand All @@ -17,5 +22,46 @@ pub async fn generate<R: Runtime>(app: &AppHandle<R>) -> Result<String> {
.filter(|message| !message.trim().is_empty())
})
.map(str::to_string)
.ok_or_else(|| anyhow::anyhow!("no generated commit message found"))
}

#[cfg(test)]
mod tests {
use super::*;
use crate::sqlite_types::ChangeSet;

fn found_with_message(generated_commit_message: Option<&str>) -> FoundSetForCurrent {
FoundSetForCurrent {
change_set: Some(ChangeSet {
id: 1,
commit_id: None,
base_commit_id: 1,
commit_message: None,
generated_commit_message: generated_commit_message.map(str::to_string),
created_at: 0,
evolution_id: None,
}),
changes: vec![],
missed_hashes: vec![],
}
}

#[test]
fn missing_generated_commit_message_is_expected_absence() {
let change_sets = vec![found_with_message(None), found_with_message(Some(" "))];

assert_eq!(stored_generated_commit_message(&change_sets), None);
}

#[test]
fn returns_first_non_empty_generated_commit_message() {
let change_sets = vec![
found_with_message(None),
found_with_message(Some("feat(nix): update shell packages")),
];

assert_eq!(
stored_generated_commit_message(&change_sets).as_deref(),
Some("feat(nix): update shell packages"),
);
}
}
Loading
Loading