Drop unused CI metadata parsing
This commit is contained in:
parent
616a82ebb7
commit
0978ed7b5e
2 changed files with 0 additions and 94 deletions
|
|
@ -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<IssueAction>,
|
||||
pub issue: Option<IssueMeta>,
|
||||
pub repository: Option<RepoMeta>,
|
||||
|
||||
// Only for development environments, may be used as fallback for `$GITHUB_TOKEN`
|
||||
#[serde(rename = "dev-token")]
|
||||
pub dev_token: Option<String>,
|
||||
}
|
||||
|
||||
#[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<CiEventMeta> {
|
||||
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<PathBuf> {
|
||||
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": "<your development access token>"
|
||||
}
|
||||
"#
|
||||
);
|
||||
anyhow::bail!("Missing development drop-in CI metadata")
|
||||
}
|
||||
Ok(p)
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
#![allow(unused)]
|
||||
|
||||
mod ci_meta;
|
||||
mod collect;
|
||||
mod context;
|
||||
mod reminder;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue