From b6f453439a64b510e2a91a2be5d905ddefa952d3 Mon Sep 17 00:00:00 2001 From: jiahao6635 Date: Thu, 18 Jan 2024 01:06:39 +0800 Subject: [PATCH] debugging interface --- src/handlers/playbook.rs | 5 ++--- src/main.rs | 2 +- src/services/playbook.rs | 39 ++++++++++++++++++++------------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/handlers/playbook.rs b/src/handlers/playbook.rs index ac23a83..b1062fa 100644 --- a/src/handlers/playbook.rs +++ b/src/handlers/playbook.rs @@ -15,7 +15,7 @@ use amp_common::sync::Synchronization; use std::sync::Arc; -use axum::extract::{Path, Query, State}; +use axum::extract::{Path, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; @@ -65,10 +65,9 @@ pub async fn create( )] pub async fn detail( Path(params): Path, - Query(recursive): Query, State(ctx): State>, ) -> Result { - Ok(Json(PlaybookService::get(ctx, params.id, params.reference, params.path, recursive).await?)) + Ok(Json(PlaybookService::get(ctx, params.id, params.reference, params.path, true).await?)) } /// Update a playbook. #[utoipa::path( diff --git a/src/main.rs b/src/main.rs index 7ceaeb0..ace6406 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use tracing_subscriber::EnvFilter; #[tokio::main] async fn main() -> anyhow::Result<()> { - let filter = EnvFilter::builder().with_default_directive(LevelFilter::INFO.into()).from_env_lossy(); + let filter = EnvFilter::builder().with_default_directive(LevelFilter::DEBUG.into()).from_env_lossy(); tracing_subscriber::fmt().with_env_filter(filter).init(); // This returns an error if the `.env` file doesn't exist, but that's not what we want diff --git a/src/services/playbook.rs b/src/services/playbook.rs index 55b5ea2..22147c0 100644 --- a/src/services/playbook.rs +++ b/src/services/playbook.rs @@ -18,7 +18,8 @@ use amp_common::scm::content::Content; use amp_common::scm::git::Tree; use amp_common::sync::Synchronization; use std::sync::Arc; -use tracing::info; +use tracing::{info}; +use url::Url; use uuid::Uuid; @@ -42,24 +43,24 @@ impl PlaybookService { let playbook_result = ctx.client.playbooks().get(&id.to_string()).map_err(ApiError::NotFoundPlaybook).ok(); match playbook_result { Some(playbook) => { - let repo = playbook.preface.repository.unwrap_or_default().repo; - match path.is_some() { - true => { - let content = ctx - .github_client - .contents() - .find(repo.as_str(), path.unwrap().as_str(), reference.as_str()) - .ok(); - files_response.content = content.unwrap_or(empty_content()); - } - false => { - let tree = ctx - .github_client - .git() - .git_trees(repo.as_str(), reference.as_str(), Option::from(recursive)) - .ok() - .unwrap_or_default(); - files_response.tree = tree.unwrap_or_default(); + let repository = playbook.preface.manifest.unwrap_or_default().meta.repository; + if let Ok(url) = Url::parse(repository.as_str()) { + let repo = &url.path()[1..]; + match path.is_some() { + true => { + let content = + ctx.github_client.contents().find(repo, path.unwrap().as_str(), reference.as_str()).ok(); + files_response.content = content.unwrap_or(empty_content()); + } + false => { + let tree = ctx + .github_client + .git() + .git_trees(repo, reference.as_str(), Option::from(recursive)) + .ok() + .unwrap_or_default(); + files_response.tree = tree.unwrap_or_default(); + } } } }