The cross-platform version manager toolset
crates.io/crates/hyper-jump
1use anyhow::Result;
2use serde::Deserialize;
3
4use crate::adapters::github::api;
5use crate::adapters::github::deserialize_response;
6use crate::domain::package::PackageSpec;
7use crate::domain::version::parse_normal_version;
8use crate::domain::version::ParsedVersion;
9use crate::domain::version::RemoteVersion;
10use crate::ports::ReleaseProvider;
11
12pub struct GitHubReleaseProvider {
13 client: Option<reqwest::Client>,
14}
15
16#[derive(Debug, Deserialize)]
17struct UpstreamVersion {
18 pub tag_name: String,
19}
20
21impl GitHubReleaseProvider {
22 pub fn new(client: Option<&reqwest::Client>) -> Self {
23 Self {
24 client: client.cloned(),
25 }
26 }
27}
28
29impl ReleaseProvider for GitHubReleaseProvider {
30 async fn latest(&self, package: &PackageSpec) -> Result<ParsedVersion> {
31 let url = package.latest_url();
32 let response = api(self.client.as_ref(), url).await?;
33 let latest: UpstreamVersion = deserialize_response(response)?;
34 parse_normal_version(&latest.tag_name).await
35 }
36
37 async fn list(&self, package: &PackageSpec) -> Result<Vec<RemoteVersion>> {
38 let url = package.releases_url();
39 let response = api(self.client.as_ref(), url).await?;
40 let versions: Vec<RemoteVersion> = deserialize_response(response)?;
41 Ok(versions)
42 }
43}