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

refactor(cli/components): fix multiples reviews #219

Merged
merged 1 commit into from
Feb 14, 2025
Merged
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
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