Skip to content

Commit

Permalink
Merge pull request #8730 from dependabot/jamiemagee/strong-type-pull-…
Browse files Browse the repository at this point in the history
…request-updater

Strong type `Dependabot::PullRequestUpdater`
  • Loading branch information
bdragon committed Jan 11, 2024
2 parents 3e69bde + 5fa17f4 commit e7698c0
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions common/lib/dependabot/pull_request_updater.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
# typed: true
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"
require "dependabot/pull_request_updater/github"
require "dependabot/pull_request_updater/gitlab"
require "dependabot/pull_request_updater/azure"

module Dependabot
class PullRequestUpdater
extend T::Sig

class BranchProtected < StandardError; end

attr_reader :source, :files, :base_commit, :old_commit, :credentials,
:pull_request_number, :author_details, :signature_key, :provider_metadata
sig { returns(Dependabot::Source) }
attr_reader :source

sig { returns(T::Array[Dependabot::DependencyFile]) }
attr_reader :files

sig { returns(String) }
attr_reader :base_commit

sig { returns(String) }
attr_reader :old_commit

sig { returns(T::Array[T::Hash[String, String]]) }
attr_reader :credentials

sig { returns(Integer) }
attr_reader :pull_request_number

sig { returns(T.nilable(T::Hash[Symbol, String])) }
attr_reader :author_details

sig { returns(T.nilable(String)) }
attr_reader :signature_key

sig { returns(T::Hash[Symbol, T.untyped]) }
attr_reader :provider_metadata

sig do
params(
source: Dependabot::Source,
base_commit: String,
old_commit: String,
files: T::Array[Dependabot::DependencyFile],
credentials: T::Array[T::Hash[String, String]],
pull_request_number: Integer,
author_details: T.nilable(T::Hash[Symbol, String]),
signature_key: T.nilable(String),
provider_metadata: T::Hash[Symbol, T.untyped]
)
.void
end
def initialize(source:, base_commit:, old_commit:, files:,
credentials:, pull_request_number:,
author_details: nil, signature_key: nil,
Expand All @@ -27,6 +68,9 @@ def initialize(source:, base_commit:, old_commit:, files:,
@provider_metadata = provider_metadata
end

# TODO: Each implementation returns a client-specific type.
# We should standardise this to return a `Dependabot::Branch` type instead.
sig { returns(T.untyped) }
def update
case source.provider
when "github" then github_updater.update
Expand All @@ -38,6 +82,7 @@ def update

private

sig { returns(Dependabot::PullRequestUpdater::Github) }
def github_updater
Github.new(
source: source,
Expand All @@ -51,6 +96,7 @@ def github_updater
)
end

sig { returns(Dependabot::PullRequestUpdater::Gitlab) }
def gitlab_updater
Gitlab.new(
source: source,
Expand All @@ -63,6 +109,7 @@ def gitlab_updater
)
end

sig { returns(Dependabot::PullRequestUpdater::Azure) }
def azure_updater
Azure.new(
source: source,
Expand Down

0 comments on commit e7698c0

Please sign in to comment.