diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-11-24 14:30:49 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-11-24 14:30:49 +0200 |
commit | 2b8d777f1039598335240bdac3f9c5f98e3d2cc6 (patch) | |
tree | 5c6c984bd857e5aadba20ca8d2abfb61d571e122 | |
parent | 9d20ba820c6cf10d902ab54dd6e7a8b5f730eebd (diff) | |
download | native-ci-simulation-2b8d777f1039598335240bdac3f9c5f98e3d2cc6.tar.gz |
trigger
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index 6a7ccd9..7ebac60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,13 +8,13 @@ use std::{ }; use axum::{ - extract::{self, State}, + extract::{Path, State}, http::StatusCode, response::IntoResponse, - routing::{get, post}, + routing::get, Json, Router, }; -use serde::{Deserialize, Serialize}; +use serde::Serialize; const SUCCESS: &str = "http://127.0.0.1:9000/succeeded"; const FAIL: &str = "http://127.0.0.1:9000/failed"; @@ -28,7 +28,7 @@ async fn main() { let app = Router::new() .route("/", get(go_away)) - .route("/runs", post(create_run)) + .route("/trigger/:commit", get(trigger_run)) .with_state(ci); axum::Server::bind(&"127.0.0.1:8000".parse().unwrap()) @@ -46,20 +46,15 @@ struct CiState { next: Arc<Mutex<usize>>, } -#[derive(Deserialize)] -struct Start { - commit: String, -} - #[derive(Serialize)] struct Run { id: String, commit: String, } -async fn create_run( +async fn trigger_run( State(ci): State<CiState>, - extract::Json(start): extract::Json<Start>, + Path(commit): Path<String>, ) -> (StatusCode, impl IntoResponse) { let mut next = ci.next.lock().expect("mutex was poisoned"); let id = *next; @@ -69,7 +64,7 @@ async fn create_run( StatusCode::CREATED, Json(Run { id: format!("{}", id), - commit: start.commit, + commit, }), ) } |