Skip to content

Commit

Permalink
Add support for govendor, fixes #157
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Feb 20, 2017
1 parent 87a547c commit 4e28b33
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/bibliothecary/parsers/go.rb
Expand Up @@ -14,7 +14,8 @@ def self.mapping
/^glide\.lock$/ => :parse_glide_lockfile,
/^Godeps\/Godeps\.json$/ => :parse_godep_json,
/^Godeps$/i => :parse_gpm,
/^vendor\/manifest$/ => :parse_gb_manifest
/^vendor\/manifest$/ => :parse_gb_manifest,
/^vendor\/vendor.json$/ => :parse_govendor
}
end

Expand All @@ -37,6 +38,11 @@ def self.parse_gpm(file_contents)
deps
end

def self.parse_govendor(file_contents)
manifest = JSON.load file_contents
map_dependencies(manifest, 'package', 'path', 'revision', 'runtime')
end

def self.parse_glide_yaml(file_contents)
manifest = YAML.load file_contents
map_dependencies(manifest, 'import', 'package', 'version', 'runtime') +
Expand Down
37 changes: 37 additions & 0 deletions spec/fixtures/vendor.json
@@ -0,0 +1,37 @@
{
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "rcwA7Jmo3eZ4bEQb8mTI78haZfc=",
"path": "github.com/Bowery/prompt",
"revision": "d43c2707a6c5a152a344c64bb4fed657e2908a81",
"revisionTime": "2016-08-08T16:52:56Z"
},
{
"checksumSHA1": "6VGFARaK8zd23IAiDf7a+gglC8k=",
"path": "github.com/dchest/safefile",
"revision": "855e8d98f1852d48dde521e0522408d1fe7e836a",
"revisionTime": "2015-10-22T12:31:44+02:00"
},
{
"checksumSHA1": "3VJcSYFds0zeIO5opOs0AoKm3Mw=",
"path": "github.com/google/shlex",
"revision": "6f45313302b9c56850fc17f99e40caebce98c716",
"revisionTime": "2015-01-27T13:39:51Z"
},
{
"checksumSHA1": "GcaTbmmzSGqTb2X6qnNtmDyew1Q=",
"path": "github.com/pkg/errors",
"revision": "a2d6902c6d2a2f194eb3fb474981ab7867c81505",
"revisionTime": "2016-06-27T22:23:52Z"
},
{
"checksumSHA1": "uwKP1AVzd+lrTMlXVFjZXXHzB7U=",
"path": "golang.org/x/tools/go/vcs",
"revision": "1727758746e7a08feaaceb9366d1468498ac2ac2",
"revisionTime": "2016-06-24T22:27:06Z"
}
],
"rootPath": "github.com/kardianos/govendor"
}
15 changes: 15 additions & 0 deletions spec/parsers/go_spec.rb
Expand Up @@ -120,11 +120,26 @@
})
end

it 'parses dependencies from govendor vendor.json file' do
expect(described_class.analyse_contents('vendor/vendor.json', load_fixture('vendor.json'))).to eq({
:platform=>"go",
:path=>"vendor/vendor.json",
:dependencies=>[
{:name=>"github.com/Bowery/prompt", :requirement=>"d43c2707a6c5a152a344c64bb4fed657e2908a81", :type=>"runtime"},
{:name=>"github.com/dchest/safefile", :requirement=>"855e8d98f1852d48dde521e0522408d1fe7e836a", :type=>"runtime"},
{:name=>"github.com/google/shlex", :requirement=>"6f45313302b9c56850fc17f99e40caebce98c716", :type=>"runtime"},
{:name=>"github.com/pkg/errors", :requirement=>"a2d6902c6d2a2f194eb3fb474981ab7867c81505", :type=>"runtime"},
{:name=>"golang.org/x/tools/go/vcs", :requirement=>"1727758746e7a08feaaceb9366d1468498ac2ac2", :type=>"runtime"}
]
})
end

it 'matches valid manifest filepaths' do
expect(described_class.match?('Godeps/Godeps.json')).to be_truthy
expect(described_class.match?('vendor/manifest')).to be_truthy
expect(described_class.match?('glide.yaml')).to be_truthy
expect(described_class.match?('glide.lock')).to be_truthy
expect(described_class.match?('Godeps')).to be_truthy
expect(described_class.match?('vendor/vendor.json')).to be_truthy
end
end

0 comments on commit 4e28b33

Please sign in to comment.