assets need names

This commit is contained in:
softprops 2019-08-25 23:33:39 -04:00
parent d2478527cf
commit c7f2407010
2 changed files with 11 additions and 8 deletions

View file

@ -35,6 +35,7 @@ pub trait AssetUploader<A: Into<Body> = File> {
github_token: &str,
github_repo: &str,
release_id: usize,
name: &str,
mime: Mime,
asset: A,
) -> Result<StatusCode, Box<dyn Error>>;
@ -85,13 +86,14 @@ impl<A: Into<Body>> AssetUploader<A> for Client {
github_token: &str,
github_repo: &str,
release_id: usize,
name: &str,
mime: mime::Mime,
asset: A,
) -> Result<StatusCode, Box<dyn Error>> {
Ok(self
.post(&format!(
"http://uploads.github.com/repos/{}/releases/{}/assets",
github_repo, release_id
"http://uploads.github.com/repos/{}/releases/{}/assets?name={}",
github_repo, release_id, name
))
.header("Authorization", format!("bearer {}", github_token))
.header("Content-Type", mime.to_string())

View file

@ -6,6 +6,7 @@ use reqwest::Client;
use serde::Deserialize;
use std::{
error::Error,
ffi::OsStr,
fs::File,
path::{Path, PathBuf},
};
@ -95,17 +96,17 @@ fn run(
if let Some(patterns) = conf.input_files {
for path in paths(patterns)? {
println!(
"⬆️ Uploading {} asset {}",
mime_or_default(&path),
path.display()
);
println!("⬆️ Uploading asset {}", path.display());
let status = uploader.upload(
conf.github_token.as_str(),
conf.github_repository.as_str(),
id,
&path
.file_name()
.and_then(OsStr::to_str)
.unwrap_or_else(|| "Unknown file"),
mime_or_default(&path),
File::open(path)?,
File::open(&path)?,
)?;
println!("uploaded with status {}", status);
}