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