implement edit
This commit is contained in:
parent
a316558140
commit
c00b92ef87
3
TODO.org
3
TODO.org
|
@ -5,7 +5,8 @@
|
||||||
CLOSED: [2020-05-30 Sat 12:23]
|
CLOSED: [2020-05-30 Sat 12:23]
|
||||||
** DONE download
|
** DONE download
|
||||||
CLOSED: [2020-05-30 Sat 14:27]
|
CLOSED: [2020-05-30 Sat 14:27]
|
||||||
** TODO edit
|
** DONE edit
|
||||||
|
CLOSED: [2020-05-30 Sat 14:49]
|
||||||
** DONE info
|
** DONE info
|
||||||
CLOSED: [2020-05-30 Sat 10:52]
|
CLOSED: [2020-05-30 Sat 10:52]
|
||||||
** TODO release
|
** TODO release
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
use crate::{gitea::*, *};
|
use crate::{gitea::*, *};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
pub(crate) async fn run(common: Common) -> Result<()> {
|
pub(crate) async fn run(common: Common, tag: String) -> Result<()> {
|
||||||
if common.tag.is_none() {
|
|
||||||
return Err(anyhow!("requires --tag"));
|
|
||||||
}
|
|
||||||
let cli = client(&common)?;
|
let cli = client(&common)?;
|
||||||
let release = get_release_by_tag(
|
let release = get_release_by_tag(
|
||||||
&cli,
|
&cli,
|
||||||
&common.server,
|
&common.server,
|
||||||
&common.owner,
|
&common.owner,
|
||||||
&common.repo,
|
&common.repo,
|
||||||
&common.tag.unwrap(),
|
&tag,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,10 @@ use cli_table::{Cell, Row, Table};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
pub(crate) async fn run(common: Common, fname: Option<PathBuf>) -> Result<()> {
|
pub(crate) async fn run(common: Common, fname: Option<PathBuf>, tag: String) -> Result<()> {
|
||||||
if common.tag.is_none() {
|
|
||||||
return Err(anyhow!("requires --tag"));
|
|
||||||
}
|
|
||||||
let cli = client(&common)?;
|
let cli = client(&common)?;
|
||||||
let release = get_release_by_tag(
|
let release =
|
||||||
&cli,
|
get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?;
|
||||||
&common.server,
|
|
||||||
&common.owner,
|
|
||||||
&common.repo,
|
|
||||||
&common.tag.unwrap(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let attachments = get_attachments_for_release(
|
let attachments = get_attachments_for_release(
|
||||||
&cli,
|
&cli,
|
||||||
&common.server,
|
&common.server,
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ use crate::{gitea::*, *};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use cli_table::{Cell, Row, Table};
|
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 cli = client(&common)?;
|
||||||
|
|
||||||
let releases: Vec<Release> = cli
|
let releases: Vec<Release> = cli
|
||||||
|
@ -18,7 +18,7 @@ pub(crate) async fn run(common: Common, json: bool) -> Result<()> {
|
||||||
.json()
|
.json()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
match common.tag {
|
match tag {
|
||||||
Some(tag) => {
|
Some(tag) => {
|
||||||
let mut release: Option<Release> = None;
|
let mut release: Option<Release> = None;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
pub(crate) mod delete;
|
pub(crate) mod delete;
|
||||||
pub(crate) mod download;
|
pub(crate) mod download;
|
||||||
|
pub(crate) mod edit;
|
||||||
pub(crate) mod info;
|
pub(crate) mod info;
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub struct Release {
|
||||||
pub created_at: String,
|
pub created_at: String,
|
||||||
pub published_at: String,
|
pub published_at: String,
|
||||||
pub author: Author,
|
pub author: Author,
|
||||||
pub assets: Vec<::serde_json::Value>,
|
pub assets: Vec<Attachment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
use cli_table::{Cell, Row};
|
use cli_table::{Cell, Row};
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -23,9 +23,6 @@ pub(crate) struct Common {
|
||||||
/// The gitea repo to operate on
|
/// The gitea repo to operate on
|
||||||
#[structopt(short, long, env = "GITEA_REPO")]
|
#[structopt(short, long, env = "GITEA_REPO")]
|
||||||
repo: String,
|
repo: String,
|
||||||
/// The version tag to operate on
|
|
||||||
#[structopt(short, long)]
|
|
||||||
tag: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name your user agent after your app?
|
// Name your user agent after your app?
|
||||||
|
@ -45,8 +42,8 @@ pub(crate) fn client(c: &Common) -> Result<Client> {
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
pub(crate) struct ReleaseMeta {
|
pub(crate) struct ReleaseMeta {
|
||||||
/// Release name
|
/// Release name
|
||||||
#[structopt(short, long, default_value = "")]
|
#[structopt(short, long)]
|
||||||
name: String,
|
name: Option<String>,
|
||||||
/// Draft release
|
/// Draft release
|
||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
draft: bool,
|
draft: bool,
|
||||||
|
@ -62,6 +59,9 @@ pub(crate) enum Cmd {
|
||||||
Delete {
|
Delete {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
common: Common,
|
common: Common,
|
||||||
|
/// The version tag to operate on
|
||||||
|
#[structopt(short, long)]
|
||||||
|
tag: String,
|
||||||
},
|
},
|
||||||
/// Downloads release artifacts
|
/// Downloads release artifacts
|
||||||
Download {
|
Download {
|
||||||
|
@ -70,16 +70,22 @@ pub(crate) enum Cmd {
|
||||||
/// Folder to download release artifacts to
|
/// Folder to download release artifacts to
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long)]
|
||||||
fname: Option<PathBuf>,
|
fname: Option<PathBuf>,
|
||||||
|
/// The version tag to operate on
|
||||||
|
#[structopt(short, long)]
|
||||||
|
tag: String,
|
||||||
},
|
},
|
||||||
/// Edits a release's description, name and other flags
|
/// Edits a release's description, name and other flags
|
||||||
Edit {
|
Edit {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
common: Common,
|
common: Common,
|
||||||
/// Release description
|
/// Release description
|
||||||
#[structopt(short, long, default_value = "")]
|
#[structopt(short, long)]
|
||||||
description: String,
|
description: Option<String>,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
release_meta: ReleaseMeta,
|
release_meta: ReleaseMeta,
|
||||||
|
/// The version tag to operate on
|
||||||
|
#[structopt(short, long)]
|
||||||
|
tag: String,
|
||||||
},
|
},
|
||||||
/// Gets release info
|
/// Gets release info
|
||||||
Info {
|
Info {
|
||||||
|
@ -87,6 +93,9 @@ pub(crate) enum Cmd {
|
||||||
common: Common,
|
common: Common,
|
||||||
#[structopt(long, short)]
|
#[structopt(long, short)]
|
||||||
json: bool,
|
json: bool,
|
||||||
|
/// The version tag to operate on
|
||||||
|
#[structopt(short, long)]
|
||||||
|
tag: Option<String>,
|
||||||
},
|
},
|
||||||
/// Create a new tag and release on Gitea
|
/// Create a new tag and release on Gitea
|
||||||
Release {
|
Release {
|
||||||
|
@ -123,9 +132,15 @@ async fn main() -> Result<()> {
|
||||||
let cmd = Cmd::from_args();
|
let cmd = Cmd::from_args();
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
Cmd::Delete { common } => cmd::delete::run(common).await,
|
Cmd::Delete { common, tag } => cmd::delete::run(common, tag).await,
|
||||||
Cmd::Download { common, fname } => cmd::download::run(common, fname).await,
|
Cmd::Download { common, fname, tag } => cmd::download::run(common, fname, tag).await,
|
||||||
Cmd::Info { common, json } => cmd::info::run(common, json).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")),
|
_ => Err(anyhow!("not implemented yet")),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue