add commit logging

This commit is contained in:
Pakin 2026-04-28 11:43:03 +07:00
parent 5bb2a6c192
commit bca1c911d3

View file

@ -370,7 +370,7 @@ struct CommitBody {
extra: HashMap<String, Value>, extra: HashMap<String, Value>,
} }
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
struct Signature { struct Signature {
username: String, username: String,
email: String, email: String,
@ -459,6 +459,8 @@ async fn commit_handler(
} }
} }
info!("committing ...");
// Validate required fields // Validate required fields
let path = match path { let path = match path {
Some(p) => p, Some(p) => p,
@ -470,6 +472,8 @@ async fn commit_handler(
} }
}; };
info!("path: [{path}]");
let signature_username = match signature_username { let signature_username = match signature_username {
Some(su) => su, Some(su) => su,
None => { None => {
@ -506,6 +510,8 @@ async fn commit_handler(
email: signature_email, email: signature_email,
}; };
info!("sig: {signature:?}");
// Get branch name from config // Get branch name from config
let branch = state let branch = state
.clone() .clone()
@ -533,14 +539,22 @@ async fn commit_handler(
} }
}; };
info!("commit success! [{commit_oid}]");
// save history // save history
let redis_pre_lock = state.redis.clone(); let redis_pre_lock = state.redis.clone();
{ {
if let Ok(mut rl) = redis_pre_lock.get().await { if let Ok(mut rl) = redis_pre_lock.get().await {
let _ = rl.rpush( match rl
format!("{}.history", path), .rpush(
format!("commit-{}", commit_oid), format!("{}.history", path),
); format!("commit-{}", commit_oid),
)
.await
{
Ok(_) => info!("history saved"),
Err(e) => error!("save history fail: {e:?}"),
}
} }
} }
@ -881,10 +895,10 @@ fn pull(
rlock.set_head(&refname)?; rlock.set_head(&refname)?;
rlock.checkout_head(Some(git2::build::CheckoutBuilder::default().force()))?; rlock.checkout_head(Some(git2::build::CheckoutBuilder::default().force()))?;
info!("Fast-forwared to {}", fetch_commit.id()); info!("Fast-forwared to {}", fetch_commit.id());
} else if analysis.0.is_normal() { } else if analysis.0.is_up_to_date() {
warn!("need manual merge");
} else {
info!("already up to date"); info!("already up to date");
} else {
return Err("cannot fast-forward, local changes would be overwritten".into());
} }
return Ok(()); return Ok(());