Class: Dependabot::PullRequestCreator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/pull_request_creator.rb,
lib/dependabot/pull_request_creator/azure.rb,
lib/dependabot/pull_request_creator/github.rb,
lib/dependabot/pull_request_creator/gitlab.rb,
lib/dependabot/pull_request_creator/labeler.rb,
lib/dependabot/pull_request_creator/message.rb,
lib/dependabot/pull_request_creator/bitbucket.rb,
lib/dependabot/pull_request_creator/codecommit.rb,
lib/dependabot/pull_request_creator/branch_namer.rb,
lib/dependabot/pull_request_creator/commit_signer.rb,
lib/dependabot/pull_request_creator/message_builder.rb,
lib/dependabot/pull_request_creator/pr_name_prefixer.rb,
lib/dependabot/pull_request_creator/branch_namer/base.rb,
lib/dependabot/pull_request_creator/branch_namer/solo_strategy.rb,
lib/dependabot/pull_request_creator/message_builder/issue_linker.rb,
lib/dependabot/pull_request_creator/message_builder/metadata_presenter.rb,
lib/dependabot/pull_request_creator/branch_namer/multi_ecosystem_strategy.rb,
lib/dependabot/pull_request_creator/branch_namer/dependency_group_strategy.rb,
lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb

Overview

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: AnnotationError, Azure, BaseCommitNotUpToDate, Bitbucket, BranchAlreadyExists, BranchNamer, Codecommit, CommitSigner, Github, Gitlab, Labeler, Message, MessageBuilder, NoHistoryInCommon, PrNamePrefixer, RepoArchived, RepoDisabled, RepoNotFound, UnexpectedError, UnmergedPRExists

Constant Summary collapse

DEFAULT_GITHUB_REDIRECTION_SERVICE =

Dependabot programmatically creates PRs which often include a large number of links to objects on ‘github.com`. GitHub hydrates these into rich links that leave a ’mention’ on target Issues/Pull Requests.

Due to the volume and nature of Dependabot PRs, these mentions are not useful and can overwhelm maintainers, so we use a redirection service to avoid enrichment.

If you wish to disable this behaviour when using Dependabot Core directly, pass a nil value when initialising this class.

"redirect.github.com"
AzureReviewers =
T.type_alias { T.nilable(T::Array[String]) }
GithubReviewers =
T.type_alias { T.nilable(T::Hash[String, T::Array[String]]) }
GitLabReviewers =
T.type_alias { T.nilable(T::Hash[Symbol, T::Array[Integer]]) }
Reviewers =
T.type_alias { T.any(AzureReviewers, GithubReviewers, GitLabReviewers) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, base_commit:, dependencies:, files:, credentials:, pr_message_header: nil, pr_message_footer: nil, custom_labels: nil, author_details: nil, signature_key: nil, commit_message_options: {}, vulnerabilities_fixed: {}, reviewers: nil, assignees: nil, milestone: nil, branch_name_separator: "/", branch_name_prefix: "dependabot", branch_name_max_length: nil, label_language: false, automerge_candidate: false, github_redirection_service: DEFAULT_GITHUB_REDIRECTION_SERVICE, custom_headers: nil, require_up_to_date_base: false, provider_metadata: {}, message: nil, dependency_group: nil, pr_message_max_length: nil, pr_message_encoding: nil) ⇒ PullRequestCreator

Returns a new instance of PullRequestCreator.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/dependabot/pull_request_creator.rb', line 182

def initialize(
  source:,
  base_commit:,
  dependencies:,
  files:,
  credentials:,
  pr_message_header: nil,
  pr_message_footer: nil,
  custom_labels: nil,
  author_details: nil,
  signature_key: nil,
  commit_message_options: {},
  vulnerabilities_fixed: {},
  reviewers: nil,
  assignees: nil,
  milestone: nil,
  branch_name_separator: "/",
  branch_name_prefix: "dependabot",
  branch_name_max_length: nil,
  label_language: false,
  automerge_candidate: false,
  github_redirection_service: DEFAULT_GITHUB_REDIRECTION_SERVICE,
  custom_headers: nil,
  require_up_to_date_base: false,
  provider_metadata: {},
  message: nil,
  dependency_group: nil,
  pr_message_max_length: nil,
  pr_message_encoding: nil
)
  @dependencies               = dependencies
  @source                     = source
  @base_commit                = base_commit
  @files                      = files
  @credentials                = credentials
  @pr_message_header          = pr_message_header
  @pr_message_footer          = pr_message_footer
  @author_details             = author_details
  @signature_key              = signature_key
  @commit_message_options     = commit_message_options
  @custom_labels              = custom_labels
  @reviewers                  = reviewers
  @assignees                  = assignees
  @milestone                  = milestone
  @vulnerabilities_fixed      = vulnerabilities_fixed
  @branch_name_separator      = branch_name_separator
  @branch_name_prefix         = branch_name_prefix
  @branch_name_max_length     = branch_name_max_length
  @label_language             = label_language
  @automerge_candidate        = automerge_candidate
  @github_redirection_service = github_redirection_service
  @custom_headers             = custom_headers
  @require_up_to_date_base    = require_up_to_date_base
  @provider_metadata          = 
  @message                    = message
  @dependency_group           = dependency_group
  @pr_message_max_length      = pr_message_max_length
  @pr_message_encoding        = pr_message_encoding

  check_dependencies_have_previous_version
end

Instance Attribute Details

#assigneesObject (readonly)

Returns the value of attribute assignees.



115
116
117
# File 'lib/dependabot/pull_request_creator.rb', line 115

def assignees
  @assignees
end

#author_detailsObject (readonly)

Returns the value of attribute author_details.



95
96
97
# File 'lib/dependabot/pull_request_creator.rb', line 95

def author_details
  @author_details
end

#base_commitObject (readonly)

Returns the value of attribute base_commit.



80
81
82
# File 'lib/dependabot/pull_request_creator.rb', line 80

def base_commit
  @base_commit
end

#branch_name_max_lengthObject (readonly)

Returns the value of attribute branch_name_max_length.



127
128
129
# File 'lib/dependabot/pull_request_creator.rb', line 127

def branch_name_max_length
  @branch_name_max_length
end

#branch_name_prefixObject (readonly)

Returns the value of attribute branch_name_prefix.



124
125
126
# File 'lib/dependabot/pull_request_creator.rb', line 124

def branch_name_prefix
  @branch_name_prefix
end

#branch_name_separatorObject (readonly)

Returns the value of attribute branch_name_separator.



121
122
123
# File 'lib/dependabot/pull_request_creator.rb', line 121

def branch_name_separator
  @branch_name_separator
end

#commit_message_optionsObject (readonly)

Returns the value of attribute commit_message_options.



101
102
103
# File 'lib/dependabot/pull_request_creator.rb', line 101

def commit_message_options
  @commit_message_options
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



83
84
85
# File 'lib/dependabot/pull_request_creator.rb', line 83

def credentials
  @credentials
end

#custom_headersObject (readonly)

Returns the value of attribute custom_headers.



133
134
135
# File 'lib/dependabot/pull_request_creator.rb', line 133

def custom_headers
  @custom_headers
end

#custom_labelsObject (readonly)

Returns the value of attribute custom_labels.



92
93
94
# File 'lib/dependabot/pull_request_creator.rb', line 92

def custom_labels
  @custom_labels
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



74
75
76
# File 'lib/dependabot/pull_request_creator.rb', line 74

def dependencies
  @dependencies
end

#dependency_groupObject (readonly)

Returns the value of attribute dependency_group.



139
140
141
# File 'lib/dependabot/pull_request_creator.rb', line 139

def dependency_group
  @dependency_group
end

#filesObject (readonly)

Returns the value of attribute files.



77
78
79
# File 'lib/dependabot/pull_request_creator.rb', line 77

def files
  @files
end

#github_redirection_serviceObject (readonly)

Returns the value of attribute github_redirection_service.



130
131
132
# File 'lib/dependabot/pull_request_creator.rb', line 130

def github_redirection_service
  @github_redirection_service
end

#milestoneObject (readonly)

Returns the value of attribute milestone.



118
119
120
# File 'lib/dependabot/pull_request_creator.rb', line 118

def milestone
  @milestone
end

#pr_message_encodingObject (readonly)

Returns the value of attribute pr_message_encoding.



145
146
147
# File 'lib/dependabot/pull_request_creator.rb', line 145

def pr_message_encoding
  @pr_message_encoding
end

Returns the value of attribute pr_message_footer.



89
90
91
# File 'lib/dependabot/pull_request_creator.rb', line 89

def pr_message_footer
  @pr_message_footer
end

#pr_message_headerObject (readonly)

Returns the value of attribute pr_message_header.



86
87
88
# File 'lib/dependabot/pull_request_creator.rb', line 86

def pr_message_header
  @pr_message_header
end

#pr_message_max_lengthObject (readonly)

Returns the value of attribute pr_message_max_length.



142
143
144
# File 'lib/dependabot/pull_request_creator.rb', line 142

def pr_message_max_length
  @pr_message_max_length
end

#provider_metadataObject (readonly)

Returns the value of attribute provider_metadata.



136
137
138
# File 'lib/dependabot/pull_request_creator.rb', line 136

def 
  @provider_metadata
end

#reviewersObject (readonly)

Returns the value of attribute reviewers.



112
113
114
# File 'lib/dependabot/pull_request_creator.rb', line 112

def reviewers
  @reviewers
end

#signature_keyObject (readonly)

Returns the value of attribute signature_key.



98
99
100
# File 'lib/dependabot/pull_request_creator.rb', line 98

def signature_key
  @signature_key
end

#sourceObject (readonly)

Returns the value of attribute source.



71
72
73
# File 'lib/dependabot/pull_request_creator.rb', line 71

def source
  @source
end

#vulnerabilities_fixedObject (readonly)

Returns the value of attribute vulnerabilities_fixed.



104
105
106
# File 'lib/dependabot/pull_request_creator.rb', line 104

def vulnerabilities_fixed
  @vulnerabilities_fixed
end

Instance Method Details

#check_dependencies_have_previous_versionObject



245
246
247
248
249
250
251
# File 'lib/dependabot/pull_request_creator.rb', line 245

def check_dependencies_have_previous_version
  return if dependencies.all? { |d| requirements_changed?(d) }
  return if dependencies.all?(&:previous_version)

  raise "Dependencies must have a previous version or changed " \
        "requirement to have a pull request created for them!"
end

#createObject



257
258
259
260
261
262
263
264
265
266
# File 'lib/dependabot/pull_request_creator.rb', line 257

def create
  case source.provider
  when "github" then github_creator.create
  when "gitlab" then gitlab_creator.create
  when "azure" then azure_creator.create
  when "bitbucket" then bitbucket_creator.create
  when "codecommit" then codecommit_creator.create
  else raise "Unsupported provider #{source.provider}"
  end
end