Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl playbook create method #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ name = "playground"
path = "src/lib.rs"

[dependencies]
amp-client = { git = "https://github.com/amphitheatre-app/amp-client-rust", tag = "v0.7.2" }
amp-common = { git = "https://github.com/amphitheatre-app/common", tag = "v0.7.2" }
amp-client = { git = "https://github.com/amphitheatre-app/amp-client-rust", tag = "v0.7.3" }
amp-common = { git = "https://github.com/amphitheatre-app/common", tag = "v0.7.3" }
anyhow = "1.0"
axum = { version = "0.7.4" }
clap = { version = "4.4.12", features = ["derive", "env"] }
Expand Down
4 changes: 1 addition & 3 deletions src/requests/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ use utoipa::ToSchema;

#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct CreatePlaybookRequest {
pub title: String,
pub description: Option<String>,
pub preface: Preface,
pub repo: String,
}
30 changes: 26 additions & 4 deletions src/services/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// limitations under the License.

use amp_client::playbooks::PlaybookPayload;
use amp_common::resource::PlaybookSpec;
use amp_common::resource::{PlaybookSpec, Preface};
use std::sync::Arc;
use amp_common::schema::GitReference;
use tracing::{error, info};

use uuid::Uuid;
Expand All @@ -23,19 +24,40 @@ use crate::context::Context;
use crate::errors::ApiError;
use crate::errors::Result;
use crate::requests::playbook::CreatePlaybookRequest;
use crate::utils::repo;

pub struct PlaybookService;

impl PlaybookService {
pub async fn create(ctx: Arc<Context>, req: &CreatePlaybookRequest) -> Result<PlaybookSpec> {
let mut title = String::new();
let mut description = String::new();

let repo = repo(req.repo.as_str()).unwrap_or_default();
let repository = ctx.github_client.repositories().find(repo.as_str()).ok().unwrap_or_default();
match repository {
Some(repository) => {
title = repo;
description = repository.description;
}
None => {
info!("Not found github repositories in {}...", repo);
}
}
let mut preface = Preface::default();
let mut reference = GitReference::default();
reference.repo = req.repo.clone();
preface.name = req.repo.clone();
preface.repository = Some(reference);
let payload = PlaybookPayload {
title: req.title.clone(),
description: req.description.clone().unwrap_or_default(),
preface: req.preface.clone(),
title,
description,
preface,
};
ctx.client.playbooks().create(payload).map_err(ApiError::FailedToCreatePlaybook)
}


pub async fn delete(ctx: Arc<Context>, id: Uuid) -> Result<u16> {
let playbooks = ctx.client.playbooks();
match playbooks.get(&id.to_string()) {
Expand Down
Loading