use crate::{changelog, cmd::*, git, version}; 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); } else /* The tag already exists */ { return Ok(()); } let desc = changelog::read(fname, tag.clone())?; let cli = gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT)?; let vtag = format!("v{}", tag); let cr = gitea::CreateRelease { body: desc, draft: rm.draft, name: rm.name.or(Some(format!("Version {}", tag))).unwrap(), prerelease: rm.pre_release, tag_name: vtag, target_commitish: "HEAD".into(), }; let _ = cli.create_release(common.owner, common.repo, cr).await?; println!("Created release {}", tag); Ok(()) }