GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit d83c1559 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'relax-danger-emoji-matching' into 'master'

Improve Emoji detection in commit messages

Closes gitlab-org/release/framework#15

See merge request gitlab-org/gitlab-ce!21799
parents 7e6ed7c7 4ef1dd09
# frozen_string_literal: true
require 'json'
# rubocop: disable Style/SignalException
# rubocop: disable Metrics/CyclomaticComplexity
# rubocop: disable Metrics/PerceivedComplexity
......@@ -8,6 +10,30 @@
# because its output is not
# very helpful, and it doesn't offer the means of ignoring merge commits.
class EmojiChecker
DIGESTS = File.expand_path('../../fixtures/emojis/digests.json', __dir__)
ALIASES = File.expand_path('../../fixtures/emojis/aliases.json', __dir__)
# A regex that indicates a piece of text _might_ include an Emoji. The regex
# alone is not enough, as we'd match `:foo:bar:baz`. Instead, we use this
# regex to save us from having to check for all possible emoji names when we
# know one definitely is not included.
LIKELY_EMOJI = /:[\+a-z0-9_\-]+:/
def initialize
names = JSON.parse( +
@emoji = { |name| ":#{name}:" }
def includes_emoji?(text)
return false unless text.match?(LIKELY_EMOJI)
@emoji.any? { |emoji| text.include?(emoji) }
def fail_commit(commit, message)
fail("#{commit.sha}: #{message}")
......@@ -33,6 +59,7 @@ end
def lint_commits(commits)
failures = false
emoji_checker =
unicode_emoji_regex = %r((
[\u{1F300}-\u{1F5FF}] |
......@@ -117,7 +144,7 @@ def lint_commits(commits)
failures = true
if commit.message.match?(/:[\+a-z0-9_\-]+:/)
if emoji_checker.includes_emoji?(commit.message)
'Avoid the use of Markdown Emoji such as `:+1:`. ' \
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment