From 86eabad6fea0b4d4383bc8ee6f16a27292bb6a6d Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 31 Jul 2023 11:40:16 +0200 Subject: [PATCH] feat: with create pull request and release Signed-off-by: kjuulh --- crates/cuddle-please/src/gitea_client.rs | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/crates/cuddle-please/src/gitea_client.rs b/crates/cuddle-please/src/gitea_client.rs index 89289cc..f14304a 100644 --- a/crates/cuddle-please/src/gitea_client.rs +++ b/crates/cuddle-please/src/gitea_client.rs @@ -371,6 +371,70 @@ impl GiteaClient { Ok(commits.number) } + + pub fn create_release( + &self, + owner: impl Into, + repo: impl Into, + version: impl Into, + body: impl Into, + prerelease: bool, + ) -> anyhow::Result { + #[derive(Clone, Debug, Serialize, Deserialize)] + struct CreateReleaseOption { + body: String, + draft: bool, + name: String, + prerelease: bool, + #[serde(alias = "tag_name")] + tag_name: String, + } + + let client = self.create_client()?; + + let owner = owner.into(); + let repo = repo.into(); + let version = version.into(); + let body = body.into(); + + let request = CreateReleaseOption { + body, + draft: false, + name: version.clone(), + prerelease, + tag_name: version.clone(), + }; + + tracing::trace!( + owner = owner, + repo = repo, + version = version, + "create release" + ); + let request = client + .post(format!( + "{}/api/v1/repos/{}/{}/releases", + &self.url.trim_end_matches("/"), + owner, + repo, + )) + .json(&request) + .build()?; + let resp = client.execute(request)?; + + if !resp.status().is_success() { + return Err(anyhow::anyhow!(resp.error_for_status().unwrap_err())); + } + let release: Release = resp.json()?; + + Ok(release) + } +} + +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +pub struct Release { + id: usize, + url: String, } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]