diff --git a/src/githubctl/pull_request_event.rs b/src/githubctl/pull_request_event.rs index daad435..944b023 100644 --- a/src/githubctl/pull_request_event.rs +++ b/src/githubctl/pull_request_event.rs @@ -1,12 +1,26 @@ +use crate::json_util::get_json_object; use crate::json_util::get_json_string; pub struct PullRequestEvent<'a> { original_event: &'a serde_json::Value, + pub action: &'a String, } impl<'a> PullRequestEvent<'a> { pub fn new(original_event: &'a serde_json::Value) -> Result> { - Ok(PullRequestEvent { original_event }) + let payload = original_event + .get("payload") + .map(get_json_object) + .expect("Ran into a PullRequestEvent without a payload."); + let action = payload + .get("action") + .map(get_json_string) + .expect("Ran into a PullRequestEvent without a payload.action."); + + Ok(PullRequestEvent { + original_event, + action, + }) } pub fn is_a(event: &'a serde_json::Value) -> Result> { diff --git a/src/main.rs b/src/main.rs index 9ea715b..204e85f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,10 +25,11 @@ async fn main() -> Result<(), Box> { } fn handle_event(event: serde_json::Value) -> Result<(), Box> { - let event = if PullRequestEvent::is_a(&event)? { - Some(PullRequestEvent::new(&event)?) - } else { - None - }; + if PullRequestEvent::is_a(&event)? { + let event = PullRequestEvent::new(&event)?; + if event.action == "opened" { + println!("PullRequestEvent action {}", event.action); + } + } Ok(()) }