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]
|
||||
** DONE info
|
||||
CLOSED: [2020-05-30 Sat 10:52]
|
||||
** TODO release
|
||||
** DONE release
|
||||
CLOSED: [2020-05-31 Sun 12:50]
|
||||
** DONE upload
|
||||
CLOSED: [2020-05-30 Sat 15:15]
|
||||
|
||||
* Core Features
|
||||
** DONE Gitea API client
|
||||
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
|
||||
|
|
|
@ -73,3 +73,11 @@ where
|
|||
|
||||
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
|
||||
.post(
|
||||
format!(
|
||||
&format!(
|
||||
"{}/api/v1/repos/{}/{}/releases/{}",
|
||||
common.server, common.owner, common.repo, release.id
|
||||
)
|
||||
.as_str(),
|
||||
),
|
||||
)
|
||||
.json(&cr)
|
||||
.send()
|
||||
|
|
|
@ -2,4 +2,5 @@ pub(crate) mod delete;
|
|||
pub(crate) mod download;
|
||||
pub(crate) mod edit;
|
||||
pub(crate) mod info;
|
||||
pub(crate) mod release;
|
||||
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(())
|
||||
}
|
12
src/gitea.rs
12
src/gitea.rs
|
@ -65,7 +65,10 @@ pub(crate) async fn get_release_by_tag(
|
|||
tag: &String,
|
||||
) -> Result<Release> {
|
||||
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()
|
||||
.await?
|
||||
.json()
|
||||
|
@ -121,13 +124,10 @@ pub(crate) async fn get_attachments_for_release(
|
|||
id: &i64,
|
||||
) -> Result<Vec<Attachment>> {
|
||||
let attachments: Vec<Attachment> = cli
|
||||
.get(
|
||||
format!(
|
||||
.get(&format!(
|
||||
"{}/api/v1/repos/{}/{}/releases/{}/assets",
|
||||
server, owner, repo, id
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
))
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -68,8 +68,7 @@ pub(crate) enum Cmd {
|
|||
Download {
|
||||
#[structopt(flatten)]
|
||||
common: Common,
|
||||
/// Folder to download release artifacts to
|
||||
#[structopt(short, long)]
|
||||
/// File to download
|
||||
fname: Option<PathBuf>,
|
||||
/// The version tag to operate on
|
||||
#[structopt(short, long)]
|
||||
|
@ -85,7 +84,6 @@ pub(crate) enum Cmd {
|
|||
#[structopt(flatten)]
|
||||
release_meta: ReleaseMeta,
|
||||
/// The version tag to operate on
|
||||
#[structopt(short, long)]
|
||||
tag: String,
|
||||
},
|
||||
/// Gets release info
|
||||
|
@ -105,6 +103,8 @@ pub(crate) enum Cmd {
|
|||
/// Changelog file to read from to create the release description
|
||||
#[structopt(short, long, default_value = "./CHANGELOG.md")]
|
||||
changelog: PathBuf,
|
||||
/// The version tag to operate on
|
||||
tag: String,
|
||||
#[structopt(flatten)]
|
||||
release_meta: ReleaseMeta,
|
||||
},
|
||||
|
@ -112,12 +112,11 @@ pub(crate) enum Cmd {
|
|||
Upload {
|
||||
#[structopt(flatten)]
|
||||
common: Common,
|
||||
/// The location of the file on the disk
|
||||
#[structopt(short, long)]
|
||||
fname: PathBuf,
|
||||
/// The version tag to operate on
|
||||
#[structopt(short, long)]
|
||||
tag: String,
|
||||
/// The location of the file on the disk
|
||||
fname: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -136,8 +135,12 @@ async fn main() -> Result<()> {
|
|||
tag,
|
||||
} => cmd::edit::run(common, description, release_meta, 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,
|
||||
|
||||
_ => Err(anyhow!("not implemented yet")),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue