diff --git a/src/github.rs b/src/github.rs index 5c27ce4..944516d 100644 --- a/src/github.rs +++ b/src/github.rs @@ -13,13 +13,19 @@ pub struct Release { pub draft: Option, } +#[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>; + ) -> Result>; } pub trait AssetUploader = File> { @@ -33,11 +39,6 @@ pub trait AssetUploader = File> { ) -> Result<(), Box>; } -#[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> { + ) -> Result> { 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::()? - .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::()? - .id), + .json()?), } } } diff --git a/src/main.rs b/src/main.rs index 0c2c835..0e94f8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(())