| skipped 16 lines |
17 | 17 | | const REPO_PATH_PREFIX: &str = "lua/astrocommunity/"; |
18 | 18 | | |
19 | 19 | | #[derive(Debug, Deserialize)] |
20 | | - | struct Tree { |
21 | | - | tree: Vec<RepoContent>, |
22 | | - | } |
23 | | - | |
24 | | - | #[derive(Debug, Deserialize)] |
25 | 20 | | struct RepoContent { |
26 | | - | path: String, |
| 21 | + | pub(crate) path: String, |
27 | 22 | | } |
28 | 23 | | |
29 | 24 | | pub struct GitOperations; |
| skipped 14 lines |
44 | 39 | | output.status.code() |
45 | 40 | | )) |
46 | 41 | | } else { |
47 | | - | Self::parse_response(output.stdout) |
| 42 | + | Self::parse_response(&output.stdout) |
48 | 43 | | } |
49 | 44 | | } |
50 | 45 | | |
51 | 46 | | fn parse_response(response: Vec<u8>) -> Result<Vec<PluginInfo>> { |
52 | | - | let tree: Tree = serde_json::from_slice(&response)?; |
| 47 | + | let tree: Vec<RepoContent> = serde_json::from_slice(&response)?; |
53 | 48 | | let re = Regex::new(r"/[^/]+$")?; |
54 | 49 | | |
55 | 50 | | // We don't know how many plugins there are, so we'll just allocate the max possible based on the number of files |
56 | | - | let mut plugins = HashSet::with_capacity(tree.tree.len()); |
57 | | - | for content in tree.tree { |
| 51 | + | let mut plugins = HashSet::with_capacity(tree.len()); |
| 52 | + | for content in tree { |
58 | 53 | | // TODO: Move the replace operations below to parse_plugin_info |
59 | 54 | | let path = re.replace(&content.path, "").replace(REPO_PATH_PREFIX, ""); |
60 | 55 | | if !path.contains(".github") && path != REPO_PATH_PREFIX { |
61 | | - | if let Some(plugin) = Self::parse_plugin_info(path) { |
| 56 | + | if let Some(plugin) = parse_plugin_info(path) { |
62 | 57 | | plugins.insert(plugin); |
63 | 58 | | } |
64 | 59 | | } |
65 | 60 | | } |
66 | 61 | | Ok(plugins.into_iter().collect()) |
67 | 62 | | } |
| 63 | + | } |
68 | 64 | | |
69 | | - | fn parse_plugin_info(path: String) -> Option<PluginInfo> { |
70 | | - | let p: Vec<&str> = path.split('/').collect(); |
71 | | - | if p.len() >= 2 { |
72 | | - | Some(PluginInfo { |
73 | | - | group: p[0].to_string(), |
74 | | - | name: p[1].to_string(), |
75 | | - | }) |
76 | | - | } else { |
77 | | - | None |
78 | | - | } |
| 65 | + | fn parse_plugin_info(path: String) -> Option<PluginInfo> { |
| 66 | + | let p: Vec<&str> = path.split('/').collect(); |
| 67 | + | if p.len() < 2 { |
| 68 | + | return None; |
79 | 69 | | } |
| 70 | + | Some(PluginInfo { |
| 71 | + | group: p[0].to_string(), |
| 72 | + | name: p[1].to_string(), |
| 73 | + | }) |
80 | 74 | | } |
81 | 75 | | |