gitea-release/src/cmd/mod.rs

137 lines
3.6 KiB
Rust
Raw Normal View History

2020-05-31 19:35:23 +00:00
use std::path::PathBuf;
use structopt::StructOpt;
pub mod cut;
pub mod drone_plugin;
2020-05-31 19:35:23 +00:00
#[derive(StructOpt, Debug, Clone)]
pub struct Common {
2020-05-31 19:35:23 +00:00
/// The gitea server to connect to
#[structopt(short, long, env = "GITEA_SERVER")]
pub server: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// The gitea token to authenticate with
#[structopt(long, env = "GITEA_TOKEN")]
pub token: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// The gitea user to authenticate as
#[structopt(short, long, env = "GITEA_AUTH_USER")]
pub auth_user: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// The owner of the gitea repo
#[structopt(short, long, env = "GITEA_OWNER")]
pub owner: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// The gitea repo to operate on
#[structopt(short, long, env = "GITEA_REPO")]
pub repo: String,
2020-07-09 15:31:09 +00:00
/// Git signature email
#[structopt(long, short = "E", env = "SIGNATURE_EMAIL", default_value = "domo@tulpa.dev")]
pub email: String,
/// Git signature username
#[structopt(long, short = "U", env = "SIGNATURE_NAME", default_value = "Domo Arigato")]
pub username: String,
2020-05-31 19:35:23 +00:00
}
#[derive(StructOpt, Debug, Clone)]
pub struct DroneEnv {
// Given by drone
2020-05-31 19:35:23 +00:00
/// push URL
#[structopt(long, env = "DRONE_GIT_HTTP_URL")]
2020-05-31 19:35:23 +00:00
pub push_url: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// repo owner
#[structopt(long, env = "DRONE_REPO_OWNER")]
2020-05-31 19:35:23 +00:00
pub owner: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// repo name
#[structopt(long, env = "DRONE_REPO_NAME")]
2020-05-31 19:35:23 +00:00
pub repo: String,
2020-07-09 15:31:09 +00:00
/// branch
#[structopt(long, env = "DRONE_REPO_BRANCH")]
pub branch: String,
// Given by the user
2020-05-31 19:35:23 +00:00
/// auth username
#[structopt(long, env = "PLUGIN_AUTH_USERNAME")]
2020-05-31 19:35:23 +00:00
pub auth_user: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// Gitea server
#[structopt(long, env = "PLUGIN_GITEA_SERVER")]
2020-05-31 19:35:23 +00:00
pub server: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// Gitea token
#[structopt(long, env = "PLUGIN_GITEA_TOKEN")]
2020-05-31 19:35:23 +00:00
pub token: String,
2020-07-09 15:31:09 +00:00
2020-05-31 19:35:23 +00:00
/// CHANGELOG path
#[structopt(long, env = "PLUGIN_CHANGELOG_PATH", default_value = "./CHANGELOG.md")]
2020-05-31 19:35:23 +00:00
pub changelog_path: PathBuf,
2020-07-09 15:31:09 +00:00
/// Default branch name
#[structopt(long, env = "PLUGIN_DEFAULT_BRANCH")]
pub default_branch: Option<String>,
2020-07-09 15:31:09 +00:00
/// Git signature email
#[structopt(long, short = "E", env = "PLUGIN_SIGNATURE_EMAIL", default_value = "domo@tulpa.dev")]
pub email: String,
/// Git signature username
#[structopt(long, short = "U", env = "PLUGIN_SIGNATURE_NAME", default_value = "Domo Arigato")]
pub username: String,
2020-05-31 19:35:23 +00:00
}
impl Into<Common> for DroneEnv {
fn into(self) -> Common {
Common {
server: self.server,
token: self.token,
auth_user: self.auth_user,
owner: self.owner,
repo: self.repo,
2020-07-09 15:31:09 +00:00
email: self.email,
username: self.username,
2020-05-31 19:35:23 +00:00
}
}
}
#[derive(StructOpt, Debug)]
pub struct ReleaseMeta {
2020-05-31 19:35:23 +00:00
/// Release name
#[structopt(short, long)]
pub name: Option<String>,
/// Draft release
#[structopt(long)]
pub draft: bool,
/// Pre-release (not suitable for production)
#[structopt(short, long)]
pub pre_release: bool,
}
#[derive(StructOpt, Debug)]
#[structopt(about = "Gitea release assistant")]
pub enum Cmd {
2020-05-31 19:35:23 +00:00
/// Create a new tag and release on Gitea
2020-07-08 23:02:31 +00:00
#[structopt(alias = "release")]
Cut {
2020-05-31 19:35:23 +00:00
#[structopt(flatten)]
common: Common,
/// 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: Option<String>,
#[structopt(flatten)]
release_meta: ReleaseMeta,
},
2020-07-08 23:02:31 +00:00
/// Runs the release process as a drone plugin
DronePlugin {
#[structopt(flatten)]
env: DroneEnv,
},
2020-05-31 19:35:23 +00:00
}