Skip to content

Commit

Permalink
chore: merge pull request #52 from websublime/fix/git-commits-process
Browse files Browse the repository at this point in the history
fix: filter unwanted commits not following conventional rules
  • Loading branch information
miguelramos authored Sep 23, 2024
2 parents 4061461 + 098df0a commit a6f59db
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "workspace-node-tools"
version = "2.0.1"
version = "2.0.2"
edition = "2021"
description = "Node workspace version tools"
repository = "https://github.com/websublime/workspace-node-tools"
Expand All @@ -19,14 +19,14 @@ serde_json = "1.0.128"
regex = "1.10.6"
wax = { version = "0.6.0", features = ["walk"] }
napi-derive = { version = "2.16.12", optional = true }
napi = { version = "2.16.10", default-features = false, features = [
napi = { version = "2.16.11", default-features = false, features = [
"napi9",
"serde-json",
"tokio_rt",
], optional = true }
icu = "1.5.0"
version-compare = "0.2"
git-cliff-core = "2.5.0"
git-cliff-core = "2.6.0"
chrono = "0.4.38"
semver = "1.0.23"
rand = "0.8.5"
Expand Down
62 changes: 34 additions & 28 deletions src/conventional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ pub struct ConventionalPackageOptions {
fn process_commits<'a>(commits: &Vec<Commit>, config: &GitConfig) -> Vec<GitCommit<'a>> {
commits
.iter()
.filter(|commit| {
let timestamp = chrono::DateTime::parse_from_rfc2822(&commit.author_date).unwrap();

let git_commit = GitCommit {
id: commit.hash.to_string(),
message: commit.message.to_string(),
author: Signature {
name: Some(commit.author_name.to_string()),
email: Some(commit.author_email.to_string()),
timestamp: timestamp.timestamp(),
},
..GitCommit::default()
};

git_commit.into_conventional().is_ok()
})
.map(|commit| {
let timestamp = chrono::DateTime::parse_from_rfc2822(&commit.author_date).unwrap();

Expand Down Expand Up @@ -154,84 +170,74 @@ fn define_config(
replace: Some(String::from(github_url)),
replace_command: None,
}]),
render_always: Some(false),
..ChangelogConfig::default()
},
git: GitConfig {
commit_parsers: Some(vec![
CommitParser {
message: Some(Regex::new("^feat").expect("failed to compile regex")),
message: Regex::new("^feat").ok(),
group: Some(String::from("<!-- 0 -->⛰️ Features")),
..CommitParser::default()
},
CommitParser {
message: Some(Regex::new("^fix").expect("failed to compile regex")),
message: Regex::new("^fix").ok(),
group: Some(String::from("<!-- 1 -->🐛 Bug Fixes")),
..CommitParser::default()
},
CommitParser {
message: Some(Regex::new("^doc").expect("failed to compile regex")),
message: Regex::new("^doc").ok(),
group: Some(String::from("<!-- 3 -->📚 Documentation")),
..CommitParser::default()
},
CommitParser {
message: Some(Regex::new("^perf").expect("failed to compile regex")),
message: Regex::new("^perf").ok(),
group: Some(String::from("<!-- 4 -->⚡ Performance")),
..CommitParser::default()
},
CommitParser {
message: Some(
Regex::new("^refactor\\(clippy\\)")
.expect("failed to compile regex"),
),
message: Regex::new("^refactor\\(clippy\\)").ok(),
skip: Some(true),
..CommitParser::default()
},
CommitParser {
message: Some(
Regex::new("^refactor").expect("failed to compile regex"),
),
message: Regex::new("^refactor").ok(),
group: Some(String::from("<!-- 2 -->🚜 Refactor")),
..CommitParser::default()
},
CommitParser {
message: Some(Regex::new("^style").expect("failed to compile regex")),
message: Regex::new("^style").ok(),
group: Some(String::from("<!-- 5 -->🎨 Styling")),
..CommitParser::default()
},
CommitParser {
message: Some(Regex::new("^test").expect("failed to compile regex")),
message: Regex::new("^test").ok(),
group: Some(String::from("<!-- 6 -->🧪 Testing")),
..CommitParser::default()
},
CommitParser {
message: Some(
Regex::new("^chore|^ci").expect("failed to compile regex"),
),
message: Regex::new("^chore|^ci").ok(),
group: Some(String::from("<!-- 7 -->⚙️ Miscellaneous Tasks")),
..CommitParser::default()
},
CommitParser {
body: Some(Regex::new(".*security").expect("failed to compile regex")),
body: Regex::new(".*security").ok(),
group: Some(String::from("<!-- 8 -->🛡️ Security")),
..CommitParser::default()
},
CommitParser {
message: Some(Regex::new("^revert").expect("failed to compile regex")),
message: Regex::new("^revert").ok(),
group: Some(String::from("<!-- 9 -->◀️ Revert")),
..CommitParser::default()
},
]),
protect_breaking_commits: Some(false),
filter_commits: Some(false),
tag_pattern: Some(
Regex::new("^((?:@[^/@]+/)?[^/@]+)(?:@([^/]+))?$")
.expect("failed to compile regex"),
),
skip_tags: Some(
Regex::new("beta|alpha|snapshot").expect("failed to compile regex"),
),
ignore_tags: Some(
Regex::new("rc|beta|alpha|snapshot").expect("failed to compile regex"),
),
filter_unconventional: Some(true),
conventional_commits: Some(true),
tag_pattern: Regex::new("^((?:@[^/@]+/)?[^/@]+)(?:@([^/]+))?$").ok(),
skip_tags: Regex::new("beta|alpha|snapshot").ok(),
ignore_tags: Regex::new("rc|beta|alpha|snapshot").ok(),
topo_order: Some(false),
sort_commits: Some(String::from("newest")),
..GitConfig::default()
Expand Down

0 comments on commit a6f59db

Please sign in to comment.