jenkins: refactor to get rid of lifetime specifiers
diff mbox

Message ID 20161121070732.6630-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show

Commit Message

Andrew Donnellan Nov. 21, 2016, 7:07 a.m. UTC
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 src/jenkins.rs | 11 ++++++-----
 src/main.rs    |  8 ++++----
 2 files changed, 10 insertions(+), 9 deletions(-)

Comments

Russell Currey Nov. 21, 2016, 7:16 a.m. UTC | #1
On Mon, 2016-11-21 at 18:07 +1100, Andrew Donnellan wrote:
> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
> ---

Applied to master as d5b7f82e, thanks.

FYI I've also rebased upstream-wip on top of this commit

Patch
diff mbox

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 6dd0b93..f450243 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -27,6 +27,7 @@  extern crate rustc_serialize;
 use std::io::Read;
 use std::time::Duration;
 use std::thread::sleep;
+use std::sync::Arc;
 
 use hyper::Client;
 use hyper::header::Location;
@@ -41,13 +42,13 @@  pub trait CIBackend { // TODO: Separate out
     fn start_test(&self, job_name: &str, params: Vec<(&str, &str)>) -> Result<String, &'static str>;
 }
 
-pub struct JenkinsBackend<'a> {
-    pub base_url: &'a str,
-    pub hyper_client: &'a Client,
+pub struct JenkinsBackend {
+    pub base_url: String,
+    pub hyper_client: Arc<Client>,
     // TODO: Authentication
 }
 
-impl<'a> CIBackend for JenkinsBackend<'a> {
+impl CIBackend for JenkinsBackend {
     /// Start a Jenkins build
     ///
     /// # Failures
@@ -76,7 +77,7 @@  pub enum JenkinsBuildStatus {
     Done,
 }
 
-impl<'a> JenkinsBackend<'a> {
+impl JenkinsBackend {
     fn get_api_json_object(&self, base_url: &str) -> rustc_serialize::json::Object {
         // TODO: Don't panic on failure, fail more gracefully
         let url = format!("{}api/json", base_url);
diff --git a/src/main.rs b/src/main.rs
index 57fd5ad..e1f1885 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -89,12 +89,12 @@  struct Args {
     flag_project: String,
 }
 
-fn run_tests(settings: &Config, client: &Client, project: &Project, tag: &str,
+fn run_tests(settings: &Config, client: Arc<Client>, project: &Project, tag: &str,
              branch_name: &str) -> Vec<TestResult> {
     let mut results: Vec<TestResult> = Vec::new();
     let jenkins = JenkinsBackend {
-        base_url: &settings.jenkins.url,
-        hyper_client: &client,
+        base_url: settings.jenkins.url.clone(),
+        hyper_client: client,
     };
     let project = project.clone();
     for job_params in project.jobs.iter() {
@@ -217,7 +217,7 @@  fn test_patch(settings: &Config, client: &Arc<Client>, project: &Project, path:
 
         // We've set up a remote branch, time to kick off tests
         let test = thread::Builder::new().name(tag.to_string()).spawn(move || {
-            return run_tests(&settings_clone, &client, &project, &tag,
+            return run_tests(&settings_clone, client, &project, &tag,
                              &branch_name);
         }).unwrap();
         results.append(&mut test.join().unwrap());