Skip to content

Commit cca5e71

Browse files
tesujiCentril
authored andcommitted
Transfer to 2018 edition (#273)
* Transfer to 2018 edition Deny Rust 2018 idioms * src: Fix redundant imports * clippy: Fix or_fun_call * clippy: Fix single_char_pattern * clippy: Fix redundant_field_names * clippy: Fix redundant_closure * clippy: Fix const_static_lifetime * Update rust-toolchain version * cargo: Sort dependencies by alphanumeric order * More clippy fixes * clone_double_ref * expect_fun_call * unnecessary_operation * ci: Reformatting config * ci: Update PostgreSQL version to 9.6 Fix unrecognized configuration parameter "idle_in_transaction_session_timeout" * Fix over rate limiting * test: Ignore `team_members_exist` We now load all usernames from the team repo, and we import into the database missing users received from the team api.
1 parent 3a8d3a0 commit cca5e71

18 files changed

+160
-173
lines changed

.travis.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
dist: trusty
1+
dist: xenial
22
notifications:
33
email: false
44
language: rust
55
rust:
6-
- nightly
6+
# sync in `rust-toolchain` file
7+
- nightly-2019-04-26
78
cache:
8-
cargo: true
99
directories:
10-
- "$HOME/.rustup"
10+
- "$HOME/.cargo"
11+
# But don't cache the cargo registry
12+
before_cache:
13+
- rm -rf "$HOME/.cargo/registry"
1114
addons:
12-
postgresql: '9.5'
15+
postgresql: "9.6"
1316
apt:
1417
packages:
1518
- curl
@@ -21,12 +24,12 @@ before_install:
2124
install:
2225
- export RUST_LOG=debug,hyper=info,rustc=error,cargo=error,jobserver=error
2326
- export GITHUB_WEBHOOK_SECRETS=none
24-
- export GITHUB_ACCESS_TOKEN=
27+
- export GITHUB_ACCESS_TOKEN="$GITHUB_ACCESS_TOKEN"
2528
- export GITHUB_SCRAPE_INTERVAL=6000
26-
- export GITHUB_USER_AGENT=none-agent-with-left-beef
29+
- export GITHUB_USER_AGENT=rfcbot-rs
2730
- export POST_COMMENTS=false
2831
- export RUST_BACKTRACE=1
29-
- export PATH=$PATH:$HOME/.cargo/bin
32+
- . "$HOME"/.cargo/env
3033
- export DATABASE_URL=postgres://localhost/dashboard
3134
- export DATABASE_POOL_SIZE=5
3235
- rustup default $(cat rust-toolchain)
@@ -36,7 +39,7 @@ install:
3639
before_script:
3740
- diesel setup
3841
- diesel migration run
39-
- psql -q -d $DATABASE_URL < githubuser-backup.pg
42+
- psql -q -d "$DATABASE_URL" < githubuser-backup.pg
4043
script:
4144
- cargo build
4245
- cargo test

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
authors = ["Adam Perry <adam.n.perry@gmail.com>"]
33
name = "rfcbot-rs"
44
version = "0.1.0"
5+
edition = "2018"
56

7+
# Sorted by alphanumeric order
68
[dependencies]
79
dotenv = "0.13.0"
810
env_logger = "0.4"
911
hex = "0.3.2"
12+
itertools = "0.8.0"
1013
lazy_static = "1.2.0"
1114
log = "0.3.6"
15+
maplit = "1.0.1"
16+
reqwest = "0.9.12"
1217
rocket = "0.4.0"
1318
rocket_contrib = { version = "0.4.0", features = ["json", "handlebars_templates"] }
1419
rust-crypto = "0.2.36"
@@ -18,9 +23,6 @@ serde_json = "1.0"
1823
toml = "0.4"
1924
url = "1.4"
2025
urlencoded = "0.5"
21-
maplit = "1.0.1"
22-
itertools = "0.8.0"
23-
reqwest = "0.9.12"
2426

2527
[dependencies.chrono]
2628
features = ["serde"]

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2019-02-22
1+
nightly-2019-04-26

src/config.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::collections::BTreeMap;
44
use std::env;
55

6-
pub const RFC_BOT_MENTION: &'static str = "@rfcbot";
7-
pub const GH_ORGS: [&'static str; 3] = ["rust-lang", "rust-lang-nursery", "rust-lang-deprecated"];
6+
pub const RFC_BOT_MENTION: &str = "@rfcbot";
7+
pub const GH_ORGS: [&str; 3] = ["rust-lang", "rust-lang-nursery", "rust-lang-deprecated"];
88

99
lazy_static! {
1010
pub static ref CONFIG: Config = {
@@ -40,30 +40,30 @@ impl Config {
4040
}
4141
}
4242

43-
const DB_URL: &'static str = "DATABASE_URL";
44-
const DB_POOL_SIZE: &'static str = "DATABASE_POOL_SIZE";
45-
const GITHUB_TOKEN: &'static str = "GITHUB_ACCESS_TOKEN";
46-
const GITHUB_WEBHOOK_SECRETS: &'static str = "GITHUB_WEBHOOK_SECRETS";
47-
const GITHUB_UA: &'static str = "GITHUB_USER_AGENT";
48-
const GITHUB_INTERVAL: &'static str = "GITHUB_SCRAPE_INTERVAL";
49-
const POST_COMMENTS: &'static str = "POST_COMMENTS";
43+
const DB_URL: &str = "DATABASE_URL";
44+
const DB_POOL_SIZE: &str = "DATABASE_POOL_SIZE";
45+
const GITHUB_TOKEN: &str = "GITHUB_ACCESS_TOKEN";
46+
const GITHUB_WEBHOOK_SECRETS: &str = "GITHUB_WEBHOOK_SECRETS";
47+
const GITHUB_UA: &str = "GITHUB_USER_AGENT";
48+
const GITHUB_INTERVAL: &str = "GITHUB_SCRAPE_INTERVAL";
49+
const POST_COMMENTS: &str = "POST_COMMENTS";
5050

5151
// this is complex, but we'll shortly need a lot more config items
5252
// so checking them automagically seems like a nice solution
5353
pub fn init() -> Result<Config, Vec<&'static str>> {
5454
let mut vars: BTreeMap<&'static str, Result<String, _>> = BTreeMap::new();
55-
let keys = vec![
55+
[
5656
DB_URL,
5757
DB_POOL_SIZE,
5858
GITHUB_TOKEN,
5959
GITHUB_WEBHOOK_SECRETS,
6060
GITHUB_UA,
6161
POST_COMMENTS,
62-
];
63-
64-
for var in keys {
62+
]
63+
.iter()
64+
.for_each(|var| {
6565
vars.insert(var, env::var(var));
66-
}
66+
});
6767

6868
let all_found = vars.iter().all(|(_, v)| v.is_ok());
6969
if all_found {
@@ -92,13 +92,13 @@ pub fn init() -> Result<Config, Vec<&'static str>> {
9292
let webhook_secrets = webhook_secrets.split(',').map(String::from).collect();
9393

9494
Ok(Config {
95-
db_url: db_url,
96-
db_pool_size: db_pool_size,
95+
db_url,
96+
db_pool_size,
9797
github_access_token: gh_token,
9898
github_user_agent: gh_ua,
9999
github_webhook_secrets: webhook_secrets,
100100
github_interval_mins: gh_interval,
101-
post_comments: post_comments,
101+
post_comments,
102102
})
103103
} else {
104104
Err(vars

src/domain/github.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct IssuePartial {
9595
impl IssuePartial {
9696
pub fn complete(self, id: i32) -> Issue {
9797
Issue {
98-
id: id,
98+
id,
9999
number: self.number,
100100
fk_milestone: self.fk_milestone,
101101
fk_user: self.fk_user,

src/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Copyright 2016 Adam Perry. Dual-licensed MIT and Apache 2.0 (see LICENSE files for details).
22

3-
use std;
43
use std::convert::From;
54
use std::io;
65

7-
use diesel;
86
use rocket_contrib::templates::handlebars;
9-
use serde_json;
107

118
pub type DashResult<T> = std::result::Result<T, DashError>;
129

src/github/client.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use std::u32;
88
use chrono::{DateTime, Utc};
99
use reqwest::{self, header::HeaderMap, Response, StatusCode};
1010
use serde::de::DeserializeOwned;
11-
use serde_json;
1211

13-
use config::CONFIG;
14-
use domain::github::GitHubUser;
15-
use error::{DashError, DashResult};
16-
use github::models::{CommentFromJson, IssueFromJson, PullRequestFromJson, PullRequestUrls};
12+
use crate::config::CONFIG;
13+
use crate::domain::github::GitHubUser;
14+
use crate::error::{DashError, DashResult};
15+
use crate::github::models::{CommentFromJson, IssueFromJson, PullRequestFromJson, PullRequestUrls};
1716

18-
pub const BASE_URL: &'static str = "https://api.github.com";
17+
pub const BASE_URL: &str = "https://api.github.com";
1918

2019
pub const DELAY: u64 = 300;
2120

@@ -129,7 +128,7 @@ impl Client {
129128
if let Some(lh) = h.get("Link") {
130129
let lh = &lh.to_str().unwrap();
131130
for link in (**lh).split(',').map(|s| s.trim()) {
132-
let tokens = link.split(';').map(|s| s.trim()).collect::<Vec<_>>();
131+
let tokens = link.split(';').map(str::trim).collect::<Vec<_>>();
133132

134133
if tokens.len() != 2 {
135134
continue;

src/github/command.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::collections::BTreeSet;
22
use std::fmt;
33

4-
use config::RFC_BOT_MENTION;
5-
use error::{DashError, DashResult};
6-
use teams::{RfcbotConfig, TeamLabel};
4+
use crate::config::RFC_BOT_MENTION;
5+
use crate::error::{DashError, DashResult};
6+
use crate::teams::{RfcbotConfig, TeamLabel};
77

88
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
99
pub enum Label {
@@ -34,7 +34,7 @@ impl Label {
3434
}
3535

3636
impl fmt::Display for Label {
37-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.write_str(self.as_str()) }
37+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.write_str(self.as_str()) }
3838
}
3939

4040
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -44,9 +44,9 @@ pub enum FcpDisposition {
4444
Postpone,
4545
}
4646

47-
const FCP_REPR_MERGE: &'static str = "merge";
48-
const FCP_REPR_CLOSE: &'static str = "close";
49-
const FCP_REPR_POSTPONE: &'static str = "postpone";
47+
const FCP_REPR_MERGE: &str = "merge";
48+
const FCP_REPR_CLOSE: &str = "close";
49+
const FCP_REPR_POSTPONE: &str = "postpone";
5050

5151
impl FcpDisposition {
5252
pub fn repr(self) -> &'static str {
@@ -268,7 +268,7 @@ impl<'a> RfcBotCommand<'a> {
268268
// Get the tokens for each command line (starts with a bot mention)
269269
command
270270
.lines()
271-
.map(|l| l.trim())
271+
.map(str::trim)
272272
.filter(|&l| l.starts_with(RFC_BOT_MENTION))
273273
.map(move |l| from_invocation_line(setup, l))
274274
.filter_map(Result::ok)
@@ -278,7 +278,7 @@ impl<'a> RfcBotCommand<'a> {
278278
#[cfg(test)]
279279
mod test {
280280
use super::*;
281-
use teams::test::TEST_SETUP;
281+
use crate::teams::test::TEST_SETUP;
282282

283283
fn parse_commands(body: &str) -> impl Iterator<Item = RfcBotCommand<'_>> {
284284
RfcBotCommand::from_str_all(&TEST_SETUP, body)

src/github/mod.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ mod nag;
77
pub mod webhooks;
88

99
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
10-
use diesel;
1110
use diesel::pg::PgConnection;
1211
use diesel::prelude::*;
1312

14-
use domain::github::*;
15-
use domain::schema::*;
16-
use error::DashResult;
17-
use DB_POOL;
13+
use crate::domain::github::*;
14+
use crate::domain::schema::*;
15+
use crate::error::DashResult;
16+
use crate::DB_POOL;
1817

1918
use self::client::Client;
2019
use self::models::{CommentFromJson, IssueFromJson, PullRequestFromJson};
@@ -34,7 +33,7 @@ pub fn most_recent_update() -> DashResult<DateTime<Utc>> {
3433
let conn = &*DB_POOL.get()?;
3534

3635
let updated: NaiveDateTime = {
37-
use domain::schema::githubsync::dsl::*;
36+
use crate::domain::schema::githubsync::dsl::*;
3837
githubsync
3938
.select(ran_at)
4039
.filter(successful.eq(true))
@@ -49,7 +48,7 @@ pub fn most_recent_update() -> DashResult<DateTime<Utc>> {
4948
pub fn record_successful_update(ingest_start: NaiveDateTime) -> DashResult<()> {
5049
let conn = &*DB_POOL.get()?;
5150
// insert a successful sync record
52-
use domain::schema::githubsync::dsl::*;
51+
use crate::domain::schema::githubsync::dsl::*;
5352
let sync_record = GitHubSyncPartial {
5453
successful: true,
5554
ran_at: ingest_start,
@@ -122,7 +121,7 @@ pub fn ingest_since(repo: &str, start: DateTime<Utc>) -> DashResult<()> {
122121
}
123122

124123
pub fn handle_pr(conn: &PgConnection, pr: PullRequestFromJson, repo: &str) -> DashResult<()> {
125-
use domain::schema::pullrequest::dsl::*;
124+
use crate::domain::schema::pullrequest::dsl::*;
126125
if let Some(ref assignee) = pr.assignee {
127126
handle_user(conn, assignee)?;
128127
}
@@ -191,7 +190,7 @@ pub fn handle_issue(conn: &PgConnection, issue: IssueFromJson, repo: &str) -> Da
191190

192191
// handle issue itself
193192
{
194-
use domain::schema::issue::dsl::*;
193+
use crate::domain::schema::issue::dsl::*;
195194

196195
diesel::insert_into(issue)
197196
.values(&i)
@@ -221,10 +220,10 @@ mod tests {
221220

222221
#[test]
223222
fn test_handle_user() {
224-
::utils::setup_test_env();
223+
crate::utils::setup_test_env();
225224
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
226-
let conn =
227-
PgConnection::establish(&db_url).expect(&format!("Error connecting to {}", db_url));
225+
let conn = PgConnection::establish(&db_url)
226+
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
228227

229228
let user = GitHubUser {
230229
id: -1,

src/github/models.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::i32;
55

66
use chrono::{DateTime, Utc};
77

8-
use domain::github::{GitHubUser, IssueComment, IssuePartial, Milestone, PullRequest};
9-
use error::DashResult;
10-
use DB_POOL;
8+
use crate::domain::github::{GitHubUser, IssueComment, IssuePartial, Milestone, PullRequest};
9+
use crate::error::DashResult;
10+
use crate::DB_POOL;
1111

1212
#[derive(Clone, Debug, Deserialize)]
1313
pub struct MilestoneFromJson {
@@ -113,14 +113,14 @@ pub struct CommentFromJson {
113113

114114
impl CommentFromJson {
115115
pub fn with_repo(self, repo: &str) -> DashResult<IssueComment> {
116+
use crate::domain::schema::issue::dsl::*;
116117
use diesel::prelude::*;
117-
use domain::schema::issue::dsl::*;
118118

119119
let issue_number = self
120120
.html_url
121121
.split('#')
122122
.next()
123-
.map(|r| r.split('/').last().map(|n| n.parse::<i32>()));
123+
.map(|r| r.split('/').last().map(str::parse));
124124

125125
let issue_number = match issue_number {
126126
Some(Some(Ok(n))) => n,

0 commit comments

Comments
 (0)