From f6da9d6b9ffcdb8a4a30d7d9f28dd37b4afb143c Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 28 Dec 2022 10:00:59 +0000 Subject: ci_webserver: allow status urls to include prefixes of full commit hashes --- src/main.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 71b9a04..a96c5e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,22 +168,18 @@ async fn handle_commit_status(Path(path): Path<(String, String, String)>, State( let remote_path = format!("{}/{}", path.0, path.1); let sha = path.2; - let commit_id: Option = if sha.len() >= 7 { - ctx.conn.lock().unwrap() - .query_row("select id from commits where sha like ?1;", [&format!("{}%", sha)], |row| row.get(0)) + let (commit_id, sha): (u64, String) = if sha.len() >= 7 { + match ctx.conn.lock().unwrap() + .query_row("select id, sha from commits where sha like ?1;", [&format!("{}%", sha)], |row| Ok((row.get_unwrap(0), row.get_unwrap(1)))) .optional() - .expect("can query") - } else { - None - }; - - let commit_id: u64 = match commit_id { - Some(commit_id) => { - commit_id - }, - None => { - return (StatusCode::NOT_FOUND, Html("no such commit".to_string())); + .expect("can query") { + Some((commit_id, sha)) => (commit_id, sha), + None => { + return (StatusCode::NOT_FOUND, Html("no such commit".to_string())); + } } + } else { + return (StatusCode::NOT_FOUND, Html("no such commit".to_string())); }; let (remote_id, repo_id): (u64, u64) = ctx.conn.lock().unwrap() -- cgit v1.1