use crate::{gitea::*, *}; use anyhow::Result; use std::path::PathBuf; pub(crate) async fn run( common: Common, fname: PathBuf, tag: Option, rm: ReleaseMeta, ) -> Result<()> { let repo = git2::Repository::open(".")?; let tag = tag.unwrap_or(version::read_version("VERSION".into())?); let desc = changelog::read(fname.clone(), tag.clone())?; if !git::has_tag(&repo, tag.clone())? { git::tag_version(&repo, tag.clone(), desc.clone())?; let _ = git::push_tags(&repo); } let desc = changelog::read(fname, tag.clone())?; let cli = client(&common)?; let cr = CreateRelease { body: desc, draft: rm.draft, name: rm.name.or(Some(format!("Version {}", tag))).unwrap(), prerelease: rm.pre_release, tag_name: tag.clone(), target_commitish: "HEAD".into(), }; let resp = cli .post(&format!( "{}/api/v1/repos/{}/{}/releases", common.server, common.owner, common.repo )) .json(&cr) .send() .await?; if !resp.status().is_success() { return Err(anyhow!("{:?} -> {}", resp.status(), resp.text().await?)); } Ok(()) }