1use std::collections::HashMap;
2use std::sync::LazyLock;
3
4fn create_gitmoji_map() -> HashMap<&'static str, (&'static str, &'static str)> {
5 let mut m = HashMap::new();
6
7 m.insert("feat", ("✨", "Introduce new features"));
8 m.insert("fix", ("🐛", "Fix a bug"));
9 m.insert("docs", ("📝", "Add or update documentation"));
10 m.insert("style", ("💄", "Add or update the UI and style files"));
11 m.insert("refactor", ("♻️", "Refactor code"));
12 m.insert("perf", ("⚡️", "Improve performance"));
13 m.insert("test", ("✅", "Add or update tests"));
14 m.insert("build", ("👷", "Add or update build scripts"));
15 m.insert("ci", ("🔧", "Add or update CI configuration"));
16 m.insert(
17 "chore",
18 ("🔨", "Other changes that don't modify src or test files"),
19 );
20 m.insert("revert", ("⏪️", "Revert changes"));
21 m.insert("wip", ("🚧", "Work in progress"));
22 m.insert("dependencies", ("⬆️", "Update dependencies"));
23 m.insert("remove", ("🔥", "Remove code or files"));
24 m.insert("i18n", ("🌐", "Internationalization and localization"));
25 m.insert("security", ("🔒️", "Fix security issues"));
26 m.insert("debug", ("🐛", "Add or update debugging code"));
27 m.insert("deployment", ("🚀", "Deploy stuff"));
28 m.insert("hotfix", ("🚑", "Critical hotfix"));
29 m.insert("accessibility", ("♿", "Improve accessibility"));
30 m.insert("analytics", ("📈", "Add or update analytics"));
31 m.insert("seo", ("🔍️", "Improve SEO"));
32 m.insert("config", ("🔧", "Add or update configuration files"));
33 m.insert("tracking", ("📈", "Add or update tracking code"));
34 m.insert("design", ("🎨", "Improve structure / format of the code"));
35 m.insert("error", ("🚨", "Fix compiler / linter warnings"));
36 m.insert("test_failure", ("💥", "Fix tests or CI failures"));
37 m.insert("data", ("📊", "Add or update data"));
38 m.insert("content", ("📝", "Add or update content"));
39 m.insert("linter", ("👕", "Add or update linters"));
40 m.insert("initial", ("🎉", "Begin a project"));
41
42 m
43}
44
45static GITMOJI_MAP: LazyLock<HashMap<&'static str, (&'static str, &'static str)>> =
46 LazyLock::new(create_gitmoji_map);
47
48const PROMPT_GITMOJI_KEYS: &[&str] = &[
49 "feat", "fix", "refactor", "perf", "test", "docs", "build", "ci", "chore", "remove",
50];
51
52pub fn get_gitmoji(commit_type: &str) -> Option<&'static str> {
53 GITMOJI_MAP.get(commit_type).map(|&(emoji, _)| emoji)
54}
55
56pub fn get_gitmoji_list() -> String {
57 let mut entries: Vec<_> = GITMOJI_MAP.iter().collect();
58 entries.sort_by_key(|(key, _)| *key);
59
60 let emoji_list = entries
61 .iter()
62 .map(|(key, (emoji, description))| format!("{emoji} - :{key}: - {description}"))
63 .collect::<Vec<String>>();
64
65 emoji_list.join("\n")
66}
67
68#[must_use]
69pub fn get_gitmoji_prompt_guide() -> String {
70 let entries = PROMPT_GITMOJI_KEYS
71 .iter()
72 .filter_map(|key| {
73 GITMOJI_MAP
74 .get(key)
75 .map(|(emoji, description)| format!("- {emoji} `:{key}:` - {description}"))
76 })
77 .collect::<Vec<_>>();
78
79 format!(
80 "Common gitmoji choices:\n{}\n- Reuse the closest option above instead of inventing a new emoji",
81 entries.join("\n")
82 )
83}