From 8e52481ede20d0eb7cf7a4dc17640499a342a831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=BCrr?= <102963075+cd-work@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:05:32 +0000 Subject: [PATCH] Fix pipeline failures showing up as complete (#1518) This fixes an issue where packages would show up as passing Phylum's analysis if they failed at any point of the pipeline. Closes #351. --- CHANGELOG.md | 1 + cli/src/commands/packages.rs | 20 ++++++++++++++------ cli/src/types.rs | 30 +++++++++++------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77ffecb20..d77cae3b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Package subcommand failing to parse API responses +- Packages which cannot be analyzed showing up as having no issues ## 7.1.0 - 2024-09-24 diff --git a/cli/src/commands/packages.rs b/cli/src/commands/packages.rs index 50936fbe8..0bd236573 100644 --- a/cli/src/commands/packages.rs +++ b/cli/src/commands/packages.rs @@ -8,8 +8,8 @@ use crate::api::PhylumApi; use crate::commands::{CommandResult, ExitCode}; use crate::filter::{Filter, FilterIssues}; use crate::format::Format; -use crate::print_user_warning; use crate::types::{PackageSpecifier, PackageSubmitResponse}; +use crate::{print_user_failure, print_user_warning}; fn parse_package(matches: &ArgMatches) -> Result { // Read required options. @@ -36,12 +36,20 @@ pub async fn handle_get_package(api: &PhylumApi, matches: &clap::ArgMatches) -> match resp { PackageSubmitResponse::AlreadyProcessed(mut resp) if resp.complete => { - let filter = matches.get_one::("filter").and_then(|v| Filter::from_str(v).ok()); - if let Some(filter) = filter { - resp.filter(&filter); - } + match resp.pipeline_error { + Some(_) => print_user_failure!( + "Package analysis failed, please contact Phylum if this package exists." + ), + None => { + let filter = + matches.get_one::("filter").and_then(|v| Filter::from_str(v).ok()); + if let Some(filter) = filter { + resp.filter(&filter); + } - resp.write_stdout(pretty_print); + resp.write_stdout(pretty_print); + }, + } }, PackageSubmitResponse::New => { print_user_warning!( diff --git a/cli/src/types.rs b/cli/src/types.rs index 267c3ac5e..bc3f5ab89 100644 --- a/cli/src/types.rs +++ b/cli/src/types.rs @@ -170,6 +170,9 @@ pub struct Package { pub complete: bool, pub release_data: Option, pub repo_url: Option, + pub hash: Option, + pub pipeline_error: Option, + pub pipeline_status: Option, } #[derive(Serialize, Deserialize)] @@ -243,25 +246,14 @@ pub enum IgnoredReason { Other, } -/// One of the authors of a package. -#[derive(Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Author { - pub name: String, - pub avatar_url: String, - pub email: String, - pub profile_url: String, -} - -/// Stats about how responsive the maintainers of a package are. -#[derive(Serialize, Deserialize)] -pub struct DeveloperResponsiveness { - pub open_issue_count: Option, - pub total_issue_count: Option, - pub open_issue_avg_duration: Option, - pub open_pull_request_count: Option, - pub total_pull_request_count: Option, - pub open_pull_request_avg_duration: Option, +/// Package status in the analysis pipeline. +#[derive(Serialize, Deserialize, Copy, Clone, PartialEq, Eq, Debug)] +pub enum PipelineStatus { + Submitted, + Downloading, + Processing, + Analyzing, + Complete, } /// Information about when package releases have happened.