Skip to content

Commit

Permalink
optimize playbook create method
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahao6635 committed Jan 19, 2024
1 parent 92d946b commit 2e622a5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/services/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,11 @@ 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)?;
let repository = ctx.github_client.repositories().find(&repo).map_err(ApiError::NotFoundRepo)?;
let description= repository.and_then(|r|r.description).unwrap_or_default();
let payload = PlaybookPayload { title:repo, description, preface: Preface::repository(&req.repo) };

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

Expand Down

0 comments on commit 2e622a5

Please sign in to comment.