Filtering to 'opened' pull request events.
This commit is contained in:
parent
be9dcee422
commit
f46a5f8a9c
@ -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>> {
|
||||
|
11
src/main.rs
11
src/main.rs
@ -25,10 +25,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
fn handle_event(event: serde_json::Value) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user