Git Product home page Git Product logo

afterparty's Introduction

afterparty

Build Status Coverage Status Software License crates.io

Where your commits go after github

Afterparty is a library for building Github webhook integrations in Rust.

docs

Find them here

usage

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.

To register your webhook with Github visit your repo's hooks configuration form https://github.com/{login}/{repo}/settings/hooks/new and select the events you want Github to notify your server about.

Hubs implements Hyper's Server Handler trait so that it may be mounted into any hyper Server.

extern crate afterparty;
extern crate 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.handle_authenticated("pull_request", "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();
}

building

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

afterparty's People

Contributors

softprops avatar bombless avatar

Watchers

James Cloos avatar Leif Grele avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.