Class: Dependabot::PullRequestCreator::Labeler

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

Constant Summary collapse

DEPENDENCIES_LABEL_REGEX =
%r{^[^/]*dependenc[^/]+$}i.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, custom_labels:, credentials:, dependencies:, includes_security_fixes:, label_language:) ⇒ Labeler

Returns a new instance of Labeler.



30
31
32
33
34
35
36
37
38
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 30

def initialize(source:, custom_labels:, credentials:, dependencies:,
               includes_security_fixes:, label_language:)
  @source                  = source
  @custom_labels           = custom_labels
  @credentials             = credentials
  @dependencies            = dependencies
  @includes_security_fixes = includes_security_fixes
  @label_language          = label_language
end

Class Attribute Details

.package_manager_labelsObject (readonly)

Returns the value of attribute package_manager_labels.



16
17
18
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 16

def package_manager_labels
  @package_manager_labels
end

Class Method Details

.label_details_for_package_manager(package_manager) ⇒ Object



18
19
20
21
22
23
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 18

def label_details_for_package_manager(package_manager)
  label_details = @package_manager_labels[package_manager]
  return label_details if label_details

  raise "Unsupported package_manager #{package_manager}"
end

.register_label_details(package_manager, label_details) ⇒ Object



25
26
27
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 25

def register_label_details(package_manager, label_details)
  @package_manager_labels[package_manager] = label_details
end

Instance Method Details

#create_default_labels_if_requiredObject



40
41
42
43
44
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 40

def create_default_labels_if_required
  create_default_dependencies_label_if_required
  create_default_security_label_if_required
  create_default_language_label_if_required
end

#label_pull_request(pull_request_number) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 54

def label_pull_request(pull_request_number)
  create_default_labels_if_required

  return if labels_for_pr.none?
  raise "Only GitHub!" unless source.provider == "github"

  github_client_for_source.add_labels_to_an_issue(
    source.repo,
    pull_request_number,
    labels_for_pr
  )
rescue Octokit::UnprocessableEntity
  retrying ||= false
  raise if retrying

  retrying = true
  retry
end

#labels_for_prObject



46
47
48
49
50
51
52
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 46

def labels_for_pr
  [
    *default_labels_for_pr,
    includes_security_fixes? ? security_label : nil,
    semver_labels_exist? ? semver_label : nil
  ].compact.uniq
end