summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-05-15 15:27:33 +0100
committerJoe Carstairs <me@joeac.net>2026-05-15 15:27:33 +0100
commitf849de20bb3ef7a36a5806108d853c577609991e (patch)
treefd1e888d3d3bb8077483eed83bf9d2fcfb7c32dc /src/main.rs
parent2068342144fe093efba9b9ff080017d294da7b6d (diff)
can configure repositories, hello world response
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 2c4d073..215f9e6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,13 +1,36 @@
+use std::path::PathBuf;
+
+use dirs::config_dir;
+
#[macro_use] extern crate rocket;
mod config;
+use config::read_config;
+use rocket::{State, http::Status};
+
+use crate::config::Config;
+
+const BIN_NAME: &str = "build-joeac";
+
#[launch]
fn rocket() -> _ {
- rocket::build().mount("/", routes![index])
+ let config_path: PathBuf = config_dir().unwrap()
+ .join(BIN_NAME).join(BIN_NAME).with_added_extension("toml");
+ let config = read_config(&config_path).inspect_err(|err|
+ eprintln!("Failed to read config. Error: {}\nProceeding with defaults", err))
+ .unwrap_or(Config::default());
+
+ rocket::build().manage(config).mount("/", routes![index])
}
-#[get("/")]
-fn index() -> &'static str {
- "Hello, world!"
+#[get("/<remote_git_repo..>")]
+fn index(remote_git_repo: PathBuf, config: &State<Config>) -> (Status, String) {
+ match remote_git_repo.to_str() {
+ None => (Status::BadRequest, format!("Failed to convert request path to unicode: {:?}", remote_git_repo)),
+ Some(remote_git_repo) => match config.repositories.iter().find(|repo| repo.remote_git_repo.eq(remote_git_repo)) {
+ None => (Status::NotFound, format!("Remote git repository not configured: {remote_git_repo}")),
+ Some(repo) => (Status::Ok, format!("Matched! {:?}", repo))
+ }
+ }
}