implement upload
This commit is contained in:
parent
c00b92ef87
commit
c1fd1650c7
|
@ -8,7 +8,8 @@ pub(crate) async fn run(
|
||||||
tag: String,
|
tag: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let cli = client(&common)?;
|
let cli = client(&common)?;
|
||||||
let release = get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?;
|
let release =
|
||||||
|
get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?;
|
||||||
|
|
||||||
let mut cr = CreateRelease {
|
let mut cr = CreateRelease {
|
||||||
body: release.body,
|
body: release.body,
|
||||||
|
@ -30,7 +31,17 @@ pub(crate) async fn run(
|
||||||
cr.draft = rm.draft;
|
cr.draft = rm.draft;
|
||||||
cr.prerelease = rm.pre_release;
|
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?;
|
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() {
|
if !resp.status().is_success() {
|
||||||
return Err(anyhow!("{:?}", resp.status()));
|
return Err(anyhow!("{:?}", resp.status()));
|
||||||
|
|
|
@ -2,3 +2,4 @@ pub(crate) mod delete;
|
||||||
pub(crate) mod download;
|
pub(crate) mod download;
|
||||||
pub(crate) mod edit;
|
pub(crate) mod edit;
|
||||||
pub(crate) mod info;
|
pub(crate) mod info;
|
||||||
|
pub(crate) mod upload;
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
use crate::{gitea::*, *};
|
||||||
|
use anyhow::Result;
|
||||||
|
use reqwest::multipart;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
pub(crate) async fn run(common: Common, fname: PathBuf, tag: String) -> Result<()> {
|
||||||
|
let cli = client(&common)?;
|
||||||
|
let bytes = {
|
||||||
|
let mut fin = File::open(&fname)?;
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
fin.read_to_end(&mut buffer)?;
|
||||||
|
buffer
|
||||||
|
};
|
||||||
|
let form = multipart::Form::new().part("attachment", multipart::Part::bytes(bytes));
|
||||||
|
let release =
|
||||||
|
get_release_by_tag(&cli, &common.server, &common.owner, &common.repo, &tag).await?;
|
||||||
|
|
||||||
|
cli.post(
|
||||||
|
format!(
|
||||||
|
"{}/api/v1/repos/{}/{}/releases/{}",
|
||||||
|
&common.server, &common.owner, &common.repo, release.id,
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
)
|
||||||
|
.query(&[("name", fname)])
|
||||||
|
.multipart(form)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
17
src/main.rs
17
src/main.rs
|
@ -111,18 +111,12 @@ pub(crate) enum Cmd {
|
||||||
Upload {
|
Upload {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
common: Common,
|
common: Common,
|
||||||
/// The name of the file
|
|
||||||
#[structopt(short, long, default_value = "")]
|
|
||||||
name: String,
|
|
||||||
/// The description of the file
|
|
||||||
#[structopt(short, long, default_value = "")]
|
|
||||||
label: String,
|
|
||||||
/// The location of the file on the disk
|
/// The location of the file on the disk
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long)]
|
||||||
fname: PathBuf,
|
fname: PathBuf,
|
||||||
/// Replace existing release artifacts?
|
/// The version tag to operate on
|
||||||
#[structopt(long)]
|
#[structopt(short, long)]
|
||||||
replace: bool,
|
tag: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +135,11 @@ async fn main() -> Result<()> {
|
||||||
tag,
|
tag,
|
||||||
} => cmd::edit::run(common, description, release_meta, tag).await,
|
} => cmd::edit::run(common, description, release_meta, tag).await,
|
||||||
Cmd::Info { common, json, tag } => cmd::info::run(common, json, tag).await,
|
Cmd::Info { common, json, tag } => cmd::info::run(common, json, tag).await,
|
||||||
|
Cmd::Upload {
|
||||||
|
common,
|
||||||
|
fname,
|
||||||
|
tag,
|
||||||
|
} => cmd::upload::run(common, fname, tag).await,
|
||||||
|
|
||||||
_ => Err(anyhow!("not implemented yet")),
|
_ => Err(anyhow!("not implemented yet")),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue