Skip to content

Commit 75099cc

Browse files
committed
Merge branch 'Byron-master' PR: #90
Fixes: #89 Fixes: #84
2 parents fc8512c + 4870871 commit 75099cc

File tree

7 files changed

+228
-252
lines changed

7 files changed

+228
-252
lines changed

Cargo.lock

+214-187
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ rustc-serialize = "0.3"
1313
regex = "0.1"
1414
postgres = { version = "0.11", features = [ "time", "rustc-serialize" ] }
1515
clap = "2.14"
16+
crates-index-diff = "2.0.0"
17+
git2 = "0.4"
1618
time = "0.1"
1719
hyper = "0.9"
1820
semver = "0.5"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Example badges for `mio` crate:
5555
* [Matthew Hall](https://github.com/mattyhall)
5656
* [Guillaume Gomez](https://github.com/GuillaumeGomez)
5757
* [Mark Simulacrum](https://github.com/Mark-Simulacrum)
58+
* [Sebastian Thiel](https://github.com/Byron)
5859

5960
#### Sponsors
6061

src/docbuilder/queue.rs

+6-65
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,20 @@
22
33

44
use super::DocBuilder;
5-
use rustc_serialize::json::{Json, Array};
6-
use hyper;
7-
use hyper::header::{Accept, qitem};
85
use db::connect_db;
96
use errors::*;
7+
use crates_index_diff::{ChangeKind, Index};
108

119

1210
impl DocBuilder {
1311
/// Updates crates.io-index repository and adds new crates into build queue
1412
pub fn get_new_crates(&mut self) -> Result<()> {
15-
try!(self.load_database_cache());
16-
17-
let body = {
18-
use std::io::Read;
19-
let client = hyper::Client::new();
20-
let mut res = try!(client.get("https://crates.io/summary")
21-
.header(Accept(vec![qitem("application/json".parse().unwrap())]))
22-
.send());
23-
let mut body = String::new();
24-
try!(res.read_to_string(&mut body));
25-
body
26-
};
27-
28-
let json = try!(Json::from_str(&body));
29-
30-
let crates = {
31-
let mut crates: Vec<(String, String)> = Vec::new();
32-
for section in ["just_updated", "new_crates"].iter() {
33-
match json.as_object()
34-
.and_then(|o| o.get(&section[..]))
35-
.and_then(|j| j.as_array())
36-
.map(get_crates_from_array) {
37-
Some(mut c) => crates.append(c.as_mut()),
38-
None => continue,
39-
}
40-
}
41-
crates
42-
};
43-
4413
let conn = try!(connect_db());
45-
for (name, version) in crates {
46-
if self.db_cache.contains(&format!("{}-{}", name, version)[..]) {
47-
continue;
48-
}
49-
let _ = conn.execute("INSERT INTO queue (name, version) VALUES ($1, $2)",
50-
&[&name, &version]);
14+
let index = try!(Index::from_path_or_cloned(&self.options.crates_io_index_path));
15+
let changes = try!(index.fetch_changes());
16+
for krate in changes.iter().filter(|k| k.kind != ChangeKind::Yanked) {
17+
conn.execute("INSERT INTO queue (name, version) VALUES ($1, $2)",
18+
&[&krate.name, &krate.version]).ok();
5119
}
5220

5321
Ok(())
@@ -80,33 +48,6 @@ impl DocBuilder {
8048
}
8149
}
8250

83-
84-
/// Returns Vec<CRATE_NAME, CRATE_VERSION> from a summary array
85-
fn get_crates_from_array<'a>(crates: &'a Array) -> Vec<(String, String)> {
86-
let mut crates_vec: Vec<(String, String)> = Vec::new();
87-
for crte in crates {
88-
let name = match crte.as_object()
89-
.and_then(|o| o.get("id"))
90-
.and_then(|i| i.as_string())
91-
.map(|s| s.to_owned()) {
92-
Some(s) => s,
93-
None => continue,
94-
};
95-
let version = match crte.as_object()
96-
.and_then(|o| o.get("max_version"))
97-
.and_then(|v| v.as_string())
98-
.map(|s| s.to_owned()) {
99-
Some(s) => s,
100-
None => continue,
101-
};
102-
crates_vec.push((name, version));
103-
}
104-
crates_vec
105-
}
106-
107-
108-
109-
11051
#[cfg(test)]
11152
mod test {
11253
extern crate env_logger;

src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use postgres;
66
use cargo;
77
use hyper;
88
use magic::MagicError;
9+
use git2;
910

1011

1112
error_chain! {
@@ -22,6 +23,7 @@ error_chain! {
2223
postgres::error::ConnectError, PostgresConnectError;
2324
postgres::error::Error, PostgresError;
2425
hyper::Error, HyperError;
26+
git2::Error, Git2Error;
2527
MagicError, MagicError;
2628
Box<cargo::CargoError>, CargoError;
2729
}

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern crate url;
2525
extern crate params;
2626
extern crate libc;
2727
extern crate badge;
28+
extern crate crates_index_diff;
29+
extern crate git2;
2830

2931
pub use self::docbuilder::DocBuilder;
3032
pub use self::docbuilder::ChrootBuilderResult;

templates/about.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<li><a href="https://github.com/mattyhall" target="_blank">Matthew Hall</a></li>
111111
<li><a href="https://github.com/GuillaumeGomez" target="_blank">Guillaume Gomez</a></li>
112112
<li><a href="https://github.com/Mark-Simulacrum" target="_blank">Mark Simulacrum</a></li>
113+
<li><a href="https://github.com/Byron" target="_blank">Sebastian Thiel</a></li>
113114
</ul>
114115

115116
<h4>Sponsors</h4>

0 commit comments

Comments
 (0)