use anyhow::Context as _; #[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)] pub struct IssueEventMeta { pub action: IssueAction, pub issue: IssueMeta, } #[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: String, } pub fn get_issue_event_meta_from_env() -> anyhow::Result { let path = std::env::var_os("GITHUB_EVENT_PATH") .context("Could not get event description file path (GITHUB_EVENT_PATH)")?; let f = std::fs::File::open(path).context("Could not open GITHUB_EVENT_PATH file")?; let meta: IssueEventMeta = serde_json::de::from_reader(f).context("Failed to parse")?; Ok(meta) } pub fn fake() -> IssueEventMeta { IssueEventMeta { action: IssueAction::Edited, issue: IssueMeta { number: 1337, repository: RepoMeta { name: "techtree".to_owned(), owner: "fafo".to_owned(), }, }, } }