Compare commits

..

No commits in common. "39538b7b01b60272600f4ab2a0bb82d3397f6cc3" and "19d5d11b0506dcf9511d8260cc8a39eb6b6baf0a" have entirely different histories.

8 changed files with 36 additions and 100 deletions

View file

@ -27,7 +27,6 @@ clap = { version = "4.4.18", features = ["derive", "help"] }
clap-verbosity-flag = "2.1.2"
git2 = "0.18.1"
libpt = { version = "0.3.11", features = ["log"] }
reqwest = "0.11.24"
serde = { version = "1.0.195", features = ["derive"] }
serde_yaml = "0.9.30"
tempfile = "3.9.0"

View file

@ -60,7 +60,7 @@ pub enum Pass {
}
impl Pass {
/// Get the pass, extracting from the underlying source
pub fn get_pass(&self) -> Result<String> {
fn get_pass(&self) -> Result<String> {
self.check()?;
Ok(match self {
Self::Text(pass) => pass.clone(),

View file

@ -20,18 +20,6 @@ pub enum Error {
SerdeYaml(#[from] serde_yaml::Error),
#[error("Could not generate the changelog")]
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)]

View file

@ -1,69 +1,30 @@
use async_trait::async_trait;
use super::ServerApi;
use crate::{
config::{packages::PackageType, Api, ApiType, Config},
config::{packages::PackageType, Config},
error::*,
};
use async_trait::async_trait;
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,
})
}
}
pub struct Forgejo;
#[async_trait]
impl ServerApi for Forgejo {
async fn init(&mut self, cfg: &Config) -> Result<()> {
async fn init(&mut self, _cfg: &Config) -> Result<()> {
todo!()
}
async fn push_release(&mut self) -> Result<()> {
let raw_url = format!(
"{}/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(())
todo!()
}
async fn push_release_artifact(&mut self) -> Result<()> {
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!()
}
}

View file

@ -2,16 +2,14 @@ use async_trait::async_trait;
use super::ServerApi;
use crate::{
config::{packages::PackageType, Api, ApiType, Config},
config::{packages::PackageType, Config},
error::*,
};
pub struct Gitea {
cfg: Api,
}
pub struct Gitea;
#[async_trait]
impl ServerApi for Gitea {
async fn init(&mut self, cfg: &Config) -> Result<()> {
async fn init(&mut self, _cfg: &Config) -> Result<()> {
todo!()
}
async fn push_release(&mut self) -> Result<()> {
@ -20,13 +18,13 @@ impl ServerApi for Gitea {
async fn push_release_artifact(&mut self) -> Result<()> {
todo!()
}
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
todo!()
}
}
impl Gitea {
pub async fn build(api: &Api) -> Result<Self> {
Ok(Self { cfg: api.clone() })
pub async fn build(_cfg: &Config) -> Result<Self> {
todo!()
}
}

View file

@ -2,16 +2,14 @@ use async_trait::async_trait;
use super::ServerApi;
use crate::{
config::{packages::PackageType, Api, ApiType, Config},
config::{packages::PackageType, Config},
error::*,
};
pub struct Github {
cfg: Api,
}
pub struct Github;
#[async_trait]
impl ServerApi for Github {
async fn init(&mut self, cfg: &Config) -> Result<()> {
async fn init(&mut self, _cfg: &Config) -> Result<()> {
todo!()
}
async fn push_release(&mut self) -> Result<()> {
@ -20,13 +18,13 @@ impl ServerApi for Github {
async fn push_release_artifact(&mut self) -> Result<()> {
todo!()
}
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
todo!()
}
}
impl Github {
pub async fn build(api: &Api) -> Result<Self> {
Ok(Self { cfg: api.clone() })
pub async fn build(_cfg: &Config) -> Result<Self> {
todo!()
}
}

View file

@ -2,16 +2,14 @@ use async_trait::async_trait;
use super::ServerApi;
use crate::{
config::{packages::PackageType, Api, ApiType, Config},
config::{packages::PackageType, Config},
error::*,
};
pub struct Gitlab {
cfg: Api,
}
pub struct Gitlab;
#[async_trait]
impl ServerApi for Gitlab {
async fn init(&mut self, cfg: &Config) -> Result<()> {
async fn init(&mut self, _cfg: &Config) -> Result<()> {
todo!()
}
async fn push_release(&mut self) -> Result<()> {
@ -20,13 +18,13 @@ impl ServerApi for Gitlab {
async fn push_release_artifact(&mut self) -> Result<()> {
todo!()
}
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
async fn push_pkg(&mut self, _pkg_type: PackageType) -> Result<()> {
todo!()
}
}
impl Gitlab {
pub async fn build(api: &Api) -> Result<Self> {
Ok(Self { cfg: api.clone() })
pub async fn build(_cfg: &Config) -> Result<Self> {
todo!()
}
}

View file

@ -1,5 +1,4 @@
use async_trait::async_trait;
use reqwest::ClientBuilder;
use crate::{
config::{packages::PackageType, ApiType, Config},
@ -15,7 +14,6 @@ use gitea::*;
use github::*;
use gitlab::*;
pub static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
pub type ApiCollection = Vec<Box<dyn ServerApi>>;
// 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<()>;
}
pub fn client_builder() -> ClientBuilder {
ClientBuilder::new().user_agent(USER_AGENT)
}
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(api.1).await?));
collection.push(Box::new(Gitea::build(cfg).await?));
}
ApiType::Gitlab => {
collection.push(Box::new(Gitlab::build(api.1).await?));
collection.push(Box::new(Gitlab::build(cfg).await?));
}
ApiType::Github => {
collection.push(Box::new(Github::build(api.1).await?));
collection.push(Box::new(Github::build(cfg).await?));
}
ApiType::Forgejo => {
collection.push(Box::new(Forgejo::build(api.1).await?));
collection.push(Box::new(Forgejo::build(cfg).await?));
}
}
}