dependabot-go_modules 0.143.2 → 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: a16d13912a07809eb337181e582a45bc828aa24c8fe8da113fad6d241387abf3
4
- data.tar.gz: c3835c430ff96912a51332a1bd30ff6bd21e1072f0ccd59eb471ae63b0b8e653
3
+ metadata.gz: 2505607e3f2717b5a8cb513b12801baa4ff1ff575e1a3a54ae21724ab1f1353d
4
+ data.tar.gz: fbac460701747cdeacd631163234633ea5d8e5779d3c8dc78e66f2721166d18d
5
5
  SHA512:
6
- metadata.gz: 75134c41a657013f42ec22494d6c73612af31862fef6afcba0e8d744f015482adbfd6f23d44772db0ed4370acd41d55f6952f22de1bb880db1233c76349bcb45
7
- data.tar.gz: 3795a50e41ad2108ca1a0ab06d3a307b4b819ed175a7b5a7afe5edd708c6950fff410ae17c53b06b96e06c82efdfa678ba1a2587a24c36a327a2d8c91a1389c6
6
+ metadata.gz: 5ea7b06a9c99783e6cc6301ceda812b728b929a1a5fc5909c6654f1b1f17c030d630a5c0e6307a39cd5f0647bb2866e6261e95e9e79d2d279f009abf803e72e9
7
+ data.tar.gz: 18b9e5f44a0f99612f53579abadc77b25b71621dfea5867b1b59f7452657e65c100990ae12ebc0b9ff27f19803260cfb667d9cd9194acb41f8fdb92f9351f786
data/helpers/Makefile CHANGED
@@ -3,7 +3,7 @@
3
3
  all: darwin linux
4
4
 
5
5
  darwin:
6
- GO111MODULE=on GOOS=darwin GOARCH=amd64 go build -o go-helpers.darwin64 .
6
+ GOOS=darwin GOARCH=amd64 go build -o go-helpers.darwin64 .
7
7
 
8
8
  linux:
9
- GO111MODULE=on GOOS=linux GOARCH=amd64 go build -o go-helpers.linux64 .
9
+ GOOS=linux GOARCH=amd64 go build -o go-helpers.linux64 .
data/helpers/build CHANGED
@@ -23,5 +23,5 @@ cd $helpers_dir
23
23
  os="$(uname -s | tr '[:upper:]' '[:lower:]')"
24
24
  echo "building $install_dir/bin/helper"
25
25
 
26
- GO111MODULE=on GOOS="$os" GOARCH=amd64 go build -o "$install_dir/bin/helper" .
27
- go clean -cache -modcache
26
+ GOOS="$os" GOARCH=amd64 go build -o "$install_dir/bin/helper" .
27
+ go clean -cache -modcache
data/helpers/go.mod CHANGED
@@ -1,16 +1,9 @@
1
1
  module github.com/dependabot/dependabot-core/go_modules/helpers
2
2
 
3
- go 1.13
3
+ go 1.16
4
4
 
5
5
  require (
6
6
  github.com/Masterminds/vcs v1.13.1
7
- github.com/dependabot/dependabot-core/go_modules/helpers/updater v0.0.0
8
7
  github.com/dependabot/gomodules-extracted v1.2.0
9
8
  golang.org/x/mod v0.4.2
10
9
  )
11
-
12
- replace github.com/dependabot/dependabot-core/go_modules/helpers/importresolver => ./importresolver
13
-
14
- replace github.com/dependabot/dependabot-core/go_modules/helpers/updater => ./updater
15
-
16
- replace github.com/dependabot/dependabot-core/go_modules/helpers/updatechecker => ./updatechecker
data/helpers/go.sum CHANGED
@@ -1,6 +1,5 @@
1
1
  github.com/Masterminds/vcs v1.13.1 h1:NL3G1X7/7xduQtA2sJLpVpfHTNBALVNSjob6KEjPXNQ=
2
2
  github.com/Masterminds/vcs v1.13.1/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHSmwVJjcKA=
3
- github.com/dependabot/gomodules-extracted v0.0.0-20181020215834-1b2f850478a3/go.mod h1:+dRXSrUymjpT4yzKtn1QmeknT1S/yAHRr35en18dHp8=
4
3
  github.com/dependabot/gomodules-extracted v1.2.0 h1:K/gTyOyhasOt4cjULvOPNiD3MAFGytp4F7e39aB+0Y0=
5
4
  github.com/dependabot/gomodules-extracted v1.2.0/go.mod h1:3NWkH8KcZVDM87JuZI8hCZzYbjfUSz98EZI53qjgMgY=
6
5
  golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
data/helpers/main.go CHANGED
@@ -46,7 +46,7 @@ func main() {
46
46
  parseArgs(helperParams.Args, &args)
47
47
  funcOut, funcErr = importresolver.VCSRemoteForImport(&args)
48
48
  default:
49
- abort(fmt.Errorf("Unrecognised function '%s'", helperParams.Function))
49
+ abort(fmt.Errorf("unrecognised function '%s'", helperParams.Function))
50
50
  }
51
51
 
52
52
  if funcErr != nil {
@@ -6,7 +6,11 @@ import (
6
6
  "golang.org/x/mod/modfile"
7
7
  )
8
8
 
9
- // Private methods lifted from the `modfile` package
9
+ // Private methods lifted from the `modfile` package.
10
+ // Last synced: 4/28/2021 from:
11
+ // https://github.com/golang/mod/blob/858fdbee9c245c8109c359106e89c6b8d321f19c/modfile/rule.go
12
+
13
+ var slashSlash = []byte("//")
10
14
 
11
15
  // setIndirect sets line to have (or not have) a "// indirect" comment.
12
16
  func setIndirect(line *modfile.Line, indirect bool) {
@@ -20,13 +24,17 @@ func setIndirect(line *modfile.Line, indirect bool) {
20
24
  line.Suffix = []modfile.Comment{{Token: "// indirect", Suffix: true}}
21
25
  return
22
26
  }
23
- // Insert at beginning of existing comment.
27
+
24
28
  com := &line.Suffix[0]
25
- space := " "
26
- if len(com.Token) > 2 && com.Token[2] == ' ' || com.Token[2] == '\t' {
27
- space = ""
29
+ text := strings.TrimSpace(strings.TrimPrefix(com.Token, string(slashSlash)))
30
+ if text == "" {
31
+ // Empty comment.
32
+ com.Token = "// indirect"
33
+ return
28
34
  }
29
- com.Token = "// indirect;" + space + com.Token[2:]
35
+
36
+ // Insert at beginning of existing comment.
37
+ com.Token = "// indirect; " + text
30
38
  return
31
39
  }
32
40
 
@@ -52,6 +60,6 @@ func isIndirect(line *modfile.Line) bool {
52
60
  if len(line.Suffix) == 0 {
53
61
  return false
54
62
  }
55
- f := strings.Fields(line.Suffix[0].Token)
56
- return (len(f) == 2 && f[1] == "indirect" || len(f) > 2 && f[1] == "indirect;") && f[0] == "//"
63
+ f := strings.Fields(strings.TrimPrefix(line.Suffix[0].Token, string(slashSlash)))
64
+ return (len(f) == 1 && f[0] == "indirect" || len(f) > 1 && f[0] == "indirect;")
57
65
  }
@@ -28,7 +28,9 @@ func UpdateDependencyFile(args *Args) (interface{}, error) {
28
28
  }
29
29
 
30
30
  for _, dep := range args.Dependencies {
31
- f.AddRequire(dep.Name, dep.Version)
31
+ if err := f.AddRequire(dep.Name, dep.Version); err != nil {
32
+ return nil, err
33
+ }
32
34
  }
33
35
 
34
36
  for _, r := range f.Require {
@@ -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
@@ -24,7 +25,7 @@ module Dependabot
24
25
  #
25
26
  # To update indirect dependencies we'll need to promote the indirect
26
27
  # dependency to the go.mod file forcing the resolver to pick this
27
- # version (possibly as # indirect)
28
+ # version (possibly as `// indirect`)
28
29
  unless dependency.top_level?
29
30
  return unless dependency.version
30
31
 
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.2
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-23 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.2
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.2
26
+ version: 0.144.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -192,8 +192,6 @@ files:
192
192
  - helpers/importresolver/main.go
193
193
  - helpers/main.go
194
194
  - helpers/updatechecker/main.go
195
- - helpers/updater/go.mod
196
- - helpers/updater/go.sum
197
195
  - helpers/updater/helpers.go
198
196
  - helpers/updater/main.go
199
197
  - lib/dependabot/go_modules.rb
@@ -204,6 +202,7 @@ files:
204
202
  - lib/dependabot/go_modules/metadata_finder.rb
205
203
  - lib/dependabot/go_modules/native_helpers.rb
206
204
  - lib/dependabot/go_modules/path_converter.rb
205
+ - lib/dependabot/go_modules/replace_stubber.rb
207
206
  - lib/dependabot/go_modules/requirement.rb
208
207
  - lib/dependabot/go_modules/resolvability_errors.rb
209
208
  - lib/dependabot/go_modules/update_checker.rb
@@ -1,3 +0,0 @@
1
- module github.com/dependabot/dependabot-core/helpers/go/updater
2
-
3
- require github.com/dependabot/gomodules-extracted v0.0.0-20181020215834-1b2f850478a3
@@ -1,2 +0,0 @@
1
- github.com/dependabot/gomodules-extracted v0.0.0-20181020215834-1b2f850478a3 h1:Xj2leY0FVyZuo+p59vkIWG3dIqo+QtjskT5O1iTiywA=
2
- github.com/dependabot/gomodules-extracted v0.0.0-20181020215834-1b2f850478a3/go.mod h1:+dRXSrUymjpT4yzKtn1QmeknT1S/yAHRr35en18dHp8=