Merge pull request #2173 from ludovic111/feat/mod-index-downloads

🤖 Agent: Merging. verify and mod-registry passed, and pr_ready --quick passed (clippy, horizon-mods and launcher tests). The index's downloads field is optional, so the schema doesn't change.
This commit is contained in:
Ludovic Marie
2026-10-26 15:02:11 +01:00
committed by GitHub
7 changed files with 40 additions and 8 deletions
+8
View File
@@ -122,6 +122,14 @@ pub struct Project {
pub key: Option<String>,
/// Newest first.
pub versions: Vec<Version>,
/// Its files' downloads from their releases, all versions together:
/// GitHub's counts, added by the registry's publish job (hourly).
#[serde(default, skip_serializing_if = "is_zero")]
pub downloads: u64,
}
fn is_zero(n: &u64) -> bool {
*n == 0
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -231,6 +231,7 @@ pub fn project(entry: &Entry, src: &Sources) -> Result<Project, Vec<String>> {
icon,
key: entry.key.as_ref().map(|k| k.trim().to_owned()),
versions,
downloads: 0,
})
}
+7 -1
View File
@@ -34,8 +34,14 @@ fn reads_the_sample_and_keeps_unknown_kinds() {
[Capability::GameRead, Capability::Hud, Capability::Chat]
);
// What CI writes reads back the same.
let again = Index::parse(&serde_json::to_string(&index).unwrap()).unwrap();
let text = serde_json::to_string(&index).unwrap();
let again = Index::parse(&text).unwrap();
assert_eq!(again, index);
// Download counts: the publish job adds them; none is left out.
assert_eq!(hud.downloads, 0);
assert!(!text.contains("downloads"));
let counted = text.replacen("\"versions\"", "\"downloads\":12345,\"versions\"", 1);
assert_eq!(Index::parse(&counted).unwrap().projects[0].downloads, 12345);
}
#[test]