File: commit-msg

package info (click to toggle)
ruby-oauth2 2.0.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,196 kB
  • sloc: ruby: 5,441; javascript: 529; sh: 4; makefile: 4
file content (54 lines) | stat: -rwxr-xr-x 1,927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby
# vim: set syntax=ruby

# Do not rely on Bundler; allow running outside a Bundler context
begin
  require "rubygems"
rescue LoadError
  # continue
end

begin
  # External gems
  require "gitmoji/regex"

  full_text = File.read(ARGV[0])
  # Is the first character a GitMoji?
  gitmoji_index = full_text =~ Gitmoji::Regex::REGEX
  if gitmoji_index == 0
    exit(0)
  else
    denied = <<~EOM
      Oh snap, think again...
      
       ______    _______      ___  _______  _______  _______  _______  ______   __
      |    _ |  |       |    |   ||       ||       ||       ||       ||      | |  |
      |   | ||  |    ___|    |   ||    ___||       ||_     _||    ___||  _    ||  |
      |   |_||_ |   |___     |   ||   |___ |       |  |   |  |   |___ | | |   ||  |
      |    __  ||    ___| ___|   ||    ___||      _|  |   |  |    ___|| |_|   ||__|
      |   |  | ||   |___ |       ||   |___ |     |_   |   |  |   |___ |       | __
      |___|  |_||_______||_______||_______||_______|  |___|  |_______||______| |__|
      
      
      Did you forget to add a relevant gitmoji? (see https://gitmoji.dev/ for tools)
      In this project, a Gitmoji must be the first grapheme of the commit message.
      What's a grapheme?
      A symbol rendered to be visually identifiable as a single character, but which may be composed of multiple Unicode code points)
      Must match: #{Gitmoji::Regex::REGEX}
      #{"Found a gitmoji at character index #{gitmoji_index}... not good enough.\n" if gitmoji_index}
      Example: git commit -m "✨ My excellent new feature"
      
    EOM
    puts denied
    exit(1)
  end
rescue LoadError => e
  failure = <<~EOM
    gitmoji-regex gem not found: #{e.class}: #{e.message}.
      Skipping gitmoji check and allowing commit to proceed.
      Recommendation: add 'gitmoji-regex' to your development dependencies to enable this check.
    
  EOM
  warn(failure)
  exit(0)
end