Merge branch 'devel'
cargo devel CI / cargo CI (push) Successful in 3m4s Details

This commit is contained in:
Christoph J. Scherr 2024-04-26 08:55:01 +02:00
commit e80b68f1c4
9 changed files with 41 additions and 33 deletions

2
.env
View File

@ -1,2 +0,0 @@
TOKEN_CSCHERR=test
TOKEN_GH=test

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ Cargo.lock
# Added by cargo
/target
.env

View File

@ -1,6 +1,6 @@
[package]
name = "autocrate"
version = "0.1.0-prealpha.4"
version = "0.1.0-prealpha.5"
edition = "2021"
publish = true
authors = ["Christoph J. Scherr <software@cscherr.de>"]
@ -28,7 +28,8 @@ clap-verbosity-flag = "2.1.2"
forgejo-api = "0.1.0"
futures = "0.3.30"
git2 = "0.18.1"
libpt = { version = "0.3.11", features = ["log"] }
libpt = { version = "0.4.2", features = ["log"] }
octocrab = "0.38.0"
reqwest = "0.11.24"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.116"

View File

@ -110,10 +110,10 @@ impl Cli {
}
};
if cli.meta {
Logger::init(None, Some(ll), true).expect("could not initialize Logger");
Logger::build(None, Some(ll), true).expect("could not initialize Logger");
} else {
// less verbose version
Logger::init_mini(Some(ll)).expect("could not initialize Logger");
Logger::build_mini(Some(ll)).expect("could not initialize Logger");
}
cli
}

View File

@ -208,8 +208,7 @@ impl Version {
panic!("{err:?}");
}
}
},
}
}
}
}

View File

@ -33,7 +33,9 @@ pub enum ServerApiError {
#[error(transparent)]
ReqwestErr(#[from] reqwest::Error),
#[error(transparent)]
ForgejoApiError(#[from] forgejo_api::ForgejoError)
ForgejoApiError(#[from] forgejo_api::ForgejoError),
#[error(transparent)]
GithubApiError(#[from] octocrab::Error)
}
#[derive(Error, Debug)]
@ -66,5 +68,5 @@ pub enum ConfigError {
#[error("An endpoint was set for an ApiType that does not require one")]
EndpointSetButNotNeeded,
#[error("No endpoint was set for an ApiType that requires one")]
NoEndpointSet
NoEndpointSet,
}

View File

@ -41,7 +41,7 @@ pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
.expect("no auth but trying to publish")
.user,
repository: api.get_cfg().repository.clone(),
text: changelog.clone(),
text: crate::changelog::Changelog::build(cfg)?.to_string(),
tag: tag.clone(),
commit_sig: commit_sig.clone(),
};

View File

@ -1,5 +1,3 @@
use std::str::FromStr;
use crate::{
config::{Api, Config},
error::*,
@ -7,15 +5,9 @@ use crate::{
};
use async_trait::async_trait;
use forgejo_api;
use libpt::log::debug;
use reqwest::{
header::{HeaderMap, HeaderValue},
Client, Url,
};
use serde_json;
pub struct Forgejo {
cfg: Api,
api: Api,
api_wrapper: forgejo_api::Forgejo,
}
@ -27,7 +19,7 @@ impl Forgejo {
)
.map_err(ServerApiError::from)?;
Ok(Self {
cfg: api.clone(),
api: api.clone(),
api_wrapper,
})
}
@ -61,6 +53,6 @@ impl ServerApi for Forgejo {
todo!()
}
fn get_cfg(&self) -> &Api {
&self.cfg
&self.api
}
}

View File

@ -1,4 +1,5 @@
use async_trait::async_trait;
use octocrab;
use super::{PublishContext, ReleaseContext, ServerApi};
use crate::{
@ -6,16 +7,36 @@ use crate::{
error::*,
};
pub struct Github {
cfg: Api,
api: Api,
}
impl Github {
pub async fn build(api: &Api) -> Result<Self> {
Ok(Self {
api: api.to_owned(),
})
}
}
#[async_trait]
impl ServerApi for Github {
async fn init(&mut self, _cfg: &Config) -> Result<()> {
todo!()
Ok(())
}
async fn push_release(&mut self, _rc: ReleaseContext) -> Result<()> {
todo!()
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
let response = octocrab::instance()
.repos(rc.username, rc.repository)
.releases()
.create(&rc.tag)
.target_commitish(&rc.commit_sig)
.name(&rc.tag)
.body(&rc.text)
.draft(rc.draft)
.prerelease(rc.prerelease)
.send()
.await
.map_err(ServerApiError::from)?;
Ok(())
}
async fn push_release_artifact(&mut self, _rc: ReleaseContext) -> Result<()> {
todo!()
@ -24,12 +45,6 @@ impl ServerApi for Github {
todo!()
}
fn get_cfg(&self) -> &Api {
&self.cfg
}
}
impl Github {
pub async fn build(api: &Api) -> Result<Self> {
Ok(Self { cfg: api.clone() })
&self.api
}
}