dependabot-common 0.120.2 → 0.121.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dependabot-common might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83263fa7e5a3d1dbd38624d9476cab98b226ef442af42cd6e9324dcb61226476
4
- data.tar.gz: a47175b2fb55cb804e95a1f438f21de893f73b3921b319bcb296e3ff7f0397da
3
+ metadata.gz: 25ecba430a3c4e0437ca444e4ac4ea59341370f1fcc9bf5732aa404ed2c76435
4
+ data.tar.gz: a5d4c9744bf13f271136c1a307cf04207a7ccc6273d0b52025361d57eb32482f
5
5
  SHA512:
6
- metadata.gz: c04da188b4d2914b86db40c0640074d45010ce6f0834117b3b6b9faf6371893af47bafd643b4d905a5db2f853c21e3c6cc8c40df38659b93281299820fb6b812
7
- data.tar.gz: f6e8639ddfc7ffdd50926c3f32e1087076f3e66ad915eb074663669537b37b993df346dda6fc35144e0fd02aedba423b609e5d6eb596d35ecc67cace0c2c12f7
6
+ metadata.gz: fd41873f07384bf578d3431471deb14ef57601e48e6a326a68a2d1bcc02cd7de504c02f26e94218591bc8e1536fb0aba030ccb15777bb9e66afb59a0f43a2cb4
7
+ data.tar.gz: 200b360a032a55d421b903bc62f6285f11650b82a9bcaf366c2842821eaff2c31337ea93cc6a6ca52569065aa1dc0b5ec9bc6309378a1c10ecb619f517c4b808
@@ -14,7 +14,7 @@ require "dependabot/shared_helpers"
14
14
  module Dependabot
15
15
  module FileFetchers
16
16
  class Base
17
- attr_reader :source, :credentials
17
+ attr_reader :source, :credentials, :repo_contents_path
18
18
 
19
19
  CLIENT_NOT_FOUND_ERRORS = [
20
20
  Octokit::NotFound,
@@ -32,10 +32,19 @@ module Dependabot
32
32
  raise NotImplementedError
33
33
  end
34
34
 
35
- def initialize(source:, credentials:)
35
+ # Creates a new FileFetcher for retrieving `DependencyFile`s.
36
+ #
37
+ # Files are typically grabbed individually via the source's API.
38
+ # repo_contents_path is an optional empty directory that will be used
39
+ # to clone the entire source repository on first read.
40
+ #
41
+ # If provided, file _data_ will be loaded from the clone.
42
+ # Submodules and directory listings are _not_ currently supported
43
+ # by repo_contents_path and still use an API trip.
44
+ def initialize(source:, credentials:, repo_contents_path: nil)
36
45
  @source = source
37
46
  @credentials = credentials
38
-
47
+ @repo_contents_path = repo_contents_path
39
48
  @linked_paths = {}
40
49
  end
41
50
 
@@ -68,14 +77,24 @@ module Dependabot
68
77
  end
69
78
 
70
79
  # Returns the path to the cloned repo
71
- def clone_repo_contents(target_directory: nil)
80
+ def clone_repo_contents
72
81
  @clone_repo_contents ||=
73
- _clone_repo_contents(target_directory: target_directory)
82
+ _clone_repo_contents(target_directory: repo_contents_path)
83
+ rescue Dependabot::SharedHelpers::HelperSubprocessFailed
84
+ raise Dependabot::RepoNotFound, source
74
85
  end
75
86
 
76
87
  private
77
88
 
78
89
  def fetch_file_if_present(filename, fetch_submodules: false)
90
+ unless repo_contents_path.nil?
91
+ begin
92
+ return load_cloned_file_if_present(filename)
93
+ rescue Dependabot::DependencyFileNotFound
94
+ return
95
+ end
96
+ end
97
+
79
98
  dir = File.dirname(filename)
80
99
  basename = File.basename(filename)
81
100
 
@@ -91,7 +110,35 @@ module Dependabot
91
110
  raise Dependabot::DependencyFileNotFound, path
92
111
  end
93
112
 
113
+ def load_cloned_file_if_present(filename)
114
+ path = Pathname.new(File.join(directory, filename)).cleanpath.to_path
115
+ repo_path = File.join(clone_repo_contents, path)
116
+ unless File.exist?(repo_path)
117
+ raise Dependabot::DependencyFileNotFound, path
118
+ end
119
+
120
+ content = File.read(repo_path)
121
+ type = if File.symlink?(repo_path)
122
+ symlink_target = File.readlink(repo_path)
123
+ "symlink"
124
+ else
125
+ "file"
126
+ end
127
+
128
+ DependencyFile.new(
129
+ name: Pathname.new(filename).cleanpath.to_path,
130
+ directory: directory,
131
+ type: type,
132
+ content: content,
133
+ symlink_target: symlink_target
134
+ )
135
+ end
136
+
94
137
  def fetch_file_from_host(filename, type: "file", fetch_submodules: false)
138
+ unless repo_contents_path.nil?
139
+ return load_cloned_file_if_present(filename)
140
+ end
141
+
95
142
  path = Pathname.new(File.join(directory, filename)).cleanpath.to_path
96
143
  content = _fetch_file_content(path, fetch_submodules: fetch_submodules)
97
144
  type = @linked_paths.key?(path.gsub(%r{^/}, "")) ? "symlink" : type
@@ -4,18 +4,19 @@ module Dependabot
4
4
  module FileUpdaters
5
5
  class Base
6
6
  attr_reader :dependencies, :dependency_files, :repo_contents_path,
7
- :credentials
7
+ :credentials, :options
8
8
 
9
9
  def self.updated_files_regex
10
10
  raise NotImplementedError
11
11
  end
12
12
 
13
13
  def initialize(dependencies:, dependency_files:, repo_contents_path: nil,
14
- credentials:)
14
+ credentials:, options: {})
15
15
  @dependencies = dependencies
16
16
  @dependency_files = dependency_files
17
17
  @repo_contents_path = repo_contents_path
18
18
  @credentials = credentials
19
+ @options = options
19
20
 
20
21
  check_required_files
21
22
  end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dependabot/dependency_file"
4
+
5
+ module Dependabot
6
+ module FileUpdaters
7
+ class VendorUpdater
8
+ # notable filenames without a reliable extension:
9
+ TEXT_FILE_NAMES = [
10
+ "README",
11
+ "LICENSE",
12
+ "Gemfile",
13
+ "Gemfile.lock",
14
+ ".bundlecache",
15
+ ".gitignore"
16
+ ].freeze
17
+
18
+ TEXT_FILE_EXTS = [
19
+ # code
20
+ ".rb",
21
+ ".erb",
22
+ ".gemspec",
23
+ ".js",
24
+ ".html",
25
+ # config
26
+ ".json",
27
+ ".xml",
28
+ ".toml",
29
+ ".yaml",
30
+ ".yml",
31
+ # docs
32
+ ".md",
33
+ ".txt",
34
+ ".go"
35
+ ].freeze
36
+
37
+ def initialize(repo_contents_path:, vendor_dir:)
38
+ @repo_contents_path = repo_contents_path
39
+ @vendor_dir = vendor_dir
40
+ end
41
+
42
+ # Returns changed files in the vendor/cache folder
43
+ #
44
+ # @param base_directory [String] Update config base directory
45
+ # @return [Array<Dependabot::DependencyFile>]
46
+ def updated_vendor_cache_files(base_directory:)
47
+ return [] unless repo_contents_path && vendor_dir
48
+
49
+ Dir.chdir(repo_contents_path) do
50
+ relative_dir = vendor_dir.sub("#{repo_contents_path}/", "")
51
+ status = SharedHelpers.run_shell_command(
52
+ "git status --untracked-files=all --porcelain=v1 #{relative_dir}"
53
+ )
54
+ changed_paths = status.split("\n").map { |l| l.split(" ") }
55
+ changed_paths.map do |type, path|
56
+ deleted = type == "D"
57
+ encoding = ""
58
+ encoded_content = File.read(path) unless deleted
59
+ if binary_file?(path)
60
+ encoding = Dependabot::DependencyFile::ContentEncoding::BASE64
61
+ encoded_content = Base64.encode64(encoded_content) unless deleted
62
+ end
63
+ Dependabot::DependencyFile.new(
64
+ name: path,
65
+ content: encoded_content,
66
+ directory: base_directory,
67
+ deleted: deleted,
68
+ content_encoding: encoding
69
+ )
70
+ end
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ attr_reader :repo_contents_path, :vendor_dir
77
+
78
+ def binary_file?(path)
79
+ return false if TEXT_FILE_NAMES.include?(File.basename(path))
80
+ return false if TEXT_FILE_EXTS.include?(File.extname(path))
81
+
82
+ true
83
+ end
84
+ end
85
+ end
86
+ end
@@ -8,6 +8,8 @@ require "digest"
8
8
  require "open3"
9
9
  require "shellwords"
10
10
 
11
+ require "dependabot/version"
12
+
11
13
  module Dependabot
12
14
  module SharedHelpers
13
15
  BUMP_TMP_FILE_PREFIX = "dependabot_"
@@ -151,13 +153,14 @@ module Dependabot
151
153
 
152
154
  def self.excon_defaults(options = nil)
153
155
  options ||= {}
156
+ headers = options.delete(:headers)
154
157
  {
155
158
  connect_timeout: 5,
156
159
  write_timeout: 5,
157
160
  read_timeout: 20,
158
161
  omit_default_port: true,
159
162
  middlewares: excon_middleware,
160
- headers: excon_headers(options[:headers])
163
+ headers: excon_headers(headers)
161
164
  }.merge(options)
162
165
  end
163
166
 
@@ -29,5 +29,15 @@ module Dependabot
29
29
  def self.register_requirement_class(package_manager, requirement_class)
30
30
  @requirement_classes[package_manager] = requirement_class
31
31
  end
32
+
33
+ @cloning_package_managers = Set[]
34
+
35
+ def self.always_clone_for_package_manager?(package_manager)
36
+ @cloning_package_managers.include?(package_manager)
37
+ end
38
+
39
+ def self.register_always_clone(package_manager)
40
+ @cloning_package_managers << package_manager
41
+ end
32
42
  end
33
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.120.2"
4
+ VERSION = "0.121.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.120.2
4
+ version: 0.121.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-codecommit
@@ -292,14 +292,14 @@ dependencies:
292
292
  requirements:
293
293
  - - "~>"
294
294
  - !ruby/object:Gem::Version
295
- version: 0.91.0
295
+ version: 0.92.0
296
296
  type: :development
297
297
  prerelease: false
298
298
  version_requirements: !ruby/object:Gem::Requirement
299
299
  requirements:
300
300
  - - "~>"
301
301
  - !ruby/object:Gem::Version
302
- version: 0.91.0
302
+ version: 0.92.0
303
303
  - !ruby/object:Gem::Dependency
304
304
  name: vcr
305
305
  requirement: !ruby/object:Gem::Requirement
@@ -356,6 +356,7 @@ files:
356
356
  - lib/dependabot/file_updaters.rb
357
357
  - lib/dependabot/file_updaters/README.md
358
358
  - lib/dependabot/file_updaters/base.rb
359
+ - lib/dependabot/file_updaters/vendor_updater.rb
359
360
  - lib/dependabot/git_commit_checker.rb
360
361
  - lib/dependabot/git_metadata_fetcher.rb
361
362
  - lib/dependabot/metadata_finders.rb