dependabot-common 0.239.0 → 0.241.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05ce845694a06ef06ec108aada0ff902b7b08a7a8fc41c23531e00b2252436ae
4
- data.tar.gz: 72cc39025cf3a411bed2f82d113474dae965e57c06b15d1abe78f93794562c8c
3
+ metadata.gz: 5b381e33a32a95b7956fbcff6abec4736f2f190b4c8ab0eece99a2181037f52e
4
+ data.tar.gz: 5006821762970d60de1f3682cd1931f9e86cd0d44d8b9d5ec6eb7778a3bf329a
5
5
  SHA512:
6
- metadata.gz: ee1859d83b60cf7ddeab1b98c04666198da262a86c5875ed6ff586c9637c877075d9687b3657f38e0bcbf5669584d545a790a2c68e82e9499e5c30b4353d9890
7
- data.tar.gz: c4f99509fbd5846a9d07caa227cc67152933da70bea50246c1d6fe20ab9fc67cbb6d141753b89a4b7ed08bf9a73e4520a3c738fa33f4169ea5a19225db9698c6
6
+ metadata.gz: 4d8272f9614610836187d6a34fc20acd78b0326d8759d633afc7879492f9edffc3189d148e643750f0f47c1fec54071545ff7d2981499f82c8273addb527fc36
7
+ data.tar.gz: 4248ef1d9c5dce4afad397af2b557e8414a673d48351924255be59d211a0538b6f98ac73ce4f75458168379301be42c0b9a03517266ac6de8d2205346e95a8d3
@@ -1,30 +1,37 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
4
5
  require "dependabot/file_fetchers/base"
5
6
  require "dependabot/config/file"
6
7
 
7
8
  module Dependabot
8
9
  module Config
9
10
  class FileFetcher < FileFetchers::Base
10
- CONFIG_FILE_PATHS = %w(.github/dependabot.yml .github/dependabot.yaml).freeze
11
+ extend T::Sig
11
12
 
13
+ CONFIG_FILE_PATHS = T.let(%w(.github/dependabot.yml .github/dependabot.yaml).freeze, T::Array[String])
14
+
15
+ sig { override.params(filenames: T::Array[String]).returns(T::Boolean) }
12
16
  def self.required_files_in?(filenames)
13
17
  CONFIG_FILE_PATHS.any? { |file| filenames.include?(file) }
14
18
  end
15
19
 
20
+ sig { override.returns(String) }
16
21
  def self.required_files_message
17
22
  "Repo must contain either a #{CONFIG_FILE_PATHS.join(' or a ')} file"
18
23
  end
19
24
 
25
+ sig { returns(T.nilable(Dependabot::DependencyFile)) }
20
26
  def config_file
21
- @config_file ||= files.first
27
+ @config_file ||= T.let(files.first, T.nilable(Dependabot::DependencyFile))
22
28
  end
23
29
 
24
30
  private
25
31
 
32
+ sig { override.returns(T::Array[Dependabot::DependencyFile]) }
26
33
  def fetch_files
27
- fetched_files = []
34
+ fetched_files = T.let([], T::Array[Dependabot::DependencyFile])
28
35
 
29
36
  CONFIG_FILE_PATHS.each do |file|
30
37
  fn = Pathname.new("/#{file}").relative_path_from(directory)
@@ -143,7 +143,7 @@ module Dependabot
143
143
  def numeric_version
144
144
  return unless version && version_class.correct?(version)
145
145
 
146
- @numeric_version ||= T.let(version_class.new(version), T.nilable(Dependabot::Version))
146
+ @numeric_version ||= T.let(version_class.new(T.must(version)), T.nilable(Dependabot::Version))
147
147
  end
148
148
 
149
149
  sig { returns(T::Hash[String, T.untyped]) }
@@ -300,7 +300,7 @@ module Dependabot
300
300
  requirements.select { |r| requirement_class.new(r[:requirement]).specific? }
301
301
  end
302
302
 
303
- sig { returns(T.class_of(Gem::Requirement)) }
303
+ sig { returns(T.class_of(Dependabot::Requirement)) }
304
304
  def requirement_class
305
305
  Utils.requirement_class_for_package_manager(package_manager)
306
306
  end
@@ -14,6 +14,8 @@ module Dependabot
14
14
  sig { returns(T.nilable(String)) }
15
15
  attr_accessor :content
16
16
 
17
+ # This is the directory of the job source, not the directory of the file itself.
18
+ # The name actually contains the relative path from the job directory.
17
19
  sig { returns(String) }
18
20
  attr_accessor :directory
19
21
 
@@ -38,11 +40,6 @@ module Dependabot
38
40
  sig { returns(T.nilable(String)) }
39
41
  attr_accessor :mode
40
42
 
41
- # The directory that this file was fetched for. This is useful for multi-directory
42
- # updates, where a set of files that are related to each other are updated together.
43
- sig { returns(T.nilable(String)) }
44
- attr_accessor :job_directory
45
-
46
43
  class ContentEncoding
47
44
  UTF_8 = "utf-8"
48
45
  BASE64 = "base64"
@@ -71,15 +68,14 @@ module Dependabot
71
68
  content_encoding: String,
72
69
  deleted: T::Boolean,
73
70
  operation: String,
74
- mode: T.nilable(String),
75
- job_directory: T.nilable(String)
71
+ mode: T.nilable(String)
76
72
  )
77
73
  .void
78
74
  end
79
75
  def initialize(name:, content:, directory: "/", type: "file",
80
76
  support_file: false, vendored_file: false, symlink_target: nil,
81
77
  content_encoding: ContentEncoding::UTF_8, deleted: false,
82
- operation: Operation::UPDATE, mode: nil, job_directory: nil)
78
+ operation: Operation::UPDATE, mode: nil)
83
79
  @name = name
84
80
  @content = content
85
81
  @directory = T.let(clean_directory(directory), String)
@@ -88,7 +84,6 @@ module Dependabot
88
84
  @vendored_file = vendored_file
89
85
  @content_encoding = content_encoding
90
86
  @operation = operation
91
- @job_directory = job_directory
92
87
 
93
88
  # Make deleted override the operation. Deleted is kept when operation
94
89
  # was introduced to keep compatibility with downstream dependants.
@@ -127,7 +122,6 @@ module Dependabot
127
122
  "mode" => mode
128
123
  }
129
124
 
130
- details["job_directory"] = job_directory if job_directory
131
125
  details["symlink_target"] = symlink_target if symlink_target
132
126
  details
133
127
  end
@@ -52,11 +52,15 @@ module Dependabot
52
52
  /^fatal: clone of '(?<url>.*)' into submodule path '.*' failed$/
53
53
  GIT_SUBMODULE_ERROR_REGEX = /(#{GIT_SUBMODULE_INACCESSIBLE_ERROR})|(#{GIT_SUBMODULE_CLONE_ERROR})/
54
54
 
55
- sig { abstract.params(filenames: T::Array[String]).returns(T::Boolean) }
56
- def self.required_files_in?(filenames); end
55
+ sig { overridable.params(filenames: T::Array[String]).returns(T::Boolean) }
56
+ def self.required_files_in?(filenames)
57
+ filenames.any?
58
+ end
57
59
 
58
- sig { abstract.returns(String) }
59
- def self.required_files_message; end
60
+ sig { overridable.returns(String) }
61
+ def self.required_files_message
62
+ "Required files are missing from configured directory"
63
+ end
60
64
 
61
65
  # Creates a new FileFetcher for retrieving `DependencyFile`s.
62
66
  #
@@ -85,6 +89,8 @@ module Dependabot
85
89
  @linked_paths = T.let({}, T::Hash[T.untyped, T.untyped])
86
90
  @submodules = T.let([], T::Array[T.untyped])
87
91
  @options = options
92
+
93
+ @files = T.let([], T::Array[DependencyFile])
88
94
  end
89
95
 
90
96
  sig { returns(String) }
@@ -104,10 +110,16 @@ module Dependabot
104
110
 
105
111
  sig { returns(T::Array[DependencyFile]) }
106
112
  def files
107
- @files ||= T.let(
108
- fetch_files.each { |f| f.job_directory = directory },
109
- T.nilable(T::Array[DependencyFile])
110
- )
113
+ return @files if @files.any?
114
+
115
+ files = fetch_files.compact
116
+ raise Dependabot::DependencyFileNotFound.new(nil, "No files found in #{directory}") unless files.any?
117
+
118
+ unless self.class.required_files_in?(files.map(&:name))
119
+ raise DependencyFileNotFound.new(nil, self.class.required_files_message)
120
+ end
121
+
122
+ @files = files
111
123
  end
112
124
 
113
125
  sig { abstract.returns(T::Array[DependencyFile]) }
@@ -1,12 +1,43 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  module Dependabot
5
7
  module FileParsers
6
8
  class Base
7
- attr_reader :dependency_files, :repo_contents_path, :credentials, :source, :options
9
+ extend T::Sig
10
+ extend T::Helpers
11
+
12
+ abstract!
13
+
14
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
15
+ attr_reader :dependency_files
16
+
17
+ sig { returns(T.nilable(String)) }
18
+ attr_reader :repo_contents_path
19
+
20
+ sig { returns(T::Array[T::Hash[String, String]]) }
21
+ attr_reader :credentials
8
22
 
9
- def initialize(dependency_files:, repo_contents_path: nil, source:,
23
+ sig { returns(T.nilable(Dependabot::Source)) }
24
+ attr_reader :source
25
+
26
+ sig { returns(T::Hash[Symbol, T.untyped]) }
27
+ attr_reader :options
28
+
29
+ sig do
30
+ params(
31
+ dependency_files: T::Array[Dependabot::DependencyFile],
32
+ source: T.nilable(Dependabot::Source),
33
+ repo_contents_path: T.nilable(String),
34
+ credentials: T::Array[T::Hash[String, String]],
35
+ reject_external_code: T::Boolean,
36
+ options: T::Hash[Symbol, T.untyped]
37
+ )
38
+ .void
39
+ end
40
+ def initialize(dependency_files:, source:, repo_contents_path: nil,
10
41
  credentials: [], reject_external_code: false, options: {})
11
42
  @dependency_files = dependency_files
12
43
  @repo_contents_path = repo_contents_path
@@ -18,16 +49,15 @@ module Dependabot
18
49
  check_required_files
19
50
  end
20
51
 
21
- def parse
22
- raise NotImplementedError
23
- end
52
+ sig { abstract.returns(Dependabot::DependencyFile) }
53
+ def parse; end
24
54
 
25
55
  private
26
56
 
27
- def check_required_files
28
- raise NotImplementedError
29
- end
57
+ sig { abstract.void }
58
+ def check_required_files; end
30
59
 
60
+ sig { params(filename: String).returns(T.nilable(Dependabot::DependencyFile)) }
31
61
  def get_original_file(filename)
32
62
  dependency_files.find { |f| f.name == filename }
33
63
  end