diff --git a/TODO.org b/TODO.org index 283f018..b9cea36 100644 --- a/TODO.org +++ b/TODO.org @@ -5,7 +5,8 @@ CLOSED: [2020-05-30 Sat 12:23] ** DONE download CLOSED: [2020-05-30 Sat 14:27] -** TODO edit +** DONE edit + CLOSED: [2020-05-30 Sat 14:49] ** DONE info CLOSED: [2020-05-30 Sat 10:52] ** TODO release diff --git a/src/cmd/delete.rs b/src/cmd/delete.rs index f5520d1..6cf29dd 100644 --- a/src/cmd/delete.rs +++ b/src/cmd/delete.rs @@ -1,17 +1,14 @@ use crate::{gitea::*, *}; use anyhow::{anyhow, Result}; -pub(crate) async fn run(common: Common) -> Result<()> { - if common.tag.is_none() { - return Err(anyhow!("requires --tag")); - } +pub(crate) async fn run(common: Common, tag: String) -> Result<()> { let cli = client(&common)?; let release = get_release_by_tag( &cli, &common.server, &common.owner, &common.repo, - &common.tag.unwrap(), + &tag, ) .await?; diff --git a/src/cmd/download.rs b/src/cmd/download.rs index 80c8d12..665049c 100644 --- a/src/cmd/download.rs +++ b/src/cmd/download.rs @@ -4,19 +4,10 @@ use cli_table::{Cell, Row, Table}; use std::fs::File; use std::io::Write; -pub(crate) async fn run(common: Common, fname: Option) -> Result<()> { - if common.tag.is_none() { - return Err(anyhow!("requires --tag")); - } +pub(crate) async fn run(common: Common, fname: Option, tag: String) -> Result<()> { let cli = client(&common)?; - let release = get_release_by_tag( - &cli, - &common.server, - &common.owner, - &common.repo, - &common.tag.unwrap(), - ) - .await?; + let release = + get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?; let attachments = get_attachments_for_release( &cli, &common.server, diff --git a/src/cmd/edit.rs b/src/cmd/edit.rs new file mode 100644 index 0000000..b9ba20c --- /dev/null +++ b/src/cmd/edit.rs @@ -0,0 +1,40 @@ +use crate::{gitea::*, *}; +use anyhow::{anyhow, Result}; + +pub(crate) async fn run( + common: Common, + description: Option, + rm: ReleaseMeta, + tag: String, +) -> Result<()> { + let cli = client(&common)?; + let release = get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?; + + let mut cr = CreateRelease{ + 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; + + let resp = cli.post(format!("{}/api/v1/repos/{}/{}/releases/{}", common.server, common.owner, common.repo, release.id).as_str()).json(&cr).send().await?; + + if !resp.status().is_success() { + return Err(anyhow!("{:?}", resp.status())); + } + + Ok(()) +} diff --git a/src/cmd/info.rs b/src/cmd/info.rs index c920d91..35c8512 100644 --- a/src/cmd/info.rs +++ b/src/cmd/info.rs @@ -2,7 +2,7 @@ use crate::{gitea::*, *}; use anyhow::{anyhow, Result}; use cli_table::{Cell, Row, Table}; -pub(crate) async fn run(common: Common, json: bool) -> Result<()> { +pub(crate) async fn run(common: Common, json: bool, tag: Option) -> Result<()> { let cli = client(&common)?; let releases: Vec = cli @@ -18,7 +18,7 @@ pub(crate) async fn run(common: Common, json: bool) -> Result<()> { .json() .await?; - match common.tag { + match tag { Some(tag) => { let mut release: Option = None; diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index f9de362..7f90d02 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -1,3 +1,4 @@ pub(crate) mod delete; pub(crate) mod download; +pub(crate) mod edit; pub(crate) mod info; diff --git a/src/gitea.rs b/src/gitea.rs index 4570bb8..72c15e6 100644 --- a/src/gitea.rs +++ b/src/gitea.rs @@ -30,7 +30,7 @@ pub struct Release { pub created_at: String, pub published_at: String, pub author: Author, - pub assets: Vec<::serde_json::Value>, + pub assets: Vec, } use cli_table::{Cell, Row}; diff --git a/src/main.rs b/src/main.rs index bed0bb9..49807e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,9 +23,6 @@ pub(crate) struct Common { /// The gitea repo to operate on #[structopt(short, long, env = "GITEA_REPO")] repo: String, - /// The version tag to operate on - #[structopt(short, long)] - tag: Option, } // Name your user agent after your app? @@ -45,8 +42,8 @@ pub(crate) fn client(c: &Common) -> Result { #[derive(StructOpt, Debug)] pub(crate) struct ReleaseMeta { /// Release name - #[structopt(short, long, default_value = "")] - name: String, + #[structopt(short, long)] + name: Option, /// Draft release #[structopt(long)] draft: bool, @@ -62,6 +59,9 @@ pub(crate) enum Cmd { Delete { #[structopt(flatten)] common: Common, + /// The version tag to operate on + #[structopt(short, long)] + tag: String, }, /// Downloads release artifacts Download { @@ -70,16 +70,22 @@ pub(crate) enum Cmd { /// Folder to download release artifacts to #[structopt(short, long)] fname: Option, + /// The version tag to operate on + #[structopt(short, long)] + tag: String, }, /// Edits a release's description, name and other flags Edit { #[structopt(flatten)] common: Common, /// Release description - #[structopt(short, long, default_value = "")] - description: String, + #[structopt(short, long)] + description: Option, #[structopt(flatten)] release_meta: ReleaseMeta, + /// The version tag to operate on + #[structopt(short, long)] + tag: String, }, /// Gets release info Info { @@ -87,6 +93,9 @@ pub(crate) enum Cmd { common: Common, #[structopt(long, short)] json: bool, + /// The version tag to operate on + #[structopt(short, long)] + tag: Option, }, /// Create a new tag and release on Gitea Release { @@ -123,9 +132,15 @@ async fn main() -> Result<()> { let cmd = Cmd::from_args(); match cmd { - Cmd::Delete { common } => cmd::delete::run(common).await, - Cmd::Download { common, fname } => cmd::download::run(common, fname).await, - Cmd::Info { common, json } => cmd::info::run(common, json).await, + Cmd::Delete { common, tag } => cmd::delete::run(common, tag).await, + Cmd::Download { common, fname, tag } => cmd::download::run(common, fname, tag).await, + Cmd::Edit { + common, + description, + release_meta, + tag, + } => cmd::edit::run(common, description, release_meta, tag).await, + Cmd::Info { common, json, tag } => cmd::info::run(common, json, tag).await, _ => Err(anyhow!("not implemented yet")), }