Skip to content

Commit

Permalink
refactor(cli/components): fix multiples reviews (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
KokaKiwi authored Feb 14, 2025
1 parent 02d30ab commit c79523a
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions crates/cli/src/commands/components/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Options {
pub async fn run(opts: Options) -> anyhow::Result<()> {
use inquire::{Confirm, Editor, Select};

use edgee_api_client::{auth::Credentials, ResultExt};
use edgee_api_client::{auth::Credentials, ErrorExt, ResultExt};

use crate::components::manifest;

Expand Down Expand Up @@ -49,7 +49,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
organization.slug, component_slug,
);

match client
let (do_update, component) = match client
.get_component_by_slug()
.org_slug(&organization.slug)
.component_slug(&component_slug)
Expand Down Expand Up @@ -77,7 +77,7 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
)
.prompt()?;

client
let component = client
.create_component()
.body(
api_types::ComponentCreateInput::builder()
Expand Down Expand Up @@ -111,40 +111,12 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
organization.slug,
component_slug,
);

(false, component.into_inner())
}
Ok(_) | Err(_) => {
client
.update_component_by_slug()
.org_slug(&organization.slug)
.component_slug(&component_slug)
.body(
api_types::ComponentUpdateParams::builder()
.description(manifest.component.description.clone())
.documentation_link(
manifest
.component
.documentation
.as_ref()
.map(|url| url.to_string()),
)
.repo_link(
manifest
.component
.repository
.as_ref()
.map(|url| url.to_string()),
),
)
.send()
.await
.api_context("Could not update component infos")?;
tracing::info!(
"Component `{}/{}` has been updated successfully!",
organization.slug,
component_slug,
);
}
}
Ok(res) => (true, res.into_inner()),
Err(err) => anyhow::bail!("Error contacting API: {}", err.into_message()),
};

let changelog =
Editor::new("Please describe the changes from the previous version").prompt_skippable()?;
Expand Down Expand Up @@ -179,6 +151,40 @@ pub async fn run(opts: Options) -> anyhow::Result<()> {
.await
.expect("Could not upload component");

if do_update {
client
.update_component_by_slug()
.org_slug(&organization.slug)
.component_slug(&component_slug)
.body(
api_types::ComponentUpdateParams::builder()
.description(manifest.component.description.clone())
.public(component.is_public)
.documentation_link(
manifest
.component
.documentation
.as_ref()
.map(|url| url.to_string()),
)
.repo_link(
manifest
.component
.repository
.as_ref()
.map(|url| url.to_string()),
),
)
.send()
.await
.api_context("Could not update component infos")?;
tracing::info!(
"Component `{}/{}` has been updated successfully!",
organization.slug,
component_slug,
);
}

tracing::info!("Creating component version...");
client
.create_component_version_by_slug()
Expand Down

0 comments on commit c79523a

Please sign in to comment.