Skip to content

Commit 21644a1

Browse files
committed
🔥 Cleanup and update
1 parent e6b6022 commit 21644a1

File tree

4 files changed

+255
-53
lines changed

4 files changed

+255
-53
lines changed

Diff for: ‎Cargo.lock

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

Diff for: ‎Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ readme = "readme.md"
1313
license = "MIT"
1414

1515
[dependencies]
16-
termion = "1.0"
16+
termion = "4"
1717
log-update = "~0.1.0"
1818
default-editor = "~0.1.0"
1919
emoji-commit-type = "~0.1.1"
2020
git2 = "~0.15.0"
2121
structopt = "~0.3"
2222
ansi_term = "~0.12"
2323

24+
[dev-dependencies]
25+
tempfile = "~3.14.0"
26+
2427
[profile.release]
2528
codegen-units = 1
2629
lto = true

Diff for: ‎src/main.rs

+3-36
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22
use std::error::Error;
33
use std::fmt;
44
use std::fs::File;
5-
use std::io::{BufRead, BufReader, Seek, Write, stderr, stdin};
5+
use std::io::{Seek, Write, stderr, stdin};
66
use std::process::{Command, exit};
77
use std::path::PathBuf;
88
use std::str::FromStr;
@@ -12,12 +12,14 @@ use termion::input::TermRead;
1212
use termion::raw::IntoRawMode;
1313

1414
use emoji_commit_type::CommitType;
15+
use message::{git_parse_existing_message, git_message_is_empty};
1516
use log_update::LogUpdate;
1617
use structopt::StructOpt;
1718
use ansi_term::Colour::{RGB, Green, Red, White};
1819

1920
mod commit_rules;
2021
mod git;
22+
mod message;
2123

2224
impl fmt::Display for commit_rules::CommitRuleValidationResult {
2325
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -143,41 +145,6 @@ fn launch_git_with_self_as_editor() {
143145
run_cmd(Command::new("git").arg("commit").env("GIT_EDITOR", self_path))
144146
}
145147

146-
fn git_parse_existing_message(file: &mut File) -> Option<(CommitType, String)> {
147-
let first_line = file.read_line().unwrap().unwrap();
148-
149-
if first_line.is_empty() {
150-
return None;
151-
}
152-
153-
154-
let first_str = first_line.chars().next().unwrap().to_string();
155-
156-
let commit_type = CommitType::iter_variants().find(|commit_type| {
157-
first_str == commit_type.emoji()
158-
});
159-
160-
if commit_type == None { return None; }
161-
162-
// Check that the rest of the commit message is empty (i.e. no body)
163-
if !git_message_is_empty(file) { return None; }
164-
165-
let emoji = commit_type.unwrap().emoji().to_string();
166-
let message = first_line.replace(&emoji, "").trim().to_string();
167-
Some((commit_type.unwrap(), message))
168-
}
169-
170-
fn git_message_is_empty(file: &mut File) -> bool {
171-
for line in BufReader::new(file).lines() {
172-
let line = line.expect("Failed to read line from git message file");
173-
174-
if !line.starts_with('#') && !line.is_empty() {
175-
return false;
176-
}
177-
}
178-
true
179-
}
180-
181148
fn collect_information_and_write_to_file(out_path: PathBuf) {
182149
let mut file = File::options().read(true).write(true).create(true).open(&out_path).unwrap();
183150
let mut initial_message: Option<String> = None;

0 commit comments

Comments
 (0)