init
This commit is contained in:
51
src/repo/mod.rs
Normal file
51
src/repo/mod.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use std::path::PathBuf;
|
||||
use crate::manifest::Manifest;
|
||||
use crate::repo::github::GithubRepo;
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use semver::Version;
|
||||
|
||||
mod github;
|
||||
|
||||
/// Since artifact binary / image
|
||||
pub struct RepoArtifact {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
pub location: RepoResource,
|
||||
pub content_type: String,
|
||||
}
|
||||
|
||||
/// A local/remote location where the artifact is located
|
||||
pub enum RepoResource {
|
||||
Remote(String),
|
||||
Local(PathBuf),
|
||||
}
|
||||
|
||||
/// A single release with one or more artifacts
|
||||
pub struct RepoRelease {
|
||||
pub version: Version,
|
||||
pub artifacts: Vec<RepoArtifact>,
|
||||
}
|
||||
|
||||
/// Generic artifact repository
|
||||
#[async_trait::async_trait]
|
||||
pub trait Repo {
|
||||
/// Get a list of release artifacts
|
||||
async fn get_releases(&self) -> Result<Vec<RepoRelease>>;
|
||||
}
|
||||
|
||||
impl TryInto<Box<dyn Repo>> for &Manifest {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_into(self) -> std::result::Result<Box<dyn Repo>, Self::Error> {
|
||||
let repo = self
|
||||
.repository
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("repository not found"))?;
|
||||
|
||||
if !repo.starts_with("https://github.com/") {
|
||||
bail!("Only github repos are supported");
|
||||
}
|
||||
|
||||
Ok(Box::new(GithubRepo::from_url(repo)?))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user