feat(trello): add command 'trello board list'
This commit is contained in:
parent
5781e2297c
commit
6977816a7f
14 changed files with 7748 additions and 171 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -35,6 +35,8 @@ enum Command {
|
|||
Check,
|
||||
Import,
|
||||
#[clap(subcommand)]
|
||||
Trello(TrelloCommand),
|
||||
#[clap(subcommand)]
|
||||
Nextcloud(NextcloudCommand),
|
||||
}
|
||||
|
||||
|
@ -62,6 +64,20 @@ enum NextcloudStackCommand {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
enum TrelloCommand {
|
||||
#[clap(subcommand)]
|
||||
Board(TrelloBoardCommand),
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
enum TrelloBoardCommand {
|
||||
List {
|
||||
#[clap(long, action = clap::ArgAction::SetTrue)]
|
||||
dump: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Ctx {
|
||||
pub fs: FileSystem,
|
||||
|
@ -116,6 +132,9 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
|
|||
Command::Init => Err(eyre!("Config file already exists. Not overwriting it.")),
|
||||
Command::Check => todo!("check"),
|
||||
Command::Import => todo!("import"),
|
||||
Command::Trello(TrelloCommand::Board(TrelloBoardCommand::List { dump })) => {
|
||||
trello::boards::list(ctx, dump).await
|
||||
}
|
||||
Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::List {
|
||||
dump,
|
||||
})) => nextcloud::board::list(ctx, dump).await,
|
||||
|
|
|
@ -215,9 +215,9 @@ mod commands {
|
|||
}
|
||||
|
||||
mod given {
|
||||
use kxio::{fs::TempFileSystem, net::MockNet, print::Printer};
|
||||
use kxio::{fs::TempFileSystem, print::Printer};
|
||||
|
||||
use crate::{config::TrelloConfig, s, AppConfig, FullCtx};
|
||||
use crate::{config::TrelloConfig, s};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -250,15 +250,15 @@ mod given {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn a_full_context(mock_net: MockNet, fs: TempFileSystem) -> FullCtx {
|
||||
FullCtx {
|
||||
fs: fs.as_real(),
|
||||
net: mock_net.into(),
|
||||
prt: given::a_printer(),
|
||||
cfg: AppConfig {
|
||||
trello: given::a_trello_config(),
|
||||
nextcloud: given::a_nextcloud_config(),
|
||||
},
|
||||
}
|
||||
}
|
||||
// pub(crate) fn a_full_context(mock_net: MockNet, fs: TempFileSystem) -> FullCtx {
|
||||
// FullCtx {
|
||||
// fs: fs.as_real(),
|
||||
// net: mock_net.into(),
|
||||
// prt: given::a_printer(),
|
||||
// cfg: AppConfig {
|
||||
// trello: given::a_trello_config(),
|
||||
// nextcloud: given::a_nextcloud_config(),
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
//
|
||||
use std::collections::HashMap;
|
||||
|
||||
// type TestResult = Result<(), Box<dyn std::error::Error>>;
|
||||
|
||||
use assert2::let_assert;
|
||||
use kxio::{
|
||||
fs::{FileSystem, TempFileSystem},
|
||||
net::{MockNet, Net},
|
||||
print::Printer,
|
||||
};
|
||||
|
||||
use crate::{config::AppConfig, f, NAME};
|
||||
use crate::{config::AppConfig, f, init::run, Ctx, NAME};
|
||||
|
||||
mod config {
|
||||
use super::*;
|
||||
|
@ -60,13 +66,8 @@ mod config {
|
|||
}
|
||||
|
||||
mod init {
|
||||
|
||||
use test_log::test;
|
||||
|
||||
use crate::{f, init::run, NAME};
|
||||
|
||||
use super::given;
|
||||
use super::*;
|
||||
use test_log::test;
|
||||
|
||||
#[test]
|
||||
fn when_file_does_not_exist_should_create() {
|
||||
|
@ -104,10 +105,7 @@ mod init {
|
|||
}
|
||||
|
||||
mod template {
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::template;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn expand_should_substitute_values() {
|
||||
|
@ -116,7 +114,7 @@ mod template {
|
|||
let params = HashMap::from([("param1", "-v1-"), ("param2", "-v2-")]);
|
||||
|
||||
//when
|
||||
let result = template::expand(template, params);
|
||||
let result = crate::template::expand(template, params);
|
||||
|
||||
//then
|
||||
assert_eq!(result, "pre-v1-mid-v2-post");
|
||||
|
@ -124,13 +122,7 @@ mod template {
|
|||
}
|
||||
|
||||
mod given {
|
||||
use kxio::{
|
||||
fs::{FileSystem, TempFileSystem},
|
||||
net::{MockNet, Net},
|
||||
print::Printer,
|
||||
};
|
||||
|
||||
use crate::Ctx;
|
||||
use super::*;
|
||||
|
||||
pub fn a_context(fs: FileSystem, net: Net, prt: Printer) -> Ctx {
|
||||
Ctx { fs, net, prt }
|
||||
|
@ -147,4 +139,32 @@ mod given {
|
|||
pub fn a_printer() -> Printer {
|
||||
kxio::print::test()
|
||||
}
|
||||
|
||||
// pub fn a_config() -> AppConfig {
|
||||
// AppConfig {
|
||||
// trello: a_trello_config(),
|
||||
// nextcloud: a_nextcloud_config(),
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn a_trello_config() -> TrelloConfig {
|
||||
// TrelloConfig {
|
||||
// api_key: s!("trello-api-key").into(),
|
||||
// api_secret: s!("trello-api-secret").into(),
|
||||
// board_name: s!("Trello Platform Changes").into(),
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn a_nextcloud_config() -> NextcloudConfig {
|
||||
// let hostname = s!("nextcloud.example.org").into();
|
||||
// let username = s!("username").into();
|
||||
// let password = s!("password").into();
|
||||
// let board_id = NextcloudBoardId::new(2);
|
||||
// NextcloudConfig {
|
||||
// hostname,
|
||||
// username,
|
||||
// password,
|
||||
// board_id,
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
7484
src/tests/responses/trello-boards-list.json
Normal file
7484
src/tests/responses/trello-boards-list.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -2,12 +2,10 @@
|
|||
use kxio::{net::Net, print::Printer};
|
||||
|
||||
use crate::api_result::APIResult;
|
||||
use crate::{
|
||||
f,
|
||||
trello::{
|
||||
use crate::config::TrelloConfig;
|
||||
use crate::trello::{
|
||||
types::{auth::TrelloAuth, board::TrelloBoard},
|
||||
url,
|
||||
},
|
||||
};
|
||||
|
||||
/// Get lists from named board that Member belongs to
|
||||
|
@ -40,12 +38,13 @@ use crate::{
|
|||
/// --url "https://api.trello.com/1/members/$TRELLO_USERNAME/boards?key=$TRELLO_KEY&token=$TRELLO_SECRET&lists=open" \
|
||||
/// --header 'Accept: application/json'
|
||||
pub async fn get_boards_that_member_belongs_to(
|
||||
auth: &TrelloAuth,
|
||||
cfg: &TrelloConfig,
|
||||
net: &Net,
|
||||
prt: &Printer,
|
||||
) -> APIResult<Vec<TrelloBoard>> {
|
||||
let auth = TrelloAuth::new(&cfg.api_key, &cfg.api_secret);
|
||||
APIResult::new(
|
||||
net.get(url(f!("/members/{}/boards?lists=open", **auth.user())))
|
||||
net.get(url("/members/me/boards?lists=open"))
|
||||
.headers(auth.into())
|
||||
.header("Accept", "application/json")
|
||||
.send()
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
//
|
||||
use kxio::{net::MockNet, print::Printer};
|
||||
|
||||
use crate::trello::types::auth::{TrelloApiKey, TrelloApiSecret, TrelloAuth, TrelloUser};
|
||||
|
||||
pub(crate) fn a_network() -> MockNet {
|
||||
kxio::net::mock()
|
||||
}
|
||||
|
@ -11,10 +9,9 @@ pub(crate) fn a_printer() -> Printer {
|
|||
kxio::print::test()
|
||||
}
|
||||
|
||||
pub(crate) fn an_auth() -> TrelloAuth {
|
||||
TrelloAuth::new(
|
||||
TrelloApiKey::new("foo"),
|
||||
TrelloApiSecret::new("bar"),
|
||||
TrelloUser::new("baz"),
|
||||
)
|
||||
}
|
||||
// pub(crate) fn an_auth<'cfg>(cfg: &'cfg TrelloConfig) -> TrelloAuth<'cfg> {
|
||||
// TrelloAuth {
|
||||
// api_key: &cfg.api_key,
|
||||
// api_secret: &cfg.api_secret,
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -1,25 +1,21 @@
|
|||
// use super::*;
|
||||
|
||||
use super::*;
|
||||
mod given;
|
||||
|
||||
type TestResult = color_eyre::Result<()>;
|
||||
|
||||
mod members {
|
||||
|
||||
//
|
||||
use std::collections::HashMap;
|
||||
|
||||
use kxio::net::StatusCode;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{
|
||||
config::TrelloConfig,
|
||||
s,
|
||||
trello::{
|
||||
api::members::get_boards_that_member_belongs_to,
|
||||
types::{board::TrelloBoard, TrelloBoardId, TrelloBoardName},
|
||||
},
|
||||
trello::{api::members::get_boards_that_member_belongs_to, types::board::TrelloBoard},
|
||||
};
|
||||
|
||||
mod given;
|
||||
|
||||
type TestResult = color_eyre::Result<()>;
|
||||
|
||||
mod members {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -27,10 +23,14 @@ mod members {
|
|||
//given
|
||||
let net = given::a_network();
|
||||
let prt = given::a_printer();
|
||||
let auth = given::an_auth();
|
||||
let trello_config = TrelloConfig {
|
||||
api_key: s!("foo").into(),
|
||||
api_secret: s!("bar").into(),
|
||||
board_name: s!("board-name").into(),
|
||||
};
|
||||
|
||||
net.on()
|
||||
.get("https://api.trello.com/1/members/baz/boards?lists=open")
|
||||
.get("https://api.trello.com/1/members/me/boards?lists=open")
|
||||
.headers(HashMap::from([
|
||||
(
|
||||
s!("authorization"),
|
||||
|
@ -40,21 +40,21 @@ mod members {
|
|||
]))
|
||||
.respond(StatusCode::OK)
|
||||
.body(s!(json!([
|
||||
{"id": "1", "name": "board-1", "lists":[]}
|
||||
{"id": "1", "name": "board-name", "lists":[]}
|
||||
])))?;
|
||||
|
||||
//when
|
||||
let result = get_boards_that_member_belongs_to(&auth, &net.into(), &prt)
|
||||
let result = get_boards_that_member_belongs_to(&trello_config, &net.into(), &prt)
|
||||
.await
|
||||
.result?;
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
vec![TrelloBoard::new(
|
||||
TrelloBoardId::new("1"),
|
||||
TrelloBoardName::new("board-1"),
|
||||
vec![]
|
||||
)]
|
||||
vec![TrelloBoard {
|
||||
id: s!("1").into(),
|
||||
name: s!("board-name").into(),
|
||||
lists: vec![]
|
||||
}]
|
||||
);
|
||||
|
||||
//then
|
||||
|
|
18
src/trello/boards.rs
Normal file
18
src/trello/boards.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
use crate::{p, FullCtx};
|
||||
|
||||
pub(crate) async fn list(ctx: FullCtx, dump: bool) -> color_eyre::Result<()> {
|
||||
let api_result =
|
||||
super::api::members::get_boards_that_member_belongs_to(&ctx.cfg.trello, &ctx.net, &ctx.prt)
|
||||
.await;
|
||||
if dump {
|
||||
p!(ctx.prt, "{}", api_result.text);
|
||||
} else {
|
||||
let mut boards = api_result.result?;
|
||||
boards.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
boards.into_iter().for_each(|board| {
|
||||
p!(ctx.prt, "{}:{}", board.id, board.name);
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
//
|
||||
// pub mod api;
|
||||
pub mod api;
|
||||
pub mod boards;
|
||||
pub mod types;
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod tests;
|
||||
|
||||
// use crate::f;
|
||||
//
|
||||
// pub fn url(path: impl Into<String>) -> String {
|
||||
// let path = path.into();
|
||||
// assert!(path.starts_with("/"));
|
||||
// f!("https://api.trello.com/1{path}")
|
||||
// }
|
||||
use crate::f;
|
||||
|
||||
pub fn url(path: impl Into<String>) -> String {
|
||||
let path = path.into();
|
||||
assert!(path.starts_with("/"));
|
||||
f!("https://api.trello.com/1{path}")
|
||||
}
|
||||
|
|
|
@ -1,43 +1,83 @@
|
|||
use crate::s;
|
||||
use crate::trello::types::auth::TrelloAuth;
|
||||
//
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod board {
|
||||
// use crate::trello::{
|
||||
// // api::boards::TrelloBoards as _,
|
||||
// types::{
|
||||
// board::TrelloBoard, TrelloBoardId, TrelloBoardName, TrelloListId, TrelloListName,
|
||||
// },
|
||||
// };
|
||||
use crate::{s, trello::types::auth::TrelloAuth};
|
||||
|
||||
// #[test]
|
||||
// fn list_of_boards_find_by_name_returns_board() {
|
||||
// //given
|
||||
// let board = TrelloBoard::new(
|
||||
// TrelloBoardId::new("2"),
|
||||
// TrelloBoardName::new("beta"),
|
||||
// vec![],
|
||||
// );
|
||||
// let boards = vec![
|
||||
// TrelloBoard::new(
|
||||
// TrelloBoardId::new("1"),
|
||||
// TrelloBoardName::new("alpha"),
|
||||
// vec![],
|
||||
// ),
|
||||
// board.clone(),
|
||||
// TrelloBoard::new(
|
||||
// TrelloBoardId::new("3"),
|
||||
// TrelloBoardName::new("gamma"),
|
||||
// vec![],
|
||||
// ),
|
||||
// ];
|
||||
//
|
||||
// //when
|
||||
// let result = boards.find_by_name(board.name());
|
||||
//
|
||||
// //then
|
||||
// assert_eq!(result, Some(&board));
|
||||
// }
|
||||
mod commands {
|
||||
mod board {
|
||||
use crate::trello::{
|
||||
api::boards::TrelloBoards as _,
|
||||
types::{
|
||||
TrelloBoard, TrelloBoardId, TrelloBoardName, TrelloList, TrelloListId,
|
||||
TrelloListName,
|
||||
},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn name_returns_name() {
|
||||
//given
|
||||
let board = TrelloBoard::new(
|
||||
TrelloBoardId::new("board-id"),
|
||||
TrelloBoardName::new("board-name"),
|
||||
vec![],
|
||||
);
|
||||
|
||||
//when
|
||||
let result = board.name();
|
||||
|
||||
//then
|
||||
assert_eq!(result, &TrelloBoardName::new("board-name"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_should_return_lists() {
|
||||
//given
|
||||
let lists = vec![TrelloList::new(
|
||||
TrelloListId::new("list-id"),
|
||||
TrelloListName::new("list-name"),
|
||||
)];
|
||||
let board = TrelloBoard::new(
|
||||
TrelloBoardId::new("board-id"),
|
||||
TrelloBoardName::new("board-name"),
|
||||
lists.clone(),
|
||||
);
|
||||
|
||||
//when
|
||||
let result = board.lists();
|
||||
|
||||
//then
|
||||
assert_eq!(result, lists);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_of_boards_find_by_name_returns_board() {
|
||||
//given
|
||||
let board = TrelloBoard::new(
|
||||
TrelloBoardId::new("2"),
|
||||
TrelloBoardName::new("beta"),
|
||||
vec![],
|
||||
);
|
||||
let boards = vec![
|
||||
TrelloBoard::new(
|
||||
TrelloBoardId::new("1"),
|
||||
TrelloBoardName::new("alpha"),
|
||||
vec![],
|
||||
),
|
||||
board.clone(),
|
||||
TrelloBoard::new(
|
||||
TrelloBoardId::new("3"),
|
||||
TrelloBoardName::new("gamma"),
|
||||
vec![],
|
||||
),
|
||||
];
|
||||
|
||||
//when
|
||||
let result = boards.find_by_name(board.name());
|
||||
|
||||
//then
|
||||
assert_eq!(result, Some(&board));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -14,12 +14,12 @@ newtype!(
|
|||
);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TrelloAuth {
|
||||
pub(crate) api_key: TrelloApiKey,
|
||||
pub(crate) api_secret: TrelloApiSecret,
|
||||
pub struct TrelloAuth<'cfg> {
|
||||
pub(crate) api_key: &'cfg TrelloApiKey,
|
||||
pub(crate) api_secret: &'cfg TrelloApiSecret,
|
||||
}
|
||||
impl TrelloAuth {
|
||||
pub const fn new(api_key: TrelloApiKey, api_secret: TrelloApiSecret) -> Self {
|
||||
impl<'cfg> TrelloAuth<'cfg> {
|
||||
pub const fn new(api_key: &'cfg TrelloApiKey, api_secret: &'cfg TrelloApiSecret) -> Self {
|
||||
Self {
|
||||
api_key,
|
||||
api_secret,
|
||||
|
@ -33,8 +33,8 @@ impl TrelloAuth {
|
|||
&self.api_secret
|
||||
}
|
||||
}
|
||||
impl From<&TrelloAuth> for HashMap<String, String> {
|
||||
fn from(value: &TrelloAuth) -> Self {
|
||||
impl<'cfg> From<TrelloAuth<'cfg>> for HashMap<String, String> {
|
||||
fn from(value: TrelloAuth) -> Self {
|
||||
HashMap::from([(
|
||||
"Authorization".into(),
|
||||
format!(
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
//
|
||||
use derive_more::derive::Constructor;
|
||||
|
||||
use crate::trello::types::list::TrelloList;
|
||||
use crate::trello::types::{TrelloBoardId, TrelloBoardName};
|
||||
|
||||
use super::{TrelloBoardId, TrelloBoardName};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, Constructor)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)]
|
||||
pub(crate) struct TrelloBoard {
|
||||
pub(crate) id: TrelloBoardId,
|
||||
pub(crate) name: TrelloBoardName,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//
|
||||
use derive_more::derive::Constructor;
|
||||
|
||||
use super::{TrelloListId, TrelloListName};
|
||||
use crate::trello::types::{TrelloListId, TrelloListName};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, Constructor)]
|
||||
pub(crate) struct TrelloList {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
pub(crate) mod auth;
|
||||
// pub(crate) mod board;
|
||||
pub(crate) mod board;
|
||||
// mod card;
|
||||
// mod list;
|
||||
mod list;
|
||||
// mod new_card;
|
||||
|
||||
use derive_more::derive::Display;
|
||||
|
||||
use crate::newtype;
|
||||
|
||||
// newtype!(TrelloBoardId, String, Display, "Board ID");
|
||||
newtype!(TrelloBoardId, String, Display, "Board ID");
|
||||
newtype!(
|
||||
TrelloBoardName,
|
||||
String,
|
||||
|
@ -17,14 +17,14 @@ newtype!(
|
|||
Ord,
|
||||
"Board Name"
|
||||
);
|
||||
// newtype!(TrelloListId, String, "List ID");
|
||||
// newtype!(
|
||||
// TrelloListName,
|
||||
// String,
|
||||
// Display,
|
||||
// PartialOrd,
|
||||
// Ord,
|
||||
// "List Name"
|
||||
// );
|
||||
newtype!(TrelloListId, String, "List ID");
|
||||
newtype!(
|
||||
TrelloListName,
|
||||
String,
|
||||
Display,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
"List Name"
|
||||
);
|
||||
// newtype!(TrelloCardId, String, Display, "Card ID");
|
||||
// newtype!(TrelloCardName, String, Display, "Card Name");
|
||||
|
|
Loading…
Reference in a new issue