Class: Dependabot::PullRequestCreator::PrNamePrefixer

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/pull_request_creator/pr_name_prefixer.rb

Constant Summary collapse

ANGULAR_PREFIXES =
%w(build chore ci docs feat fix perf refactor style
test).freeze
ESLINT_PREFIXES =
%w(Breaking Build Chore Docs Fix New Update
Upgrade).freeze
GITMOJI_PREFIXES =
%w(alien ambulance apple arrow_down arrow_up art beers
bento bookmark boom bug building_construction bulb
busts_in_silhouette camera_flash card_file_box
chart_with_upwards_trend checkered_flag
children_crossing clown_face construction
construction_worker egg fire globe_with_meridians
green_apple green_heart hankey heavy_minus_sign
heavy_plus_sign iphone lipstick lock loud_sound memo
mute ok_hand package page_facing_up pencil2 penguin
pushpin recycle rewind robot rocket rotating_light
see_no_evil sparkles speech_balloon tada truck
twisted_rightwards_arrows whale wheelchair
white_check_mark wrench zap).freeze

Instance Method Summary collapse

Constructor Details

#initialize(source:, dependencies:, credentials:, security_fix: false) ⇒ PrNamePrefixer

Returns a new instance of PrNamePrefixer.



28
29
30
31
32
33
# File 'lib/dependabot/pull_request_creator/pr_name_prefixer.rb', line 28

def initialize(source:, dependencies:, credentials:, security_fix: false)
  @dependencies = dependencies
  @source       = source
  @credentials  = credentials
  @security_fix = security_fix
end

Instance Method Details

#capitalize_first_word?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dependabot/pull_request_creator/pr_name_prefixer.rb', line 41

def capitalize_first_word?
  case last_dependabot_commit_style
  when :gitmoji then true
  when :conventional_prefix, :conventional_prefix_with_scope
    last_dependabot_commit_message.match?(/: (\[Security\] )?(B|U)/)
  else
    if using_angular_commit_messages? || using_eslint_commit_messages?
      prefixes = ANGULAR_PREFIXES + ESLINT_PREFIXES
      semantic_msgs = recent_commit_messages.select do |message|
        prefixes.any? { |pre| message.match?(/#{pre}[:(]/i) }
      end

      return true if semantic_msgs.all? { |m| m.match?(/:\s+\[?[A-Z]/) }
      return false if semantic_msgs.all? { |m| m.match?(/:\s+\[?[a-z]/) }
    end

    !commit_prefix&.match(/\A[a-z]/)
  end
end

#pr_name_prefixObject



35
36
37
38
39
# File 'lib/dependabot/pull_request_creator/pr_name_prefixer.rb', line 35

def pr_name_prefix
  prefix = commit_prefix.to_s
  prefix += security_prefix if security_fix?
  prefix.gsub("⬆️ 🔒", "⬆️🔒")
end