Skip to content

Commit 74a0db9

Browse files
cargo fmt
1 parent 2cb1397 commit 74a0db9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2375
-1740
lines changed

build.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ fn main() {
1313
if let Ok(database_url) = env::var("TEST_DATABASE_URL") {
1414
let connection = PgConnection::establish(&database_url)
1515
.expect("Could not connect to TEST_DATABASE_URL");
16-
run_pending_migrations(&connection)
17-
.expect("Error running migrations");
16+
run_pending_migrations(&connection).expect("Error running migrations");
1817
}
1918
}
2019
}

src/app.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ pub struct App {
3434

3535
/// The `AppMiddleware` injects an `App` instance into the `Request` extensions
3636
pub struct AppMiddleware {
37-
app: Arc<App>
37+
app: Arc<App>,
3838
}
3939

4040
impl App {
4141
pub fn new(config: &Config) -> App {
42-
let mut github = oauth2::Config::new(
43-
&config.gh_client_id,
44-
&config.gh_client_secret,
45-
"https://github.com/login/oauth/authorize",
46-
"https://github.com/login/oauth/access_token",
47-
);
42+
let mut github = oauth2::Config::new(&config.gh_client_id,
43+
&config.gh_client_secret,
44+
"https://github.com/login/oauth/authorize",
45+
"https://github.com/login/oauth/access_token");
4846

4947
github.scopes.push(String::from("read:org"));
5048

@@ -105,13 +103,15 @@ impl AppMiddleware {
105103
}
106104

107105
impl Middleware for AppMiddleware {
108-
fn before(&self, req: &mut Request) -> Result<(), Box<Error+Send>> {
106+
fn before(&self, req: &mut Request) -> Result<(), Box<Error + Send>> {
109107
req.mut_extensions().insert(self.app.clone());
110108
Ok(())
111109
}
112110

113-
fn after(&self, req: &mut Request, res: Result<Response, Box<Error+Send>>)
114-
-> Result<Response, Box<Error+Send>> {
111+
fn after(&self,
112+
req: &mut Request,
113+
res: Result<Response, Box<Error + Send>>)
114+
-> Result<Response, Box<Error + Send>> {
115115
req.mut_extensions().pop::<Arc<App>>().unwrap();
116116
res
117117
}
@@ -124,7 +124,6 @@ pub trait RequestApp {
124124

125125
impl<T: Request + ?Sized> RequestApp for T {
126126
fn app(&self) -> &Arc<App> {
127-
self.extensions().find::<Arc<App>>()
128-
.expect("Missing app")
127+
self.extensions().find::<Arc<App>>().expect("Missing app")
129128
}
130129
}

src/badge.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,35 @@ use std::collections::HashMap;
1212
pub enum Badge {
1313
#[serde(rename = "travis-ci")]
1414
TravisCi {
15-
repository: String, branch: Option<String>,
15+
repository: String,
16+
branch: Option<String>,
1617
},
1718
#[serde(rename = "appveyor")]
1819
Appveyor {
19-
repository: String, branch: Option<String>, service: Option<String>,
20+
repository: String,
21+
branch: Option<String>,
22+
service: Option<String>,
2023
},
2124
#[serde(rename = "gitlab")]
2225
GitLab {
23-
repository: String, branch: Option<String>,
24-
},
25-
#[serde(rename = "is-it-maintained-issue-resolution")]
26-
IsItMaintainedIssueResolution {
2726
repository: String,
27+
branch: Option<String>,
2828
},
29+
#[serde(rename = "is-it-maintained-issue-resolution")]
30+
IsItMaintainedIssueResolution { repository: String },
2931
#[serde(rename = "is-it-maintained-open-issues")]
30-
IsItMaintainedOpenIssues {
31-
repository: String,
32-
},
32+
IsItMaintainedOpenIssues { repository: String },
3333
#[serde(rename = "codecov")]
3434
Codecov {
35-
repository: String, branch: Option<String>, service: Option<String>,
35+
repository: String,
36+
branch: Option<String>,
37+
service: Option<String>,
3638
},
3739
#[serde(rename = "coveralls")]
3840
Coveralls {
39-
repository: String, branch: Option<String>, service: Option<String>,
41+
repository: String,
42+
branch: Option<String>,
43+
service: Option<String>,
4044
},
4145
}
4246

@@ -51,8 +55,7 @@ impl Queryable<badges::SqlType, Pg> for Badge {
5155

5256
fn build((_, badge_type, attributes): Self::Row) -> Self {
5357
let json = json!({"badge_type": badge_type, "attributes": attributes});
54-
serde_json::from_value(json)
55-
.expect("Invalid CI badge in the database")
58+
serde_json::from_value(json).expect("Invalid CI badge in the database")
5659
}
5760
}
5861

@@ -63,13 +66,13 @@ impl Badge {
6366

6467
pub fn badge_type(&self) -> &'static str {
6568
match *self {
66-
Badge::TravisCi {..} => "travis-ci",
67-
Badge::Appveyor {..} => "appveyor",
68-
Badge::GitLab{..} => "gitlab",
69-
Badge::IsItMaintainedIssueResolution{..} => "is-it-maintained-issue-resolution",
70-
Badge::IsItMaintainedOpenIssues{..} => "is-it-maintained-open-issues",
71-
Badge::Codecov{..} => "codecov",
72-
Badge::Coveralls{..} => "coveralls",
69+
Badge::TravisCi { .. } => "travis-ci",
70+
Badge::Appveyor { .. } => "appveyor",
71+
Badge::GitLab { .. } => "gitlab",
72+
Badge::IsItMaintainedIssueResolution { .. } => "is-it-maintained-issue-resolution",
73+
Badge::IsItMaintainedOpenIssues { .. } => "is-it-maintained-open-issues",
74+
Badge::Codecov { .. } => "codecov",
75+
Badge::Coveralls { .. } => "coveralls",
7376
}
7477
}
7578

@@ -97,20 +100,21 @@ impl Badge {
97100
let json = json!({"badge_type": k, "attributes": attributes_json});
98101
if serde_json::from_value::<Badge>(json).is_ok() {
99102
new_badges.push(NewBadge {
100-
crate_id: krate.id,
101-
badge_type: &**k,
102-
attributes: attributes_json,
103-
});
103+
crate_id: krate.id,
104+
badge_type: &**k,
105+
attributes: attributes_json,
106+
});
104107
} else {
105108
invalid_badges.push(&**k);
106109
}
107110
}
108111
}
109112

110113
conn.transaction(|| {
111-
delete(badges::table.filter(badges::crate_id.eq(krate.id))).execute(conn)?;
112-
insert(&new_badges).into(badges::table).execute(conn)?;
113-
Ok(invalid_badges)
114-
})
114+
delete(badges::table.filter(badges::crate_id.eq(krate.id)))
115+
.execute(conn)?;
116+
insert(&new_badges).into(badges::table).execute(conn)?;
117+
Ok(invalid_badges)
118+
})
115119
}
116120
}

src/bin/delete-crate.rs

+39-23
Original file line numberDiff line numberDiff line change
@@ -30,80 +30,96 @@ fn main() {
3030

3131
fn delete(tx: &postgres::transaction::Transaction) {
3232
let name = match env::args().nth(1) {
33-
None => { println!("needs a crate-name argument"); return }
33+
None => {
34+
println!("needs a crate-name argument");
35+
return;
36+
}
3437
Some(s) => s,
3538
};
3639

3740
let krate = Crate::find_by_name(tx, &name).unwrap();
38-
print!("Are you sure you want to delete {} ({}) [y/N]: ", name, krate.id);
41+
print!("Are you sure you want to delete {} ({}) [y/N]: ",
42+
name,
43+
krate.id);
3944
io::stdout().flush().unwrap();
4045
let mut line = String::new();
4146
io::stdin().read_line(&mut line).unwrap();
42-
if !line.starts_with("y") { return }
47+
if !line.starts_with("y") {
48+
return;
49+
}
4350

4451
let versions = krate.versions(tx).unwrap();
4552

4653
for v in versions.iter() {
4754
println!("deleting version {} ({})", v.num, v.id);
4855
let n = tx.execute("DELETE FROM version_downloads WHERE version_id = $1",
49-
&[&v.id]).unwrap();
56+
&[&v.id])
57+
.unwrap();
5058
println!(" {} download records deleted", n);
5159
let n = tx.execute("DELETE FROM version_authors WHERE version_id = $1",
52-
&[&v.id]).unwrap();
60+
&[&v.id])
61+
.unwrap();
5362
println!(" {} author records deleted", n);
54-
let n = tx.execute("DELETE FROM dependencies WHERE version_id = $1",
55-
&[&v.id]).unwrap();
63+
let n = tx.execute("DELETE FROM dependencies WHERE version_id = $1", &[&v.id])
64+
.unwrap();
5665
println!(" {} dependencies deleted", n);
57-
tx.execute("DELETE FROM versions WHERE id = $1",
58-
&[&v.id]).unwrap();
66+
tx.execute("DELETE FROM versions WHERE id = $1", &[&v.id])
67+
.unwrap();
5968
}
6069

6170
println!("deleting follows");
62-
let n = tx.execute("DELETE FROM follows WHERE crate_id = $1",
63-
&[&krate.id]).unwrap();
71+
let n = tx.execute("DELETE FROM follows WHERE crate_id = $1", &[&krate.id])
72+
.unwrap();
6473
println!(" {} deleted", n);
6574

6675
println!("deleting crate download records");
6776
let n = tx.execute("DELETE FROM crate_downloads WHERE crate_id = $1",
68-
&[&krate.id]).unwrap();
77+
&[&krate.id])
78+
.unwrap();
6979
println!(" {} deleted", n);
7080

7181
println!("deleting crate owners");
72-
let n = tx.execute("DELETE FROM crate_owners WHERE crate_id = $1",
73-
&[&krate.id]).unwrap();
82+
let n = tx.execute("DELETE FROM crate_owners WHERE crate_id = $1", &[&krate.id])
83+
.unwrap();
7484
println!(" {} deleted", n);
7585

7686
println!("disabling reserved crate name trigger");
7787
let _ = tx.execute("ALTER TABLE crates DISABLE TRIGGER trigger_ensure_crate_name_not_reserved;",
78-
&[]).unwrap();
88+
&[])
89+
.unwrap();
7990

8091
println!("deleting crate keyword connections");
8192
let n = tx.execute("DELETE FROM crates_keywords WHERE crate_id = $1",
82-
&[&krate.id]).unwrap();
93+
&[&krate.id])
94+
.unwrap();
8395
println!(" {} deleted", n);
8496

8597
println!("deleting crate category connections");
8698
let n = tx.execute("DELETE FROM crates_categories WHERE crate_id = $1",
87-
&[&krate.id]).unwrap();
99+
&[&krate.id])
100+
.unwrap();
88101
println!(" {} deleted", n);
89102

90103
println!("enabling reserved crate name trigger");
91104
let _ = tx.execute("ALTER TABLE crates ENABLE TRIGGER trigger_ensure_crate_name_not_reserved;",
92-
&[]).unwrap();
105+
&[])
106+
.unwrap();
93107

94108
println!("deleting crate badges");
95-
let n = tx.execute("DELETE FROM badges WHERE crate_id = $1",
96-
&[&krate.id]).unwrap();
109+
let n = tx.execute("DELETE FROM badges WHERE crate_id = $1", &[&krate.id])
110+
.unwrap();
97111
println!(" {} deleted", n);
98112

99113
println!("deleting the crate");
100-
let n = tx.execute("DELETE FROM crates WHERE id = $1",
101-
&[&krate.id]).unwrap();
114+
let n = tx.execute("DELETE FROM crates WHERE id = $1", &[&krate.id])
115+
.unwrap();
102116
println!(" {} deleted", n);
103117

104118
print!("commit? [y/N]: ");
105119
io::stdout().flush().unwrap();
106120
let mut line = String::new();
107121
io::stdin().read_line(&mut line).unwrap();
108-
if !line.starts_with("y") { panic!("aborting transaction"); }
122+
if !line.starts_with("y") {
123+
panic!("aborting transaction");
124+
}
109125
}

src/bin/delete-version.rs

+28-12
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,56 @@ fn main() {
3131

3232
fn delete(tx: &postgres::transaction::Transaction) {
3333
let name = match env::args().nth(1) {
34-
None => { println!("needs a crate-name argument"); return }
34+
None => {
35+
println!("needs a crate-name argument");
36+
return;
37+
}
3538
Some(s) => s,
3639
};
3740
let version = match env::args().nth(2) {
38-
None => { println!("needs a version argument"); return }
41+
None => {
42+
println!("needs a version argument");
43+
return;
44+
}
3945
Some(s) => s,
4046
};
4147
let version = semver::Version::parse(&version).unwrap();
4248

4349
let krate = Crate::find_by_name(tx, &name).unwrap();
44-
let v = Version::find_by_num(tx, krate.id, &version).unwrap().unwrap();
45-
print!("Are you sure you want to delete {}#{} ({}) [y/N]: ", name, version,
50+
let v = Version::find_by_num(tx, krate.id, &version)
51+
.unwrap()
52+
.unwrap();
53+
print!("Are you sure you want to delete {}#{} ({}) [y/N]: ",
54+
name,
55+
version,
4656
v.id);
4757
io::stdout().flush().unwrap();
4858
let mut line = String::new();
4959
io::stdin().read_line(&mut line).unwrap();
50-
if !line.starts_with("y") { return }
60+
if !line.starts_with("y") {
61+
return;
62+
}
5163

5264
println!("deleting version {} ({})", v.num, v.id);
5365
let n = tx.execute("DELETE FROM version_downloads WHERE version_id = $1",
54-
&[&v.id]).unwrap();
66+
&[&v.id])
67+
.unwrap();
5568
println!(" {} download records deleted", n);
5669
let n = tx.execute("DELETE FROM version_authors WHERE version_id = $1",
57-
&[&v.id]).unwrap();
70+
&[&v.id])
71+
.unwrap();
5872
println!(" {} author records deleted", n);
59-
let n = tx.execute("DELETE FROM dependencies WHERE version_id = $1",
60-
&[&v.id]).unwrap();
73+
let n = tx.execute("DELETE FROM dependencies WHERE version_id = $1", &[&v.id])
74+
.unwrap();
6175
println!(" {} dependencies deleted", n);
62-
tx.execute("DELETE FROM versions WHERE id = $1",
63-
&[&v.id]).unwrap();
76+
tx.execute("DELETE FROM versions WHERE id = $1", &[&v.id])
77+
.unwrap();
6478

6579
print!("commit? [y/N]: ");
6680
io::stdout().flush().unwrap();
6781
let mut line = String::new();
6882
io::stdin().read_line(&mut line).unwrap();
69-
if !line.starts_with("y") { panic!("aborting transaction"); }
83+
if !line.starts_with("y") {
84+
panic!("aborting transaction");
85+
}
7086
}

0 commit comments

Comments
 (0)