-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buildable, add vers-plugin crate, fix names
- Loading branch information
Showing
24 changed files
with
259 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ Cargo.lock | |
/target | ||
|
||
.DS_Store | ||
.idea/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,10 +1,13 @@ | ||
[package] | ||
name = "github" | ||
name = "vers-github" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
octocrab = "0.25" | ||
vers-types = { path = "../types" } | ||
octocrab = "0.28" | ||
vers-plugin = { path = "../vers-plugin" } | ||
vers-types = { path = "../vers-types" } | ||
tracing = "0.1" | ||
regex = "1.0" |
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
use octocrab::models::repos::{Asset, Release}; | ||
use regex::Regex; | ||
use std::path::PathBuf; | ||
use vers_types::*; | ||
use vers_plugin::*; | ||
|
||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
||
fn main() {} | ||
|
||
#[derive(Debug, Default)] | ||
struct VersGithub; | ||
|
||
impl VersPlugin for VersGithub { | ||
fn load(&self) { | ||
todo!() | ||
} | ||
|
||
fn list_versions(&self, name: Option<&str>) -> PluginResult<Vec<Version>> { | ||
todo!() | ||
} | ||
|
||
fn get_version(&self, name: Option<&str>, version: &str) -> PluginResult<String> { | ||
todo!() | ||
} | ||
|
||
fn get_version_assets(&self, name: Option<&str>, version: &Version) -> PluginResult<Vec<vers_types::Asset>> { | ||
todo!() | ||
} | ||
|
||
fn get_download_path(&self, base_path: &PathBuf, name: Option<&str>, version: &Version) -> &PathBuf { | ||
todo!() | ||
} | ||
} | ||
|
||
pub async fn get_repo_releases( | ||
owner: &'_ str, | ||
repo: &'_ str, | ||
pre_release: bool, | ||
) -> Result<Vec<String>> { | ||
Ok(octocrab::instance() | ||
.repos(owner, repo) | ||
.releases() | ||
.list() | ||
.per_page(100) | ||
.send() | ||
.await? | ||
.items | ||
.iter() | ||
.filter_map(|release| match pre_release { | ||
true => Some(release.tag_name.to_string()), | ||
false => match release.prerelease { | ||
true => None, | ||
false => Some(release.tag_name.to_string()), | ||
}, | ||
}) | ||
.collect()) | ||
} | ||
|
||
pub async fn get_specific_release_for_repo( | ||
owner: &'_ str, | ||
repo: &'_ str, | ||
version: &'_ Version, | ||
) -> Result<Release> { | ||
tracing::info!( | ||
"Getting release({}) for {}/{}", | ||
version.as_tag(), | ||
owner, | ||
repo | ||
); | ||
let octo = octocrab::instance(); | ||
if version == &Version::Latest { | ||
match octo.repos(owner, repo).releases().get_latest().await { | ||
Ok(latest_release) => Ok(latest_release), | ||
Err(e) => Err(e.into()), | ||
} | ||
} else { | ||
match octo | ||
.repos(owner, repo) | ||
.releases() | ||
.get_by_tag(&version.as_tag()) | ||
.await | ||
{ | ||
Ok(tagged_release) => Ok(tagged_release), | ||
Err(_) => { | ||
match octo | ||
.repos(owner, repo) | ||
.releases() | ||
.get_by_tag(&format!("v{}", version.as_tag())) | ||
.await | ||
{ | ||
Ok(tagged_release) => Ok(tagged_release), | ||
Err(e) => Err(e.into()), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub async fn get_latest_release_tag(owner: &'_ str, repo: &'_ str) -> Option<Version> { | ||
match octocrab::instance() | ||
.repos(owner, repo) | ||
.releases() | ||
.get_latest() | ||
.await | ||
{ | ||
Ok(tag) => Some(parse_version(&tag.tag_name)), | ||
Err(_) => None, | ||
} | ||
} | ||
|
||
pub fn get_platform_specific_asset( | ||
release: &'_ Release, | ||
system: &'_ System, | ||
user_pattern: &'_ str, | ||
) -> Vec<Asset> { | ||
release | ||
.assets | ||
.iter() | ||
.filter_map(|asset| -> Option<Asset> { | ||
if !user_pattern.is_empty() { | ||
let r = Regex::new(user_pattern).unwrap_or_else(|_| { | ||
panic!("{} is not a valid Regular Expression", user_pattern) | ||
}); | ||
tracing::debug!("Matching '{}' against '{}'", r.as_str(), &asset.name); | ||
if r.is_match(&asset.name) { | ||
Some(asset.clone()) | ||
} else { | ||
None | ||
} | ||
} else if system.is_match(&asset.name) { | ||
tracing::debug!("Asset info: {:?}", asset.name); | ||
Some(asset.clone()) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect() | ||
} |
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,11 +1,9 @@ | ||
[package] | ||
name = "types" | ||
name = "vers-plugin" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
semver = "1.0" | ||
test-case = "3.1" | ||
regex = "1.9" | ||
vers-types = { path = "../vers-types" } |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::path::PathBuf; | ||
use vers_types::{Asset, Version}; | ||
|
||
pub type PluginResult<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>; | ||
|
||
pub trait VersPlugin: Default { | ||
/// | ||
fn load(&self); | ||
/// Retrieve a list of versions | ||
fn list_versions(&self, name: Option<&str>) -> PluginResult<Vec<Version>>; | ||
/// | ||
fn get_version(&self, name: Option<&str>, version: &str) -> PluginResult<String>; | ||
/// | ||
fn get_version_assets(&self, name: Option<&str>, version: &Version) -> PluginResult<Vec<Asset>>; | ||
/// | ||
fn get_download_path(&self, base_path: &PathBuf, name: Option<&str>, version: &Version) -> &PathBuf; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! register_plugin { | ||
() => {}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "vers-types" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
regex = "1.9" | ||
semver = "1.0" | ||
test-case = "3.1" | ||
thiserror = "1.0" | ||
serde = "1.0" |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub struct Asset { | ||
pub name: String, | ||
pub download_url: String, | ||
} |
Oops, something went wrong.