Create PipelineRun in response to webhook triggers.

This commit is contained in:
Tom Alexander
2024-09-28 19:43:26 -04:00
parent b8444344c4
commit ed1e1c08d0
9 changed files with 345 additions and 125 deletions

View File

@@ -22,7 +22,9 @@ use self::crd_pipeline_run::PipelineRun;
use self::discovery::discover_matching_push_triggers;
use self::discovery::discover_webhook_bridge_config;
use self::gitea_client::GiteaClient;
use self::hook_push::HookPush;
use self::in_repo_config::InRepoConfig;
use self::kubernetes::run_pipelines;
use self::webhook::hook;
use self::webhook::verify_signature;
use kube::CustomResourceExt;
@@ -32,9 +34,10 @@ mod discovery;
mod gitea_client;
mod hook_push;
mod in_repo_config;
mod kubernetes;
mod webhook;
const EXAMPLE_PIPELINE_RUN: &'static str = include_str!("../example_pipeline_run.json");
const EXAMPLE_WEBHOOK_PAYLOAD: &'static str = include_str!("../example_webhook_payload.json");
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -59,7 +62,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.get_tree(
"talexander",
"webhook_bridge",
"6d3b9e9db82d7857baa114d89efcb1bf470f448d",
"b8444344c4821e87a894cd195f8bec39cd501f68",
)
.await?;
let in_repo_config = discover_webhook_bridge_config(&gitea, &repo_tree).await?;
@@ -67,14 +70,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
discover_matching_push_triggers(&gitea, &repo_tree, "refs/heads/main", &in_repo_config)
.await?;
// let jobs: Api<PipelineRun> = Api::namespaced(kubernetes_client, "lighthouse");
// let jobs: Api<PipelineRun> = Api::default_namespaced(kubernetes_client);
// tracing::info!("Using crd: {}", serde_json::to_string(&PipelineRun::crd())?);
let webhook_payload: HookPush = serde_json::from_str(EXAMPLE_WEBHOOK_PAYLOAD)?;
// let test_run: PipelineRun = serde_json::from_str(EXAMPLE_PIPELINE_RUN)?;
// let pp = PostParams::default();
// let created_run = jobs.create(&pp, &test_run).await?;
run_pipelines(webhook_payload, pipelines, kubernetes_client).await?;
// let app = Router::new()
// .route("/hook", post(hook))