Add parsing of the in-repo config file format.

This commit is contained in:
Tom Alexander
2024-09-28 14:29:18 -04:00
parent 201709c360
commit c32a8650f5
5 changed files with 119 additions and 15 deletions

31
src/in_repo_config.rs Normal file
View File

@@ -0,0 +1,31 @@
use serde::Deserialize;
use serde::Serialize;
/// The webhook_bridge.toml file that lives inside repos that have their CI triggered by webhook_bridge.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct InRepoConfig {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) version: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) push: Vec<TriggerPush>,
}
/// A config for a job that is triggered by a push to a git repo.
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct TriggerPush {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) source: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) clone_uri: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) branches: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) skip_branches: Vec<String>,
}

View File

@@ -20,6 +20,7 @@ use tracing_subscriber::util::SubscriberInitExt;
use self::crd_pipeline_run::PipelineRun;
use self::gitea_client::GiteaClient;
use self::in_repo_config::InRepoConfig;
use self::webhook::hook;
use self::webhook::verify_signature;
use kube::CustomResourceExt;
@@ -27,9 +28,11 @@ use kube::CustomResourceExt;
mod crd_pipeline_run;
mod gitea_client;
mod hook_push;
mod in_repo_config;
mod webhook;
const EXAMPLE_PIPELINE_RUN: &'static str = include_str!("../example_pipeline_run.json");
const TEST_IN_REPO_CONFIG: &'static str = include_str!("../.webhook_bridge/webhook_bridge.toml");
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -50,13 +53,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let gitea_api_token = std::env::var("WEBHOOK_BRIDGE_OAUTH_TOKEN")?;
let gitea = GiteaClient::new(gitea_api_root, gitea_api_token);
gitea
.get_tree(
"talexander",
"organic",
"841a348dd02f31ee8828f069b2a948712369069d",
)
.await?;
// gitea
// .get_tree(
// "talexander",
// "organic",
// "841a348dd02f31ee8828f069b2a948712369069d",
// )
// .await?;
let parsed_in_repo_config: InRepoConfig = toml::from_str(TEST_IN_REPO_CONFIG)?;
// let jobs: Api<PipelineRun> = Api::namespaced(kubernetes_client, "lighthouse");
// let jobs: Api<PipelineRun> = Api::default_namespaced(kubernetes_client);