Skip to content

Commit

Permalink
Merge branch 'Byron-master' PR: #90
Browse files Browse the repository at this point in the history
Fixes: #89
Fixes: #84
  • Loading branch information
onur committed Dec 26, 2016
2 parents fc8512c + 4870871 commit 75099cc
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 252 deletions.
401 changes: 214 additions & 187 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ rustc-serialize = "0.3"
regex = "0.1"
postgres = { version = "0.11", features = [ "time", "rustc-serialize" ] }
clap = "2.14"
crates-index-diff = "2.0.0"
git2 = "0.4"
time = "0.1"
hyper = "0.9"
semver = "0.5"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Example badges for `mio` crate:
* [Matthew Hall](https://github.com/mattyhall)
* [Guillaume Gomez](https://github.com/GuillaumeGomez)
* [Mark Simulacrum](https://github.com/Mark-Simulacrum)
* [Sebastian Thiel](https://github.com/Byron)

#### Sponsors

Expand Down
71 changes: 6 additions & 65 deletions src/docbuilder/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,20 @@

use super::DocBuilder;
use rustc_serialize::json::{Json, Array};
use hyper;
use hyper::header::{Accept, qitem};
use db::connect_db;
use errors::*;
use crates_index_diff::{ChangeKind, Index};


impl DocBuilder {
/// Updates crates.io-index repository and adds new crates into build queue
pub fn get_new_crates(&mut self) -> Result<()> {
try!(self.load_database_cache());

let body = {
use std::io::Read;
let client = hyper::Client::new();
let mut res = try!(client.get("https://crates.io/summary")
.header(Accept(vec![qitem("application/json".parse().unwrap())]))
.send());
let mut body = String::new();
try!(res.read_to_string(&mut body));
body
};

let json = try!(Json::from_str(&body));

let crates = {
let mut crates: Vec<(String, String)> = Vec::new();
for section in ["just_updated", "new_crates"].iter() {
match json.as_object()
.and_then(|o| o.get(&section[..]))
.and_then(|j| j.as_array())
.map(get_crates_from_array) {
Some(mut c) => crates.append(c.as_mut()),
None => continue,
}
}
crates
};

let conn = try!(connect_db());
for (name, version) in crates {
if self.db_cache.contains(&format!("{}-{}", name, version)[..]) {
continue;
}
let _ = conn.execute("INSERT INTO queue (name, version) VALUES ($1, $2)",
&[&name, &version]);
let index = try!(Index::from_path_or_cloned(&self.options.crates_io_index_path));
let changes = try!(index.fetch_changes());
for krate in changes.iter().filter(|k| k.kind != ChangeKind::Yanked) {
conn.execute("INSERT INTO queue (name, version) VALUES ($1, $2)",
&[&krate.name, &krate.version]).ok();
}

Ok(())
Expand Down Expand Up @@ -80,33 +48,6 @@ impl DocBuilder {
}
}


/// Returns Vec<CRATE_NAME, CRATE_VERSION> from a summary array
fn get_crates_from_array<'a>(crates: &'a Array) -> Vec<(String, String)> {
let mut crates_vec: Vec<(String, String)> = Vec::new();
for crte in crates {
let name = match crte.as_object()
.and_then(|o| o.get("id"))
.and_then(|i| i.as_string())
.map(|s| s.to_owned()) {
Some(s) => s,
None => continue,
};
let version = match crte.as_object()
.and_then(|o| o.get("max_version"))
.and_then(|v| v.as_string())
.map(|s| s.to_owned()) {
Some(s) => s,
None => continue,
};
crates_vec.push((name, version));
}
crates_vec
}




#[cfg(test)]
mod test {
extern crate env_logger;
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use postgres;
use cargo;
use hyper;
use magic::MagicError;
use git2;


error_chain! {
Expand All @@ -22,6 +23,7 @@ error_chain! {
postgres::error::ConnectError, PostgresConnectError;
postgres::error::Error, PostgresError;
hyper::Error, HyperError;
git2::Error, Git2Error;
MagicError, MagicError;
Box<cargo::CargoError>, CargoError;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern crate url;
extern crate params;
extern crate libc;
extern crate badge;
extern crate crates_index_diff;
extern crate git2;

pub use self::docbuilder::DocBuilder;
pub use self::docbuilder::ChrootBuilderResult;
Expand Down
1 change: 1 addition & 0 deletions templates/about.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<li><a href="https://github.com/mattyhall" target="_blank">Matthew Hall</a></li>
<li><a href="https://github.com/GuillaumeGomez" target="_blank">Guillaume Gomez</a></li>
<li><a href="https://github.com/Mark-Simulacrum" target="_blank">Mark Simulacrum</a></li>
<li><a href="https://github.com/Byron" target="_blank">Sebastian Thiel</a></li>
</ul>

<h4>Sponsors</h4>
Expand Down

0 comments on commit 75099cc

Please sign in to comment.