Filtering to 'opened' pull request events.
This commit is contained in:
@@ -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>> {
|
||||
|
||||
Reference in New Issue
Block a user