Filtering to 'opened' pull request events.

This commit is contained in:
Tom Alexander
2022-05-12 08:53:20 -04:00
parent be9dcee422
commit f46a5f8a9c
2 changed files with 21 additions and 6 deletions

View File

@@ -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<Self, Box<dyn std::error::Error>> {
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<bool, Box<dyn std::error::Error>> {