diff --git a/cli/src/clients.rs b/cli/src/clients.rs index 1a88c7dd..b37d317e 100644 --- a/cli/src/clients.rs +++ b/cli/src/clients.rs @@ -4,8 +4,8 @@ use std::path::PathBuf; use anyhow::Context; use crate::types::{ - BundleUploadStatus, CreateBundleUploadRequest, CreateBundleUploadResponse, CreateRepoRequest, - GetQuarantineBulkTestStatusRequest, QuarantineConfig, Repo, UpdateBundleUploadRequest, + CreateBundleUploadRequest, CreateBundleUploadResponse, CreateRepoRequest, + GetQuarantineBulkTestStatusRequest, QuarantineConfig, Repo, }; use crate::utils::status_code_help; @@ -47,35 +47,6 @@ pub async fn create_trunk_repo( Ok(()) } -pub async fn update_bundle_upload_status( - origin: &str, - api_token: &str, - id: &str, - upload_status: &BundleUploadStatus, -) -> anyhow::Result<()> { - let client = reqwest::Client::new(); - let resp = client - .patch(format!("{}/v1/metrics/updateBundleUpload", origin)) - .timeout(TRUNK_API_TIMEOUT) - .header(reqwest::header::CONTENT_TYPE, "application/json") - .header(TRUNK_API_TOKEN_HEADER, api_token) - .json(&UpdateBundleUploadRequest { - id: id.to_owned(), - upload_status: upload_status.to_owned(), - }) - .send() - .await - .map_err(|e| anyhow::anyhow!(e).context("Failed to update bundle upload status"))?; - - if resp.status() != reqwest::StatusCode::OK { - return Err( - anyhow::anyhow!("{}: {}", resp.status(), status_code_help(resp.status())) - .context("Failed to update bundle upload status"), - ); - } - - Ok(()) -} pub async fn create_bundle_upload_intent( origin: &str, diff --git a/cli/src/main.rs b/cli/src/main.rs index a1150a44..190fd465 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -7,7 +7,7 @@ use tokio_retry::strategy::ExponentialBackoff; use tokio_retry::Retry; use trunk_analytics_cli::bundler::BundlerUtil; use trunk_analytics_cli::clients::{ - create_bundle_upload_intent, create_trunk_repo, put_bundle_to_s3, update_bundle_upload_status, + create_bundle_upload_intent, create_trunk_repo, put_bundle_to_s3, }; use trunk_analytics_cli::codeowners::CodeOwners; use trunk_analytics_cli::constants::{ @@ -18,8 +18,7 @@ use trunk_analytics_cli::runner::{ }; use trunk_analytics_cli::scanner::{BundleRepo, EnvScanner}; use trunk_analytics_cli::types::{ - BundleMeta, BundleUploadStatus, QuarantineBulkTestStatus, QuarantineRunResult, RunResult, - META_VERSION, + BundleMeta, QuarantineBulkTestStatus, QuarantineRunResult, RunResult, META_VERSION, }; use trunk_analytics_cli::utils::{from_non_empty_or_default, parse_custom_tags}; @@ -257,7 +256,7 @@ async fn run_upload( ), org: org_url_slug.clone(), repo: repo.clone(), - bundle_upload_id: upload.id.clone(), + bundle_upload_id: upload.id, tags, file_sets, envs, @@ -296,42 +295,14 @@ async fn run_upload( log::info!("Flushed temporary tarball to {:?}", bundle_time_file); if dry_run { - if let Err(e) = update_bundle_upload_status( - &api_address, - &token, - &upload.id, - &BundleUploadStatus::DryRun, - ) - .await - { - log::warn!("Failed to update bundle upload status: {}", e); - } else { - log::debug!("Updated bundle upload status to DRY_RUN"); - } log::info!("Dry run, skipping upload."); return Ok(exit_code); } - let upload_status = Retry::spawn(default_delay(), || { + Retry::spawn(default_delay(), || { put_bundle_to_s3(&upload.url, &bundle_time_file) }) - .await - .map(|_| BundleUploadStatus::UploadComplete) - .unwrap_or_else(|e| { - log::error!("Failed to upload bundle to S3 after retries: {}", e); - BundleUploadStatus::UploadFailed - }); - if let Err(e) = - update_bundle_upload_status(&api_address, &token, &upload.id, &upload_status).await - { - log::warn!( - "Failed to update bundle upload status to {:#?}: {}", - upload_status, - e - ) - } else { - log::debug!("Updated bundle upload status to {:#?}", upload_status) - } + .await?; let remote_urls = vec![repo.repo_url.clone()]; Retry::spawn(default_delay(), || { diff --git a/cli/src/types.rs b/cli/src/types.rs index b2b629f8..f64dc1da 100644 --- a/cli/src/types.rs +++ b/cli/src/types.rs @@ -33,25 +33,6 @@ pub struct CreateBundleUploadRequest { pub org_url_slug: String, } -#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)] -pub enum BundleUploadStatus { - #[serde(rename = "PENDING")] - Pending, - #[serde(rename = "UPLOAD_COMPLETE")] - UploadComplete, - #[serde(rename = "UPLOAD_FAILED")] - UploadFailed, - #[serde(rename = "DRY_RUN")] - DryRun, -} - -#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)] -pub struct UpdateBundleUploadRequest { - pub id: String, - #[serde(rename = "uploadStatus")] - pub upload_status: BundleUploadStatus, -} - #[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)] pub struct GetQuarantineBulkTestStatusRequest { pub repo: Repo, diff --git a/cli/tests/test_utils/mock_server.rs b/cli/tests/test_utils/mock_server.rs index 5209e414..015de7e5 100644 --- a/cli/tests/test_utils/mock_server.rs +++ b/cli/tests/test_utils/mock_server.rs @@ -8,21 +8,20 @@ use axum::body::Bytes; use axum::extract::State; use axum::http::StatusCode; use axum::response::Response; -use axum::routing::{any, patch, post, put}; +use axum::routing::{any, post, put}; use axum::{Json, Router}; use tempfile::tempdir; use tokio::net::TcpListener; use tokio::spawn; use trunk_analytics_cli::types::{ CreateBundleUploadRequest, CreateBundleUploadResponse, CreateRepoRequest, - GetQuarantineBulkTestStatusRequest, QuarantineConfig, UpdateBundleUploadRequest, + GetQuarantineBulkTestStatusRequest, QuarantineConfig, }; #[derive(Debug, Clone, PartialEq, Eq)] pub enum RequestPayload { CreateRepo(CreateRepoRequest), CreateBundleUpload(CreateBundleUploadRequest), - UpdateBundleUpload(UpdateBundleUploadRequest), GetQuarantineBulkTestStatus(GetQuarantineBulkTestStatusRequest), S3Upload(PathBuf), } @@ -55,10 +54,6 @@ pub async fn spawn_mock_server() -> SharedMockServerState { "/v1/metrics/createBundleUpload", post(create_bundle_handler), ) - .route( - "/v1/metrics/updateBundleUpload", - patch(update_bundle_handler), - ) .route( "/v1/metrics/getQuarantineConfig", post(get_quarantining_config_handler), @@ -121,22 +116,6 @@ async fn create_bundle_handler( }) } -#[allow(dead_code)] // TODO: move this to its own crate to get rid of the need for this -#[axum::debug_handler] -async fn update_bundle_handler( - State(state): State, - Json(update_bundle_upload_request): Json, -) -> Response { - state - .requests - .lock() - .unwrap() - .push(RequestPayload::UpdateBundleUpload( - update_bundle_upload_request, - )); - Response::new(String::from("OK")) -} - #[allow(dead_code)] // TODO: move this to its own crate to get rid of the need for this #[axum::debug_handler] async fn get_quarantining_config_handler( diff --git a/cli/tests/upload.rs b/cli/tests/upload.rs index 21851e42..a406b0c2 100644 --- a/cli/tests/upload.rs +++ b/cli/tests/upload.rs @@ -10,8 +10,8 @@ use test_utils::mock_git_repo::setup_repo_with_commit; use test_utils::mock_server::{spawn_mock_server, RequestPayload}; use trunk_analytics_cli::codeowners::CodeOwners; use trunk_analytics_cli::types::{ - BundleMeta, BundleUploadStatus, CreateBundleUploadRequest, CreateRepoRequest, FileSetType, - GetQuarantineBulkTestStatusRequest, Repo, UpdateBundleUploadRequest, + BundleMeta, CreateBundleUploadRequest, CreateRepoRequest, FileSetType, + GetQuarantineBulkTestStatusRequest, Repo, }; mod test_utils; @@ -65,7 +65,7 @@ async fn upload_bundle() { .failure(); let requests = state.requests.lock().unwrap().clone(); - assert_eq!(requests.len(), 5); + assert_eq!(requests.len(), 4); let mut requests_iter = requests.into_iter(); assert_eq!( @@ -156,14 +156,6 @@ async fn upload_bundle() { assert_eq!(bundled_file.owners, ["@user"]); assert_eq!(bundled_file.team, None); - assert_eq!( - requests_iter.next().unwrap(), - RequestPayload::UpdateBundleUpload(UpdateBundleUploadRequest { - id: "test-bundle-upload-id".to_string(), - upload_status: BundleUploadStatus::UploadComplete - }), - ); - assert_eq!( requests_iter.next().unwrap(), RequestPayload::CreateRepo(CreateRepoRequest {