From e66550f2effda74bc8518e10771d37fd47e607b2 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 26 Apr 2024 08:54:23 +0200 Subject: [PATCH] github should maybe work --- .autocrate.yaml | 14 +++++++------- .env | 2 -- .gitignore | 1 + Cargo.toml | 3 ++- src/error.rs | 2 ++ src/serverapi/forgejo.rs | 6 +++--- src/serverapi/github.rs | 37 ++++++++++++++++++++++++++----------- 7 files changed, 41 insertions(+), 24 deletions(-) delete mode 100644 .env diff --git a/.autocrate.yaml b/.autocrate.yaml index 427c875..f1cec2b 100644 --- a/.autocrate.yaml +++ b/.autocrate.yaml @@ -13,13 +13,13 @@ uses: - cscherr api: - # github: - # type: github - # repository: autocrate - # auth: - # user: PlexSheep - # pass: - # !env TOKEN_GH + github: + type: github + repository: autocrate + auth: + user: PlexSheep + pass: + !env TOKEN_GH cscherr: type: forgejo endpoint: https://git.cscherr.de diff --git a/.env b/.env deleted file mode 100644 index b544a1e..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -TOKEN_CSCHERR=test -TOKEN_GH=test diff --git a/.gitignore b/.gitignore index 193d30e..35ef9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ Cargo.lock # Added by cargo /target +.env diff --git a/Cargo.toml b/Cargo.toml index c3733db..b2eb710 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] @@ -29,6 +29,7 @@ forgejo-api = "0.1.0" futures = "0.3.30" git2 = "0.18.1" 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" diff --git a/src/error.rs b/src/error.rs index 991d1e0..6f80b38 100644 --- a/src/error.rs +++ b/src/error.rs @@ -34,6 +34,8 @@ pub enum ServerApiError { ReqwestErr(#[from] reqwest::Error), #[error(transparent)] ForgejoApiError(#[from] forgejo_api::ForgejoError), + #[error(transparent)] + GithubApiError(#[from] octocrab::Error) } #[derive(Error, Debug)] diff --git a/src/serverapi/forgejo.rs b/src/serverapi/forgejo.rs index 6dcc2c5..511f1b6 100644 --- a/src/serverapi/forgejo.rs +++ b/src/serverapi/forgejo.rs @@ -7,7 +7,7 @@ use async_trait::async_trait; use forgejo_api; pub struct Forgejo { - cfg: Api, + api: Api, api_wrapper: forgejo_api::Forgejo, } @@ -19,7 +19,7 @@ impl Forgejo { ) .map_err(ServerApiError::from)?; Ok(Self { - cfg: api.clone(), + api: api.clone(), api_wrapper, }) } @@ -53,6 +53,6 @@ impl ServerApi for Forgejo { todo!() } fn get_cfg(&self) -> &Api { - &self.cfg + &self.api } } diff --git a/src/serverapi/github.rs b/src/serverapi/github.rs index 468a983..596f1c8 100644 --- a/src/serverapi/github.rs +++ b/src/serverapi/github.rs @@ -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 { + 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 { - Ok(Self { cfg: api.clone() }) + &self.api } }