gitea-release/src/cmd/edit.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

2020-05-30 18:50:21 +00:00
use crate::{gitea::*, *};
use anyhow::{anyhow, Result};
pub(crate) async fn run(
common: Common,
description: Option<String>,
rm: ReleaseMeta,
tag: String,
) -> Result<()> {
let cli = client(&common)?;
2020-05-30 19:15:18 +00:00
let release =
get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?;
2020-05-30 18:50:21 +00:00
2020-05-30 19:15:18 +00:00
let mut cr = CreateRelease {
2020-05-30 18:50:21 +00:00
body: release.body,
draft: release.draft,
name: release.name,
prerelease: release.prerelease,
tag_name: release.tag_name,
target_commitish: release.target_commitish,
};
if let Some(description) = description {
cr.body = description;
}
if let Some(name) = rm.name {
cr.name = name;
}
cr.draft = rm.draft;
cr.prerelease = rm.pre_release;
2020-05-30 19:15:18 +00:00
let resp = cli
.post(&format!(
"{}/api/v1/repos/{}/{}/releases/{}",
common.server, common.owner, common.repo, release.id
))
2020-05-30 19:15:18 +00:00
.json(&cr)
.send()
.await?;
2020-05-30 18:50:21 +00:00
if !resp.status().is_success() {
return Err(anyhow!("{:?}", resp.status()));
}
Ok(())
}