implement release command
This commit is contained in:
parent
d14bf14d4b
commit
604ee570a1
6
TODO.org
6
TODO.org
|
@ -9,12 +9,14 @@
|
||||||
CLOSED: [2020-05-30 Sat 14:49]
|
CLOSED: [2020-05-30 Sat 14:49]
|
||||||
** DONE info
|
** DONE info
|
||||||
CLOSED: [2020-05-30 Sat 10:52]
|
CLOSED: [2020-05-30 Sat 10:52]
|
||||||
** TODO release
|
** DONE release
|
||||||
|
CLOSED: [2020-05-31 Sun 12:50]
|
||||||
** DONE upload
|
** DONE upload
|
||||||
CLOSED: [2020-05-30 Sat 15:15]
|
CLOSED: [2020-05-30 Sat 15:15]
|
||||||
|
|
||||||
* Core Features
|
* Core Features
|
||||||
** DONE Gitea API client
|
** DONE Gitea API client
|
||||||
CLOSED: [2020-05-30 Sat 10:52]
|
CLOSED: [2020-05-30 Sat 10:52]
|
||||||
** TODO CHANGELOG.md parsing
|
** DONE CHANGELOG.md parsing
|
||||||
|
CLOSED: [2020-05-31 Sun 12:50]
|
||||||
** TODO VERSION parsing
|
** TODO VERSION parsing
|
||||||
|
|
|
@ -73,3 +73,11 @@ where
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn read_changelog() {
|
||||||
|
assert!(super::read("CHANGELOG.md".into(), "0.1.0".into()).is_ok());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -33,11 +33,10 @@ pub(crate) async fn run(
|
||||||
|
|
||||||
let resp = cli
|
let resp = cli
|
||||||
.post(
|
.post(
|
||||||
format!(
|
&format!(
|
||||||
"{}/api/v1/repos/{}/{}/releases/{}",
|
"{}/api/v1/repos/{}/{}/releases/{}",
|
||||||
common.server, common.owner, common.repo, release.id
|
common.server, common.owner, common.repo, release.id
|
||||||
)
|
),
|
||||||
.as_str(),
|
|
||||||
)
|
)
|
||||||
.json(&cr)
|
.json(&cr)
|
||||||
.send()
|
.send()
|
||||||
|
|
|
@ -2,4 +2,5 @@ pub(crate) mod delete;
|
||||||
pub(crate) mod download;
|
pub(crate) mod download;
|
||||||
pub(crate) mod edit;
|
pub(crate) mod edit;
|
||||||
pub(crate) mod info;
|
pub(crate) mod info;
|
||||||
|
pub(crate) mod release;
|
||||||
pub(crate) mod upload;
|
pub(crate) mod upload;
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
use crate::{gitea::*, *};
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub(crate) async fn run(
|
||||||
|
common: Common,
|
||||||
|
fname: PathBuf,
|
||||||
|
tag: String,
|
||||||
|
rm: ReleaseMeta,
|
||||||
|
) -> Result<()> {
|
||||||
|
let desc = changelog::read(fname, tag.clone())?;
|
||||||
|
let cli = client(&common)?;
|
||||||
|
let cr = CreateRelease {
|
||||||
|
body: desc,
|
||||||
|
draft: rm.draft,
|
||||||
|
name: rm.name.or(Some(format!("Version {}", tag))).unwrap(),
|
||||||
|
prerelease: rm.pre_release,
|
||||||
|
tag_name: tag.clone(),
|
||||||
|
target_commitish: tag,
|
||||||
|
};
|
||||||
|
|
||||||
|
let resp = cli
|
||||||
|
.post(&format!(
|
||||||
|
"{}/api/v1/repos/{}/{}/releases",
|
||||||
|
common.server, common.owner, common.repo
|
||||||
|
))
|
||||||
|
.json(&cr)
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !resp.status().is_success() {
|
||||||
|
return Err(anyhow!("{:?}", resp.status()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
16
src/gitea.rs
16
src/gitea.rs
|
@ -65,7 +65,10 @@ pub(crate) async fn get_release_by_tag(
|
||||||
tag: &String,
|
tag: &String,
|
||||||
) -> Result<Release> {
|
) -> Result<Release> {
|
||||||
let releases: Vec<Release> = cli
|
let releases: Vec<Release> = cli
|
||||||
.get(format!("{}/api/v1/repos/{}/{}/releases", server, owner, repo).as_str())
|
.get(&format!(
|
||||||
|
"{}/api/v1/repos/{}/{}/releases",
|
||||||
|
server, owner, repo
|
||||||
|
))
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.json()
|
.json()
|
||||||
|
@ -121,13 +124,10 @@ pub(crate) async fn get_attachments_for_release(
|
||||||
id: &i64,
|
id: &i64,
|
||||||
) -> Result<Vec<Attachment>> {
|
) -> Result<Vec<Attachment>> {
|
||||||
let attachments: Vec<Attachment> = cli
|
let attachments: Vec<Attachment> = cli
|
||||||
.get(
|
.get(&format!(
|
||||||
format!(
|
"{}/api/v1/repos/{}/{}/releases/{}/assets",
|
||||||
"{}/api/v1/repos/{}/{}/releases/{}/assets",
|
server, owner, repo, id
|
||||||
server, owner, repo, id
|
))
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
)
|
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.json()
|
.json()
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -68,8 +68,7 @@ pub(crate) enum Cmd {
|
||||||
Download {
|
Download {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
common: Common,
|
common: Common,
|
||||||
/// Folder to download release artifacts to
|
/// File to download
|
||||||
#[structopt(short, long)]
|
|
||||||
fname: Option<PathBuf>,
|
fname: Option<PathBuf>,
|
||||||
/// The version tag to operate on
|
/// The version tag to operate on
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long)]
|
||||||
|
@ -85,7 +84,6 @@ pub(crate) enum Cmd {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
release_meta: ReleaseMeta,
|
release_meta: ReleaseMeta,
|
||||||
/// The version tag to operate on
|
/// The version tag to operate on
|
||||||
#[structopt(short, long)]
|
|
||||||
tag: String,
|
tag: String,
|
||||||
},
|
},
|
||||||
/// Gets release info
|
/// Gets release info
|
||||||
|
@ -105,6 +103,8 @@ pub(crate) enum Cmd {
|
||||||
/// Changelog file to read from to create the release description
|
/// Changelog file to read from to create the release description
|
||||||
#[structopt(short, long, default_value = "./CHANGELOG.md")]
|
#[structopt(short, long, default_value = "./CHANGELOG.md")]
|
||||||
changelog: PathBuf,
|
changelog: PathBuf,
|
||||||
|
/// The version tag to operate on
|
||||||
|
tag: String,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
release_meta: ReleaseMeta,
|
release_meta: ReleaseMeta,
|
||||||
},
|
},
|
||||||
|
@ -112,12 +112,11 @@ pub(crate) enum Cmd {
|
||||||
Upload {
|
Upload {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
common: Common,
|
common: Common,
|
||||||
/// The location of the file on the disk
|
|
||||||
#[structopt(short, long)]
|
|
||||||
fname: PathBuf,
|
|
||||||
/// The version tag to operate on
|
/// The version tag to operate on
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long)]
|
||||||
tag: String,
|
tag: String,
|
||||||
|
/// The location of the file on the disk
|
||||||
|
fname: PathBuf,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,8 +135,12 @@ async fn main() -> Result<()> {
|
||||||
tag,
|
tag,
|
||||||
} => cmd::edit::run(common, description, release_meta, tag).await,
|
} => cmd::edit::run(common, description, release_meta, tag).await,
|
||||||
Cmd::Info { common, json, tag } => cmd::info::run(common, json, tag).await,
|
Cmd::Info { common, json, tag } => cmd::info::run(common, json, tag).await,
|
||||||
|
Cmd::Release {
|
||||||
|
common,
|
||||||
|
changelog,
|
||||||
|
tag,
|
||||||
|
release_meta,
|
||||||
|
} => cmd::release::run(common, changelog, tag, release_meta).await,
|
||||||
Cmd::Upload { common, fname, tag } => cmd::upload::run(common, fname, tag).await,
|
Cmd::Upload { common, fname, tag } => cmd::upload::run(common, fname, tag).await,
|
||||||
|
|
||||||
_ => Err(anyhow!("not implemented yet")),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue