Skip to content

Commit 33a197f

Browse files
committed
release: v0.2.0
1 parent c133919 commit 33a197f

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ghl"
3-
version = "0.1.4"
3+
version = "0.2.0"
44
edition = "2021"
55

66
[dependencies]

src/config.rs

+23-36
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ use home::home_dir;
22
use std::{ffi::OsStr, fs, io::Error};
33

44
use colored::*;
5-
use inquire::{validator::Validation, Confirm, Editor, InquireError, Text};
6-
7-
const PR_PREFIX: [&str; 9] = [
8-
"Add ", "Clean ", "Fix ", "Improve ", "Remove ", "Update ", "Rework ", "Ignore ", "Bump ",
9-
];
5+
use inquire::{validator::Validation, Confirm, Editor, InquireError, Select, Text};
106

117
pub struct Config {
128
pub pr_name: String,
@@ -99,29 +95,33 @@ impl Config {
9995
false => Ok(Validation::Valid),
10096
};
10197

102-
let pr_name_validator =
103-
|value: &str| match PR_PREFIX.iter().any(|current| value.starts_with(current)) {
104-
true => Ok(Validation::Valid),
105-
false => {
106-
let mut output = PR_PREFIX
107-
.iter()
108-
.map(|current| format!("- {}...", current))
109-
.collect::<Vec<String>>()
110-
.join("\n");
111-
output =
112-
"The name must start with one of the following:\n".to_owned() + &output;
113-
Ok(Validation::Invalid(output.into()))
114-
}
115-
};
116-
11798
let linear_branch = Text::new("Linear branch name:")
11899
.with_validator(not_empty_validator)
119100
.prompt()?;
120101

121-
let mut pr_name = Text::new("Pull request name:")
122-
.with_validators(&[Box::new(not_empty_validator), Box::new(pr_name_validator)])
102+
let type_options: Vec<&str> = vec![
103+
"feat", "fix", "refactor", "perf", "style", "test", "docs", "build", "ops", "chore",
104+
];
105+
106+
let _type = Select::new("Type:", type_options).prompt()?;
107+
108+
let scope = Text::new("Scope (optional):").prompt_skippable()?;
109+
110+
let name = Text::new("Name:")
111+
.with_validators(&[Box::new(not_empty_validator)])
123112
.prompt()?;
124113

114+
let mut pr_name = match scope {
115+
Some(scope) => {
116+
if scope.is_empty() {
117+
format!("{}: {}", _type, name)
118+
} else {
119+
format!("{}({}): {}", _type, scope, name)
120+
}
121+
}
122+
None => format!("{}: {}", _type, name),
123+
};
124+
125125
let splited_branch = linear_branch.split('-').collect::<Vec<&str>>();
126126
if splited_branch.len() > 1 {
127127
pr_name = format!(
@@ -132,20 +132,7 @@ impl Config {
132132
)
133133
}
134134

135-
let prefix = pr_name.split(' ').collect::<Vec<&str>>()[0];
136-
let branch_prefix = match prefix {
137-
"Add" => "feature",
138-
"Clean" => "rework",
139-
"Fix" => "fix",
140-
"Improve" => "rework",
141-
"Remove" => "feature",
142-
"Update" => "feature",
143-
"Rework" => "rework",
144-
"Ignore" => "feature",
145-
"Bump" => "core",
146-
_ => return Err(InquireError::Custom("Invalid input".into())),
147-
};
148-
let branch = format!("{}/{}", branch_prefix, &linear_branch);
135+
let branch = format!("{}/{}", _type, &linear_branch);
149136

150137
Ok(Config { pr_name, branch })
151138
}

0 commit comments

Comments
 (0)