generated from PlexSheep/rs-base
Compare commits
No commits in common. "ff9306047e62722e35340627c0813c16ad9792f6" and "e76775233812120c45bef1963ca6735b5547ad6c" have entirely different histories.
ff9306047e
...
e767752338
8 changed files with 54 additions and 68 deletions
|
@ -119,20 +119,6 @@ pub struct Api {
|
||||||
/// Name of the repository on the Git server, as git itself has no concept of repository name
|
/// Name of the repository on the Git server, as git itself has no concept of repository name
|
||||||
pub repository: String,
|
pub repository: String,
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Api {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self.server_type {
|
|
||||||
ApiType::Github => write!(
|
|
||||||
f,
|
|
||||||
"{}",
|
|
||||||
self.server_type
|
|
||||||
.default_endpoint()
|
|
||||||
.expect("no default endpoint set for github")
|
|
||||||
),
|
|
||||||
_ => write!(f, "{}", self.endpoint.clone().expect("no endpoint set")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl YamlConfigSection for Api {
|
impl YamlConfigSection for Api {
|
||||||
fn check(&self) -> Result<()> {
|
fn check(&self) -> Result<()> {
|
||||||
self.server_type.check()?;
|
self.server_type.check()?;
|
||||||
|
@ -273,10 +259,10 @@ impl YamlConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub yaml: YamlConfig,
|
pub yaml: YamlConfig,
|
||||||
pub cli: Cli,
|
pub cli: Cli,
|
||||||
|
pub repo: git2::Repository,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,6 +319,7 @@ impl Config {
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
yaml,
|
yaml,
|
||||||
|
repo,
|
||||||
path,
|
path,
|
||||||
cli: cli.clone(),
|
cli: cli.clone(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,38 +1,26 @@
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use git2;
|
use git2;
|
||||||
use libpt::log::error;
|
|
||||||
|
|
||||||
use crate::error::ConfigError;
|
|
||||||
use crate::{config::Config, error::Result};
|
use crate::{config::Config, error::Result};
|
||||||
|
|
||||||
pub(crate) fn get_repo() -> Result<git2::Repository> {
|
pub async fn tag(cfg: &Config) -> Result<git2::Tag> {
|
||||||
let repo = match git2::Repository::open_from_env() {
|
|
||||||
Ok(repo) => repo,
|
|
||||||
Err(_err) => {
|
|
||||||
let err = ConfigError::GitRepoNotFound.into();
|
|
||||||
error!("{err}");
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(repo)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn tag<'repo>(repo: &'repo mut git2::Repository, cfg: &Config) -> Result<git2::Tag<'repo>> {
|
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
// TODO: allow force
|
// TODO: allow force
|
||||||
// TODO: allow setting a message
|
// TODO: allow setting a message
|
||||||
// TODO: maybe using git as cmd is fancier?
|
// TODO: maybe using git as cmd is fancier?
|
||||||
let target = repo
|
let target = cfg
|
||||||
|
.repo
|
||||||
.find_object(
|
.find_object(
|
||||||
repo.head().unwrap().target().unwrap(),
|
cfg.repo.head().unwrap().target().unwrap(),
|
||||||
Some(git2::ObjectType::Commit),
|
Some(git2::ObjectType::Commit),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let tagger = repo.signature().expect("could not get signature");
|
let tagger = cfg.repo.signature().expect("could not get signature");
|
||||||
let message = String::new();
|
let message = String::new();
|
||||||
let force = true;
|
let force = true;
|
||||||
let tag = repo
|
let tag = cfg
|
||||||
|
.repo
|
||||||
.tag(
|
.tag(
|
||||||
&cfg.yaml.version.get_version(),
|
&cfg.yaml.version.get_version(),
|
||||||
// "importantversion",
|
// "importantversion",
|
||||||
|
@ -42,7 +30,7 @@ pub async fn tag<'repo>(repo: &'repo mut git2::Repository, cfg: &Config) -> Resu
|
||||||
force,
|
force,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let tag: git2::Tag = repo.find_tag(tag).unwrap();
|
let tag: git2::Tag = cfg.repo.find_tag(tag).unwrap();
|
||||||
Ok(tag)
|
Ok(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +41,12 @@ pub async fn push(_cfg: &Config) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_commit_sig<'repo>(repo: &'repo git2::Repository) -> Result<String> {
|
pub async fn get_commit_sig(cfg: &Config) -> Result<String> {
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
// TODO: maybe using git as cmd is fancier?
|
// TODO: maybe using git as cmd is fancier?
|
||||||
let target = repo
|
let target = cfg
|
||||||
.find_commit(repo.head().unwrap().target().unwrap())
|
.repo
|
||||||
|
.find_commit(cfg.repo.head().unwrap().target().unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Ok(target.id().to_string())
|
Ok(target.id().to_string())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
error::*,
|
error::*,
|
||||||
git::{self, get_commit_sig, push, tag},
|
git::{get_commit_sig, push, tag},
|
||||||
serverapi::ApiCollection,
|
serverapi::ApiCollection,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures::{self, stream::FuturesUnordered, StreamExt};
|
use futures::{self, stream::FuturesUnordered, StreamExt};
|
||||||
use libpt::log::info;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||||
pub struct ReleaseContext {
|
pub struct ReleaseContext {
|
||||||
|
@ -21,10 +20,8 @@ pub struct ReleaseContext {
|
||||||
|
|
||||||
pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
|
pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
let _changelog = crate::changelog::Changelog::build(cfg)?.to_string();
|
let tag = tag(cfg).await?.name().unwrap().to_string();
|
||||||
let mut repo = git::get_repo()?;
|
let commit_sig = get_commit_sig(cfg).await?;
|
||||||
let tag = tag(&mut repo, cfg).await?.name().unwrap().to_string();
|
|
||||||
let commit_sig = get_commit_sig(&repo).await?;
|
|
||||||
push(cfg).await?; // we assume that we only need to push the current branch to the singular
|
push(cfg).await?; // we assume that we only need to push the current branch to the singular
|
||||||
// remote, expecting that the repositories are somehow mirrored
|
// remote, expecting that the repositories are somehow mirrored
|
||||||
// TODO: push to multiple remotes?
|
// TODO: push to multiple remotes?
|
||||||
|
@ -36,17 +33,16 @@ pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
|
||||||
draft: true,
|
draft: true,
|
||||||
prerelease: true,
|
prerelease: true,
|
||||||
username: api
|
username: api
|
||||||
.get_inner()
|
.get_cfg()
|
||||||
.clone()
|
.clone()
|
||||||
.auth
|
.auth
|
||||||
.expect("no auth but trying to publish")
|
.expect("no auth but trying to publish")
|
||||||
.user,
|
.user,
|
||||||
repository: api.get_inner().repository.clone(),
|
repository: api.get_cfg().repository.clone(),
|
||||||
text: crate::changelog::Changelog::build(cfg)?.to_string(),
|
text: crate::changelog::Changelog::build(cfg)?.to_string(),
|
||||||
tag: tag.clone(),
|
tag: tag.clone(),
|
||||||
commit_sig: commit_sig.clone(),
|
commit_sig: commit_sig.clone(),
|
||||||
};
|
};
|
||||||
info!("pushing release for {}", api.get_inner());
|
|
||||||
results.push(api.push_release(specific_rc));
|
results.push(api.push_release(specific_rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,11 @@ use forgejo_api;
|
||||||
|
|
||||||
pub struct Forgejo {
|
pub struct Forgejo {
|
||||||
api: Api,
|
api: Api,
|
||||||
cfg: Config,
|
|
||||||
api_wrapper: forgejo_api::Forgejo,
|
api_wrapper: forgejo_api::Forgejo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Forgejo {
|
impl Forgejo {
|
||||||
pub async fn build(api: &Api, cfg: &Config) -> Result<Self> {
|
pub async fn build(api: &Api) -> Result<Self> {
|
||||||
let api_wrapper: forgejo_api::Forgejo = forgejo_api::Forgejo::new(
|
let api_wrapper: forgejo_api::Forgejo = forgejo_api::Forgejo::new(
|
||||||
forgejo_api::Auth::Token(&api.auth.clone().unwrap().pass.get_pass()?),
|
forgejo_api::Auth::Token(&api.auth.clone().unwrap().pass.get_pass()?),
|
||||||
api.endpoint.clone().unwrap(),
|
api.endpoint.clone().unwrap(),
|
||||||
|
@ -21,7 +20,6 @@ impl Forgejo {
|
||||||
.map_err(ServerApiError::from)?;
|
.map_err(ServerApiError::from)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
api: api.clone(),
|
api: api.clone(),
|
||||||
cfg: cfg.clone(),
|
|
||||||
api_wrapper,
|
api_wrapper,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -29,6 +27,9 @@ impl Forgejo {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Forgejo {
|
impl ServerApi for Forgejo {
|
||||||
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
|
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
|
||||||
let body: forgejo_api::structs::CreateReleaseOption =
|
let body: forgejo_api::structs::CreateReleaseOption =
|
||||||
forgejo_api::structs::CreateReleaseOption {
|
forgejo_api::structs::CreateReleaseOption {
|
||||||
|
@ -51,7 +52,7 @@ impl ServerApi for Forgejo {
|
||||||
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
fn get_inner(&self) -> &Api {
|
fn get_cfg(&self) -> &Api {
|
||||||
&self.api
|
&self.api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,14 @@ use crate::{
|
||||||
error::*,
|
error::*,
|
||||||
};
|
};
|
||||||
pub struct Gitea {
|
pub struct Gitea {
|
||||||
api: Api,
|
cfg: Api,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Gitea {
|
impl ServerApi for Gitea {
|
||||||
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
async fn push_release(&mut self, _rc: ReleaseContext) -> Result<()> {
|
async fn push_release(&mut self, _rc: ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -20,13 +23,13 @@ impl ServerApi for Gitea {
|
||||||
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
fn get_inner(&self) -> &Api {
|
fn get_cfg(&self) -> &Api {
|
||||||
&self.api
|
&self.cfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gitea {
|
impl Gitea {
|
||||||
pub async fn build(api: &Api, cfg: &Config) -> Result<Self> {
|
pub async fn build(api: &Api) -> Result<Self> {
|
||||||
Ok(Self { api: api.clone() })
|
Ok(Self { cfg: api.clone() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct Github {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Github {
|
impl Github {
|
||||||
pub async fn build(api: &Api, cfg: &Config) -> Result<Self> {
|
pub async fn build(api: &Api) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
api: api.to_owned(),
|
api: api.to_owned(),
|
||||||
})
|
})
|
||||||
|
@ -20,6 +20,9 @@ impl Github {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Github {
|
impl ServerApi for Github {
|
||||||
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
|
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
|
||||||
let _response = octocrab::instance()
|
let _response = octocrab::instance()
|
||||||
.repos(rc.username, rc.repository)
|
.repos(rc.username, rc.repository)
|
||||||
|
@ -41,7 +44,7 @@ impl ServerApi for Github {
|
||||||
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
fn get_inner(&self) -> &Api {
|
fn get_cfg(&self) -> &Api {
|
||||||
&self.api
|
&self.api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,14 @@ use crate::{
|
||||||
error::*,
|
error::*,
|
||||||
};
|
};
|
||||||
pub struct Gitlab {
|
pub struct Gitlab {
|
||||||
api: Api,
|
cfg: Api,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ServerApi for Gitlab {
|
impl ServerApi for Gitlab {
|
||||||
|
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
async fn push_release(&mut self, _rc: ReleaseContext) -> Result<()> {
|
async fn push_release(&mut self, _rc: ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
@ -20,13 +23,13 @@ impl ServerApi for Gitlab {
|
||||||
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
async fn push_pkg(&mut self, _pc: PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
fn get_inner(&self) -> &Api {
|
fn get_cfg(&self) -> &Api {
|
||||||
&self.api
|
&self.cfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gitlab {
|
impl Gitlab {
|
||||||
pub async fn build(api: &Api, cfg: &Config) -> Result<Self> {
|
pub async fn build(api: &Api) -> Result<Self> {
|
||||||
Ok(Self { api: api.clone() })
|
Ok(Self { cfg: api.clone() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,11 @@ pub static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_P
|
||||||
// The `async_trait` crate can be used to work around this limitation.
|
// The `async_trait` crate can be used to work around this limitation.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ServerApi {
|
pub trait ServerApi {
|
||||||
|
async fn init(&mut self, cfg: &Config) -> Result<()>;
|
||||||
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()>;
|
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()>;
|
||||||
async fn push_release_artifact(&mut self, rc: ReleaseContext) -> Result<()>;
|
async fn push_release_artifact(&mut self, rc: ReleaseContext) -> Result<()>;
|
||||||
async fn push_pkg(&mut self, pc: PublishContext) -> Result<()>;
|
async fn push_pkg(&mut self, pc: PublishContext) -> Result<()>;
|
||||||
fn get_inner(&self) -> &config::Api;
|
fn get_cfg(&self) -> &config::Api;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type ApiCollectionInner = Vec<Box<dyn ServerApi>>;
|
pub(crate) type ApiCollectionInner = Vec<Box<dyn ServerApi>>;
|
||||||
|
@ -44,19 +45,22 @@ impl ApiCollection {
|
||||||
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, cfg).await?));
|
collection.push(Box::new(Gitea::build(api.1).await?));
|
||||||
}
|
}
|
||||||
ApiType::Gitlab => {
|
ApiType::Gitlab => {
|
||||||
collection.push(Box::new(Gitlab::build(api.1, cfg).await?));
|
collection.push(Box::new(Gitlab::build(api.1).await?));
|
||||||
}
|
}
|
||||||
ApiType::Github => {
|
ApiType::Github => {
|
||||||
collection.push(Box::new(Github::build(api.1, cfg).await?));
|
collection.push(Box::new(Github::build(api.1).await?));
|
||||||
}
|
}
|
||||||
ApiType::Forgejo => {
|
ApiType::Forgejo => {
|
||||||
collection.push(Box::new(Forgejo::build(api.1, cfg).await?));
|
collection.push(Box::new(Forgejo::build(api.1).await?));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for api in collection.iter_mut() {
|
||||||
|
api.init(cfg).await?;
|
||||||
|
}
|
||||||
Ok(ApiCollection { collection })
|
Ok(ApiCollection { collection })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue