dependabot-go_modules 0.143.6 → 0.144.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f7da85db7e862802674637b2eb899ef4152e6689f21cf02c11e58413575e54a
4
- data.tar.gz: 2893d638801caff1e75ea27fd8d54e11f64aea4cb4430ca1ae035662ed3a6d36
3
+ metadata.gz: 2505607e3f2717b5a8cb513b12801baa4ff1ff575e1a3a54ae21724ab1f1353d
4
+ data.tar.gz: fbac460701747cdeacd631163234633ea5d8e5779d3c8dc78e66f2721166d18d
5
5
  SHA512:
6
- metadata.gz: 6a600a27b41908437b8b4e6c0859843b4315f12d4a42eccb1d95f2fb471089ebf718ca508e368be9d09eaba53586e63254085738a6aa59641b28331db3b4cdd4
7
- data.tar.gz: 9243bdb791e8c652c78a12993ef6e5611ca5738a2e20f0885fd51456d5be5c42c463fa73e4dd99db4496f6ec7d915e956aee94d759b272584ad1bf641a3933c9
6
+ metadata.gz: 5ea7b06a9c99783e6cc6301ceda812b728b929a1a5fc5909c6654f1b1f17c030d630a5c0e6307a39cd5f0647bb2866e6261e95e9e79d2d279f009abf803e72e9
7
+ data.tar.gz: 18b9e5f44a0f99612f53579abadc77b25b71621dfea5867b1b59f7452657e65c100990ae12ebc0b9ff27f19803260cfb667d9cd9194acb41f8fdb92f9351f786
@@ -4,6 +4,7 @@ require "open3"
4
4
  require "dependabot/dependency"
5
5
  require "dependabot/file_parsers/base/dependency_set"
6
6
  require "dependabot/go_modules/path_converter"
7
+ require "dependabot/go_modules/replace_stubber"
7
8
  require "dependabot/errors"
8
9
  require "dependabot/file_parsers"
9
10
  require "dependabot/file_parsers/base"
@@ -17,7 +18,7 @@ module Dependabot
17
18
  dependency_set = Dependabot::FileParsers::Base::DependencySet.new
18
19
 
19
20
  required_packages.each do |dep|
20
- dependency_set << dependency_from_details(dep) unless dep["Indirect"]
21
+ dependency_set << dependency_from_details(dep) unless skip_dependency?(dep)
21
22
  end
22
23
 
23
24
  dependency_set.dependencies
@@ -109,11 +110,8 @@ module Dependabot
109
110
  # we can use in their place. Using generated paths is safer as it
110
111
  # means we don't need to worry about references to parent
111
112
  # directories, etc.
112
- (JSON.parse(stdout)["Replace"] || []).
113
- map { |r| r["New"]["Path"] }.
114
- compact.
115
- select { |p| p.start_with?(".") || p.start_with?("/") }.
116
- map { |p| [p, "./" + Digest::SHA2.hexdigest(p)] }
113
+ manifest = JSON.parse(stdout)
114
+ ReplaceStubber.new(repo_contents_path).stub_paths(manifest, go_mod.directory)
117
115
  end
118
116
  end
119
117
 
@@ -163,6 +161,17 @@ module Dependabot
163
161
 
164
162
  raw_version.match(GIT_VERSION_REGEX).named_captures.fetch("sha")
165
163
  end
164
+
165
+ def skip_dependency?(dep)
166
+ return true if dep["Indirect"]
167
+
168
+ begin
169
+ path_uri = URI.parse("https://#{dep['Path']}")
170
+ !path_uri.host.include?(".")
171
+ rescue URI::InvalidURIError
172
+ false
173
+ end
174
+ end
166
175
  end
167
176
  end
168
177
  end
@@ -4,6 +4,7 @@ require "dependabot/shared_helpers"
4
4
  require "dependabot/errors"
5
5
  require "dependabot/go_modules/file_updater"
6
6
  require "dependabot/go_modules/native_helpers"
7
+ require "dependabot/go_modules/replace_stubber"
7
8
  require "dependabot/go_modules/resolvability_errors"
8
9
 
9
10
  module Dependabot
@@ -222,37 +223,8 @@ module Dependabot
222
223
  # process afterwards.
223
224
  def replace_directive_substitutions(manifest)
224
225
  @replace_directive_substitutions ||=
225
- (manifest["Replace"] || []).
226
- map { |r| r["New"]["Path"] }.
227
- compact.
228
- select { |p| stub_replace_path?(p) }.
229
- map { |p| [p, "./" + Digest::SHA2.hexdigest(p)] }.
230
- to_h
231
- end
232
-
233
- # returns true if the provided path should be replaced with a stub
234
- def stub_replace_path?(path)
235
- return true if absolute_path?(path)
236
- return false unless relative_replacement_path?(path)
237
-
238
- resolved_path = module_pathname.join(path).realpath
239
- inside_repo_contents_path = resolved_path.to_s.start_with?(repo_contents_path.to_s)
240
- !inside_repo_contents_path
241
- rescue Errno::ENOENT
242
- true
243
- end
244
-
245
- def absolute_path?(path)
246
- path.start_with?("/")
247
- end
248
-
249
- def relative_replacement_path?(path)
250
- # https://golang.org/ref/mod#go-mod-file-replace
251
- path.start_with?("./") || path.start_with?("../")
252
- end
253
-
254
- def module_pathname
255
- @module_pathname ||= Pathname.new(repo_contents_path).join(directory.sub(%r{^/}, ""))
226
+ Dependabot::GoModules::ReplaceStubber.new(repo_contents_path).
227
+ stub_paths(manifest, directory)
256
228
  end
257
229
 
258
230
  def substitute_all(substitutions)
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ module GoModules
5
+ # Given a go.mod file, find all `replace` directives pointing to a path
6
+ # on the local filesystem outside of the current checkout, and return a hash
7
+ # mapping the original path to a hash of the path.
8
+ #
9
+ # This lets us substitute all parts of the go.mod that are dependent on
10
+ # the layout of the filesystem with a structure we can reproduce (i.e.
11
+ # no paths such as ../../../foo), run the Go tooling, then reverse the
12
+ # process afterwards.
13
+ class ReplaceStubber
14
+ def initialize(repo_contents_path)
15
+ @repo_contents_path = repo_contents_path
16
+ end
17
+
18
+ def stub_paths(manifest, directory)
19
+ (manifest["Replace"] || []).
20
+ map { |r| r["New"]["Path"] }.
21
+ compact.
22
+ select { |p| stub_replace_path?(p, directory) }.
23
+ map { |p| [p, "./" + Digest::SHA2.hexdigest(p)] }.
24
+ to_h
25
+ end
26
+
27
+ private
28
+
29
+ def stub_replace_path?(path, directory)
30
+ return true if absolute_path?(path)
31
+ return false unless relative_replacement_path?(path)
32
+ return true if @repo_contents_path.nil?
33
+
34
+ resolved_path = module_pathname(directory).join(path).realpath
35
+ inside_repo_contents_path = resolved_path.to_s.start_with?(@repo_contents_path.to_s)
36
+ !inside_repo_contents_path
37
+ rescue Errno::ENOENT
38
+ true
39
+ end
40
+
41
+ def absolute_path?(path)
42
+ path.start_with?("/")
43
+ end
44
+
45
+ def relative_replacement_path?(path)
46
+ # https://golang.org/ref/mod#go-mod-file-replace
47
+ path.start_with?("./") || path.start_with?("../")
48
+ end
49
+
50
+ def module_pathname(directory)
51
+ @module_pathname ||= Pathname.new(@repo_contents_path).join(directory.sub(%r{^/}, ""))
52
+ end
53
+ end
54
+ end
55
+ end
@@ -16,7 +16,8 @@ module Dependabot
16
16
  /no go-import meta tags/,
17
17
  # Package url 404s
18
18
  /404 Not Found/,
19
- /Repository not found/
19
+ /Repository not found/,
20
+ /unrecognized import path/
20
21
  ].freeze
21
22
 
22
23
  def latest_resolvable_version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-go_modules
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.143.6
4
+ version: 0.144.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dependabot-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.143.6
19
+ version: 0.144.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.143.6
26
+ version: 0.144.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +202,7 @@ files:
202
202
  - lib/dependabot/go_modules/metadata_finder.rb
203
203
  - lib/dependabot/go_modules/native_helpers.rb
204
204
  - lib/dependabot/go_modules/path_converter.rb
205
+ - lib/dependabot/go_modules/replace_stubber.rb
205
206
  - lib/dependabot/go_modules/requirement.rb
206
207
  - lib/dependabot/go_modules/resolvability_errors.rb
207
208
  - lib/dependabot/go_modules/update_checker.rb