-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openvsx): impl basic support for openvsx
Signed-off-by: DragonBillow <[email protected]>
- Loading branch information
Showing
2 changed files
with
154 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,78 @@ | ||
#![allow(unused_assignments)] | ||
|
||
use std::str::FromStr; | ||
|
||
use log::*; | ||
|
||
use openvsx::apis::{configuration::Configuration, registry_api_api}; | ||
use openvsx::{ | ||
apis::{configuration::Configuration, registry_api_api}, | ||
models::VersionReference, | ||
}; | ||
|
||
async fn get_matched_version_of( | ||
pub async fn get_matched_version_of( | ||
config: &Configuration, | ||
namespace: &str, | ||
extension: &str, | ||
engine_ver: &semver::Version, | ||
) -> Option<String> { | ||
match registry_api_api::get_version_references1(config, namespace, extension, None, None).await | ||
{ | ||
Ok(res) => { | ||
for ver in res.versions { | ||
todo!() | ||
) -> Vec<VersionReference> { | ||
loop { | ||
let mut offset = 0usize; | ||
let size = 20usize; | ||
|
||
match registry_api_api::get_version_references1( | ||
config, | ||
namespace, | ||
extension, | ||
Some(size as i32), | ||
Some(offset as i32), | ||
) | ||
.await | ||
{ | ||
Ok(res) => { | ||
// FIXME: get all available version for it. | ||
offset += res.versions.len(); | ||
|
||
let mut fn_res = vec![]; | ||
for ver in res.versions { | ||
if ver.version.is_none() { | ||
continue; | ||
} | ||
if ver | ||
.engines | ||
.iter() | ||
.flatten() | ||
.filter_map(|(_, v)| semver::VersionReq::from_str(v).ok()) | ||
.any(|ver| ver.matches(engine_ver)) | ||
{ | ||
fn_res.push(ver.clone()); | ||
} | ||
} | ||
|
||
if !fn_res.is_empty() { | ||
return fn_res; | ||
} | ||
} | ||
Err(err) => { | ||
warn!("Error happend when get matched version of {namespace}.{extension} for {engine_ver}"); | ||
return vec![]; | ||
} | ||
todo!() | ||
} | ||
Err(err) => { | ||
warn!("Error happend when get matched version of {namespace}.{extension} for {engine_ver}"); | ||
None | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn test_get_version() { | ||
let a = get_matched_version_of( | ||
&Default::default(), | ||
"redhat", | ||
"java", | ||
&semver::Version::new(1, 77, 0), | ||
) | ||
.await; | ||
assert!(!a.is_empty()); | ||
} | ||
} |