diff --git a/src/ci_meta.rs b/src/ci_meta.rs deleted file mode 100644 index 91872de..0000000 --- a/src/ci_meta.rs +++ /dev/null @@ -1,93 +0,0 @@ -use std::path::PathBuf; - -use anyhow::Context as _; - -#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)] -pub struct CiEventMeta { - pub action: Option, - pub issue: Option, - pub repository: Option, - - // Only for development environments, may be used as fallback for `$GITHUB_TOKEN` - #[serde(rename = "dev-token")] - pub dev_token: Option, -} - -#[derive(serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq)] -#[serde(rename_all = "lowercase")] -pub enum IssueAction { - Opened, - Reopened, - Closed, - Assigned, - Unassigned, - Edited, - #[serde(rename = "label_updated")] - LabelUpdated, - Labeled, - #[serde(rename = "label_cleared")] - LabelCleared, - Unlabeled, -} - -#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)] -pub struct IssueMeta { - pub number: u64, - // pub repository: RepoMeta, -} - -#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)] -pub struct RepoMeta { - pub name: String, - pub owner: OwnerMeta, -} - -#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)] -pub struct OwnerMeta { - username: String, -} - -pub fn get_ci_meta_or_fallback() -> anyhow::Result { - use std::io::Read as _; - - let path = if let Some(p) = std::env::var_os("GITHUB_EVENT_PATH") { - PathBuf::from(p) - } else { - dev_environment_path()? - }; - - let mut f = std::fs::File::open(&path).context("Could not open GITHUB_EVENT_PATH file")?; - let mut s = String::new(); - f.read_to_string(&mut s)?; - log::info!("Event Metadata: \n{s}"); - - let f = std::fs::File::open(&path).context("Could not open GITHUB_EVENT_PATH file")?; - let meta: CiEventMeta = serde_json::de::from_reader(f).context("Failed to parse")?; - - Ok(meta) -} - -fn dev_environment_path() -> anyhow::Result { - log::warn!("Not running in CI, using .dev-environment.json metadata instead."); - let p = PathBuf::from(".dev-environment.json"); - if !p.exists() { - log::error!( - "{}", - r#"When not running in CI environment, -metadata has to be substituded using a `.dev-environment.json` file. - -Example content: - -{ - "repository": { - "owner": "rahix", - "name": "arbeitsschutz" - }, - "dev-token": "" -} -"# - ); - anyhow::bail!("Missing development drop-in CI metadata") - } - Ok(p) -} diff --git a/src/main.rs b/src/main.rs index 22cbfc4..76e192c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,5 @@ #![allow(unused)] -mod ci_meta; mod collect; mod context; mod reminder;