From 6afb3da17e7d990ea057a2fd3a5c2cc73ab9f895 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 12 Mar 2022 17:32:16 +0000 Subject: [PATCH] Each release shouldn't have more than one crate file --- src/providers/gitlab.rs | 56 ++++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/src/providers/gitlab.rs b/src/providers/gitlab.rs index 850e405..062cea8 100644 --- a/src/providers/gitlab.rs +++ a/src/providers/gitlab.rs @@ -183,52 +183,32 @@ .json() .await?; - Ok::<_, anyhow::Error>(Some( + let expected_file_name = format!("{}-{}.crate", release.name, release.version); + + Ok::<_, anyhow::Error>( package_files .into_iter() - .filter_map(|package_file| { - #[allow(clippy::case_sensitive_file_extension_comparisons)] - if package_file.file_name.ends_with(".crate") { - if package_file.file_name - == format!("{}-{}.crate", release.name, release.version) - { - Some(( - package_path.clone(), - Release { - name: release.name.clone(), - version: release.version.clone(), - checksum: package_file.file_sha256, - }, - )) - } else { - tracing::info!( - "{}/{}/{}/{} should be called {}-{}.crate", - project, - release.name, - release.version, - package_file.file_name, - release.name, - release.version - ); - None - } - } else { - None - } - }) - .collect(), - )) + .find(|package_file| package_file.file_name == expected_file_name) + .map(move |package_file| { + ( + package_path.clone(), + Release { + name: release.name, + version: release.version, + checksum: package_file.file_sha256, + }, + ) + }), + ) })); } } - let x: Vec> = futures + futures .err_into() .filter_map(|v| async move { v.and_then(|v| v).transpose() }) .try_collect() - .await?; - - Ok(x.into_iter().flatten().collect()) + .await } async fn fetch_metadata_for_release( @@ -263,7 +243,7 @@ Err(anyhow::Error::msg( resp.message .or(resp.error) - .map_or_else(|| Cow::Borrowed("unknown error"), Cow::Owned) + .map_or_else(|| Cow::Borrowed("unknown error"), Cow::Owned), )) } } -- rgit 0.1.3