refactor: remove board_id and board_name from config file
Some checks failed
Test / build (map[name:stable]) (push) Successful in 2m47s
Test / build (map[name:nightly]) (push) Successful in 2m57s
Release Please / Release-plz (push) Failing after 23s

This commit is contained in:
Paul Campbell 2024-12-19 07:05:10 +00:00
parent 2df105bd65
commit 3249da92b0
12 changed files with 109 additions and 101 deletions

View file

@ -1,26 +1,21 @@
//
use color_eyre::eyre::{OptionExt as _, Result};
use color_eyre::eyre::Result;
use crate::{f, p, trello::model::board::TrelloBoards as _, FullCtx};
use crate::{p, FullCtx};
pub(crate) async fn run(ctx: &FullCtx) -> Result<()> {
{
// test trello by getting a list of the boards for the user
p!(ctx.prt, ">> Testing Trello details...");
let boards = ctx.trello_client().boards().await.result?;
p!(ctx.prt, "<<< Trello Credentials: OKAY");
let board_name = &ctx.cfg.trello.board_name;
p!(ctx.prt, ">> Trello Board: {board_name}");
let board = boards
.find_by_name(board_name)
.ok_or_eyre(f!("board not found: {board_name}"))?;
p!(ctx.prt, "<<< Trello Board: OKAY");
for list in &board.lists {
p!(ctx.prt, "<<<< List: {}", list.name);
p!(ctx.prt, "<<< Trello Boards");
for board in &boards {
p!(ctx.prt, "<<<< Board: {}", board.name);
}
}
{
// test nextcloud by getting a list of the boards for the user
p!(ctx.prt, ">> Testing Nextcloud details...");
let deck_client = ctx.deck_client();
let boards = deck_client.get_boards().await.result?;
@ -28,19 +23,6 @@ pub(crate) async fn run(ctx: &FullCtx) -> Result<()> {
for board in &boards {
p!(ctx.prt, "<<<< Board: {}", board.title);
}
p!(ctx.prt, "<<< Nextcloud Credentials: OKAY");
let board = boards
.iter()
.find(|b| b.id == ctx.cfg.nextcloud.board_id)
.ok_or_eyre("board not found")?;
p!(ctx.prt, "<<< Nextcloud Board: {}", board.title);
let stacks = deck_client
.get_stacks(ctx.cfg.nextcloud.board_id)
.await
.result?;
for stack in stacks {
p!(ctx.prt, "<<<< Stack: {}", stack.title);
}
}
Ok(())

View file

@ -7,7 +7,7 @@ use crate::{
nextcloud::{
card::NextcloudCardCommand,
deck::NextcloudDeckCommand,
model::{NextcloudBoardId, NextcloudHostname, NextcloudPassword, NextcloudUsername},
model::{NextcloudHostname, NextcloudPassword, NextcloudUsername},
stack::NextcloudStackCommand,
},
FullCtx,
@ -57,5 +57,4 @@ pub struct NextcloudConfig {
pub(crate) hostname: NextcloudHostname,
pub(crate) username: NextcloudUsername,
pub(crate) password: NextcloudPassword,
pub(crate) board_id: NextcloudBoardId,
}

View file

@ -7,6 +7,11 @@ use crate::Command;
//
use super::*;
#[rstest::fixture]
fn board_id() -> NextcloudBoardId {
NextcloudBoardId::new(1)
}
#[rstest::fixture]
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
@ -14,7 +19,7 @@ fn ctx() -> FullCtx {
let nextcloud_config = given::a_nextcloud_config();
let hostname = &nextcloud_config.hostname;
let board_id = nextcloud_config.board_id;
let board_id = board_id();
let mock_net = given::a_network();
mock_net
@ -33,11 +38,10 @@ fn ctx() -> FullCtx {
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn dump(ctx: FullCtx) {
async fn dump(ctx: FullCtx, board_id: NextcloudBoardId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
let board_id = ctx.cfg.nextcloud.board_id;
//when
Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::Get {
@ -58,7 +62,7 @@ async fn dump(ctx: FullCtx) {
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn no_dump(ctx: FullCtx) {
async fn no_dump(ctx: FullCtx, board_id: NextcloudBoardId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -66,7 +70,7 @@ async fn no_dump(ctx: FullCtx) {
//when
Command::Nextcloud(NextcloudCommand::Board(NextcloudBoardCommand::Get {
dump: false,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
}))
.execute(&ctx)
.await

View file

@ -8,6 +8,11 @@ use std::path::PathBuf;
//
use super::*;
#[rstest::fixture]
fn board_id() -> NextcloudBoardId {
NextcloudBoardId::new(2)
}
#[rstest::fixture]
fn stack_id() -> NextcloudStackId {
NextcloudStackId::new(1)
@ -29,7 +34,7 @@ fn ctx_path() -> (FullCtx, PathBuf, TempFileSystem) {
let nextcloud_config = given::a_nextcloud_config();
let hostname = &nextcloud_config.hostname;
let board_id = &nextcloud_config.board_id;
let board_id = board_id();
let stack_id = stack_id();
let card_id = card_id();
@ -91,6 +96,7 @@ fn ctx_path() -> (FullCtx, PathBuf, TempFileSystem) {
#[test_log::test(tokio::test)]
async fn dump(
ctx_path: (FullCtx, PathBuf, TempFileSystem),
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
) {
@ -103,7 +109,7 @@ async fn dump(
Command::Nextcloud(NextcloudCommand::Card(
NextcloudCardCommand::AddAttachment {
dump: true,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
card_id: card_id.into(),
file: path,
@ -125,6 +131,7 @@ async fn dump(
#[test_log::test(tokio::test)]
async fn no_dump(
ctx_path: (FullCtx, PathBuf, TempFileSystem),
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
) {
@ -137,7 +144,7 @@ async fn no_dump(
Command::Nextcloud(NextcloudCommand::Card(
NextcloudCardCommand::AddAttachment {
dump: false,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
card_id: card_id.into(),
file: path,

View file

@ -1,5 +1,10 @@
use super::*;
#[rstest::fixture]
fn board_id() -> NextcloudBoardId {
NextcloudBoardId::new(1)
}
#[rstest::fixture]
fn stack_id() -> NextcloudStackId {
NextcloudStackId::new(1)
@ -19,14 +24,16 @@ fn label_id() -> NextcloudLabelId {
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
let nextcloud_config = given::a_nextcloud_config();
let hostname = &nextcloud_config.hostname;
let board_id = board_id();
let stack_id = stack_id();
let card_id = card_id();
let mock_net = given::a_network();
mock_net
.on()
.put(crate::f!(
"{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1/cards/1/assignLabel",
nextcloud_config.hostname,
nextcloud_config.board_id
"{hostname}/index.php/apps/deck/api/v1.0/boards/{board_id}/stacks/{stack_id}/cards/{card_id}/assignLabel",
))
.body(json!({ "labelId": 1 }).to_string())
.respond(StatusCode::OK)
@ -48,6 +55,7 @@ fn ctx() -> FullCtx {
#[test_log::test(tokio::test)]
async fn dump(
ctx: FullCtx,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
label_id: NextcloudLabelId,
@ -59,7 +67,7 @@ async fn dump(
//when
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel {
dump: true,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
card_id: card_id.into(),
label_id: label_id.into(),
@ -77,6 +85,7 @@ async fn dump(
#[test_log::test(tokio::test)]
async fn no_dump(
ctx: FullCtx,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
label_id: NextcloudLabelId,
@ -88,7 +97,7 @@ async fn no_dump(
//when
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel {
dump: false,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
card_id: card_id.into(),
label_id: label_id.into(),

View file

@ -1,6 +1,11 @@
//
use super::*;
#[rstest::fixture]
fn board_id() -> NextcloudBoardId {
NextcloudBoardId::new(2)
}
#[rstest::fixture]
fn stack_id() -> NextcloudStackId {
NextcloudStackId::new(1)
@ -10,14 +15,15 @@ fn stack_id() -> NextcloudStackId {
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
let nextcloud_config = given::a_nextcloud_config();
let hostname = &nextcloud_config.hostname;
let board_id = board_id();
let stack_id = stack_id();
let mock_net = given::a_network();
mock_net
.on()
.post(crate::f!(
"{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1/cards",
nextcloud_config.hostname,
nextcloud_config.board_id
"{hostname}/index.php/apps/deck/api/v1.0/boards/{board_id}/stacks/{stack_id}/cards",
))
.respond(StatusCode::OK)
.body(include_str!(
@ -40,7 +46,12 @@ fn ctx() -> FullCtx {
#[case::no_desc(None)]
#[case::desc(Some(s!("my new description")))]
#[test_log::test(tokio::test)]
async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description: Option<String>) {
async fn dump(
ctx: FullCtx,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
#[case] description: Option<String>,
) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -48,7 +59,7 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description: Opt
//when
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Create {
dump: true,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
title: "my new card".to_string(),
description,
@ -69,7 +80,12 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description: Opt
#[case::no_desc(None)]
#[case::desc(Some(s!("my new description")))]
#[test_log::test(tokio::test)]
async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description: Option<String>) {
async fn no_dump(
ctx: FullCtx,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
#[case] description: Option<String>,
) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -77,7 +93,7 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, #[case] description:
//when
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Create {
dump: false,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
title: "my new card".to_string(),
description,

View file

@ -1,6 +1,11 @@
//
use super::*;
#[rstest::fixture]
fn board_id() -> NextcloudBoardId {
NextcloudBoardId::new(2)
}
#[rstest::fixture]
fn stack_id() -> NextcloudStackId {
NextcloudStackId::new(1)
@ -15,14 +20,15 @@ fn card_id() -> NextcloudCardId {
fn ctx() -> FullCtx {
let fs = given::a_filesystem();
let nextcloud_config = given::a_nextcloud_config();
let hostname = &nextcloud_config.hostname;
let board_id = board_id();
let stack_id = stack_id();
let mock_net = given::a_network();
mock_net
.on()
.get(crate::f!(
"{}/index.php/apps/deck/api/v1.0/boards/{}/stacks/1/cards/321",
nextcloud_config.hostname,
nextcloud_config.board_id
"{hostname}/index.php/apps/deck/api/v1.0/boards/{board_id}/stacks/{stack_id}/cards/321",
))
.respond(StatusCode::OK)
.body(include_str!(
@ -43,7 +49,12 @@ fn ctx() -> FullCtx {
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId) {
async fn dump(
ctx: FullCtx,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -51,7 +62,7 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId
//when
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get {
dump: true,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
card_id: card_id.into(),
}))
@ -69,7 +80,12 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId) {
async fn no_dump(
ctx: FullCtx,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -77,7 +93,7 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCar
//when
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get {
dump: false,
board_id: ctx.cfg.nextcloud.board_id.into(),
board_id: board_id.into(),
stack_id: stack_id.into(),
card_id: card_id.into(),
}))

View file

@ -7,8 +7,13 @@ use crate::Command;
use super::*;
#[rstest::fixture]
fn stack_id() -> i64 {
318
fn board_id() -> NextcloudBoardId {
NextcloudBoardId::new(1)
}
#[rstest::fixture]
fn stack_id() -> NextcloudStackId {
NextcloudStackId::new(318)
}
#[rstest::fixture]
@ -17,7 +22,7 @@ fn ctx() -> FullCtx {
let nextcloud_config = given::a_nextcloud_config();
let hostname = nextcloud_config.hostname;
let board_id = nextcloud_config.board_id;
let board_id = board_id();
let stack_id = stack_id();
let mock_net = given::a_network();
@ -37,7 +42,7 @@ fn ctx() -> FullCtx {
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn dump(ctx: FullCtx) {
async fn dump(ctx: FullCtx, board_id: NextcloudBoardId, stack_id: NextcloudStackId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -45,8 +50,8 @@ async fn dump(ctx: FullCtx) {
//when
Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::Get {
dump: true,
board_id: ctx.cfg.nextcloud.board_id.into(),
stack_id: stack_id(),
board_id: board_id.into(),
stack_id: stack_id.into(),
}))
.execute(&ctx)
.await
@ -62,7 +67,7 @@ async fn dump(ctx: FullCtx) {
#[rstest::rstest]
#[test_log::test(tokio::test)]
async fn no_dump(ctx: FullCtx) {
async fn no_dump(ctx: FullCtx, board_id: NextcloudBoardId, stack_id: NextcloudStackId) {
//given
let prt = ctx.prt.clone();
let prt = prt.as_test().unwrap();
@ -70,8 +75,8 @@ async fn no_dump(ctx: FullCtx) {
//when
Command::Nextcloud(NextcloudCommand::Stack(NextcloudStackCommand::Get {
dump: false,
board_id: ctx.cfg.nextcloud.board_id.into(),
stack_id: stack_id(),
board_id: board_id.into(),
stack_id: stack_id.into(),
}))
.execute(&ctx)
.await

View file

@ -49,12 +49,10 @@ async fn test_full_ctx_clients() -> Result<()> {
"[trello]",
"api_key = 'foo'",
"api_secret = 'bar'",
"board_name = 'target'",
"[nextcloud]",
"hostname = 'http://localhost:8000'",
"username = 'bob'",
"password = '1 <3 alice!'",
"board_id = 23",
]
.join("\n"),
)?;
@ -77,13 +75,11 @@ async fn test_full_ctx_clients() -> Result<()> {
trello: TrelloConfig {
api_key: s!("foo").into(),
api_secret: s!("bar").into(),
board_name: s!("target").into(),
},
nextcloud: NextcloudConfig {
hostname: s!("http://localhost:8000").into(),
username: s!("bob").into(),
password: s!("1 <3 alice!").into(),
board_id: 23.into(),
}
}
);
@ -91,7 +87,7 @@ async fn test_full_ctx_clients() -> Result<()> {
Ok(())
}
#[tokio::test]
#[test_log::test(tokio::test)]
async fn test_run() -> Result<()> {
//given
let fs = kxio::fs::temp()?;
@ -103,12 +99,10 @@ async fn test_run() -> Result<()> {
"[trello]",
"api_key = 'foo'",
"api_secret = 'bar'",
"board_name = 'DevProjects'",
"[nextcloud]",
"hostname = 'http://localhost:8000'",
"username = 'bob'",
"password = '1 <3 alice!'",
"board_id = 1",
]
.join("\n"),
)?;
@ -126,12 +120,6 @@ async fn test_run() -> Result<()> {
.respond(StatusCode::OK)
.body(include_bytes!("responses/nextcloud-deck-get.json").as_slice())
.expect("nextcloud deck get");
mock_net
.on()
.get("http://localhost:8000/index.php/apps/deck/api/v1.0/boards/1/stacks")
.respond(StatusCode::OK)
.body(include_bytes!("responses/nextcloud-board-get.json").as_slice())
.expect("nextcloud board get");
let ctx = Ctx {
fs: fs.as_real(),
@ -156,24 +144,18 @@ async fn test_run() -> Result<()> {
output.trim(),
[
">> Testing Trello details...",
"<<< Trello Credentials: OKAY",
">> Trello Board: DevProjects",
"<<< Trello Board: OKAY",
"<<<< List: BRAINSTORM 🤔",
"<<<< List: TODO 📚",
"<<<< List: DOING ⚙️",
"<<<< List: DONE! 🙌🏽",
"<<<< List: Icebox ❄️",
"<<< Trello Boards",
"<<<< Board: 0 Business: Cossmass Infinities",
"<<<< Board: 3 Editing: Cossmass Infinities",
"<<<< Board: 4 Published: Cossmass Infinities",
"<<<< Board: Daily Notes 2022",
"<<<< Board: DevProjects",
"<<<< Board: Fulfilment: Cossmass Infinities",
">> Testing Nextcloud details...",
"<<< Nextcloud Boards",
"<<<< Board: Personal Board",
"<<<< Board: 4 Published: Cossmass Infinities",
"<<<< Board: Fulfilment: Cossmass Infinities",
"<<< Nextcloud Credentials: OKAY",
"<<< Nextcloud Board: Personal Board",
"<<<< Stack: Done",
"<<<< Stack: Doing",
"<<<< Stack: To do",
]
.join("\n")
);

View file

@ -11,13 +11,10 @@ fn load_config() {
"[trello]",
"api_key = \"trello-api-key\"",
"api_secret = \"trello-api-secret\"",
"board_name = \"trello-board-name\"",
"",
"[nextcloud]",
"hostname = \"nextcloud-hostname\"",
"username = \"nextcloud-username\"",
"password = \"nextcloud-password\"",
"board_id = 22",
]
.join("\n"),
)
@ -34,13 +31,11 @@ fn load_config() {
trello: TrelloConfig {
api_key: s!("trello-api-key").into(),
api_secret: s!("trello-api-secret").into(),
board_name: s!("trello-board-name").into(),
},
nextcloud: NextcloudConfig {
hostname: s!("nextcloud-hostname").into(),
username: s!("nextcloud-username").into(),
password: s!("nextcloud-password").into(),
board_id: 22.into()
}
}
);

View file

@ -30,7 +30,6 @@ pub(crate) fn a_trello_config() -> TrelloConfig {
TrelloConfig {
api_key: s!("trello-api-key").into(),
api_secret: s!("trello-api-secret").into(),
board_name: s!("trello-board-name").into(),
}
}
@ -38,12 +37,10 @@ pub(crate) fn a_nextcloud_config() -> NextcloudConfig {
let hostname = s!("https://host-name").into();
let username = s!("username").into();
let password = s!("password").into();
let board_id = 2.into();
NextcloudConfig {
hostname,
username,
password,
board_id,
}
}

View file

@ -8,10 +8,7 @@ use crate::{
board::TrelloBoardCommand,
card::TrelloCardCommand,
member::TrelloMemberCommand,
model::{
auth::{TrelloApiKey, TrelloApiSecret},
TrelloBoardName,
},
model::auth::{TrelloApiKey, TrelloApiSecret},
stack::TrelloStackCommand,
},
FullCtx,
@ -62,5 +59,4 @@ impl Execute for TrelloCommand {
pub struct TrelloConfig {
pub(crate) api_key: TrelloApiKey,
pub(crate) api_secret: TrelloApiSecret,
pub(crate) board_name: TrelloBoardName,
}