generated from PlexSheep/rs-base
Compare commits
No commits in common. "39538b7b01b60272600f4ab2a0bb82d3397f6cc3" and "19d5d11b0506dcf9511d8260cc8a39eb6b6baf0a" have entirely different histories.
39538b7b01
...
19d5d11b05
8 changed files with 36 additions and 100 deletions
|
@ -27,7 +27,6 @@ clap = { version = "4.4.18", features = ["derive", "help"] }
|
||||||
clap-verbosity-flag = "2.1.2"
|
clap-verbosity-flag = "2.1.2"
|
||||||
git2 = "0.18.1"
|
git2 = "0.18.1"
|
||||||
libpt = { version = "0.3.11", features = ["log"] }
|
libpt = { version = "0.3.11", features = ["log"] }
|
||||||
reqwest = "0.11.24"
|
|
||||||
serde = { version = "1.0.195", features = ["derive"] }
|
serde = { version = "1.0.195", features = ["derive"] }
|
||||||
serde_yaml = "0.9.30"
|
serde_yaml = "0.9.30"
|
||||||
tempfile = "3.9.0"
|
tempfile = "3.9.0"
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub enum Pass {
|
||||||
}
|
}
|
||||||
impl Pass {
|
impl Pass {
|
||||||
/// Get the pass, extracting from the underlying source
|
/// Get the pass, extracting from the underlying source
|
||||||
pub fn get_pass(&self) -> Result<String> {
|
fn get_pass(&self) -> Result<String> {
|
||||||
self.check()?;
|
self.check()?;
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
Self::Text(pass) => pass.clone(),
|
Self::Text(pass) => pass.clone(),
|
||||||
|
|
12
src/error.rs
12
src/error.rs
|
@ -20,18 +20,6 @@ pub enum Error {
|
||||||
SerdeYaml(#[from] serde_yaml::Error),
|
SerdeYaml(#[from] serde_yaml::Error),
|
||||||
#[error("Could not generate the changelog")]
|
#[error("Could not generate the changelog")]
|
||||||
ChangelogError(#[from] ChangelogError),
|
ChangelogError(#[from] ChangelogError),
|
||||||
#[error("Server Api error")]
|
|
||||||
ServerApiError(#[from] ServerApiError)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum ServerApiError {
|
|
||||||
#[error(transparent)]
|
|
||||||
ParseUrl(#[from] url::ParseError),
|
|
||||||
#[error(transparent)]
|
|
||||||
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
|
|
||||||
#[error(transparent)]
|
|
||||||
ReqwestErr(#[from] reqwest::Error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
|
|
@ -1,69 +1,30 @@
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::ServerApi;
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
pub struct Forgejo;
|
||||||
use reqwest::{
|
|
||||||
header::{HeaderMap, HeaderValue}, Client, Method, Request, RequestBuilder, Url
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Forgejo {
|
|
||||||
cfg: Api,
|
|
||||||
client: Client,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Forgejo {
|
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
|
||||||
let mut headers: HeaderMap = HeaderMap::new();
|
|
||||||
// may be left empty if we only do reads from publically accessible urls
|
|
||||||
if api.auth.is_some() {
|
|
||||||
let _ = headers.insert(
|
|
||||||
"Authorization",
|
|
||||||
HeaderValue::from_str(api.auth.clone().unwrap().pass.get_pass()?.as_str())
|
|
||||||
.map_err(ServerApiError::from)?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let client = super::client_builder()
|
|
||||||
.default_headers(headers)
|
|
||||||
.build()
|
|
||||||
.map_err(ServerApiError::from)?;
|
|
||||||
Ok(Self {
|
|
||||||
cfg: api.clone(),
|
|
||||||
client,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Forgejo {
|
impl ServerApi for Forgejo {
|
||||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release(&mut self) -> Result<()> {
|
async fn push_release(&mut self) -> Result<()> {
|
||||||
let raw_url = format!(
|
todo!()
|
||||||
"{}/api/v1/repos/{user}/{repository}/releases",
|
|
||||||
self.cfg.endpoint
|
|
||||||
);
|
|
||||||
let body = format!(r#"
|
|
||||||
{{
|
|
||||||
"body": "{text}",
|
|
||||||
"draft": {draft},
|
|
||||||
"name": "{name}",
|
|
||||||
"prerelease": {prerelease},
|
|
||||||
"tag_name": "{tag}",
|
|
||||||
"target_commitish": "{commit_sig}"
|
|
||||||
}}
|
|
||||||
"#);
|
|
||||||
|
|
||||||
let request = self.client.post().body(body).build()?;
|
|
||||||
let response = self.client.execute(request).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Forgejo {
|
||||||
|
pub async fn build(_cfg: &Config) -> Result<Self> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,14 @@ use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::ServerApi;
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
};
|
};
|
||||||
pub struct Gitea {
|
pub struct Gitea;
|
||||||
cfg: Api,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Gitea {
|
impl ServerApi for Gitea {
|
||||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release(&mut self) -> Result<()> {
|
async fn push_release(&mut self) -> Result<()> {
|
||||||
|
@ -20,13 +18,13 @@ impl ServerApi for Gitea {
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gitea {
|
impl Gitea {
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
pub async fn build(_cfg: &Config) -> Result<Self> {
|
||||||
Ok(Self { cfg: api.clone() })
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,14 @@ use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::ServerApi;
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
};
|
};
|
||||||
pub struct Github {
|
pub struct Github;
|
||||||
cfg: Api,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Github {
|
impl ServerApi for Github {
|
||||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release(&mut self) -> Result<()> {
|
async fn push_release(&mut self) -> Result<()> {
|
||||||
|
@ -20,13 +18,13 @@ impl ServerApi for Github {
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Github {
|
impl Github {
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
pub async fn build(_cfg: &Config) -> Result<Self> {
|
||||||
Ok(Self { cfg: api.clone() })
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,14 @@ use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::ServerApi;
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
};
|
};
|
||||||
pub struct Gitlab {
|
pub struct Gitlab;
|
||||||
cfg: Api,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Gitlab {
|
impl ServerApi for Gitlab {
|
||||||
async fn init(&mut self, cfg: &Config) -> Result<()> {
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release(&mut self) -> Result<()> {
|
async fn push_release(&mut self) -> Result<()> {
|
||||||
|
@ -20,13 +18,13 @@ impl ServerApi for Gitlab {
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gitlab {
|
impl Gitlab {
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
pub async fn build(_cfg: &Config) -> Result<Self> {
|
||||||
Ok(Self { cfg: api.clone() })
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use reqwest::ClientBuilder;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, ApiType, Config},
|
config::{packages::PackageType, ApiType, Config},
|
||||||
|
@ -15,7 +14,6 @@ use gitea::*;
|
||||||
use github::*;
|
use github::*;
|
||||||
use gitlab::*;
|
use gitlab::*;
|
||||||
|
|
||||||
pub static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
|
|
||||||
pub type ApiCollection = Vec<Box<dyn ServerApi>>;
|
pub type ApiCollection = Vec<Box<dyn ServerApi>>;
|
||||||
|
|
||||||
// NOTE: in stable rust, traits can normally not contain async methods,
|
// NOTE: in stable rust, traits can normally not contain async methods,
|
||||||
|
@ -29,25 +27,21 @@ pub trait ServerApi {
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()>;
|
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn client_builder() -> ClientBuilder {
|
|
||||||
ClientBuilder::new().user_agent(USER_AGENT)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn init_servers(cfg: &Config) -> Result<ApiCollection> {
|
pub async fn init_servers(cfg: &Config) -> Result<ApiCollection> {
|
||||||
let mut collection: ApiCollection = ApiCollection::new();
|
let mut collection: ApiCollection = ApiCollection::new();
|
||||||
for api in &cfg.yaml.api {
|
for api in &cfg.yaml.api {
|
||||||
match api.1.server_type {
|
match api.1.server_type {
|
||||||
ApiType::Gitea => {
|
ApiType::Gitea => {
|
||||||
collection.push(Box::new(Gitea::build(api.1).await?));
|
collection.push(Box::new(Gitea::build(cfg).await?));
|
||||||
}
|
}
|
||||||
ApiType::Gitlab => {
|
ApiType::Gitlab => {
|
||||||
collection.push(Box::new(Gitlab::build(api.1).await?));
|
collection.push(Box::new(Gitlab::build(cfg).await?));
|
||||||
}
|
}
|
||||||
ApiType::Github => {
|
ApiType::Github => {
|
||||||
collection.push(Box::new(Github::build(api.1).await?));
|
collection.push(Box::new(Github::build(cfg).await?));
|
||||||
}
|
}
|
||||||
ApiType::Forgejo => {
|
ApiType::Forgejo => {
|
||||||
collection.push(Box::new(Forgejo::build(api.1).await?));
|
collection.push(Box::new(Forgejo::build(cfg).await?));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue