sourcehut-mirror-bridge/src/main.rs

47 lines
1.0 KiB
Rust

use anyhow::{anyhow, Result};
use serde::Deserialize;
use tiny_http::{Header, Server};
mod webhook;
fn default_bind() -> String {
"0.0.0.0:8000".to_string()
}
fn default_sourcehut_api() -> String {
"https://git.sr.ht/query".to_string()
}
#[derive(Deserialize, Debug)]
struct Config {
#[serde(default = "default_bind")]
bind: String,
#[serde(default = "default_sourcehut_api")]
sourcehut_api: String,
sourcehut_token: String,
gitea_api_base: String,
gitea_auth: String,
url: String,
repositories: String,
}
fn main() -> Result<()> {
let config = envy::prefixed("MIRROR_").from_env::<Config>()?;
// Set up webhooks via GQL API to sourcehut
let mut srht_api = webhook::SourceHutAPI::new(&config.sourcehut_api, &config.sourcehut_token);
srht_api.init_webhook(&config.url)?;
let server = Server::http(config.bind).map_err(|err| anyhow!(err))?;
let json = Header::from_bytes(&b"Content-Type"[..], &b"application/json"[..]).unwrap();
for request in server.incoming_requests() {}
Ok(())
}