Skip to content

Commit

Permalink
Fix pipeline failures showing up as complete
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cd-work committed Oct 10, 2024
1 parent b70eb19 commit 472cd96
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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

Expand Down
20 changes: 14 additions & 6 deletions cli/src/commands/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageSpecifier> {
// Read required options.
Expand All @@ -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::<String>("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::<String>("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!(
Expand Down
30 changes: 11 additions & 19 deletions cli/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ pub struct Package {
pub complete: bool,
pub release_data: Option<PackageReleaseData>,
pub repo_url: Option<String>,
pub hash: Option<String>,
pub pipeline_error: Option<String>,
pub pipeline_status: Option<PipelineStatus>,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -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<usize>,
pub total_issue_count: Option<usize>,
pub open_issue_avg_duration: Option<u32>,
pub open_pull_request_count: Option<usize>,
pub total_pull_request_count: Option<usize>,
pub open_pull_request_avg_duration: Option<u32>,
/// 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.
Expand Down

0 comments on commit 472cd96

Please sign in to comment.