Skip to content

Commit

Permalink
Merge pull request #483 from librariesio/mikeyoung85/go-custom-manifest
Browse files Browse the repository at this point in the history
Parse a Resolved Dependencies json File for Go
  • Loading branch information
mikeyoung85 authored Nov 24, 2020
2 parents d2f83dc + 49496ac commit 3d8b99b
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ All available config options are in: https://github.com/librariesio/bibliothecar
- Gopkg.lock
- go.mod
- go.sum
- go-resolved-dependencies.json
- Elm
- elm-package.json
- elm_dependencies.json
Expand Down
12 changes: 11 additions & 1 deletion lib/bibliothecary/parsers/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def self.mapping
match_filename("Gopkg.lock") => {
kind: 'lockfile',
parser: :parse_dep_lockfile
}
},
match_filename("go-resolved-dependencies.json") => {
kind: 'lockfile',
parser: :parse_go_resolved
},
}
end

Expand Down Expand Up @@ -140,6 +144,12 @@ def self.parse_go_sum(file_contents)
deps.uniq
end

def self.parse_go_resolved(file_contents)
JSON.parse(file_contents)
.select { |dep| dep["Main"] != "true" }
.map { |dep| { name: dep["Path"], requirement: dep["Version"], type: 'runtime' } }
end

def self.map_dependencies(manifest, attr_name, dep_attr_name, version_attr_name, type)
manifest.fetch(attr_name,[]).map do |dependency|
{
Expand Down
2 changes: 1 addition & 1 deletion lib/bibliothecary/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bibliothecary
VERSION = "6.9.2"
VERSION = "6.9.3"
end
85 changes: 85 additions & 0 deletions spec/fixtures/go-resolved-dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
[{
"Path": "main",
"Main": "true",
"Version": "",
"Indirect": "false"
},
{
"Path": "cloud.google.com/go",
"Main": "false",
"Version": "v0.36.0",
"Indirect": "true"
},
{
"Path": "dmitri.shuralyov.com/app/changes",
"Main": "false",
"Version": "v0.0.0-20180602232624-0a106ad413e3",
"Indirect": "true"
},
{
"Path": "dmitri.shuralyov.com/html/belt",
"Main": "false",
"Version": "v0.0.0-20180602232347-f7d459c86be0",
"Indirect": "true"
},
{
"Path": "dmitri.shuralyov.com/service/change",
"Main": "false",
"Version": "v0.0.0-20181023043359-a85b471d5412",
"Indirect": "true"
},
{
"Path": "dmitri.shuralyov.com/state",
"Main": "false",
"Version": "v0.0.0-20180228185332-28bcc343414c",
"Indirect": "true"
},
{
"Path": "git.apache.org/thrift.git",
"Main": "false",
"Version": "v0.0.0-20180902110319-2566ecd5d999",
"Indirect": "true"
},
{
"Path": "github.com/BurntSushi/toml",
"Main": "false",
"Version": "v0.3.1",
"Indirect": "true"
},
{
"Path": "github.com/Masterminds/semver",
"Main": "false",
"Version": "v1.5.0",
"Indirect": "true"
},
{
"Path": "github.com/Masterminds/semver/v3",
"Main": "false",
"Version": "v3.0.3",
"Indirect": "true"
},
{
"Path": "github.com/OneOfOne/xxhash",
"Main": "false",
"Version": "v1.2.2",
"Indirect": "true"
},
{
"Path": "github.com/ajg/form",
"Main": "false",
"Version": "v1.5.1",
"Indirect": "true"
},
{
"Path": "github.com/alecthomas/template",
"Main": "false",
"Version": "v0.0.0-20160405071501-a0175ee3bccc",
"Indirect": "true"
},
{
"Path": "github.com/alecthomas/units",
"Main": "false",
"Version": "v0.0.0-20151022065526-2efee857e7cf",
"Indirect": "true"
}
]
25 changes: 25 additions & 0 deletions spec/parsers/go_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,30 @@
})
end

it 'parses dependencies from go-resolved-dependencies.json file' do
expect(described_class.analyse_contents('go-resolved-dependencies.json', load_fixture('go-resolved-dependencies.json'))).to eq({
:platform=>"go",
:path=>"go-resolved-dependencies.json",
:dependencies=>[
{:name=>"cloud.google.com/go", :requirement=>"v0.36.0", :type=>"runtime"},
{:name=>"dmitri.shuralyov.com/app/changes", :requirement=>"v0.0.0-20180602232624-0a106ad413e3", :type=>"runtime"},
{:name=>"dmitri.shuralyov.com/html/belt", :requirement=>"v0.0.0-20180602232347-f7d459c86be0", :type=>"runtime"},
{:name=>"dmitri.shuralyov.com/service/change", :requirement=>"v0.0.0-20181023043359-a85b471d5412", :type=>"runtime"},
{:name=>"dmitri.shuralyov.com/state", :requirement=>"v0.0.0-20180228185332-28bcc343414c", :type=>"runtime"},
{:name=>"git.apache.org/thrift.git", :requirement=>"v0.0.0-20180902110319-2566ecd5d999", :type=>"runtime"},
{:name=>"github.com/BurntSushi/toml", :requirement=>"v0.3.1", :type=>"runtime"},
{:name=>"github.com/Masterminds/semver", :requirement=>"v1.5.0", :type=>"runtime"},
{:name=>"github.com/Masterminds/semver/v3", :requirement=>"v3.0.3", :type=>"runtime"},
{:name=>"github.com/OneOfOne/xxhash", :requirement=>"v1.2.2", :type=>"runtime"},
{:name=>"github.com/ajg/form", :requirement=>"v1.5.1", :type=>"runtime"},
{:name=>"github.com/alecthomas/template", :requirement=>"v0.0.0-20160405071501-a0175ee3bccc", :type=>"runtime"},
{:name=>"github.com/alecthomas/units", :requirement=>"v0.0.0-20151022065526-2efee857e7cf", :type=>"runtime"},
],
kind: 'lockfile',
success: true
})
end

it 'matches valid manifest filepaths' do
expect(described_class.match?('go.mod')).to be_truthy
expect(described_class.match?('go.sum')).to be_truthy
Expand All @@ -273,5 +297,6 @@
expect(described_class.match?('vendor/vendor.json')).to be_truthy
expect(described_class.match?('Gopkg.toml')).to be_truthy
expect(described_class.match?('Gopkg.lock')).to be_truthy
expect(described_class.match?('go-resolved-dependencies.json')).to be_truthy
end
end

0 comments on commit 3d8b99b

Please sign in to comment.