improve info ux

This commit is contained in:
softprops 2019-08-25 12:44:14 -04:00
parent 445ef7dd5c
commit 5c57a70256
2 changed files with 16 additions and 15 deletions

View file

@ -13,13 +13,19 @@ pub struct Release {
pub draft: Option<bool>,
}
#[derive(Deserialize)]
pub struct ReleaseResponse {
pub id: usize,
pub html_url: String,
}
pub trait Releaser {
fn release(
&self,
github_token: &str,
github_repo: &str,
release: Release,
) -> Result<usize, Box<dyn Error>>;
) -> Result<ReleaseResponse, Box<dyn Error>>;
}
pub trait AssetUploader<A: Into<Body> = File> {
@ -33,11 +39,6 @@ pub trait AssetUploader<A: Into<Body> = File> {
) -> Result<(), Box<dyn Error>>;
}
#[derive(Deserialize)]
struct ReleaseResponse {
id: usize,
}
impl Releaser for Client {
// https://developer.github.com/v3/repos/releases/#create-a-release
// https://developer.github.com/v3/repos/releases/#edit-a-release
@ -46,7 +47,7 @@ impl Releaser for Client {
github_token: &str,
github_repo: &str,
release: Release,
) -> Result<usize, Box<dyn Error>> {
) -> Result<ReleaseResponse, Box<dyn Error>> {
let endpoint = format!("https://api.github.com/repos/{}/releases", github_repo);
let mut existing = self
.get(&format!("{}/tags/{}", endpoint, release.tag_name))
@ -61,8 +62,7 @@ impl Releaser for Client {
.header("Authorization", format!("bearer {}", github_token))
.json(&release)
.send()?
.json::<ReleaseResponse>()?
.id),
.json()?),
_ => Ok(self
.patch(&format!(
"https://api.github.com/repos/{}/releases/{}",
@ -72,8 +72,7 @@ impl Releaser for Client {
.header("Authorization", format!("bearer {}", github_token))
.json(&release)
.send()?
.json::<ReleaseResponse>()?
.id),
.json()?),
}
}
}

View file

@ -1,6 +1,6 @@
mod github;
use github::{AssetUploader, Release, Releaser};
use github::{AssetUploader, Release, ReleaseResponse, Releaser};
use reqwest::Client;
use serde::Deserialize;
use std::{
@ -57,7 +57,7 @@ fn run(
return Ok(());
}
let release_id = releaser.release(
let ReleaseResponse { id, html_url } = releaser.release(
conf.github_token.as_str(),
conf.github_repository.as_str(),
release(&conf),
@ -73,15 +73,17 @@ fn run(
Ok(paths)
});
for path in paths? {
log::info!("Uploading path {}", path.display());
log::info!("⬆️ Uploading path {}", path.display());
uploader.upload(
conf.github_token.as_str(),
conf.github_repository.as_str(),
release_id,
id,
mime_or_default(&path),
File::open(path)?,
)?;
}
println!("🎉 Release ready at {}", html_url);
}
Ok(())