2024-09-28 14:29:18 -04:00
|
|
|
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 {
|
2024-09-28 16:51:27 -04:00
|
|
|
pub(crate) version: String,
|
2024-09-28 14:29:18 -04:00
|
|
|
|
|
|
|
#[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>,
|
|
|
|
}
|
2024-09-28 16:51:27 -04:00
|
|
|
|
|
|
|
impl InRepoConfig {
|
|
|
|
pub(crate) fn from_str<S: AsRef<str>>(
|
|
|
|
contents: S,
|
|
|
|
) -> Result<InRepoConfig, Box<dyn std::error::Error>> {
|
|
|
|
let parsed_in_repo_config: InRepoConfig = toml::from_str(contents.as_ref())?;
|
|
|
|
assert!(
|
|
|
|
parsed_in_repo_config.version == "0.0.1",
|
|
|
|
"We only support version 0.0.1 currently."
|
|
|
|
);
|
|
|
|
Ok(parsed_in_repo_config)
|
|
|
|
}
|
|
|
|
}
|