Skip to content

Commit

Permalink
Merge pull request #7 from rust-playground/update-deps
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
deankarn authored Jun 23, 2022
2 parents f2f6a6a + 190f69c commit 637af66
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 295 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ members = [
# good read - https://lifthrasiir.github.io/rustlog/why-is-a-rust-executable-large.html
[profile.release]
lto = true
strip = true
codegen-units = 1
panic = 'abort' # not a normal but a pretty backtrace for panics not really necessary in release build
4 changes: 2 additions & 2 deletions alfred-workflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ categories = ["development-tools"]
[dependencies]
alfred = "4.0.2"
dirs = "4.0.0"
anyhow = "1.0.44"
anyhow = "1.0.58"

[dependencies.rusqlite]
features = [
"bundled-full",
]
version = "0.26.1"
version = "0.27.0"
20 changes: 14 additions & 6 deletions alfred-workflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{anyhow, Error};
use rusqlite::Connection;
use std::{fs, io::Write};

/// Opens or creates if not exists an SQLite database.
/// Opens or creates if not exists an `SQLite` database.
///
/// # Arguments
/// * `name` - The name of the workflow, which will create a dedicated sub-directory for.vec!
Expand All @@ -14,6 +14,10 @@ use std::{fs, io::Write};
/// # Remarks
/// `name` must be unique or it may conflict with other workflows.
///
/// # Errors
///
/// Will return `Err` if connection to database fails
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -48,12 +52,12 @@ where
.join(name);

let db = path.join("db.sqlite3");
if !db.exists() {
fs::create_dir_all(path)?;
if db.exists() {
conn = Connection::open(&db)?;
f(&conn)?
} else {
conn = Connection::open(&db)?
fs::create_dir_all(path)?;
conn = Connection::open(&db)?;
f(&conn)?;
}
Ok(conn)
}
Expand All @@ -64,6 +68,10 @@ where
/// * `writer` - the writer to writer iterms to.vec!
/// * `items` - the Alfred items to be written.vec!
///
/// # Errors
///
/// Will return `Err` if items cannot be serialized to JSON.
///
/// # Examples
/// ```
/// use alfred::{json, Item};
Expand All @@ -81,6 +89,6 @@ pub fn write_items<W>(writer: W, items: &[Item]) -> Result<(), Error>
where
W: Write,
{
json::write_items(writer, &items[..])
json::write_items(writer, items)
.map_err(|e| anyhow!("failed to write alfred items->json: {}", e))
}
18 changes: 9 additions & 9 deletions buildkite-workflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT"
name = "buildkite-workflow"
readme = "README.md"
repository = "https://github.com/rust-playground/alfred-workflows-rs/tree/master/buildkite-workflow"
version = "1.1.0"
version = "1.2.0"

[[bin]]
name = "buildkite-workflow"
Expand All @@ -21,29 +21,29 @@ path = "src/bin/main.rs"
[dependencies]
alfred = "4.0.2"
dirs = "4.0.0"
regex = "1.5.4"
serde_json = "1.0.68"
structopt = "0.3.25"
anyhow = "1.0.44"
thiserror = "1.0.30"
regex = "1.5.6"
serde_json = "1.0.81"
anyhow = "1.0.58"
thiserror = "1.0.31"
clap = { version = "3.2.5", features = ["env", "derive"] }

[dependencies.chrono]
features = ["serde"]
version = "0.4.19"

[dependencies.reqwest]
features = ["rustls-tls","blocking", "json"]
version = "0.11.6"
version = "0.11.11"

[dependencies.rusqlite]
features = [
"bundled-full",
]
version = "0.26.1"
version = "0.27.0"

[dependencies.serde]
features = ["derive"]
version = "1.0.130"
version = "1.0.137"

[lib]
name = "buildkite_workflow_lib"
Expand Down
51 changes: 22 additions & 29 deletions buildkite-workflow/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,57 @@
use alfred::{json, Item};
use anyhow::Error;
use buildkite_workflow_lib::workflow::BuildkiteWorkflow;
use buildkite_workflow_lib::workflow::Workflow;
use clap::Parser;
use std::io::Write;
use std::process::Command;
use std::{env, io};
use structopt::StructOpt;

const SUBCOMMAND_REFRESH: &str = "refresh";
const SUBCOMMAND_OPEN: &str = "open";

#[derive(Debug, StructOpt)]
struct Opt {
#[derive(Debug, Parser)]
#[clap(version = env!("CARGO_PKG_VERSION"), author = env!("CARGO_PKG_AUTHORS"), about = env!("CARGO_PKG_DESCRIPTION"))]
struct Opts {
args: Vec<String>,
}

fn main() -> Result<(), Error> {
let opt = Opt::from_args();
let opt = Opts::parse();

let api_key = env::var("API_KEY")?;
let database_url = env::var("DATABASE_URL")?;
let mut wf = BuildkiteWorkflow::new(&api_key, &database_url)?;
let mut wf = Workflow::new(&api_key, &database_url)?;

match opt.args.len() {
0 => {
let refresh = alfred::ItemBuilder::new(SUBCOMMAND_REFRESH)
.subtitle("Refresh Cache, be patient you will be notified once complete")
.arg(SUBCOMMAND_REFRESH)
.into_item();
write_items(io::stdout(), &[refresh])?
write_items(io::stdout(), &[refresh])?;
}
1 => {
let arg = opt.args.get(0).unwrap();
match arg.as_ref() {
SUBCOMMAND_REFRESH => {
wf.refresh_cache()?;
println!("Successfully Refreshed Buildkite cache");
}
_ => {
let results = wf.query(&opt.args)?;
write_items(io::stdout(), &results)?
}
if opt.args.first().expect("a valid argument") == SUBCOMMAND_REFRESH {
wf.refresh_cache()?;
println!("Successfully Refreshed Buildkite cache");
} else {
let results = wf.query(&opt.args)?;
write_items(io::stdout(), &results)?;
}
}
2 => {
let arg = opt.args.get(0).unwrap();
match arg.as_ref() {
SUBCOMMAND_OPEN => {
Command::new("open")
.arg(&opt.args.get(1).unwrap())
.output()?;
}
_ => {
let results = wf.query(&opt.args)?;
write_items(io::stdout(), &results)?
}
if opt.args.first().expect("a valid argument") == SUBCOMMAND_OPEN {
Command::new("open")
.arg(&opt.args.get(1).unwrap())
.output()?;
} else {
let results = wf.query(&opt.args)?;
write_items(io::stdout(), &results)?;
}
}
_ => {
let results = wf.query(&opt.args)?;
write_items(io::stdout(), &results)?
write_items(io::stdout(), &results)?;
}
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions buildkite-workflow/src/buildkite_api/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Provider {
pub settings: ProviderSettings,
}

#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Serialize, Deserialize)]
pub struct ProviderSettings {
pub publish_commit_status: bool,
Expand Down
24 changes: 21 additions & 3 deletions buildkite-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ use crate::database::DbContext;
use crate::errors::Error;
use alfred::Item;

pub struct BuildkiteWorkflow<'a> {
pub struct Workflow<'a> {
api_key: &'a str,
db: DbContext,
}

impl<'a> BuildkiteWorkflow<'a> {
impl<'a> Workflow<'a> {
/// Create a new Workflow
///
/// # Errors
///
/// Will return `Err` if database connection fails.
///
#[inline]
pub fn new(api_key: &'a str, database_url: &str) -> Result<Self, Error> {
let db = DbContext::new(database_url)?;
Ok(BuildkiteWorkflow { api_key, db })
Ok(Workflow { api_key, db })
}

/// Refreshes DB with all Buildkite information.
///
/// # Errors
///
/// Will return `Err` if database connection fails or hitting the `Buildkite` API fails
///
#[inline]
pub fn refresh_cache(&mut self) -> Result<(), Error> {
self.db.run_migrations()?;
Expand All @@ -41,6 +53,12 @@ impl<'a> BuildkiteWorkflow<'a> {
Ok(())
}

/// Queries the stored information using the given query.
///
/// # Errors
///
/// Will return `Err` if database connection fails.
///
#[inline]
pub fn query<'items>(&self, repo_name: &[String]) -> Result<Vec<Item<'items>>, Error> {
self.db
Expand Down
2 changes: 1 addition & 1 deletion datadog-workflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ version = "0.11.6"
features = [
"bundled-full",
]
version = "0.26.1"
version = "0.27.0"

[dependencies.serde]
features = ["derive"]
Expand Down
1 change: 0 additions & 1 deletion datadog-workflow/src/datadog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use reqwest::blocking::Client;
const APPLICATION_KEY: &str = "application_key";
const API_KEY: &str = "api_key";

#[derive(Debug)]
pub struct DatadogAPI<'a> {
api_key: &'a str,
application_key: &'a str,
Expand Down
11 changes: 6 additions & 5 deletions date-formats-workflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ license = "MIT"
name = "date-formats-workflow"
readme = "README.md"
repository = "https://github.com/rust-playground/alfred-workflows-rs/tree/master/date-formats-workflow"
version = "1.3.1"
version = "1.4.0"

[dependencies]
alfred = "4.0.2"
chrono = "0.4.19"
chrono-tz = "0.6.0"
clap = "2.33.3"
thiserror = "1.0.30"
anyhow = "1.0.44"
chrono-tz = "0.6.1"
clap = { version = "3.2.5", features = ["cargo"] }
thiserror = "1.0.31"
anyhow = "1.0.58"
anydate = "0.3.0"
10 changes: 0 additions & 10 deletions date-formats-workflow/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io;
use std::num::ParseIntError;
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -9,13 +8,4 @@ pub enum Error {

#[error("failed to write alfred items->json {}", _0)]
WriteItems(#[from] io::Error),

#[error("failed to parse integer {}", _0)]
ParseInt(#[from] ParseIntError),

#[error("failed to parse DateTime")]
ParseDateTime,

#[error("failed to parse DateTime from unix timestamp")]
UnixTimestamp,
}
Loading

0 comments on commit 637af66

Please sign in to comment.