Skip to main content

Module gitmoji

Module gitmoji 

Source
Expand description

Gitmoji mapping (issue #85).

This repo standardises commits as <emoji> <type>(#<issue>): <subject> (Gitmoji + Conventional Commits β€” see CONTRIBUTING.md). The mapping branch_type β†’ emoji shortcode is universal across the project, so we bake a default table into the binary and let .gwm.toml override individual entries via a [gitmoji] block:

[gitmoji]
feat = ":rocket:"  # team uses πŸš€ for new features instead of ✨

Three surfaces consume this module:

  1. gwm commit-prefix β€” prints :sparkles: feat(#41): for the current or named branch (with --unicode to emit ✨ instead).
  2. gwm types --gitmoji β€” extends the branch-type list with the unicode + shortcode columns.
  3. gwm hooks install commit-msg β€” installs a .git/hooks/commit-msg that shells out to gwm commit-prefix --unicode and auto-prepends the prefix when missing.

The shortcode β†’ unicode table is intentionally kept small (the ten built-in branch types + :question: as the unknown-type fallback) to avoid pulling in a heavy gh-emoji-style dependency for a handful of entries.

StructsΒ§

GitmojiMap
Resolved branch_type β†’ shortcode table. The BTreeMap choice is load-bearing: it gives deterministic iteration order (alphabetical by branch type), which gwm types --gitmoji relies on so a CI diff against the previous run is byte-stable.

ConstantsΒ§

DEFAULT_GITMOJI
Built-in branch_type β†’ shortcode table. Lifted to a &[(&str, &str)] const so the static table stays compile-time and zero-alloc at the storage level; the runtime view materialises on demand via default_map. The list mirrors the ten built-in branch types declared in naming::BRANCH_TYPES.

FunctionsΒ§

default_map
Materialise the built-in table as a GitmojiMap. The runtime cost is one allocation per built-in entry β€” measured at ~1Β΅s total in release builds, dominated by the BTreeMap insertions, so we don’t cache.
load
Load .gwm.toml’s [gitmoji] block from the given repo root and merge it on top of the built-in defaults. Returns the built-in defaults verbatim when the file is missing or the block is absent.
resolve_prefix
Render the canonical commit prefix for a branch: <emoji> <type>(#<issue>):. Use unicode = true to substitute the shortcode for its real emoji character (e.g. :sparkles: β†’ ✨).
shortcode_to_unicode
Map a :shortcode: to its unicode character. Covers the ten built-in defaults plus a curated set of the most commonly-used Gitmoji shortcodes (the ones a team [gitmoji] override is statistically likely to swap to β€” :rocket:, :fire:, :lock:, :art:, :lipstick:, …). Anything outside the table round-trips verbatim: rendering an arbitrary user string under --unicode would require the full 3000-entry Gitmoji set (a heavy dep) and shortcodes remain valid commit-message decoration anyway. The :question: fallback covers the unknown-branch-type path inside resolve_prefix.