Skip to content

Commit f5f8825

Browse files
Make changelog OneToMany
1 parent ad67354 commit f5f8825

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

ixx/src/action/index/packages.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ pub(crate) async fn index_packages(module: &IndexModule, config: &Config) -> any
161161
Ok(())
162162
}
163163

164+
fn one_or_many_to_url(something: Option<OneOrMany<String>>) -> Vec<Url> {
165+
match something {
166+
None => vec![],
167+
Some(OneOrMany::One(homepage)) => Url::parse(&homepage)
168+
.with_context(|| format!("Failed to parse URL '{homepage}'"))
169+
.ok()
170+
.into_iter()
171+
.collect(),
172+
Some(OneOrMany::Many(homepages)) => homepages
173+
.into_iter()
174+
.filter_map(|homepage| {
175+
Url::parse(&homepage)
176+
.with_context(|| format!("Failed to parse URL '{homepage}'"))
177+
.ok()
178+
})
179+
.collect(),
180+
}
181+
}
182+
164183
fn into_package(url_prefix: &Url, package: package::Package) -> anyhow::Result<libixx::Package> {
165184
static CVE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"CVE-(\d{4})-(\d+)").unwrap());
166185
static GHSA_REGEX: LazyLock<Regex> =
@@ -169,7 +188,7 @@ fn into_package(url_prefix: &Url, package: package::Package) -> anyhow::Result<l
169188
Ok(libixx::Package {
170189
attr_name: package.attr_name,
171190
broken: package.broken,
172-
changelog: package.changelog,
191+
changelogs: one_or_many_to_url(package.changelog),
173192
cpe: package.cpe,
174193
declaration: package
175194
.declaration
@@ -181,22 +200,7 @@ fn into_package(url_prefix: &Url, package: package::Package) -> anyhow::Result<l
181200
disabled: package.disabled,
182201
download_page: package.download_page,
183202
eval_error: package.eval_error,
184-
homepages: match package.homepage {
185-
None => vec![],
186-
Some(OneOrMany::One(homepage)) => Url::parse(&homepage)
187-
.with_context(|| format!("Failed to parse URL '{homepage}'"))
188-
.ok()
189-
.into_iter()
190-
.collect(),
191-
Some(OneOrMany::Many(homepages)) => homepages
192-
.into_iter()
193-
.filter_map(|homepage| {
194-
Url::parse(&homepage)
195-
.with_context(|| format!("Failed to parse URL '{homepage}'"))
196-
.ok()
197-
})
198-
.collect(),
199-
},
203+
homepages: one_or_many_to_url(package.homepage),
200204
known_vulnerabilities: package
201205
.known_vulnerabilities
202206
.unwrap_or_default()

ixx/src/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::Declaration;
77
pub struct Package {
88
pub attr_name: String,
99
pub broken: Option<bool>,
10-
pub changelog: Option<String>,
10+
pub changelog: Option<OneOrMany<String>>,
1111
pub cpe: Option<String>,
1212
pub declaration: Option<Declaration>,
1313
pub description: Option<String>,

libixx/src/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub struct Package {
77
pub attr_name: String,
88
#[serde(skip_serializing_if = "Option::is_none")]
99
pub broken: Option<bool>,
10-
#[serde(skip_serializing_if = "Option::is_none")]
11-
pub changelog: Option<String>,
10+
#[serde(skip_serializing_if = "Vec::is_empty")]
11+
pub changelogs: Vec<Url>,
1212
#[serde(skip_serializing_if = "Option::is_none")]
1313
pub cpe: Option<String>,
1414
#[serde(skip_serializing_if = "Option::is_none")]

0 commit comments

Comments
 (0)