implement edit

This commit is contained in:
Cadey Ratio 2020-05-30 14:50:21 -04:00
parent a316558140
commit c00b92ef87
8 changed files with 76 additions and 31 deletions

View File

@ -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

View File

@ -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?;

View File

@ -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<PathBuf>) -> Result<()> {
if common.tag.is_none() {
return Err(anyhow!("requires --tag"));
}
pub(crate) async fn run(common: Common, fname: Option<PathBuf>, 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,

40
src/cmd/edit.rs Normal file
View File

@ -0,0 +1,40 @@
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)?;
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(())
}

View File

@ -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<String>) -> Result<()> {
let cli = client(&common)?;
let releases: Vec<Release> = 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<Release> = None;

View File

@ -1,3 +1,4 @@
pub(crate) mod delete;
pub(crate) mod download;
pub(crate) mod edit;
pub(crate) mod info;

View File

@ -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<Attachment>,
}
use cli_table::{Cell, Row};

View File

@ -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<String>,
}
// Name your user agent after your app?
@ -45,8 +42,8 @@ pub(crate) fn client(c: &Common) -> Result<Client> {
#[derive(StructOpt, Debug)]
pub(crate) struct ReleaseMeta {
/// Release name
#[structopt(short, long, default_value = "")]
name: String,
#[structopt(short, long)]
name: Option<String>,
/// 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<PathBuf>,
/// 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<String>,
#[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<String>,
},
/// 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")),
}