From 8a0f9223e3a65323409f4c268bb212effc111089 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 27 Jan 2017 16:18:41 -0500 Subject: [PATCH 1/7] remove unneeded stuff --- http/src/lib.rs | 5 ----- src/bin/populate.rs | 1 - src/main.rs | 6 +----- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/http/src/lib.rs b/http/src/lib.rs index 4d17e4f..8a270ed 100644 --- a/http/src/lib.rs +++ b/http/src/lib.rs @@ -47,9 +47,7 @@ impl Service for Contributors { fn call(&self, req: Request) -> Self::Future { // redirect to ssl // from http://jaketrent.com/post/https-redirect-node-heroku/ - println!("request!"); if let Some(raw) = req.headers().get_raw("x-forwarded-proto") { - println!("seen header: {:?}", raw); if raw != &b"https"[..] { return ::futures::finished( Response::new() @@ -62,8 +60,6 @@ impl Service for Contributors { // first, we serve static files let path = req.path().to_string(); - println!("PATH: {:?}", path); - // ... you trying to do something bad? if path.contains("./") || path.contains("../") { // GET OUT @@ -73,7 +69,6 @@ impl Service for Contributors { } if path.starts_with("/public") && Path::new(&path[1..]).exists() { - println!("serve static arm\npath: {}", path); let mut f = File::open(&path[1..]).unwrap(); let mut source = Vec::new(); f.read_to_end(&mut source).unwrap(); diff --git a/src/bin/populate.rs b/src/bin/populate.rs index 9a9e67a..8b1b366 100644 --- a/src/bin/populate.rs +++ b/src/bin/populate.rs @@ -69,7 +69,6 @@ fn main() { // get path to git repo let path = matches.value_of("filepath").unwrap(); - println!("Path to rust repo: {}", path); // create releases diff --git a/src/main.rs b/src/main.rs index fdf08ab..4295970 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,10 +62,7 @@ fn about(_: Request) -> futures::Finished { ) } -fn all_time(req: Request) -> futures::Finished { - let path = req.path(); - println!("all-time arm\npath: {}", path); - +fn all_time(_: Request) -> futures::Finished { let handlebars = Handlebars::new(); let mut source = String::new(); @@ -102,7 +99,6 @@ fn catch_all(req: Request) -> futures::Finished { data.insert("release".to_string(), Value::String(release_name.clone())); - println!("releases arm\npath: {}", path); let mut f = File::open("templates/release.hbs").unwrap(); f.read_to_string(&mut source).unwrap(); From 5145d30b7e88892f34d08b15bffd888a1e478d1c Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 27 Jan 2017 16:24:34 -0500 Subject: [PATCH 2/7] first bit of slog --- Cargo.lock | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 51 ++++++++++++++++------------- 3 files changed, 124 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5e0f45..c9631f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,15 @@ name = "cfg-if" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "chrono" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.19.3" @@ -103,6 +112,8 @@ dependencies = [ "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", + "slog 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-term 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -299,6 +310,16 @@ dependencies = [ "unicode-normalization 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "isatty" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itoa" version = "0.1.1" @@ -427,6 +448,33 @@ dependencies = [ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-traits" version = "0.1.36" @@ -681,6 +729,42 @@ name = "slab" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "slog" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "slog-extra" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "slog 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "slog-stream" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "slog 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-extra 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "slog-term" +version = "1.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", + "isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "slog 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-stream 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "smallvec" version = "0.2.1" @@ -939,6 +1023,7 @@ dependencies = [ "checksum byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "29b2aa490a8f546381308d68fc79e6bd753cd3ad839f7a7172897f1feedfa175" "checksum caseless 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8950b075cff75cdabadee97148a8b5816c7cf62e5948a6005b5255d564b42fe7" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" +"checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00" "checksum clap 2.19.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95b78f3fe0fc94c13c731714363260e04b557a637166f33a4570d3189d642374" "checksum cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0e3d6405328b6edb412158b3b7710e2634e23f3614b9bb1c412df7952489a626" "checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" @@ -960,6 +1045,7 @@ dependencies = [ "checksum hyper 0.11.0-a.0 (git+https://github.com/hyperium/hyper)" = "" "checksum hyper 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)" = "bcb3fc65554155980167fb821d05c7c66177f92464976c0b676a19d9e03387a7" "checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11" +"checksum isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fa500db770a99afe2a0f2229be2a3d09c7ed9d7e4e8440bf71253141994e240f" "checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" @@ -976,6 +1062,9 @@ dependencies = [ "checksum miow 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3a78d2605eb97302c10cf944b8d96b0a2a890c52957caf92fcd1f24f69049579" "checksum native-tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b805ee0e8fa268f67a4e5c7f4f80adb8af1fc4428ea0ce5b0ecab1430ef17ec0" "checksum net2 0.2.26 (registry+https://github.com/rust-lang/crates.io-index)" = "5edf9cb6be97212423aed9413dd4729d62b370b5e1c571750e882cebbbc1e3e2" +"checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" +"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92" +"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" "checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" "checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39" "checksum openssl 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0c00da69323449142e00a5410f0e022b39e8bbb7dc569cee8fc6af279279483c" @@ -1008,6 +1097,10 @@ dependencies = [ "checksum serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "67f7d2e9edc3523a9c8ec8cd6ec481b3a27810aafee3e625d311febd3e656b4c" "checksum serde_urlencoded 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53d4ebaa8d1d4f90d1b63dfca81ccd98ac20e1e479dbae393cbaf60f6fecd8d8" "checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23" +"checksum slog 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c68be52239f59c2d13609defb3d0848b27dc0de1f2a9cec63a13c3a8330e961d" +"checksum slog-extra 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f571614f815a4dc3aad7b9052d1e3eefd5ab76bb36efa90d4dc9ac134142b445" +"checksum slog-stream 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f0fee00b80a7a44f82c5cf44ba03b6dc2712f9c14469a62ad90ea0911635c5" +"checksum slog-term 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "042bf221ecd4f30ca35d73f390f0de260d0696eddc9bf4e3d2ffcae96a4e2e30" "checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013" "checksum solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "172382bac9424588d7840732b250faeeef88942e37b6e35317dce98cafdd75b2" "checksum strsim 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "67f84c44fbb2f91db7fef94554e6b2ac05909c9c0b0bc23bb98d3a1aebfe7f7c" diff --git a/Cargo.toml b/Cargo.toml index 74c6fb8..ef7aa7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,8 @@ dotenv = "0.8.0" caseless = "0.1.2" unicode-normalization = "0.1.0" clap = "2.19.0" +slog = "1.4.1" +slog-term = "1.3.5" [dependencies.http] path = "./http" diff --git a/src/main.rs b/src/main.rs index 4295970..1e24698 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,10 @@ extern crate reqwest; extern crate serde; extern crate serde_json; +#[macro_use] +extern crate slog; +extern crate slog_term; + extern crate http; use hyper::StatusCode; @@ -28,6 +32,31 @@ use std::fs::File; use serde_json::value::Value; +use slog::DrainExt; + +fn main() { + dotenv::dotenv().ok(); + let log = slog::Logger::root(slog_term::streamer().full().build().fuse(), o!("version" => env!("CARGO_PKG_VERSION"))); + + let addr = format!("0.0.0.0:{}", env::args().nth(1).unwrap_or(String::from("1337"))).parse().unwrap(); + + let server = http::Server; + let mut contributors = http::Contributors::new(); + + contributors.add_route("/", root); + + contributors.add_route("/about", about); + + contributors.add_route("/all-time", all_time); + + // * is the catch-all route + contributors.add_route("*", catch_all); + + info!(log, "Starting server, listening on http://{}", addr); + + server.run(&addr, contributors); +} + fn root(_: Request) -> futures::Finished { let handlebars = Handlebars::new(); @@ -120,25 +149,3 @@ fn catch_all(req: Request) -> futures::Finished { .with_body(handlebars.template_render(&source, &data).unwrap()) ) } - -fn main() { - dotenv::dotenv().ok(); - - let addr = format!("0.0.0.0:{}", env::args().nth(1).unwrap_or(String::from("1337"))).parse().unwrap(); - - let server = http::Server; - let mut contributors = http::Contributors::new(); - - contributors.add_route("/", root); - - contributors.add_route("/about", about); - - contributors.add_route("/all-time", all_time); - - // * is the catch-all route - contributors.add_route("*", catch_all); - - println!("Starting server, listening on http://{}", addr); - - server.run(&addr, contributors); -} From 2e0405f0bd8a60c15f8d237864597394cbac05f0 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 27 Jan 2017 16:29:18 -0500 Subject: [PATCH 3/7] add a bunch more logging --- src/bin/new-release.rs | 16 +++++++++++----- src/bin/populate.rs | 21 ++++++++++++++------- src/bin/the-big-red-button.rs | 13 ++++++++++--- src/bin/update-commit-db.rs | 14 +++++++++++--- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/bin/new-release.rs b/src/bin/new-release.rs index 7721f59..88d8146 100644 --- a/src/bin/new-release.rs +++ b/src/bin/new-release.rs @@ -3,8 +3,13 @@ extern crate contributors; extern crate diesel; extern crate clap; +#[macro_use] +extern crate slog; +extern crate slog_term; + use diesel::prelude::*; use clap::{App, Arg}; +use slog::DrainExt; fn main() { let matches = App::new("new-release") @@ -16,6 +21,7 @@ fn main() { .takes_value(true) .required(true)) .get_matches(); + let log = slog::Logger::root(slog_term::streamer().full().build().fuse(), o!("version" => env!("CARGO_PKG_VERSION"))); use contributors::schema::releases::dsl::*; use contributors::models::Release; @@ -28,19 +34,19 @@ fn main() { let new_release = num + 1; let new_release_name = format!("1.{}.0", new_release); - println!("Previous release: {}", release.version); - println!("Creating new release release: {}", new_release_name); + info!(log, "Previous release: {}", release.version); + info!(log, "Creating new release release: {}", new_release_name); if releases.filter(version.eq(&new_release_name)).first::(&connection).is_ok() { panic!("Release {} already exists! Something must be wrong.", new_release_name); } let path = matches.value_of("filepath").unwrap(); - println!("Path to rust repo: {}", path); + info!(log, "Path to rust repo: {}", path); let new_release = contributors::create_release(&connection, &new_release_name); - println!("Created release {}", new_release.version); + info!(log, "Created release {}", new_release.version); - println!("Assigning commits for {}", new_release.version); + info!(log, "Assigning commits for {}", new_release.version); contributors::assign_commits(&new_release.version, &release.version, &path); } diff --git a/src/bin/populate.rs b/src/bin/populate.rs index 8b1b366..a48ec7b 100644 --- a/src/bin/populate.rs +++ b/src/bin/populate.rs @@ -13,12 +13,17 @@ extern crate reqwest; extern crate serde; extern crate serde_json; +#[macro_use] +extern crate slog; +extern crate slog_term; + extern crate clap; use diesel::prelude::*; use diesel::pg::PgConnection; use dotenv::dotenv; use clap::{App, Arg}; +use slog::DrainExt; use std::env; use std::process::Command; @@ -43,6 +48,8 @@ fn main() { .required(true)) .get_matches(); + let log = slog::Logger::root(slog_term::streamer().full().build().fuse(), o!("version" => env!("CARGO_PKG_VERSION"))); + let connection = establish_connection(); // check that we have no releases @@ -76,10 +83,10 @@ fn main() { contributors::create_release(&connection, "master"); // then let's get to the real releases: - println!("creating first release: 0.1"); + info!(log, "creating first release: 0.1"); let first_release = contributors::create_release(&connection, "0.1"); - println!("Creating other releases"); + info!(log, "Creating other releases"); let releases = ["0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "0.10", "0.11.0", "0.12.0", "1.0.0-alpha", "1.0.0-alpha.2", "1.0.0-beta", "1.0.0", "1.1.0", "1.2.0", "1.3.0", "1.4.0", "1.5.0", "1.6.0", "1.7.0", "1.8.0", "1.9.0", "1.10.0", "1.11.0", "1.12.0", "1.12.1", "1.13.0", "1.14.0"]; @@ -102,10 +109,10 @@ fn main() { .output() .expect("failed to execute process"); - let log = git_log.stdout; - let log = String::from_utf8(log).unwrap(); + let git_log = git_log.stdout; + let git_log = String::from_utf8(git_log).unwrap(); - for log_line in log.split('\n') { + for log_line in git_log.split('\n') { // there is a last, blank line if log_line == "" { continue; @@ -117,7 +124,7 @@ fn main() { let author_email = split.next().unwrap(); let author_name = split.next().unwrap(); - println!("Creating commit: {}", sha); + info!(log, "Creating commit: {}", sha); // We tag all commits initially to the first release. Each release will // set this properly below. @@ -157,5 +164,5 @@ fn main() { contributors::assign_commits("1.14.0", "1.13.0", &path); contributors::assign_commits("master", "1.14.0", &path); - println!("Done!"); + info!(log, "Done!"); } diff --git a/src/bin/the-big-red-button.rs b/src/bin/the-big-red-button.rs index d1a24a6..c51532c 100644 --- a/src/bin/the-big-red-button.rs +++ b/src/bin/the-big-red-button.rs @@ -2,23 +2,30 @@ extern crate contributors; extern crate diesel; +#[macro_use] +extern crate slog; +extern crate slog_term; + +use slog::DrainExt; + use diesel::prelude::*; fn main() { + let log = slog::Logger::root(slog_term::streamer().full().build().fuse(), o!("version" => env!("CARGO_PKG_VERSION"))); use contributors::schema::releases::dsl::*; use contributors::schema::commits::dsl::*; let connection = contributors::establish_connection(); - println!("Deleting releases"); + info!(log, "Deleting releases"); diesel::delete(releases) .execute(&connection) .expect("Error deleting releases"); - println!("Deleting commits"); + info!(log, "Deleting commits"); diesel::delete(commits) .execute(&connection) .expect("Error deleting releases"); - println!("Done."); + info!(log, "Done."); } diff --git a/src/bin/update-commit-db.rs b/src/bin/update-commit-db.rs index ba5bdaa..b6cdec1 100644 --- a/src/bin/update-commit-db.rs +++ b/src/bin/update-commit-db.rs @@ -15,6 +15,12 @@ extern crate serde; extern crate serde_derive; extern crate serde_json; +#[macro_use] +extern crate slog; +extern crate slog_term; + +use slog::DrainExt; + use diesel::prelude::*; use diesel::pg::PgConnection; use dotenv::dotenv; @@ -51,6 +57,8 @@ pub fn establish_connection() -> PgConnection { } fn main() { + let log = slog::Logger::root(slog_term::streamer().full().build().fuse(), o!("version" => env!("CARGO_PKG_VERSION"))); + use contributors::schema::releases::dsl::*; use contributors::models::Release; use contributors::schema::commits::dsl::*; @@ -66,16 +74,16 @@ fn main() { let master_release = releases.filter(version.eq("master")).first::(&connection).expect("could not find release"); for object in response.0 { - println!("Found commit with sha {}", object.sha); + info!(log, "Found commit with sha {}", object.sha); // do we have this commit? If so, ignore it. match commits.filter(sha.eq(&object.sha)).first::(&connection) { Ok(commit) => { - println!("Commit {} already in db, skipping", commit.sha); + info!(log, "Commit {} already in db, skipping", commit.sha); continue; }, Err(_) => { - println!("Creating commit {} for release {}", object.sha, master_release.version); + info!(log, "Creating commit {} for release {}", object.sha, master_release.version); // this commit will be part of master contributors::create_commit(&connection, &object.sha, &object.commit.author.name, &object.commit.author.email, &master_release); From 9542e56d9d6ce322769f5ef799c9b54a5c29b78d Mon Sep 17 00:00:00 2001 From: Jakub Matraszek Date: Thu, 26 Jan 2017 19:51:00 +0100 Subject: [PATCH 4/7] Fix building binaries --- Cargo.toml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ef7aa7b..f36d8b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,18 @@ version = "0.1.0" [[bin]] name = "contributors" doc = false +[[bin]] +name = "populate" +path = "bin/populate" +doc = false +[[bin]] +name = "update-commit-db" +path = "bin/update-commit-db" +doc = false +[[bin]] +name = "the-big-red-button" +path = "bin/the-big-red-button" +doc = false [dependencies] futures = "0.1.7" From fede1de693426344f5dca8c91b8fc0f15b47dac2 Mon Sep 17 00:00:00 2001 From: Jakub Matraszek Date: Thu, 26 Jan 2017 20:04:36 +0100 Subject: [PATCH 5/7] This should work --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f36d8b4..1061524 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,15 +10,15 @@ name = "contributors" doc = false [[bin]] name = "populate" -path = "bin/populate" +path = "src/bin/populate" doc = false [[bin]] name = "update-commit-db" -path = "bin/update-commit-db" +path = "src/bin/update-commit-db" doc = false [[bin]] name = "the-big-red-button" -path = "bin/the-big-red-button" +path = "src/bin/the-big-red-button" doc = false [dependencies] From 2d8a9a1cb20f7baf95c02e179882980089475041 Mon Sep 17 00:00:00 2001 From: Jakub Matraszek Date: Thu, 26 Jan 2017 20:08:18 +0100 Subject: [PATCH 6/7] Forgot file extensions... hope this is the last one --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1061524..b4eb2ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,15 +10,15 @@ name = "contributors" doc = false [[bin]] name = "populate" -path = "src/bin/populate" +path = "src/bin/populate.rs" doc = false [[bin]] name = "update-commit-db" -path = "src/bin/update-commit-db" +path = "src/bin/update-commit-db.rs" doc = false [[bin]] name = "the-big-red-button" -path = "src/bin/the-big-red-button" +path = "src/bin/the-big-red-button.rs" doc = false [dependencies] From a798597183063745b831a8a3eb37d144b3aa8e77 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 27 Jan 2017 16:37:02 -0500 Subject: [PATCH 7/7] remove print logging from src/lib.rs --- src/bin/populate.rs | 62 ++++++++++++++++++++++----------------------- src/lib.rs | 24 ++++++++++-------- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/src/bin/populate.rs b/src/bin/populate.rs index a48ec7b..20889be 100644 --- a/src/bin/populate.rs +++ b/src/bin/populate.rs @@ -132,37 +132,37 @@ fn main() { } // assign commits to their release - contributors::assign_commits("0.2", "0.1", &path); - contributors::assign_commits("0.3", "0.2", &path); - contributors::assign_commits("0.4", "0.3", &path); - contributors::assign_commits("0.5", "0.4", &path); - contributors::assign_commits("0.6", "0.5", &path); - contributors::assign_commits("0.7", "0.6", &path); - contributors::assign_commits("0.8", "0.7", &path); - contributors::assign_commits("0.9", "0.8", &path); - contributors::assign_commits("0.10", "0.9", &path); - contributors::assign_commits("0.11.0", "0.10", &path); - contributors::assign_commits("0.12.0", "0.11.0", &path); - contributors::assign_commits("1.0.0-alpha", "0.12.0", &path); - contributors::assign_commits("1.0.0-alpha.2", "1.0.0-alpha", &path); - contributors::assign_commits("1.0.0-beta", "1.0.0-alpha.2", &path); - contributors::assign_commits("1.0.0", "1.0.0-beta", &path); - contributors::assign_commits("1.1.0", "1.0.0", &path); - contributors::assign_commits("1.2.0", "1.1.0", &path); - contributors::assign_commits("1.3.0", "1.2.0", &path); - contributors::assign_commits("1.4.0", "1.3.0", &path); - contributors::assign_commits("1.5.0", "1.4.0", &path); - contributors::assign_commits("1.6.0", "1.5.0", &path); - contributors::assign_commits("1.7.0", "1.6.0", &path); - contributors::assign_commits("1.8.0", "1.7.0", &path); - contributors::assign_commits("1.9.0", "1.8.0", &path); - contributors::assign_commits("1.10.0", "1.9.0", &path); - contributors::assign_commits("1.11.0", "1.10.0", &path); - contributors::assign_commits("1.12.0", "1.11.0", &path); - contributors::assign_commits("1.12.1", "1.12.0", &path); - contributors::assign_commits("1.13.0", "1.12.0", &path); - contributors::assign_commits("1.14.0", "1.13.0", &path); - contributors::assign_commits("master", "1.14.0", &path); + contributors::assign_commits(&log, "0.2", "0.1", &path); + contributors::assign_commits(&log, "0.3", "0.2", &path); + contributors::assign_commits(&log, "0.4", "0.3", &path); + contributors::assign_commits(&log, "0.5", "0.4", &path); + contributors::assign_commits(&log, "0.6", "0.5", &path); + contributors::assign_commits(&log, "0.7", "0.6", &path); + contributors::assign_commits(&log, "0.8", "0.7", &path); + contributors::assign_commits(&log, "0.9", "0.8", &path); + contributors::assign_commits(&log, "0.10", "0.9", &path); + contributors::assign_commits(&log, "0.11.0", "0.10", &path); + contributors::assign_commits(&log, "0.12.0", "0.11.0", &path); + contributors::assign_commits(&log, "1.0.0-alpha", "0.12.0", &path); + contributors::assign_commits(&log, "1.0.0-alpha.2", "1.0.0-alpha", &path); + contributors::assign_commits(&log, "1.0.0-beta", "1.0.0-alpha.2", &path); + contributors::assign_commits(&log, "1.0.0", "1.0.0-beta", &path); + contributors::assign_commits(&log, "1.1.0", "1.0.0", &path); + contributors::assign_commits(&log, "1.2.0", "1.1.0", &path); + contributors::assign_commits(&log, "1.3.0", "1.2.0", &path); + contributors::assign_commits(&log, "1.4.0", "1.3.0", &path); + contributors::assign_commits(&log, "1.5.0", "1.4.0", &path); + contributors::assign_commits(&log, "1.6.0", "1.5.0", &path); + contributors::assign_commits(&log, "1.7.0", "1.6.0", &path); + contributors::assign_commits(&log, "1.8.0", "1.7.0", &path); + contributors::assign_commits(&log, "1.9.0", "1.8.0", &path); + contributors::assign_commits(&log, "1.10.0", "1.9.0", &path); + contributors::assign_commits(&log, "1.11.0", "1.10.0", &path); + contributors::assign_commits(&log, "1.12.0", "1.11.0", &path); + contributors::assign_commits(&log, "1.12.1", "1.12.0", &path); + contributors::assign_commits(&log, "1.13.0", "1.12.0", &path); + contributors::assign_commits(&log, "1.14.0", "1.13.0", &path); + contributors::assign_commits(&log, "master", "1.14.0", &path); info!(log, "Done!"); } diff --git a/src/lib.rs b/src/lib.rs index fe18d50..167f5a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,10 @@ use std::process::Command; extern crate serde_json; +#[macro_use] +extern crate slog; +extern crate slog_term; + pub mod schema; pub mod models; @@ -115,10 +119,10 @@ pub fn inaccurate_sort(strings: &mut Vec) { strings.sort_by(|a, b| str_cmp(&a, &b)); } -pub fn assign_commits(release_name: &str, previous_release: &str, path: &str) { +pub fn assign_commits(log: &slog::Logger, release_name: &str, previous_release: &str, path: &str) { let connection = establish_connection(); - println!("Assigning commits to release {}", release_name); + info!(log, "Assigning commits to release {}", release_name); let git_log = Command::new("git") .arg("-C") @@ -131,16 +135,16 @@ pub fn assign_commits(release_name: &str, previous_release: &str, path: &str) { .output() .expect("failed to execute process"); - let log = git_log.stdout; - let log = String::from_utf8(log).unwrap(); + let git_log = git_log.stdout; + let git_log = String::from_utf8(git_log).unwrap(); - for sha_name in log.split('\n') { + for sha_name in git_log.split('\n') { // there is a last, blank line if sha_name == "" { continue; } - println!("Assigning commit {} to release {}", sha_name, release_name); + info!(log, "Assigning commit {} to release {}", sha_name, release_name); use schema::releases::dsl::*; use models::Release; @@ -168,10 +172,10 @@ pub fn assign_commits(release_name: &str, previous_release: &str, path: &str) { .output() .expect("failed to execute process"); - let log = git_log.stdout; - let log = String::from_utf8(log).unwrap(); + let git_log = git_log.stdout; + let git_log = String::from_utf8(git_log).unwrap(); - let log_line = log.split('\n').nth(0).unwrap(); + let log_line = git_log.split('\n').nth(0).unwrap(); let mut split = log_line.splitn(3, ' '); @@ -179,7 +183,7 @@ pub fn assign_commits(release_name: &str, previous_release: &str, path: &str) { let the_author_email = split.next().unwrap(); let the_author_name = split.next().unwrap(); - println!("Creating commit {} for release {}", the_sha, the_release.version); + info!(log, "Creating commit {} for release {}", the_sha, the_release.version); create_commit(&connection, &the_sha, &the_author_name, &the_author_email, &the_release); },