aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: e5f7235f0ef9d93a7b4e150bedc82018f6bd69fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#[macro_use]
extern crate rouille;

extern crate kipper;

use std::io::Read;

use kipper::jenkins;
use kipper::pull_request::CommitRef;

fn main() {
    rouille::start_server("localhost:8000", move |request| {
        router!(request,
            (POST) (/github/pull_request_event) => {
                let mut body = String::new();

                match request.data() {
                    None => rouille::Response::text("400 Bad Request")
                        .with_status_code(400),
                    Some(mut data) => {
                        try_or_400!(data.read_to_string(&mut body));

                        let commit_ref = CommitRef::new(body.as_ref());

                        jenkins::find_and_track_build_and_update_status(commit_ref);

                        rouille::Response::text("202 Accepted")
                            .with_status_code(202)
                    }
                }
            },

            _ => rouille::Response::text("404 Not Found")
                    .with_status_code(404)
        )
    });
}