From 0b0efb83ec621ab3a6aeb5d055c69cce3e9d4011 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Mon, 13 May 2024 11:19:17 +0800 Subject: [PATCH] feat: make email optional in coauthor --- buildit-utils/src/lib.rs | 8 ++------ server/src/bot.rs | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/buildit-utils/src/lib.rs b/buildit-utils/src/lib.rs index 9df169d..32fefb0 100644 --- a/buildit-utils/src/lib.rs +++ b/buildit-utils/src/lib.rs @@ -42,8 +42,7 @@ pub struct FindUpdate { pub async fn find_update_and_update_checksum( pkg: &str, abbs_path: &Path, - user_name: &str, - user_email: &str, + coauthor: &str, ) -> anyhow::Result { let _lock = ABBS_REPO_LOCK.lock().await; @@ -139,10 +138,7 @@ pub async fn find_update_and_update_checksum( Command::new("git") .arg("commit") .arg("-m") - .arg(format!( - "{}\n\nCo-authored-by: {} <{}>", - title, user_name, user_email - )) + .arg(format!("{}\n\nCo-authored-by: {}", title, coauthor)) .current_dir(&abbs_path) .output() .context("Creating git commit")?; diff --git a/server/src/bot.rs b/server/src/bot.rs index 442936a..297dd0a 100644 --- a/server/src/bot.rs +++ b/server/src/bot.rs @@ -726,20 +726,19 @@ pub async fn answer(bot: Bot, msg: Message, cmd: Command, pool: DbPool) -> Respo } }; - match find_update_and_update_checksum( - &package, - &ARGS.abbs_path, - user.github_login - .as_ref() - .map(|s| s.as_str()) - .unwrap_or("Unknown"), - user.github_email - .as_ref() - .map(|s| s.as_str()) - .unwrap_or("unknown@unknown.com"), - ) - .await - { + let mut coauthor_parts = vec![]; + if let Some(name) = &user.github_name { + coauthor_parts.push(name.clone()); + } + if let Some(login) = &user.github_login { + coauthor_parts.push(format!("(@{})", login)); + } + if let Some(email) = &user.github_email { + coauthor_parts.push(format!("<{}>", email)); + } + let coauthor = coauthor_parts.join(" "); + + match find_update_and_update_checksum(&package, &ARGS.abbs_path, &coauthor).await { Ok(f) => { match buildit_utils::github::open_pr( app_private_key,