Parse the pipeline templates.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::crd_pipeline_run::PipelineRun;
|
||||
use crate::gitea_client::GiteaClient;
|
||||
use crate::gitea_client::Tree;
|
||||
use crate::gitea_client::TreeFileReference;
|
||||
@@ -31,7 +32,8 @@ pub(crate) async fn discover_matching_push_triggers<RE: AsRef<str>>(
|
||||
repo_tree: &Tree,
|
||||
git_ref: RE,
|
||||
in_repo_config: &InRepoConfig,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
) -> Result<Vec<PipelineTemplate>, Box<dyn std::error::Error>> {
|
||||
let mut ret = Vec::new();
|
||||
let ref_to_branch_regex = Regex::new(r"refs/heads/(?P<branch>.+)")?;
|
||||
let captures = ref_to_branch_regex
|
||||
.captures(git_ref.as_ref())
|
||||
@@ -42,7 +44,6 @@ pub(crate) async fn discover_matching_push_triggers<RE: AsRef<str>>(
|
||||
let push_triggers = in_repo_config.get_push_triggers_for_branch(branch)?;
|
||||
for trigger in push_triggers {
|
||||
let path_to_source = normalize_path(Path::new(".webhook_bridge").join(&trigger.source));
|
||||
debug!("Loading path {}", path_to_source.display());
|
||||
let pipeline_template = repo_tree
|
||||
.files
|
||||
.iter()
|
||||
@@ -50,10 +51,17 @@ pub(crate) async fn discover_matching_push_triggers<RE: AsRef<str>>(
|
||||
.next()
|
||||
.ok_or("Trigger source not found in remote repo.")?;
|
||||
let pipeline_contents = String::from_utf8(gitea.read_file(pipeline_template).await?)?;
|
||||
debug!("Pipeline contents: {}", pipeline_contents);
|
||||
debug!("Pipeline template contents: {}", pipeline_contents);
|
||||
|
||||
let pipeline: PipelineRun = serde_yaml::from_str(&pipeline_contents)?;
|
||||
ret.push(PipelineTemplate::new(
|
||||
trigger.name.clone(),
|
||||
trigger.clone_uri.clone(),
|
||||
pipeline,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
@@ -76,3 +84,24 @@ fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct PipelineTemplate {
|
||||
pub(crate) name: String,
|
||||
pub(crate) clone_uri: Option<String>,
|
||||
pub(crate) pipeline: PipelineRun,
|
||||
}
|
||||
|
||||
impl PipelineTemplate {
|
||||
pub(crate) fn new<N: Into<String>, C: Into<Option<String>>>(
|
||||
name: N,
|
||||
clone_uri: C,
|
||||
pipeline: PipelineRun,
|
||||
) -> PipelineTemplate {
|
||||
PipelineTemplate {
|
||||
name: name.into(),
|
||||
clone_uri: clone_uri.into(),
|
||||
pipeline,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,12 +59,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.get_tree(
|
||||
"talexander",
|
||||
"webhook_bridge",
|
||||
"c32a8650f509b5e4bbf6df0c210a3a01ad405eb5",
|
||||
"6d3b9e9db82d7857baa114d89efcb1bf470f448d",
|
||||
)
|
||||
.await?;
|
||||
let in_repo_config = discover_webhook_bridge_config(&gitea, &repo_tree).await?;
|
||||
|
||||
discover_matching_push_triggers(&gitea, &repo_tree, "refs/heads/main", &in_repo_config).await?;
|
||||
let pipelines =
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user