diff options
Diffstat (limited to 'server/src/githook.rs')
| -rw-r--r-- | server/src/githook.rs | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/server/src/githook.rs b/server/src/githook.rs index 057ee47..f0e872a 100644 --- a/server/src/githook.rs +++ b/server/src/githook.rs @@ -6,7 +6,6 @@ use std::os::unix::net::UnixStream; use std::path::PathBuf; use tokio::io::{self, AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::task; -use users::get_current_username; mod fs_utils; mod git; @@ -33,11 +32,6 @@ impl fmt::Display for IoError { impl Error for IoError {} -async fn get_socket() -> Result<String, git::Error> { - let repo = git::Repository::new(PathBuf::from("."), true, None::<String>, None::<String>); - repo.config_get("eyeballs.socket").await -} - #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { let pre = match std::env::current_exe()? @@ -49,40 +43,41 @@ async fn main() -> Result<(), Box<dyn Error>> { _ => return Err(Box::<dyn Error>::from("Invalid hook executable name")), }; - let user = match get_current_username() { - Some(username) => match username.into_string() { - Ok(valid_username) => valid_username, - Err(_) => return Err(Box::<dyn Error>::from("Invalid username for current user")), - }, - None => { - return Err(Box::<dyn Error>::from( - "Unable to get username of current user", - )) - } - }; - let input = io::stdin(); let reader = BufReader::new(input); let mut lines = reader.lines(); let mut request = git_socket::GitHookRequest { pre, - user, receive: Vec::new(), }; + + let repo = git::Repository::new(PathBuf::from("."), true, None::<String>, None::<String>); + while let Some(line) = lines.next_line().await? { let data: Vec<&str> = line.split(' ').collect(); if data.len() == 3 { + let mut commiter: Option<String> = None; + if pre && data[1] != git::EMPTY { + match repo.get_commiter(data[1]).await { + Ok(user) => { + commiter = Some(user.username); + } + Err(_) => {} + } + } + request.receive.push(git_socket::GitReceive { old_value: data[0].to_string(), new_value: data[1].to_string(), reference: data[2].to_string(), + commiter: commiter, }) } } - let socket = PathBuf::from(get_socket().await?); + let socket = PathBuf::from(repo.config_get("eyeballs.socket").await?); let response = task::spawn_blocking(move || { let stream = UnixStream::connect(socket).map_err(|e| IoError::new(e.to_string()))?; |
