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:, automerge_candidate:) ⇒ Labeler

Returns a new instance of Labeler.



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

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

Class Attribute Details

.package_manager_labelsObject (readonly)

Returns the value of attribute package_manager_labels.



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

def package_manager_labels
  @package_manager_labels
end

Class Method Details

.label_details_for_package_manager(package_manager) ⇒ Object



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

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



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

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

Instance Method Details

#create_default_labels_if_requiredObject



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

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



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

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, Octokit::NotFound
  retry_count ||= 0
  retry_count += 1
  raise if retry_count > 10

  sleep(rand(1..1.99))
  retry
end

#labels_for_prObject



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

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