From patchwork Fri Aug 10 08:04:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 956053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41myND0ynkz9s5b for ; Fri, 10 Aug 2018 18:05:16 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41myNC6v3qzDrpW for ; Fri, 10 Aug 2018 18:05:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=au1.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=andrew.donnellan@au1.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41myN84D5MzDqww for ; Fri, 10 Aug 2018 18:05:12 +1000 (AEST) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7A83kAM144786 for ; Fri, 10 Aug 2018 04:05:10 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ks6h7rtvt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 10 Aug 2018 04:05:10 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Aug 2018 09:05:07 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 10 Aug 2018 09:05:04 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7A853DF35455212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 10 Aug 2018 08:05:03 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5CD411C04A; Fri, 10 Aug 2018 11:05:09 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E8AD511C05B; Fri, 10 Aug 2018 11:05:08 +0100 (BST) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 10 Aug 2018 11:05:08 +0100 (BST) Received: from intelligence.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 012CEA0120; Fri, 10 Aug 2018 18:05:01 +1000 (AEST) From: Andrew Donnellan To: snowpatch@lists.ozlabs.org, ruscur@russell.cc Date: Fri, 10 Aug 2018 18:04:55 +1000 X-Mailer: git-send-email 2.11.0 X-TM-AS-GCONF: 00 x-cbid: 18081008-0020-0000-0000-000002B4C23A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18081008-0021-0000-0000-00002101D9E7 Message-Id: <20180810080455.30462-1-andrew.donnellan@au1.ibm.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-08-10_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808100088 Subject: [snowpatch] [PATCH] Fix clippy warnings X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Fix a whole bunch of clippy warnings. Signed-off-by: Andrew Donnellan --- src/main.rs | 48 ++++++++++++++++++++++-------------------------- src/patchwork.rs | 22 +++++++++++++--------- src/settings.rs | 21 +++++++++------------ src/utils.rs | 2 +- 4 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/main.rs b/src/main.rs index ba9e6dba1371..7a0debaebec4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,7 +118,7 @@ fn run_tests( continue; } let mut jenkins_params = Vec::<(&str, &str)>::new(); - for (param_name, param_value) in job.parameters.iter() { + for (param_name, param_value) in &job.parameters { // TODO(ajd): do this more neatly debug!("Param name {}, value {}", ¶m_name, ¶m_value); jenkins_params.push((param_name, param_value)); @@ -151,7 +151,7 @@ fn run_tests( format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(), ), state: test_result, - context: Some(format!("{}", job.title.replace("/", "_")).to_string()), + context: Some(job.title.replace("/", "_")), target_url: Some(jenkins.get_results_url(&build_url_real, &job.parameters)), }); } @@ -170,7 +170,7 @@ fn test_patch( if !path.is_file() { return results; } - let tag = utils::sanitise_path(path.file_name().unwrap().to_str().unwrap().to_string()); + let tag = utils::sanitise_path(path.file_name().unwrap().to_str().unwrap()); let mut remote = repo.find_remote(&project.remote_name).unwrap(); let mut push_callbacks = RemoteCallbacks::new(); @@ -318,18 +318,16 @@ fn main() { let proxy = Proxy::all(&proxy_url).unwrap_or_else(|e| { panic!("Couldn't set proxy: {:?}, error: {}", proxy_url, e); }); - let mut c = Client::builder().proxy(proxy).build().unwrap_or_else(|e| { + Client::builder().proxy(proxy).build().unwrap_or_else(|e| { panic!( "Couldn't create client with proxy: {:?}, error: {}", proxy_url, e ); - }); - c + }) } _ => { debug!("snowpatch starting without a HTTP proxy"); - let mut c = Client::new(); - c + Client::new() } }); @@ -347,7 +345,7 @@ fn main() { if args.flag_patch > 0 { info!("snowpatch is testing a patch from Patchwork."); - let patch = patchwork.get_patch(&(args.flag_patch as u64)).unwrap(); + let patch = patchwork.get_patch(u64::from(args.flag_patch)).unwrap(); match settings.projects.get(&patch.project.link_name) { None => panic!("Couldn't find project {}", &patch.project.link_name), Some(project) => { @@ -357,7 +355,7 @@ fn main() { } else { patchwork.get_patch_mbox(&patch) }; - test_patch(&settings, &client, project, &mbox, true); + test_patch(&settings, &client, &project, &mbox, true); } } return; @@ -365,7 +363,7 @@ fn main() { if args.flag_series > 0 { info!("snowpatch is testing a series from Patchwork."); - let series = patchwork.get_series(&(args.flag_series as u64)).unwrap(); + let series = patchwork.get_series(u64::from(args.flag_series)).unwrap(); // The last patch in the series, so its dependencies are the whole series let patch = patchwork .get_patch_by_url(&series.patches.last().unwrap().url) @@ -375,14 +373,14 @@ fn main() { Some(project) => { let dependencies = patchwork.get_patch_dependencies(&patch); let mbox = patchwork.get_patches_mbox(dependencies); - let results = test_patch(&settings, &client, project, &mbox, true); + let results = test_patch(&settings, &client, &project, &mbox, true); // Delete the temporary directory with the patch in it fs::remove_dir_all(mbox.parent().unwrap()) .unwrap_or_else(|err| error!("Couldn't delete temp directory: {}", err)); if project.push_results { for result in results { - patchwork.post_test_result(result, &patch.checks).unwrap(); + patchwork.post_test_result(&result, &patch.checks).unwrap(); } } } @@ -391,12 +389,12 @@ fn main() { } // At this point, specifying a project is required - let project = settings.projects.get(&args.flag_project).unwrap(); + let project = &settings.projects[&args.flag_project]; if args.flag_mbox != "" { info!("snowpatch is testing a local patch."); let patch = Path::new(&args.flag_mbox); - test_patch(&settings, &client, project, patch, true); + test_patch(&settings, &client, &project, patch, true); return; } @@ -407,20 +405,18 @@ fn main() { * If the patch is part of a series, apply all of its dependencies. * Spawn tests. */ - 'daemon: loop { - let patch_list; - + loop { // TODO: This is hacky and we should refactor out daemon vs patch/count // mode - if args.flag_count > 0 { - patch_list = patchwork + let patch_list = if args.flag_count > 0 { + patchwork .get_patch_query_num(&args.flag_project, args.flag_count as usize) - .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err)); + .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err)) } else { - patch_list = patchwork + patchwork .get_patch_query(&args.flag_project) - .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err)); - } + .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err)) + }; info!("snowpatch is ready to test new revisions from Patchwork."); for patch in patch_list { // If it's already been tested, we can skip it @@ -478,14 +474,14 @@ fn main() { patchwork.get_patch_mbox(&patch) }; - let results = test_patch(&settings, &client, project, &mbox, hefty_tests); + let results = test_patch(&settings, &client, &project, &mbox, hefty_tests); // Delete the temporary directory with the patch in it fs::remove_dir_all(mbox.parent().unwrap()) .unwrap_or_else(|err| error!("Couldn't delete temp directory: {}", err)); if project.push_results { for result in results { - patchwork.post_test_result(result, &patch.checks).unwrap(); + patchwork.post_test_result(&result, &patch.checks).unwrap(); } } } diff --git a/src/patchwork.rs b/src/patchwork.rs index 31ac8ef95911..a0722c7df0c6 100644 --- a/src/patchwork.rs +++ b/src/patchwork.rs @@ -218,7 +218,7 @@ impl PatchworkServer { PatchworkServer { url: url.clone(), client: client.clone(), - headers: headers, + headers, } } @@ -266,7 +266,7 @@ impl PatchworkServer { pub fn post_test_result( &self, - result: TestResult, + result: &TestResult, checks_url: &str, ) -> Result { let encoded = serde_json::to_string(&result).unwrap(); @@ -286,7 +286,7 @@ impl PatchworkServer { Ok(resp.status()) } - pub fn get_patch(&self, patch_id: &u64) -> Result { + pub fn get_patch(&self, patch_id: u64) -> Result { let url = format!( "{}{}/patches/{}{}", &self.url, PATCHWORK_API, patch_id, PATCHWORK_QUERY @@ -304,8 +304,11 @@ impl PatchworkServer { &self.url, PATCHWORK_API, PATCHWORK_QUERY, project ); - serde_json::from_str(&self.get_url_string(&url) - .unwrap_or_else(|err| panic!("Failed to connect to Patchwork: {}", err))) + serde_json::from_str( + &self + .get_url_string(&url) + .unwrap_or_else(|err| panic!("Failed to connect to Patchwork: {}", err)), + ) } fn get_next_link(&self, resp: &Response) -> Option { @@ -332,7 +335,8 @@ impl PatchworkServer { )); while let Some(real_url) = url { - let resp = self.get_url(&real_url) + let resp = self + .get_url(&real_url) .unwrap_or_else(|err| panic!("Failed to connect to Patchwork: {}", err)); url = self.get_next_link(&resp); let new_patches: Vec = serde_json::from_reader(resp)?; @@ -364,7 +368,7 @@ impl PatchworkServer { pub fn get_patch_mbox(&self, patch: &Patch) -> PathBuf { let dir = TempDir::new("snowpatch").unwrap().into_path(); let mut path = dir.clone(); - let tag = utils::sanitise_path(patch.name.clone()); + let tag = utils::sanitise_path(&patch.name); path.push(format!("{}.mbox", tag)); let mut mbox_resp = self.get_url(&patch.mbox).unwrap(); @@ -380,7 +384,7 @@ impl PatchworkServer { pub fn get_patches_mbox(&self, patches: Vec) -> PathBuf { let dir = TempDir::new("snowpatch").unwrap().into_path(); let mut path = dir.clone(); - let tag = utils::sanitise_path(patches.last().unwrap().name.clone()); + let tag = utils::sanitise_path(&patches.last().unwrap().name); path.push(format!("{}.mbox", tag)); let mut mbox = OpenOptions::new() @@ -399,7 +403,7 @@ impl PatchworkServer { path } - pub fn get_series(&self, series_id: &u64) -> Result { + pub fn get_series(&self, series_id: u64) -> Result { let url = format!( "{}{}/series/{}{}", &self.url, PATCHWORK_API, series_id, PATCHWORK_QUERY diff --git a/src/settings.rs b/src/settings.rs index 2d3935451cd9..241580b36e20 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -157,18 +157,18 @@ impl<'de> Deserialize<'de> for Job { let job: String = job.ok_or_else(|| de::Error::missing_field("job"))?; let remote = remote.ok_or_else(|| de::Error::missing_field("remote"))?; let branch = branch.ok_or_else(|| de::Error::missing_field("branch"))?; - let title = title.unwrap_or(job.clone()); + let title = title.unwrap_or_else(|| job.clone()); let hefty = hefty.unwrap_or(false); let warn_on_fail = warn_on_fail.unwrap_or(false); Ok(Job { - job: job, - title: title, - remote: remote, - branch: branch, - hefty: hefty, - warn_on_fail: warn_on_fail, - parameters: parameters, + job, + title, + remote, + branch, + hefty, + warn_on_fail, + parameters, }) } } @@ -188,10 +188,7 @@ pub struct Config { pub fn parse(path: &str) -> Config { let mut toml_config = String::new(); - let mut file = match File::open(&path) { - Ok(file) => file, - Err(_) => panic!("Couldn't open config file, exiting."), - }; + let mut file = File::open(&path).expect("Couldn't open config file, exiting."); file.read_to_string(&mut toml_config) .unwrap_or_else(|err| panic!("Couldn't read config: {}", err)); diff --git a/src/utils.rs b/src/utils.rs index 10ffd9562ae2..5f791afd59eb 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,7 +13,7 @@ // utils.rs - snowpatch generic helpers // -pub fn sanitise_path(path: String) -> String { +pub fn sanitise_path(path: &str) -> String { path.replace("/", "_") .replace("\\", "_") .replace(".", "_")