Class: Dependabot::PullRequestCreator::BranchNamer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependencies:, files:, target_branch:, separator: "/") ⇒ BranchNamer

Returns a new instance of BranchNamer.



11
12
13
14
15
16
# File 'lib/dependabot/pull_request_creator/branch_namer.rb', line 11

def initialize(dependencies:, files:, target_branch:, separator: "/")
  @dependencies  = dependencies
  @files         = files
  @target_branch = target_branch
  @separator     = separator
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



9
10
11
# File 'lib/dependabot/pull_request_creator/branch_namer.rb', line 9

def dependencies
  @dependencies
end

#filesObject (readonly)

Returns the value of attribute files.



9
10
11
# File 'lib/dependabot/pull_request_creator/branch_namer.rb', line 9

def files
  @files
end

#separatorObject (readonly)

Returns the value of attribute separator.



9
10
11
# File 'lib/dependabot/pull_request_creator/branch_namer.rb', line 9

def separator
  @separator
end

#target_branchObject (readonly)

Returns the value of attribute target_branch.



9
10
11
# File 'lib/dependabot/pull_request_creator/branch_namer.rb', line 9

def target_branch
  @target_branch
end

Instance Method Details

#new_branch_nameObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/CyclomaticComplexity



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/pull_request_creator/branch_namer.rb', line 21

def new_branch_name
  @name ||=
    if dependencies.count > 1 && updating_a_property?
      property_name
    elsif dependencies.count > 1 && updating_a_dependency_set?
      dependency_set.fetch(:group)
    elsif dependencies.count > 1
      dependencies.map(&:name).join("-and-").tr(":", "-")
    elsif library? && ref_changed?(dependencies.first)
      dep = dependencies.first
      "#{dep.name.tr(':', '-')}-#{new_ref(dep)}"
    elsif library?
      dep = dependencies.first
      "#{dep.name.tr(':', '-')}-#{sanitized_requirement(dep)}"
    else
      dep = dependencies.first
      "#{dep.name.tr(':', '-')}-#{new_version(dep)}"
    end

  branch_name = File.join(prefixes, @name).gsub(%r{/\.}, "/dot-")

  # Some users need branch names without slashes
  branch_name.gsub("/", separator)
end