2020-05-30 16:24:04 +00:00
|
|
|
use crate::{gitea::*, *};
|
|
|
|
use anyhow::{anyhow, Result};
|
|
|
|
use cli_table::{Cell, Row, Table};
|
|
|
|
|
2020-05-30 18:50:21 +00:00
|
|
|
pub(crate) async fn run(common: Common, json: bool, tag: Option<String>) -> Result<()> {
|
2020-05-30 16:24:04 +00:00
|
|
|
let cli = client(&common)?;
|
|
|
|
|
|
|
|
let releases: Vec<Release> = cli
|
|
|
|
.get(
|
|
|
|
format!(
|
|
|
|
"{}/api/v1/repos/{}/{}/releases",
|
|
|
|
&common.server, &common.owner, &common.repo
|
|
|
|
)
|
|
|
|
.as_str(),
|
|
|
|
)
|
|
|
|
.send()
|
|
|
|
.await?
|
|
|
|
.json()
|
|
|
|
.await?;
|
|
|
|
|
2020-05-30 18:50:21 +00:00
|
|
|
match tag {
|
2020-05-30 16:24:04 +00:00
|
|
|
Some(tag) => {
|
|
|
|
let mut release: Option<Release> = None;
|
|
|
|
|
|
|
|
for rls in releases {
|
|
|
|
if tag == rls.tag_name {
|
|
|
|
release = Some(rls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if release.is_none() {
|
|
|
|
return Err(anyhow!("tag {} not found", tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
if json {
|
|
|
|
println!("{}", serde_json::to_string_pretty(&release)?);
|
|
|
|
} else {
|
|
|
|
let rls = release.unwrap();
|
|
|
|
let table = Table::new(
|
|
|
|
vec![
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::new(&"id", Default::default()),
|
|
|
|
Cell::new(&rls.id, Default::default()),
|
|
|
|
]),
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::new(&"author", Default::default()),
|
|
|
|
Cell::new(
|
|
|
|
&format!("{} - {}", rls.author.full_name, rls.author.username),
|
|
|
|
Default::default(),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::new(&"tag", Default::default()),
|
|
|
|
Cell::new(&rls.tag_name, Default::default()),
|
|
|
|
]),
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::new(&"created at", Default::default()),
|
|
|
|
Cell::new(&rls.created_at, Default::default()),
|
|
|
|
]),
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::new(&"name", Default::default()),
|
|
|
|
Cell::new(&rls.name, Default::default()),
|
|
|
|
]),
|
|
|
|
Row::new(vec![
|
|
|
|
Cell::new(&"body", Default::default()),
|
|
|
|
Cell::new(&rls.body, Default::default()),
|
|
|
|
]),
|
|
|
|
],
|
|
|
|
Default::default(),
|
|
|
|
)?;
|
|
|
|
table.print_stdout()?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
if json {
|
|
|
|
println!("{}", serde_json::to_string_pretty(&releases)?);
|
|
|
|
} else {
|
|
|
|
let mut rows: Vec<Row> = vec![Row::new(vec![
|
|
|
|
Cell::new(&"id", Default::default()),
|
|
|
|
Cell::new(&"tag", Default::default()),
|
|
|
|
Cell::new(&"created at", Default::default()),
|
|
|
|
Cell::new(&"commit", Default::default()),
|
|
|
|
Cell::new(&"author", Default::default()),
|
|
|
|
Cell::new(&"name", Default::default()),
|
|
|
|
])];
|
|
|
|
for release in releases {
|
|
|
|
rows.push(release.row())
|
|
|
|
}
|
|
|
|
|
|
|
|
let table = Table::new(rows, Default::default())?;
|
|
|
|
table.print_stdout()?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|