Skip to content

Commit

Permalink
Move Pivotal API to separate Crate
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspustina committed Mar 11, 2020
1 parent 6126ef5 commit 8d2fccb
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 18 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ homepage = "https://github.com/centerdevice/ceres"
travis-ci = { repository = "centerdevice/ceres", branch = "master" }
codecov = { repository = "centerdevice/ceres", branch = "master", service = "github" }

[workspace]
members = [
"crates/pivotal_api"
]

[dependencies]
centerdevice = "0.4"
clams = "^0.0.16"
Expand All @@ -33,6 +38,7 @@ mime_guess = "1.8"
prettytable-rs = "^0.7"
regex = "^1.0"
hyper = "0.11.9" # Strongly connected to reqwest
pivotal_api = { path = "crates/pivotal_api" }
reqwest = { version = "0.8.6", features = ["unstable"] }
rusoto_core = "0.31.0"
rusoto_credential = "0.10.0"
Expand Down
23 changes: 23 additions & 0 deletions crates/pivotal_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "pivotal_api"
version = "0.0.1"
authors = ["Lukas Pustina <[email protected]>"]
description = "Pivotal API"
repository = "https://github.com/centerdevice/ceres.git"
homepage = "https://github.com/centerdevice/ceres"
workspace = "../.."

[dependencies]
error-chain = "^0.12"
log = "^0.4"
futures = "0.1"
hyper = "0.11.9" # Strongly connected to reqwest
reqwest = { version = "0.8.6", features = ["unstable"] }
serde = "^1.0"
serde_derive = "^1.0"
serde_json = "^1.0"
tokio-core = "^0.1"

[dev-dependencies]
quickcheck = "^0.6"
spectral = "^0.6"
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
#[macro_use]
extern crate error_chain;
extern crate futures;
#[macro_use]
extern crate hyper;
#[macro_use]
extern crate log;
#[macro_use]
extern crate reqwest;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;

header! { (XTrackerToken, "X-TrackerToken") => [String] }

use futures::{Future, Stream};
use futures::future::result;
use reqwest::header::{ContentType, Connection};
use reqwest::unstable::async::{Client as ReqwestClient};
use serde::de::DeserializeOwned;
use serde_json;

use modules::stories::XTrackerToken;
use modules::stories::errors::*;
error_chain! {
errors {
FailedToQueryPivotalApi {
description("Failed to query Pivotal Tracker API")
}
}
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Story {
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ extern crate handlebars;
extern crate hubcaps;
extern crate ignore;
extern crate itertools;
#[macro_use]
extern crate hyper;
#[macro_use]
extern crate log;
extern crate mime;
extern crate mime_guess;
extern crate pivotal_api;
extern crate prettytable;
extern crate regex;
extern crate reqwest;
Expand All @@ -28,7 +28,6 @@ extern crate rusoto_sts;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
extern crate service_world;
extern crate subprocess;
Expand Down
8 changes: 5 additions & 3 deletions src/modules/stories/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use run_config::RunConfig;
use output::stories::OutputType;
use output::stories::{JsonOutputStory, MarkDownOutputStory, OutputStory};
use modules::{Result as ModuleResult, Error as ModuleError, ErrorKind as ModuleErrorKind, Module};
use modules::stories::pivotal_api::*;
use pivotal_api::{get_story, get_project_members, Story, ProjectMember};
use modules::stories::errors::*;

pub const NAME: &str = "export";
Expand Down Expand Up @@ -75,11 +75,13 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
let client = ReqwestClient::new(&core.handle());

let work = get_story(&client, project_id, story_id, &token);
let story = core.run(work)?;
let story = core.run(work)
.chain_err(|| ErrorKind::FailedToQueryPivotalApi)?;
debug!("{:#?}", story);

let work = get_project_members(&client, project_id, &token);
let members = core.run(work)?;
let members = core.run(work)
.chain_err(|| ErrorKind::FailedToQueryPivotalApi)?;
debug!("{:#?}", members);

info!("Outputting instance descriptions");
Expand Down
4 changes: 0 additions & 4 deletions src/modules/stories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ mod errors {
}
}

pub mod pivotal_api;

header! { (XTrackerToken, "X-TrackerToken") => [String] }

sub_module!("stories", "Manage stories", export, prepare, start);

10 changes: 7 additions & 3 deletions src/modules/stories/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio_core;
use config::CeresConfig as Config;
use run_config::RunConfig;
use modules::{Result as ModuleResult, Error as ModuleError, ErrorKind as ModuleErrorKind, Module};
use modules::stories::pivotal_api::*;
use pivotal_api::{create_task, get_story, set_description, Story};
use modules::stories::errors::*;

pub const NAME: &str = "prepare";
Expand Down Expand Up @@ -80,14 +80,16 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
let client = ReqwestClient::new(&core.handle());

let f = get_story(&client, project_id, story_id, &token)
.map_err(|e| Error::with_chain(e, ErrorKind::FailedToQueryPivotalApi))
.and_then(|story|
if story.tasks.is_empty() || force {
future::ok(story)
} else {
future::err(Error::from_kind(ErrorKind::StoryHasTasksAlready))
}
);
let story: Story = core.run(f)?;
let story: Story = core.run(f)
.chain_err(|| ErrorKind::FailedToQueryPivotalApi)?;
debug!("{:#?}", story);

info!("Creating tasks");
Expand All @@ -97,6 +99,7 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
.map(|(pos, x)| {
let f = create_task(&client, project_id, story_id, &token, pos+1, x);
core.run(f)
.chain_err(|| ErrorKind::FailedToQueryPivotalApi)
})
.collect();
let result = result?;
Expand All @@ -105,7 +108,8 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
info!("Adding description");
let description = format!("{}\n\n{}\n", story.description.unwrap_or_else(|| "".to_string()), NO_RISK_ASSESSMET);
let f = set_description(&client, project_id, story_id, &token, &description);
let result = core.run(f)?;
let result = core.run(f)
.chain_err(|| ErrorKind::FailedToQueryPivotalApi)?;
debug!("{:#?}", result);

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion src/modules/stories/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio_core;
use config::CeresConfig as Config;
use run_config::RunConfig;
use modules::{Result as ModuleResult, Error as ModuleError, ErrorKind as ModuleErrorKind, Module};
use modules::stories::pivotal_api::*;
use pivotal_api::{get_story, start_story, StoryState};
use modules::stories::errors::*;

pub const NAME: &str = "start";
Expand Down Expand Up @@ -61,6 +61,7 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
let client = ReqwestClient::new(&core.handle());

let work = get_story(&client, project_id, story_id, &token)
.map_err(|e| Error::with_chain(e, ErrorKind::FailedToQueryPivotalApi))
.and_then(|story|
if story.estimate.is_none() {
future::err(Error::from_kind(ErrorKind::StoryIsNotEstimated))
Expand All @@ -72,6 +73,7 @@ fn do_call(args: &ArgMatches, run_config: &RunConfig, config: &Config) -> Result
)
.and_then(|story|
start_story(&client, project_id, story.id, &token)
.map_err(|e| Error::with_chain(e, ErrorKind::FailedToQueryPivotalApi))
);
let result = core.run(work)?;

Expand Down
2 changes: 1 addition & 1 deletion src/output/stories/markdown_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn render<T: Write>(writer: &mut T, story: &formatting::Story) -> Result<()> {
mod formatting {
use std::collections::HashMap;

use modules::stories::pivotal_api::{self, Label, PullRequest, StoryState, StoryType, Task};
use pivotal_api::{self, Label, PullRequest, StoryState, StoryType, Task};

pub trait FromWithPersonLookup<'a, T> {
fn from_with(_: &'a T, persons: &HashMap<u64, &'a str>) -> Self;
Expand Down
2 changes: 1 addition & 1 deletion src/output/stories/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use modules::stories::pivotal_api::{ProjectMember, Story};
use pivotal_api::{ProjectMember, Story};

use std::{io::Write, str::FromStr};

Expand Down

0 comments on commit 8d2fccb

Please sign in to comment.