Filtering for pull request events.
This commit is contained in:
parent
f36546a470
commit
f7d2a2e57d
39
src/main.rs
39
src/main.rs
@ -3,7 +3,7 @@ extern crate log;
|
|||||||
|
|
||||||
mod githubctl;
|
mod githubctl;
|
||||||
|
|
||||||
use serde_json;
|
use serde_json::{self, Map};
|
||||||
|
|
||||||
const USERNAME: &'static str = include_str!("../.username");
|
const USERNAME: &'static str = include_str!("../.username");
|
||||||
const TOKEN: &'static str = include_str!("../.pat");
|
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?;
|
github.watch_repo(ORG, REPO).await?;
|
||||||
loop {
|
loop {
|
||||||
let event = github.get_event().await?;
|
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"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user