From d74fff547e45d43f066e8d3959abe117e871ea31 Mon Sep 17 00:00:00 2001 From: jiahao6635 Date: Thu, 1 Feb 2024 00:37:42 +0800 Subject: [PATCH 1/2] Example Change the logs name value --- src/services/logger.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/logger.rs b/src/services/logger.rs index 07fea3c..c959e0e 100644 --- a/src/services/logger.rs +++ b/src/services/logger.rs @@ -25,6 +25,11 @@ impl LoggerService { pub async fn logs(ctx: Arc, id: Uuid) -> Result { let playbook = ctx.client.playbooks().get(&id.to_string()).map_err(ApiError::NotFoundPlaybook)?; - Ok(ctx.client.actors().logs(&id.to_string(), &playbook.title)) + if let Some(characters) = playbook.characters { + let character = characters.first().unwrap(); + Ok(ctx.client.actors().logs(&id.to_string(), &character.meta.name)) + } else { + Err(ApiError::BadPlaybook("The playbook has no characters".to_string())) + } } } From b33ff7c4e3961871322b64a6e684acc718affbd0 Mon Sep 17 00:00:00 2001 From: jiahao6635 Date: Wed, 7 Feb 2024 18:21:43 +0800 Subject: [PATCH 2/2] Example Change the create name value --- src/services/playbook.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/playbook.rs b/src/services/playbook.rs index b260714..16d65c5 100644 --- a/src/services/playbook.rs +++ b/src/services/playbook.rs @@ -24,13 +24,14 @@ use crate::context::Context; use crate::errors::ApiError; use crate::errors::Result; use crate::requests::playbook::CreatePlaybookRequest; -use crate::utils::repo; +use crate::utils::{repo, unwrap_or_error}; pub struct PlaybookService; impl PlaybookService { pub async fn create(ctx: Arc, req: &CreatePlaybookRequest) -> Result { let repo = repo(&req.repo)?; + let name = unwrap_or_error(repo.split('/').nth(1), "The repo name is None")?.to_string(); let repository = ctx.github_client.repositories().find(&repo).map_err(ApiError::NotFoundRepo)?; let description = repository.and_then(|r| r.description).unwrap_or_default(); let repository = GitReference { @@ -43,7 +44,7 @@ impl PlaybookService { if repository.reference().is_none() { return Err(ApiError::BadPlaybookRequest("Requires either branch, tag or rev".to_string())); } - let preface = Preface { name: req.repo.clone(), repository: Some(repository), ..Preface::default() }; + let preface = Preface { name, repository: Some(repository), ..Preface::default() }; let payload = PlaybookPayload { title: repo, description, preface }; ctx.client.playbooks().create(payload).map_err(ApiError::FailedToCreatePlaybook)