diff --git a/depdive/src/ghcomment.rs b/depdive/src/ghcomment.rs index 725e30b..39ff059 100644 --- a/depdive/src/ghcomment.rs +++ b/depdive/src/ghcomment.rs @@ -5,6 +5,7 @@ use anyhow::Result; use markdown_gen::markdown::{AsMarkdown, List, Markdown}; use std::cell::RefCell; +use url::Url; #[derive(PartialEq)] #[allow(dead_code)] @@ -89,6 +90,16 @@ impl GitHubCommentGenerator { Ok(()) } + pub fn add_hyperlinked_list>( + &self, + items: &[(T, Option)], + list_style: ListStyle, + ) -> Result<()> { + self.append_comment(&Self::get_hyperlinked_list(items, list_style)?); + self.add_newline(2); + Ok(()) + } + pub fn get_list>( items: &[T], list_style: ListStyle, @@ -117,6 +128,24 @@ impl GitHubCommentGenerator { Self::extract_markdown_generator(md) } + pub fn get_hyperlinked_list>( + items: &[(T, Option)], + list_style: ListStyle, + ) -> Result { + let mut md = Self::get_markdown_generator(); + let mut list = List::new(list_style == ListStyle::Numbered); + for (body, url) in items { + let body = body.as_ref(); + if let Some(url) = url.as_ref() { + list = list.item(body.link_to(url.as_ref())); + } else { + list = list.item(body); + } + } + md.write(list)?; + Self::extract_markdown_generator(md) + } + pub fn add_collapsible_section(&self, title: &str, body: &str) { self.append_comment(&Self::get_collabsible_section(title, body)); self.add_newline(2); diff --git a/depdive/src/lib.rs b/depdive/src/lib.rs index aeb0d64..d504d33 100644 --- a/depdive/src/lib.rs +++ b/depdive/src/lib.rs @@ -10,6 +10,7 @@ use guppy::MetadataCommand; use separator::Separatable; use std::path::Path; use tabled::Tabled; +use url::Url; mod advisory; mod code; @@ -341,28 +342,28 @@ impl UpdateAnalyzer { ), ]); if !report.updated_version.known_advisories.is_empty() { - let ids: Vec = report + let ids: Vec<(String, Option)> = report .updated_version .known_advisories .iter() - .map(|a| a.id.clone()) + .map(|a| (a.id.clone(), a.url.clone())) .collect(); gh.add_collapsible_section( ":bomb: The updated version contains known advisories", - &GitHubCommentGenerator::get_list(&ids, Bulleted, Code)?, + &GitHubCommentGenerator::get_hyperlinked_list(&ids, Bulleted)?, ); } - let fixed_advisories: Vec = report + let fixed_advisories: Vec<(String, Option)> = report .prior_version .known_advisories .iter() .filter(|a| !report.updated_version.known_advisories.contains(a)) - .map(|a| a.id.clone()) + .map(|a| (a.id.clone(), a.url.clone())) .collect(); if !fixed_advisories.is_empty() { gh.add_collapsible_section( ":tada: This update fixes known advisories", - &GitHubCommentGenerator::get_list(&fixed_advisories, Bulleted, Code)?, + &GitHubCommentGenerator::get_hyperlinked_list(&fixed_advisories, Bulleted)?, ); }