diff --git a/script-meta-v2.json b/script-meta-v2.json index 336ec04..f0eab74 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -138,11 +138,11 @@ }, "sync.rs": { "script_name": "sync.rs", - "script_length": 1978, - "script_sha256": "2218487f955e8021c2e4b5b56b9aa4bec6cde89839ae45449bb852c5696cb72e", + "script_length": 2973, + "script_sha256": "a94a20258431e8dd7534e1078f9894de799a220f99b993ba9f2e56dc760804ea", "script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/sync-rs/src/main.rs", "publish_time": 1737272563310, - "update_time": 1750428425867 + "update_time": 1775318648698 }, "xattr.rs": { "script_name": "xattr.rs", diff --git a/script-meta.json b/script-meta.json index 13e4341..49938a4 100644 --- a/script-meta.json +++ b/script-meta.json @@ -81,8 +81,8 @@ }, "sync-rs": { "script_name": "sync-rs", - "script_length": 1978, - "script_sha256": "2218487f955e8021c2e4b5b56b9aa4bec6cde89839ae45449bb852c5696cb72e" + "script_length": 2973, + "script_sha256": "a94a20258431e8dd7534e1078f9894de799a220f99b993ba9f2e56dc760804ea" }, "xattr-rs": { "script_name": "xattr-rs", diff --git a/sync-rs/src/main.rs b/sync-rs/src/main.rs old mode 100644 new mode 100755 index 85cbfe3..e3cbc01 --- a/sync-rs/src/main.rs +++ b/sync-rs/src/main.rs @@ -9,7 +9,7 @@ use std::env; use std::path::PathBuf; use std::process::Command; -use rust_util::{failure_and_exit, information, success, warning}; +use rust_util::{failure, failure_and_exit, information, success, warning}; fn main() -> Result<(), Box> { if let Some(args_1) = env::args().nth(1) { @@ -27,7 +27,29 @@ fn main() -> Result<(), Box> { information!("Git Add All"); Command::new("git").args(&["add", "."]).spawn()?.wait()?; information!("Git Commit All"); - Command::new("git").args(&["commit", "-a", "-m", "'auto sync'"]).spawn()?.wait()?; + information!("AI summarizing..."); + let ai_summarize_output = Command::new("sh") + .args(&["-c", r##"xh --ignore-stdin https://hatter.ink/ai/commit-summarize.json -f "Authorization:Bearer $(get-secret.ts --id ai-commit-summarize-token)" gitStatus="$(git status)" gitDiff="$(git diff)" | jq .data.summary -r"##]) + .output()?; + let mut message = "auto sync".to_string(); + information!("{:?}", ai_summarize_output); + if ai_summarize_output.status.success() { + if let Ok(summarized_message) = String::from_utf8(ai_summarize_output.stdout) { + success!("AI summarized message: {}", summarized_message); + message = summarized_message; + } else { + warning!("AI summarized message is not UTF-8"); + } + } else { + failure!( + "AI summarize failed, status: {}", + ai_summarize_output.status + ); + } + Command::new("git") + .args(&["commit", "-a", "-m", &message]) + .spawn()? + .wait()?; information!("Git Push"); Command::new("git").args(&["push"]).spawn()?.wait()?; information!("Sync Server Repo"); @@ -52,11 +74,15 @@ pub fn find_parents_exists_dir(dir: &str) -> Option { match PathBuf::from(".").canonicalize() { Err(_) => None, Ok(mut path) => loop { - if path.join(dir).is_dir() { return Some(path); } - if !path.pop() { return None; } - } + if path.join(dir).is_dir() { + return Some(path); + } + if !path.pop() { + return None; + } + }, } } -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250620T220543+08:00.MEUCIHsFQ1sf53x3ATTLFkMQ -// oUau9y550grtnm7yGglEoDI/AiEAgZcouLIJXHP042IFnhkTljMo67O9Cs6MlpvNT+BzOA8= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260405T000314+08:00.MEYCIQCOflkXKihoc6wfiGml +// TObfzEuzkqKg3yEfU+swKk7aJgIhALHUGopxnHNXjSoWziiQt9U1xb8qGpamrsHdd20nrTjx