Class: Dependabot::PullRequestCreator::Labeler

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/pull_request_creator/labeler.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

DEPENDENCIES_LABEL_REGEX =
%r{^[^/]*dependenc[^/]+$}i
DEFAULT_DEPENDENCIES_LABEL =
"dependencies"
DEFAULT_SECURITY_LABEL =
"security"

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.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 53

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.



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

def package_manager_labels
  @package_manager_labels
end

Class Method Details

.label_details_for_package_manager(package_manager) ⇒ Object



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

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



36
37
38
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 36

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

Instance Method Details

#create_default_labels_if_requiredObject



66
67
68
69
70
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 66

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 83

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"

  T.unsafe(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



73
74
75
76
77
78
79
80
# File 'lib/dependabot/pull_request_creator/labeler.rb', line 73

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