summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <git@iximeow.net>2022-12-28 10:00:59 +0000
committeriximeow <git@iximeow.net>2022-12-28 10:00:59 +0000
commitf6da9d6b9ffcdb8a4a30d7d9f28dd37b4afb143c (patch)
treec91f1645dcd0f8dfb49d1942441b06203772b544 /src
parent2903c0696ff1851cf6598bff456c30b9f64529a6 (diff)
ci_webserver: allow status urls to include prefixes of full commit hashes
Diffstat (limited to 'src')
-rw-r--r--src/main.rs24
1 files changed, 10 insertions, 14 deletions
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<u64> = 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("<html><body>no such commit</body></html>".to_string()));
+ .expect("can query") {
+ Some((commit_id, sha)) => (commit_id, sha),
+ None => {
+ return (StatusCode::NOT_FOUND, Html("<html><body>no such commit</body></html>".to_string()));
+ }
}
+ } else {
+ return (StatusCode::NOT_FOUND, Html("<html><body>no such commit</body></html>".to_string()));
};
let (remote_id, repo_id): (u64, u64) = ctx.conn.lock().unwrap()