forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull_request_updater.rb
125 lines (107 loc) · 3.54 KB
/
pull_request_updater.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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
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,
provider_metadata: {})
@source = source
@base_commit = base_commit
@old_commit = old_commit
@files = files
@credentials = credentials
@pull_request_number = pull_request_number
@author_details = author_details
@signature_key = signature_key
@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
when "gitlab" then gitlab_updater.update
when "azure" then azure_updater.update
else raise "Unsupported provider #{source.provider}"
end
end
private
sig { returns(Dependabot::PullRequestUpdater::Github) }
def github_updater
Github.new(
source: source,
base_commit: base_commit,
old_commit: old_commit,
files: files,
credentials: credentials,
pull_request_number: pull_request_number,
author_details: author_details,
signature_key: signature_key
)
end
sig { returns(Dependabot::PullRequestUpdater::Gitlab) }
def gitlab_updater
Gitlab.new(
source: source,
base_commit: base_commit,
old_commit: old_commit,
files: files,
credentials: credentials,
pull_request_number: pull_request_number,
target_project_id: provider_metadata[:target_project_id]
)
end
sig { returns(Dependabot::PullRequestUpdater::Azure) }
def azure_updater
Azure.new(
source: source,
base_commit: base_commit,
old_commit: old_commit,
files: files,
credentials: credentials,
pull_request_number: pull_request_number,
author_details: author_details
)
end
end
end