|
|
|
@ -3,7 +3,7 @@ extern crate log;
|
|
|
|
|
|
|
|
|
|
mod githubctl;
|
|
|
|
|
|
|
|
|
|
use serde_json;
|
|
|
|
|
use serde_json::{self, Map};
|
|
|
|
|
|
|
|
|
|
const USERNAME: &'static str = include_str!("../.username");
|
|
|
|
|
const TOKEN: &'static str = include_str!("../.pat");
|
|
|
|
@ -17,6 +17,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
github.watch_repo(ORG, REPO).await?;
|
|
|
|
|
loop {
|
|
|
|
|
let event = github.get_event().await?;
|
|
|
|
|
println!("{}", serde_json::to_string(&event)?);
|
|
|
|
|
// println!("{}", serde_json::to_string(&event)?);
|
|
|
|
|
handle_event(event)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_event(event: serde_json::Value) -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
let event_object = get_json_object(&event);
|
|
|
|
|
let event_type = event_object.get("type").map(get_json_string);
|
|
|
|
|
match event_type {
|
|
|
|
|
Some(event_type_string) if event_type_string == "PullRequestEvent" => {
|
|
|
|
|
println!("{}", serde_json::to_string(&event)?);
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
};
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_json_object(obj: &serde_json::Value) -> &Map<String, serde_json::Value> {
|
|
|
|
|
match obj {
|
|
|
|
|
serde_json::Value::Null => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Bool(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Number(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::String(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Array(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Object(event_object) => event_object,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_json_string(str: &serde_json::Value) -> &String {
|
|
|
|
|
match str {
|
|
|
|
|
serde_json::Value::Null => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Bool(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Number(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::String(txt) => txt,
|
|
|
|
|
serde_json::Value::Array(_) => panic!("Unexpected json type"),
|
|
|
|
|
serde_json::Value::Object(_) => panic!("Unexpected json type"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|