gitflow_core/
compatibility.rs1use serde::Deserialize;
10
11const MATRIX_JSON: &str = include_str!("../resources/compatibility-matrix.json");
13
14#[derive(Debug, Deserialize)]
16struct MatrixRoot {
17 #[allow(
19 dead_code,
20 reason = "Deserialized for validation, not yet used at runtime"
21 )]
22 schema_version: u32,
23 #[allow(
25 dead_code,
26 reason = "Deserialized for validation, not yet used at runtime"
27 )]
28 updated_at: String,
29 platforms: Vec<PlatformCompat>,
31}
32
33#[derive(Debug, Clone, Deserialize)]
35pub struct PlatformCompat {
36 pub name: String,
38 pub identifier: String,
40 pub cli_binary: String,
42 pub min_version: String,
44 pub tested_versions: Vec<String>,
46 pub install_url: String,
48 pub doc_link: String,
50}
51
52#[must_use]
58#[allow(
59 clippy::expect_used,
60 reason = "Embedded JSON is compile-time data; parse failure means corrupted build artifacts"
61)]
62pub fn platform_compatibility() -> Vec<PlatformCompat> {
63 let root: MatrixRoot =
64 serde_json::from_str(MATRIX_JSON).expect("embedded compatibility-matrix.json is invalid");
65 root.platforms
66}
67
68#[must_use]
70pub fn platform_requirement(identifier: &str) -> Option<PlatformCompat> {
71 platform_compatibility()
72 .into_iter()
73 .find(|p| p.identifier == identifier)
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn test_should_load_all_three_platforms() {
82 let platforms = platform_compatibility();
83 assert_eq!(platforms.len(), 3);
84 }
85
86 #[test]
87 fn test_should_return_github_requirement() {
88 let gh = platform_requirement("github").expect("github should exist");
89 assert_eq!(gh.cli_binary, "gh");
90 assert_eq!(gh.min_version, "2.0.0");
91 assert!(!gh.install_url.is_empty());
92 assert!(!gh.doc_link.is_empty());
93 }
94
95 #[test]
96 fn test_should_return_gitcode_min_version_0_6() {
97 let gc = platform_requirement("gitcode").expect("gitcode should exist");
98 assert_eq!(gc.min_version, "0.6.0");
99 }
100
101 #[test]
102 fn test_should_return_none_for_unknown_platform() {
103 assert!(platform_requirement("bitbucket").is_none());
104 }
105}