generated from PlexSheep/rs-base
release and server api skeletons
This commit is contained in:
parent
2568d96ac3
commit
0f1b82c4c9
|
@ -73,7 +73,7 @@ impl YamlConfigSection for ApiAuth {
|
|||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Api {
|
||||
pub r#type: ApiType,
|
||||
pub server_type: ApiType,
|
||||
pub endpoint: Url,
|
||||
/// May be left empty if the Api does not need auth or the auth is part of the
|
||||
/// [endpoint](Api::endpoint) [Url].
|
||||
|
@ -81,7 +81,7 @@ pub struct Api {
|
|||
}
|
||||
impl YamlConfigSection for Api {
|
||||
fn check(&self) -> Result<()> {
|
||||
self.r#type.check()?;
|
||||
self.server_type.check()?;
|
||||
match self.endpoint.socket_addrs(|| None) {
|
||||
Ok(_) => (),
|
||||
Err(err) => return Err(err.into()),
|
||||
|
|
|
@ -5,6 +5,7 @@ use autocrate::{
|
|||
Config,
|
||||
},
|
||||
release::release,
|
||||
serverapi::init_servers,
|
||||
publish::publish,
|
||||
error::*,
|
||||
};
|
||||
|
@ -19,10 +20,11 @@ async fn main() -> Result<()> {
|
|||
println!("{}", Changelog::build(&cfg)?);
|
||||
}
|
||||
Commands::Release { .. } => {
|
||||
release(&cfg)?;
|
||||
init_servers(&cfg).await?;
|
||||
release(&cfg).await?;
|
||||
}
|
||||
Commands::Publish { .. } => {
|
||||
publish(&cfg)?;
|
||||
publish(&cfg).await?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{config::Config, error::*};
|
||||
pub fn publish(cfg: &Config) -> Result<()> {
|
||||
pub async fn publish(cfg: &Config) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
use crate::{config::Config, error::*};
|
||||
|
||||
pub fn release(cfg: &Config) -> Result<()> {
|
||||
pub async fn release(cfg: &Config) -> Result<()> {
|
||||
// TODO: git tag
|
||||
// TODO: version bump
|
||||
// TODO: version select interactive
|
||||
// TODO: version select automated
|
||||
// TODO: push to each server
|
||||
// TODO: release to each server
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use super::ServerApi;
|
||||
use crate::{
|
||||
config::{ApiType, Config},
|
||||
error::*,
|
||||
};
|
||||
pub struct Gitea;
|
||||
|
||||
#[async_trait]
|
||||
impl ServerApi for Gitea {
|
||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
async fn push_release(&mut self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Gitea {
|
||||
pub async fn build(cfg: &Config) -> Result<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use super::ServerApi;
|
||||
use crate::{
|
||||
config::{ApiType, Config},
|
||||
error::*,
|
||||
};
|
||||
pub struct Github;
|
||||
|
||||
#[async_trait]
|
||||
impl ServerApi for Github {
|
||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
async fn push_release(&mut self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Github {
|
||||
pub async fn build(cfg: &Config) -> Result<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use super::ServerApi;
|
||||
use crate::{
|
||||
config::{ApiType, Config},
|
||||
error::*,
|
||||
};
|
||||
pub struct Gitlab;
|
||||
|
||||
#[async_trait]
|
||||
impl ServerApi for Gitlab {
|
||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
async fn push_release(&mut self) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Gitlab {
|
||||
pub async fn build(cfg: &Config) -> Result<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
config::{ApiType, Config},
|
||||
error::*,
|
||||
};
|
||||
|
||||
pub mod gitea;
|
||||
pub mod github;
|
||||
pub mod gitlab;
|
||||
use gitea::*;
|
||||
use github::*;
|
||||
use gitlab::*;
|
||||
|
||||
pub type ApiCollection = Vec<Box<dyn ServerApi>>;
|
||||
|
||||
// NOTE: in stable rust, traits can normally not contain async methods,
|
||||
// see [here](https://stackoverflow.com/questions/65921581/how-can-i-define-an-async-method-in-a-trait).
|
||||
// The `async_trait` crate can be used to work around this limitation.
|
||||
#[async_trait]
|
||||
pub trait ServerApi {
|
||||
async fn init(&mut self, cfg: &Config) -> Result<()>;
|
||||
async fn push_release(&mut self) -> Result<()>;
|
||||
}
|
||||
|
||||
pub async fn init_servers(cfg: &Config) -> Result<ApiCollection> {
|
||||
let mut collection: ApiCollection = ApiCollection::new();
|
||||
for api in &cfg.yaml.api {
|
||||
match api.1.server_type {
|
||||
ApiType::Gitea => {
|
||||
collection.push(Box::new(Gitea::build(cfg).await?));
|
||||
}
|
||||
ApiType::Gitlab => {
|
||||
collection.push(Box::new(Gitlab::build(cfg).await?));
|
||||
}
|
||||
ApiType::Github => {
|
||||
collection.push(Box::new(Github::build(cfg).await?));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(collection)
|
||||
}
|
Loading…
Reference in New Issue