generated from PlexSheep/rs-base
contexts for api actions
cargo devel CI / cargo CI (push) Failing after 4m0s
Details
cargo devel CI / cargo CI (push) Failing after 4m0s
Details
This commit is contained in:
parent
39538b7b01
commit
45ba3f6b97
|
@ -1,4 +1,7 @@
|
||||||
use crate::{config::Config, error::*};
|
use crate::{config::Config, error::*};
|
||||||
|
|
||||||
|
pub struct PublishContext;
|
||||||
|
|
||||||
pub async fn publish(_cfg: &Config) -> Result<()> {
|
pub async fn publish(_cfg: &Config) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
use crate::{config::Config, error::*, serverapi::ApiCollection};
|
use crate::{config::Config, error::*, serverapi::ApiCollection};
|
||||||
|
|
||||||
|
pub struct ReleaseContext {
|
||||||
|
pub draft: bool,
|
||||||
|
pub prerelease: bool,
|
||||||
|
pub username: String,
|
||||||
|
pub repository: String,
|
||||||
|
pub text: String,
|
||||||
|
pub tag: String,
|
||||||
|
pub commit_sig: String
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
|
pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
|
||||||
// TODO: git tag
|
// TODO: git tag
|
||||||
// TODO: push to each server
|
// TODO: push to each server
|
||||||
|
|
||||||
// TODO: release to each server
|
// TODO: release to each server
|
||||||
tag(cfg).await?;
|
tag(cfg).await?;
|
||||||
for api in apis.iter_mut() {
|
todo!();
|
||||||
api.push_release().await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
for api in apis.iter_mut() {
|
|
||||||
api.push_release().await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: check that the release is made
|
// TODO: check that the release is made
|
||||||
// TODO: generate artifacts
|
// TODO: generate artifacts
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use super::ServerApi;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Api, ApiType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
|
serverapi::{PublishContext, ReleaseContext, ServerApi},
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
header::{HeaderMap, HeaderValue}, Client, Method, Request, RequestBuilder, Url
|
header::{HeaderMap, HeaderValue},
|
||||||
|
Client, Method, Request, RequestBuilder, Url,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Forgejo {
|
pub struct Forgejo {
|
||||||
|
@ -40,30 +41,38 @@ 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, rc: &ReleaseContext) -> Result<()> {
|
||||||
let raw_url = format!(
|
let raw_url = format!(
|
||||||
"{}/api/v1/repos/{user}/{repository}/releases",
|
"{}/api/v1/repos/{}/{}/releases",
|
||||||
self.cfg.endpoint
|
self.cfg.endpoint, rc.username, rc.repository
|
||||||
);
|
);
|
||||||
let body = format!(r#"
|
let url = Url::parse(&raw_url).map_err(ServerApiError::from)?;
|
||||||
|
let body = format!(
|
||||||
|
r#"
|
||||||
{{
|
{{
|
||||||
"body": "{text}",
|
"body": "{}",
|
||||||
"draft": {draft},
|
"draft": {},
|
||||||
"name": "{name}",
|
"name": "{}",
|
||||||
"prerelease": {prerelease},
|
"prerelease": {},
|
||||||
"tag_name": "{tag}",
|
"tag_name": "{}",
|
||||||
"target_commitish": "{commit_sig}"
|
"target_commitish": "{}"
|
||||||
}}
|
}}
|
||||||
"#);
|
"#,
|
||||||
|
rc.text, rc.draft, rc.tag, rc.prerelease, rc.tag, rc.commit_sig
|
||||||
|
);
|
||||||
|
|
||||||
let request = self.client.post().body(body).build()?;
|
let request = self
|
||||||
let response = self.client.execute(request).await?;
|
.client
|
||||||
|
.post(url)
|
||||||
|
.body(body)
|
||||||
|
.build().map_err(ServerApiError::from)?;
|
||||||
|
let response = self.client.execute(request).await.map_err(ServerApiError::from)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, pc: &PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::{PublishContext, ReleaseContext, ServerApi};
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Api, ApiType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
|
@ -14,13 +14,13 @@ 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, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, pc: &PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::{PublishContext, ReleaseContext, ServerApi};
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Api, ApiType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
|
@ -14,13 +14,13 @@ 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, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, pc: &PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use super::ServerApi;
|
use super::{PublishContext, ReleaseContext, ServerApi};
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, Api, ApiType, Config},
|
config::{packages::PackageType, Api, ApiType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
|
@ -14,13 +14,13 @@ 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, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_release_artifact(&mut self) -> Result<()> {
|
async fn push_release_artifact(&mut self, rc: &ReleaseContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()> {
|
async fn push_pkg(&mut self, pc: &PublishContext) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ use async_trait::async_trait;
|
||||||
use reqwest::ClientBuilder;
|
use reqwest::ClientBuilder;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{packages::PackageType, ApiType, Config},
|
config::{ApiType, Config},
|
||||||
error::*,
|
error::*,
|
||||||
|
publish::PublishContext,
|
||||||
|
release::ReleaseContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod forgejo;
|
pub mod forgejo;
|
||||||
|
@ -24,9 +26,9 @@ pub type ApiCollection = Vec<Box<dyn ServerApi>>;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ServerApi {
|
pub trait ServerApi {
|
||||||
async fn init(&mut self, cfg: &Config) -> Result<()>;
|
async fn init(&mut self, cfg: &Config) -> Result<()>;
|
||||||
async fn push_release(&mut self) -> Result<()>;
|
async fn push_release(&mut self, rc: &ReleaseContext) -> Result<()>;
|
||||||
async fn push_release_artifact(&mut self) -> Result<()>;
|
async fn push_release_artifact(&mut self, rc: &ReleaseContext) -> Result<()>;
|
||||||
async fn push_pkg(&mut self, pkg_type: PackageType) -> Result<()>;
|
async fn push_pkg(&mut self, pc: &PublishContext) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn client_builder() -> ClientBuilder {
|
pub fn client_builder() -> ClientBuilder {
|
||||||
|
@ -51,5 +53,8 @@ pub async fn init_servers(cfg: &Config) -> Result<ApiCollection> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for api in collection.iter_mut() {
|
||||||
|
api.init(&cfg).await?;
|
||||||
|
}
|
||||||
Ok(collection)
|
Ok(collection)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue