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

View File

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