Class: Dependabot::PullRequestCreator

Inherits:
Object
  • Object
show all
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/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/message_builder/issue_linker.rb,
lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb

Defined Under Namespace

Classes: Azure, BranchNamer, CommitSigner, Github, Gitlab, Labeler, MessageBuilder, NoHistoryInCommon, PrNamePrefixer, RepoArchived, RepoNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, base_commit:, dependencies:, files:, credentials:, pr_message_footer: nil, custom_labels: nil, author_details: nil, signature_key: nil, commit_message_options: {}, reviewers: nil, assignees: nil, milestone: nil, vulnerabilities_fixed: {}, branch_name_separator: "/", branch_name_prefix: "dependabot", label_language: false, automerge_candidate: false, github_redirection_service: "github-redirect.dependabot.com", custom_headers: nil) ⇒ PullRequestCreator

Returns a new instance of PullRequestCreator.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dependabot/pull_request_creator.rb', line 26

def initialize(source:, base_commit:, dependencies:, files:, credentials:,
               pr_message_footer: nil, custom_labels: nil,
               author_details: nil, signature_key: nil,
               commit_message_options: {},
               reviewers: nil, assignees: nil, milestone: nil,
               vulnerabilities_fixed: {}, branch_name_separator: "/",
               branch_name_prefix: "dependabot",
               label_language: false, automerge_candidate: false,
               github_redirection_service: "github-redirect.dependabot.com",
               custom_headers: nil)
  @dependencies               = dependencies
  @source                     = source
  @base_commit                = base_commit
  @files                      = files
  @credentials                = credentials
  @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
  @label_language             = label_language
  @automerge_candidate        = automerge_candidate
  @github_redirection_service = github_redirection_service
  @custom_headers             = custom_headers

  check_dependencies_have_previous_version
end

Instance Attribute Details

#assigneesObject (readonly)

Returns the value of attribute assignees.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def assignees
  @assignees
end

#author_detailsObject (readonly)

Returns the value of attribute author_details.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def author_details
  @author_details
end

#base_commitObject (readonly)

Returns the value of attribute base_commit.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def base_commit
  @base_commit
end

#branch_name_prefixObject (readonly)

Returns the value of attribute branch_name_prefix.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def branch_name_prefix
  @branch_name_prefix
end

#branch_name_separatorObject (readonly)

Returns the value of attribute branch_name_separator.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def branch_name_separator
  @branch_name_separator
end

#commit_message_optionsObject (readonly)

Returns the value of attribute commit_message_options.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def commit_message_options
  @commit_message_options
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def credentials
  @credentials
end

#custom_headersObject (readonly)

Returns the value of attribute custom_headers.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def custom_headers
  @custom_headers
end

#custom_labelsObject (readonly)

Returns the value of attribute custom_labels.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def custom_labels
  @custom_labels
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def dependencies
  @dependencies
end

#filesObject (readonly)

Returns the value of attribute files.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def files
  @files
end

#github_redirection_serviceObject (readonly)

Returns the value of attribute github_redirection_service.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def github_redirection_service
  @github_redirection_service
end

#milestoneObject (readonly)

Returns the value of attribute milestone.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def milestone
  @milestone
end

Returns the value of attribute pr_message_footer.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def pr_message_footer
  @pr_message_footer
end

#reviewersObject (readonly)

Returns the value of attribute reviewers.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def reviewers
  @reviewers
end

#signature_keyObject (readonly)

Returns the value of attribute signature_key.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def signature_key
  @signature_key
end

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def source
  @source
end

#vulnerabilities_fixedObject (readonly)

Returns the value of attribute vulnerabilities_fixed.



18
19
20
# File 'lib/dependabot/pull_request_creator.rb', line 18

def vulnerabilities_fixed
  @vulnerabilities_fixed
end

Instance Method Details

#check_dependencies_have_previous_versionObject



60
61
62
63
64
65
66
# File 'lib/dependabot/pull_request_creator.rb', line 60

def check_dependencies_have_previous_version
  return if library? && 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



68
69
70
71
72
73
74
75
# File 'lib/dependabot/pull_request_creator.rb', line 68

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