improve info ux
This commit is contained in:
parent
445ef7dd5c
commit
5c57a70256
2 changed files with 16 additions and 15 deletions
|
@ -13,13 +13,19 @@ pub struct Release {
|
||||||
pub draft: Option<bool>,
|
pub draft: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct ReleaseResponse {
|
||||||
|
pub id: usize,
|
||||||
|
pub html_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Releaser {
|
pub trait Releaser {
|
||||||
fn release(
|
fn release(
|
||||||
&self,
|
&self,
|
||||||
github_token: &str,
|
github_token: &str,
|
||||||
github_repo: &str,
|
github_repo: &str,
|
||||||
release: Release,
|
release: Release,
|
||||||
) -> Result<usize, Box<dyn Error>>;
|
) -> Result<ReleaseResponse, Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AssetUploader<A: Into<Body> = File> {
|
pub trait AssetUploader<A: Into<Body> = File> {
|
||||||
|
@ -33,11 +39,6 @@ pub trait AssetUploader<A: Into<Body> = File> {
|
||||||
) -> Result<(), Box<dyn Error>>;
|
) -> Result<(), Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct ReleaseResponse {
|
|
||||||
id: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Releaser for Client {
|
impl Releaser for Client {
|
||||||
// https://developer.github.com/v3/repos/releases/#create-a-release
|
// https://developer.github.com/v3/repos/releases/#create-a-release
|
||||||
// https://developer.github.com/v3/repos/releases/#edit-a-release
|
// https://developer.github.com/v3/repos/releases/#edit-a-release
|
||||||
|
@ -46,7 +47,7 @@ impl Releaser for Client {
|
||||||
github_token: &str,
|
github_token: &str,
|
||||||
github_repo: &str,
|
github_repo: &str,
|
||||||
release: Release,
|
release: Release,
|
||||||
) -> Result<usize, Box<dyn Error>> {
|
) -> Result<ReleaseResponse, Box<dyn Error>> {
|
||||||
let endpoint = format!("https://api.github.com/repos/{}/releases", github_repo);
|
let endpoint = format!("https://api.github.com/repos/{}/releases", github_repo);
|
||||||
let mut existing = self
|
let mut existing = self
|
||||||
.get(&format!("{}/tags/{}", endpoint, release.tag_name))
|
.get(&format!("{}/tags/{}", endpoint, release.tag_name))
|
||||||
|
@ -61,8 +62,7 @@ impl Releaser for Client {
|
||||||
.header("Authorization", format!("bearer {}", github_token))
|
.header("Authorization", format!("bearer {}", github_token))
|
||||||
.json(&release)
|
.json(&release)
|
||||||
.send()?
|
.send()?
|
||||||
.json::<ReleaseResponse>()?
|
.json()?),
|
||||||
.id),
|
|
||||||
_ => Ok(self
|
_ => Ok(self
|
||||||
.patch(&format!(
|
.patch(&format!(
|
||||||
"https://api.github.com/repos/{}/releases/{}",
|
"https://api.github.com/repos/{}/releases/{}",
|
||||||
|
@ -72,8 +72,7 @@ impl Releaser for Client {
|
||||||
.header("Authorization", format!("bearer {}", github_token))
|
.header("Authorization", format!("bearer {}", github_token))
|
||||||
.json(&release)
|
.json(&release)
|
||||||
.send()?
|
.send()?
|
||||||
.json::<ReleaseResponse>()?
|
.json()?),
|
||||||
.id),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
mod github;
|
mod github;
|
||||||
|
|
||||||
use github::{AssetUploader, Release, Releaser};
|
use github::{AssetUploader, Release, ReleaseResponse, Releaser};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -57,7 +57,7 @@ fn run(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let release_id = releaser.release(
|
let ReleaseResponse { id, html_url } = releaser.release(
|
||||||
conf.github_token.as_str(),
|
conf.github_token.as_str(),
|
||||||
conf.github_repository.as_str(),
|
conf.github_repository.as_str(),
|
||||||
release(&conf),
|
release(&conf),
|
||||||
|
@ -73,15 +73,17 @@ fn run(
|
||||||
Ok(paths)
|
Ok(paths)
|
||||||
});
|
});
|
||||||
for path in paths? {
|
for path in paths? {
|
||||||
log::info!("Uploading path {}", path.display());
|
log::info!("⬆️ Uploading path {}", path.display());
|
||||||
uploader.upload(
|
uploader.upload(
|
||||||
conf.github_token.as_str(),
|
conf.github_token.as_str(),
|
||||||
conf.github_repository.as_str(),
|
conf.github_repository.as_str(),
|
||||||
release_id,
|
id,
|
||||||
mime_or_default(&path),
|
mime_or_default(&path),
|
||||||
File::open(path)?,
|
File::open(path)?,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("🎉 Release ready at {}", html_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue