where your commits go after github
Afterparty is a library for building Github webhook integrations in Rust.
Find them here
Afterparty has two key abstractions, a Hook
: a handler interface webhook deliveries, and a Hub
: a registry for hooks. A Hub
delivers Delivery
instances to interested hooks.
A Delivery
encodes all relevant webhook request information including a unique identifier for the delivery, the event name, and statically typed payload represented as an enumerated type of Event
.
Hooks subscribe to Events via Hub
's a handle
and handle_authenticated
functions.
To subscribe to multiple events, subscribe with "*" and pattern match on the provided delivery's payload value.
Hubs implements Hyper's Server Handler trait so that it may be mounted into any hyper Server.
```rust extern crate afterparty; extern create hyper;
use hyper::Server; use afterparty::{Delivery, Event, Hub};
fn main() { let mut hub = Hub::new(); hub.handle("*", |delivery: &Delivery| { println!("rec delivery {:#?}", delivery) }); hub.handleauthenticated("pullrequest", "secret", |delivery: &Delivery| { println!("rec authenticated delivery"); match delivery.payload { Event::PullRequest { ref action, ref sender, .. } => { println!("sender {} action {}", sender.login, action) }, _ => () } }); let svc = Server::http("0.0.0.0:4567") .handle(hub) println!("hub is up"); srv.unwrap(); } ```
As far as rust project builds go this one is somewhat interesting. This library uses serde for json encoding/decoding
and is focused on stable rust releases so a tactic for code generatation at build time is employed. Before that happens
an attempt is made to synthesize structs based on Github api documentation json vendored in the data directory.
A known issue exists where the repo deployments_url
field is omitted with a fresh set of json. serde will error at
deserializing because of this. This field was hand added within the json vendored dataset for the time being. Serde 0.7
will likely be released soon and will enable this library to avoid these kinds of runtime deserialization errors for
missing fields.
Doug Tangren (softprops) 2015-2016