Add parsing of the in-repo config file format.
This commit is contained in:
parent
201709c360
commit
c32a8650f5
19
.webhook_bridge/webhook_bridge.toml
Normal file
19
.webhook_bridge/webhook_bridge.toml
Normal file
@ -0,0 +1,19 @@
|
||||
version = "0.0.1"
|
||||
|
||||
[[push]]
|
||||
name = "rust-test"
|
||||
source = "pipeline-rust-test.yaml"
|
||||
clone_uri = "git@code.fizz.buzz:talexander/webhook_bridge.git"
|
||||
branches = [ "^main$", "^master$" ]
|
||||
|
||||
[[push]]
|
||||
name = "clippy"
|
||||
source = "pipeline-rust-clippy.yaml"
|
||||
clone_uri = "git@code.fizz.buzz:talexander/webhook_bridge.git"
|
||||
skip_branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
||||
|
||||
[[push]]
|
||||
name = "format"
|
||||
source = "pipeline-format.yaml"
|
||||
clone_uri = "git@code.fizz.buzz:talexander/webhook_bridge.git"
|
||||
skip_branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
57
Cargo.lock
generated
57
Cargo.lock
generated
@ -805,9 +805,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.2.6"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
||||
checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown",
|
||||
@ -1717,6 +1717,15 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
@ -2001,6 +2010,40 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.8.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.4.13"
|
||||
@ -2299,6 +2342,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"tokio",
|
||||
"toml",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
@ -2465,6 +2509,15 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.52.0"
|
||||
|
@ -7,7 +7,7 @@ description = "Trigger tekton jobs with gitea webhooks."
|
||||
license = "0BSD"
|
||||
repository = "https://code.fizz.buzz/talexander/webhook_bridge"
|
||||
readme = "README.md"
|
||||
keywords = ["tekton", "gitea", "webhook"]
|
||||
keywords = ["gitea", "webhook"]
|
||||
categories = ["development-tools"]
|
||||
resolver = "2"
|
||||
include = [
|
||||
@ -18,25 +18,21 @@ include = [
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
# default form, http1, json, matched-path, original-uri, query, tokio, tower-log, tracing
|
||||
axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "http2", "json"] }
|
||||
base64 = "0.22.1"
|
||||
hmac = "0.12.1"
|
||||
http-body-util = "0.1.2"
|
||||
k8s-openapi = { version = "0.22.0", default-features = false, features = ["v1_30"] }
|
||||
# default client, config, rustls-tls
|
||||
kube = { version = "0.92.1", default-features = false, features = ["client", "config", "rustls-tls", "derive", "runtime"] }
|
||||
reqwest = "0.12.5"
|
||||
schemars = "0.8.21"
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
# default std
|
||||
serde_json = { version = "1.0.120", default-features = false, features = ["std"] }
|
||||
sha2 = "0.10.8"
|
||||
tokio = { version = "1.38.0", default-features = false, features = ["macros", "process", "rt-multi-thread", "signal"] }
|
||||
toml = { version = "0.8.19", default-features = false, features = ["display", "parse"] }
|
||||
tower-http = { version = "0.5.2", default-features = false, features = ["trace", "timeout"] }
|
||||
# default attributes, std, tracing-attributes
|
||||
tracing = { version = "0.1.40", default-features = false, features = ["attributes", "std", "tracing-attributes", "async-await"] }
|
||||
# default alloc, ansi, fmt, nu-ansi-term, registry, sharded-slab, smallvec, std, thread_local, tracing-log
|
||||
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["alloc", "ansi", "fmt", "nu-ansi-term", "registry", "sharded-slab", "smallvec", "std", "thread_local", "tracing-log", "env-filter"] }
|
||||
|
||||
[profile.release-lto]
|
||||
|
31
src/in_repo_config.rs
Normal file
31
src/in_repo_config.rs
Normal 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>,
|
||||
}
|
19
src/main.rs
19
src/main.rs
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user