implement upload
This commit is contained in:
parent
c00b92ef87
commit
c1fd1650c7
|
@ -8,9 +8,10 @@ pub(crate) async fn run(
|
|||
tag: String,
|
||||
) -> Result<()> {
|
||||
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,
|
||||
draft: release.draft,
|
||||
name: release.name,
|
||||
|
@ -30,7 +31,17 @@ pub(crate) async fn run(
|
|||
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?;
|
||||
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()));
|
||||
|
|
|
@ -2,3 +2,4 @@ pub(crate) mod delete;
|
|||
pub(crate) mod download;
|
||||
pub(crate) mod edit;
|
||||
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 {
|
||||
#[structopt(flatten)]
|
||||
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
|
||||
#[structopt(short, long)]
|
||||
fname: PathBuf,
|
||||
/// Replace existing release artifacts?
|
||||
#[structopt(long)]
|
||||
replace: bool,
|
||||
/// The version tag to operate on
|
||||
#[structopt(short, long)]
|
||||
tag: String,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -141,6 +135,11 @@ async fn main() -> Result<()> {
|
|||
tag,
|
||||
} => cmd::edit::run(common, description, release_meta, 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")),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue