feat: with vx.x.x
This commit is contained in:
parent
2485b537b6
commit
55f711272f
@ -1,7 +0,0 @@
|
||||
pub fn is_conventional_commit(commit_message: &str) -> eyre::Result<bool> {
|
||||
let re = regex::Regex::new(
|
||||
r"(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z ]+\))?: .{1,72}",
|
||||
)?;
|
||||
|
||||
Ok(re.is_match(commit_message))
|
||||
}
|
41
src/main.rs
41
src/main.rs
@ -1,19 +1,20 @@
|
||||
mod bump;
|
||||
mod conventional_commits;
|
||||
mod gitea;
|
||||
mod semantic;
|
||||
mod validate_pr;
|
||||
|
||||
use clap::Command;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use tracing_subscriber::{filter::LevelFilter, EnvFilter};
|
||||
|
||||
const VERSION: &'static str = "<dev>";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
dotenv::dotenv().unwrap();
|
||||
color_eyre::install().unwrap();
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.pretty()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.with_env_filter(EnvFilter::default().add_directive(LevelFilter::INFO.into()))
|
||||
.init();
|
||||
|
||||
let matches = clap::Command::new("releaser")
|
||||
@ -24,12 +25,44 @@ async fn main() -> eyre::Result<()> {
|
||||
.subcommand(
|
||||
Command::new("validate").about("Validate the semantic versioning of the software"),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("validate:pr")
|
||||
.about("Validate the semantic versioning of the software")
|
||||
.arg(clap::Arg::new("owner").long("owner").required(true))
|
||||
.arg(clap::Arg::new("repo").long("repo").required(true))
|
||||
.arg(
|
||||
clap::Arg::new("pull_request_id")
|
||||
.long("pull-request-id")
|
||||
.required(true)
|
||||
.value_parser(clap::value_parser!(u32).range(0..)),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::new("current_version")
|
||||
.long("current-version")
|
||||
.required(true),
|
||||
),
|
||||
)
|
||||
.subcommand(Command::new("bump").about("Bump the semantic versioning in git tags"))
|
||||
.get_matches();
|
||||
|
||||
match matches.subcommand() {
|
||||
Some(("release", sub_matches)) => {}
|
||||
Some(("validate", sub_matches)) => {}
|
||||
Some(("validate:pr", sub_matches)) => {
|
||||
let owner = sub_matches.get_one::<String>("owner").unwrap();
|
||||
let repo = sub_matches.get_one::<String>("repo").unwrap();
|
||||
let pull_request_id = sub_matches.get_one::<u32>("pull_request_id").unwrap();
|
||||
let current_version = sub_matches.get_one::<String>("current_version").unwrap();
|
||||
|
||||
match validate_pr::validate_pr(&owner, &repo, *pull_request_id, ¤t_version)
|
||||
.await?
|
||||
{
|
||||
Some(version) => {
|
||||
tracing::info!(version = version, "bumping version")
|
||||
}
|
||||
None => tracing::info!(version = current_version, "no version bump required!"),
|
||||
}
|
||||
}
|
||||
Some(("bump", sub_matches)) => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -80,7 +80,16 @@ fn increment_major(v: &mut Version) {
|
||||
}
|
||||
|
||||
pub fn bump_semver(semver: &str, bump_type: BumpType) -> Result<String, semver::Error> {
|
||||
let mut version = Version::parse(semver)?;
|
||||
let mut contains_start_v = false;
|
||||
|
||||
let semver = if semver.starts_with("v") {
|
||||
contains_start_v = true;
|
||||
semver.replace("v", "")
|
||||
} else {
|
||||
semver.to_string()
|
||||
};
|
||||
|
||||
let mut version = Version::parse(&semver)?;
|
||||
|
||||
match bump_type {
|
||||
BumpType::Major => increment_major(&mut version),
|
||||
@ -88,8 +97,12 @@ pub fn bump_semver(semver: &str, bump_type: BumpType) -> Result<String, semver::
|
||||
BumpType::Patch => increment_patch(&mut version),
|
||||
}
|
||||
|
||||
if contains_start_v {
|
||||
Ok(format!("v{version}"))
|
||||
} else {
|
||||
Ok(version.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
18
src/validate_pr.rs
Normal file
18
src/validate_pr.rs
Normal file
@ -0,0 +1,18 @@
|
||||
pub async fn validate_pr(
|
||||
owner: &str,
|
||||
repo: &str,
|
||||
pull_request_id: u32,
|
||||
current_version: &str,
|
||||
) -> eyre::Result<Option<String>> {
|
||||
let base_url = &std::env::var("GITEA_BASE_URL").unwrap();
|
||||
let token = &std::env::var("GITEA_ACCESS_TOKEN").unwrap();
|
||||
|
||||
let commit_titles =
|
||||
crate::gitea::get_pull_request_commits(base_url, owner, repo, pull_request_id, token)
|
||||
.await?;
|
||||
|
||||
match crate::semantic::get_most_significant_bump(&commit_titles) {
|
||||
Some(bump) => Ok(Some(crate::semantic::bump_semver(current_version, bump)?)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user