Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

With reqwest #1

Merged
merged 3 commits into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# v2.0.0 (unreleased)

Switch from `curl` & `rustc_serialize` to `reqwest` & `serde`

This makes it far more future proof and additionally does not require
openssl on Mac or Windows!

# v1.0.0 (2016-02-02)

The missing `after_all_success` hook for Travis

Did you ever wanted to run a task after all jobs of your build finished and succeeded?
Then this is for you.

Travis doesn't offer a `after_all_success` hook, so it is necessary to work around that.
This tool allows to wait for all builds and run a single task on the build leader,
that is on the node of the first job in the build matrix

See the README on <https://github.com/badboy/travis-after-all-rs> for more information.

Documentation is online at <http://badboy.github.io/travis-after-all-rs>

This is a port of the original Python script: <https://github.com/dmakhno/travis_after_all>
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ homepage = "https://github.com/badboy/travis-after-all-rs"
repository = "https://github.com/badboy/travis-after-all-rs"

[dependencies]
curl = "0.2.16"
rustc-serialize = "0.3.16"
reqwest = "0.4.0"
serde = "0.9.6"
serde_derive = "0.9.6"
serde_json = "0.9.5"

[[bin]]
name = "travis-after-all"
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::error;
use std::env::VarError;
use std::error::Error as StdError;
use std::num::ParseIntError;
use rustc_serialize::json::DecoderError;
use reqwest;

/// All possible error cases
#[derive(Debug)]
Expand Down Expand Up @@ -62,8 +62,8 @@ impl From<ParseIntError> for Error {
}
}

impl From<DecoderError> for Error {
fn from(err: DecoderError) -> Error {
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Error {
Error::Generic(err.description().into())
}
}
26 changes: 14 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@
//! ```
#![deny(missing_docs)]

extern crate curl;
extern crate rustc_serialize;
extern crate reqwest;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

use std::thread;
use std::time::Duration;
use std::env;
use std::str::FromStr;
use rustc_serialize::json;
use curl::http;
use reqwest::{RedirectPolicy, StatusCode};
use reqwest::header::UserAgent;

mod error;
mod matrix;
Expand Down Expand Up @@ -113,19 +116,18 @@ impl Build {
/// Fetch the build matrix for the current build
pub fn build_matrix(&self) -> Result<Matrix, Error> {
let url = format!("{}/builds/{}", self.travis_api_url, self.build_id);
let res = http::handle()
.get(url)
.follow_redirects(true)
.header("User-Agent", USER_AGENT)
.exec()
let mut client = reqwest::Client::new().unwrap();
client.redirect(RedirectPolicy::limited(5));
let mut res = client.get(&url)
.header(UserAgent(USER_AGENT.to_string()))
.send()
.unwrap();

if res.get_code() == 404 {
if *res.status() == StatusCode::NotFound {
return Err(Error::BuildNotFound);
}

let body = String::from_utf8(res.move_body()).unwrap();
Ok(try!(json::decode(&body)))
res.json().map_err(|e| From::from(e))
}

/// Wait for all non-leader jobs to finish
Expand Down
4 changes: 2 additions & 2 deletions src/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// A single job and relevant information
#[derive(Debug, RustcDecodable, RustcEncodable)]
#[derive(Debug, Serialize, Deserialize)]
pub struct MatrixElement {
finished_at: Option<String>,
result: Option<u32>,
Expand All @@ -8,7 +8,7 @@ pub struct MatrixElement {
}

/// A list of jobs
#[derive(Debug, RustcDecodable, RustcEncodable)]
#[derive(Debug, Serialize, Deserialize)]
pub struct Matrix {
id: u32,
matrix: Vec<MatrixElement>,
Expand Down