Support optional URL prefix for hook URL

This commit is contained in:
Brian Tarricone 2023-09-15 23:39:47 -07:00
parent 3a2da3fba8
commit bddff51ab3
2 changed files with 15 additions and 2 deletions

View File

@ -16,6 +16,7 @@ pub struct RepoConfig {
pub struct Config {
pub bind_address: Option<String>,
pub bind_port: Option<u16>,
pub url_prefix: Option<String>,
#[serde(deserialize_with = "deser_user_id")]
pub user_id: OwnedUserId,
pub password: String,

View File

@ -161,8 +161,20 @@ async fn run() -> anyhow::Result<()> {
let matrix_client = matrix_connect(&config).await.context("Failed to connect to Matrix")?;
let gitlab = warp::path!("hooks" / "gitlab")
.and(warp::path::end())
let gitlab_root_path = if let Some(url_prefix) = config.url_prefix.as_ref() {
url_prefix.split('/').fold(warp::any().boxed(), |last, segment| {
if segment.is_empty() {
last
} else {
last.and(warp::path(segment.to_string())).boxed()
}
})
} else {
warp::any().boxed()
};
let gitlab = gitlab_root_path
.and(warp::path!("hooks" / "gitlab"))
.and(warp::post())
.and(warp::header::<String>("x-gitlab-token"))
.and(warp::body::json())