gurney_client 1.0.0 → 2.0.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 +4 -4
- data/CHANGELOG.md +12 -2
- data/README.md +59 -33
- data/exe/gurney +2 -2
- data/lib/gurney_client/api.rb +52 -0
- data/lib/gurney_client/cli.rb +106 -0
- data/lib/gurney_client/config.rb +52 -0
- data/lib/gurney_client/report.rb +53 -0
- data/lib/gurney_client/repository.rb +67 -0
- data/lib/gurney_client/version.rb +3 -0
- data/lib/gurney_client.rb +10 -0
- metadata +16 -133
- data/.gitignore +0 -4
- data/.rspec +0 -1
- data/.ruby-version +0 -1
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -59
- data/Rakefile +0 -6
- data/git_hook_sample +0 -3
- data/gurney.gemspec +0 -29
- data/gurney.yml.sample +0 -6
- data/lib/gurney/api.rb +0 -46
- data/lib/gurney/cli/option_parser.rb +0 -60
- data/lib/gurney/cli.rb +0 -111
- data/lib/gurney/config.rb +0 -22
- data/lib/gurney/dependency.rb +0 -28
- data/lib/gurney/dependency_collector.rb +0 -64
- data/lib/gurney/git_file_reader.rb +0 -25
- data/lib/gurney/source/base.rb +0 -15
- data/lib/gurney/source/bundler.rb +0 -35
- data/lib/gurney/source/npm.rb +0 -58
- data/lib/gurney/source/pnpm.rb +0 -54
- data/lib/gurney/source/ruby_version.rb +0 -27
- data/lib/gurney/source/yarn.rb +0 -28
- data/lib/gurney/version.rb +0 -3
- data/lib/gurney.rb +0 -14
data/.gitignore
DELETED
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--require spec_helper
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
3.2
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
gurney_client (1.0.0)
|
|
5
|
-
bundler (< 4)
|
|
6
|
-
colorize (~> 0.8)
|
|
7
|
-
git (~> 1.5)
|
|
8
|
-
httparty (>= 0.24, < 1.0)
|
|
9
|
-
logger (>= 1.6, < 2.0)
|
|
10
|
-
ostruct (>= 0.6, < 1.0)
|
|
11
|
-
|
|
12
|
-
GEM
|
|
13
|
-
remote: https://rubygems.org/
|
|
14
|
-
specs:
|
|
15
|
-
addressable (2.8.7)
|
|
16
|
-
public_suffix (>= 2.0.2, < 7.0)
|
|
17
|
-
byebug (11.0.1)
|
|
18
|
-
colorize (0.8.1)
|
|
19
|
-
csv (3.3.5)
|
|
20
|
-
diff-lcs (1.6.2)
|
|
21
|
-
git (1.19.1)
|
|
22
|
-
addressable (~> 2.8)
|
|
23
|
-
rchardet (~> 1.8)
|
|
24
|
-
httparty (0.24.2)
|
|
25
|
-
csv
|
|
26
|
-
mini_mime (>= 1.0.0)
|
|
27
|
-
multi_xml (>= 0.5.2)
|
|
28
|
-
logger (1.6.1)
|
|
29
|
-
mini_mime (1.1.5)
|
|
30
|
-
multi_xml (0.6.0)
|
|
31
|
-
ostruct (0.6.3)
|
|
32
|
-
public_suffix (5.1.1)
|
|
33
|
-
rake (13.4.2)
|
|
34
|
-
rchardet (1.8.0)
|
|
35
|
-
rspec (3.10.0)
|
|
36
|
-
rspec-core (~> 3.10.0)
|
|
37
|
-
rspec-expectations (~> 3.10.0)
|
|
38
|
-
rspec-mocks (~> 3.10.0)
|
|
39
|
-
rspec-core (3.10.2)
|
|
40
|
-
rspec-support (~> 3.10.0)
|
|
41
|
-
rspec-expectations (3.10.2)
|
|
42
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
-
rspec-support (~> 3.10.0)
|
|
44
|
-
rspec-mocks (3.10.3)
|
|
45
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
46
|
-
rspec-support (~> 3.10.0)
|
|
47
|
-
rspec-support (3.10.3)
|
|
48
|
-
|
|
49
|
-
PLATFORMS
|
|
50
|
-
ruby
|
|
51
|
-
|
|
52
|
-
DEPENDENCIES
|
|
53
|
-
byebug
|
|
54
|
-
gurney_client!
|
|
55
|
-
rake
|
|
56
|
-
rspec (~> 3.10.0)
|
|
57
|
-
|
|
58
|
-
BUNDLED WITH
|
|
59
|
-
2.7.2
|
data/Rakefile
DELETED
data/git_hook_sample
DELETED
data/gurney.gemspec
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require "gurney/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "gurney_client"
|
|
7
|
-
spec.version = Gurney::VERSION
|
|
8
|
-
spec.authors = ["Martin Schaflitzl"]
|
|
9
|
-
spec.email = ["martin.schaflitzl@makandra.de"]
|
|
10
|
-
|
|
11
|
-
spec.summary = 'Gurney is a small tool to extract yarn and RubyGems dependencies from project files and report them to a web api.'
|
|
12
|
-
spec.homepage = "https://github.com/makandra/gurney"
|
|
13
|
-
spec.license = "MIT"
|
|
14
|
-
spec.metadata = { 'rubygems_mfa_required' => 'true' }
|
|
15
|
-
spec.required_ruby_version = '>= 3.2'
|
|
16
|
-
|
|
17
|
-
spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
|
|
18
|
-
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
19
|
-
spec.bindir = 'exe'
|
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
-
spec.require_paths = ["lib"]
|
|
22
|
-
|
|
23
|
-
spec.add_runtime_dependency 'colorize', '~> 0.8'
|
|
24
|
-
spec.add_runtime_dependency 'httparty', '>= 0.24', '< 1.0'
|
|
25
|
-
spec.add_runtime_dependency 'bundler', '< 4'
|
|
26
|
-
spec.add_runtime_dependency 'git', '~> 1.5'
|
|
27
|
-
spec.add_runtime_dependency 'logger', '>= 1.6', '< 2.0'
|
|
28
|
-
spec.add_runtime_dependency 'ostruct', '>= 0.6', '< 1.0'
|
|
29
|
-
end
|
data/gurney.yml.sample
DELETED
data/lib/gurney/api.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'httparty'
|
|
2
|
-
require 'cgi'
|
|
3
|
-
|
|
4
|
-
module Gurney
|
|
5
|
-
class Api
|
|
6
|
-
|
|
7
|
-
def initialize(base_url:, token:)
|
|
8
|
-
@base_url = base_url
|
|
9
|
-
@token = token
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def post_dependencies(dependencies:, branch:, project_id:, repo_path: nil)
|
|
13
|
-
data = { dependencies: dependencies }
|
|
14
|
-
data[:repository_path] = repo_path if repo_path
|
|
15
|
-
|
|
16
|
-
url = base_url
|
|
17
|
-
url.gsub! '<project_id>', CGI.escape(project_id)
|
|
18
|
-
url.gsub! '<branch>', CGI.escape(branch)
|
|
19
|
-
|
|
20
|
-
post_json(url, data.to_json)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
attr_reader :base_url, :token
|
|
26
|
-
|
|
27
|
-
def post_json(url, json)
|
|
28
|
-
response = HTTParty.post(url,
|
|
29
|
-
body: json,
|
|
30
|
-
headers: { 'X-AuthToken' => @token,
|
|
31
|
-
'Content-Type': 'application/json'},
|
|
32
|
-
)
|
|
33
|
-
unless response.success?
|
|
34
|
-
if response.code == 404
|
|
35
|
-
raise ApiError.new("#{response.code} API url is probably wrong")
|
|
36
|
-
else
|
|
37
|
-
raise ApiError.new("#{response.code} #{response.body}")
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
class ApiError < Exception
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
require 'optparse'
|
|
2
|
-
require 'ostruct'
|
|
3
|
-
|
|
4
|
-
module Gurney
|
|
5
|
-
class CLI
|
|
6
|
-
class OptionParser
|
|
7
|
-
|
|
8
|
-
def self.parse(args)
|
|
9
|
-
options = OpenStruct.new
|
|
10
|
-
options.hook = false
|
|
11
|
-
options.client_hook = false
|
|
12
|
-
options.config_file = 'gurney.yml'
|
|
13
|
-
|
|
14
|
-
option_parser = ::OptionParser.new do |opts|
|
|
15
|
-
opts.banner = "Usage: gurney [options]"
|
|
16
|
-
|
|
17
|
-
opts.on('',
|
|
18
|
-
'--api-url [API URL]',
|
|
19
|
-
"Url for web api call, can have parameters for <project_id> and <branch>" ,
|
|
20
|
-
"example: --api-url \"http://example.com/project/<project_id>/branch/<branch>\"") do |api_url|
|
|
21
|
-
options.api_url = api_url
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
opts.on('', '--api-token [API TOKEN]', 'Token to be send to the api in the X-AuthToken header') do |api_token|
|
|
25
|
-
options.api_token = api_token
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
opts.on('-c', '--config [CONFIG FILE]', 'Config file to use') do |config_file|
|
|
29
|
-
options.config_file = config_file
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
opts.on('-h', '--hook', 'Run as a git post-receive hook') do |hook|
|
|
33
|
-
options.hook = hook
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
opts.on('', '--client-hook', 'Run as a git pre-push hook') do |client_hook|
|
|
37
|
-
options.client_hook = client_hook
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
opts.on('-p', '--project-id [PROJECT ID]', 'Specify project id for api') do |project_id|
|
|
41
|
-
options.project_id = project_id
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
opts.on('', '--prefix [PATH]', 'Specify the prefix of dependency paths') do |prefix|
|
|
45
|
-
options.prefix = prefix
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
opts.on_tail('', '--help', 'Prints this help') do
|
|
49
|
-
puts opts
|
|
50
|
-
exit
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
option_parser.parse!(args)
|
|
55
|
-
options
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
data/lib/gurney/cli.rb
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'optparse'
|
|
2
|
-
require 'securerandom'
|
|
3
|
-
require 'colorize'
|
|
4
|
-
require 'open3'
|
|
5
|
-
require 'git'
|
|
6
|
-
require 'fileutils'
|
|
7
|
-
|
|
8
|
-
module Gurney
|
|
9
|
-
|
|
10
|
-
class Error < StandardError; end
|
|
11
|
-
|
|
12
|
-
class CLI
|
|
13
|
-
HOOK_STDIN_REGEX = /(?<old>[0-9a-f]{40}) (?<new>[0-9a-f]{40}) refs\/heads\/(?<ref>\w+)/m
|
|
14
|
-
CLIENT_HOOK_STDIN_REGEX = /refs\/heads\/(?<ref>\w+) (?<new>[0-9a-f]{40}) refs\/heads\/(?<remote_ref>\w+) (?<remote_sha>[0-9a-f]{40})/m
|
|
15
|
-
MAIN_BRANCHES = ['master', 'main'].freeze
|
|
16
|
-
|
|
17
|
-
def self.run(cmd_parameter=[])
|
|
18
|
-
new(cmd_parameter).run
|
|
19
|
-
rescue SystemExit
|
|
20
|
-
# Do nothing
|
|
21
|
-
rescue Gurney::ApiError => e
|
|
22
|
-
puts "Gurney API error".red
|
|
23
|
-
puts e.message.red
|
|
24
|
-
rescue Gurney::Error => e
|
|
25
|
-
puts "Gurney error: #{e.message}".red
|
|
26
|
-
rescue Exception
|
|
27
|
-
puts "Gurney: an unexpected error occurred".red
|
|
28
|
-
raise
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def initialize(cmd_parameter=[])
|
|
32
|
-
@options = Gurney::CLI::OptionParser.parse(cmd_parameter)
|
|
33
|
-
@git = if options.hook
|
|
34
|
-
Git.bare(ENV['GIT_DIR'] || Dir.pwd)
|
|
35
|
-
else
|
|
36
|
-
unless Dir.exist? './.git'
|
|
37
|
-
raise Gurney::Error.new('Must be run within a git repository')
|
|
38
|
-
end
|
|
39
|
-
Git.open('.')
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
config_file = MAIN_BRANCHES.find do |branch|
|
|
43
|
-
git_file_reader = GitFileReader.new(git, branch, read_from_git: options.hook)
|
|
44
|
-
file = git_file_reader.read(options.config_file)
|
|
45
|
-
break file if file
|
|
46
|
-
end
|
|
47
|
-
if options.hook && !config_file
|
|
48
|
-
# Git hooks are activated by the config file. Without, do nothing.
|
|
49
|
-
exit 0
|
|
50
|
-
end
|
|
51
|
-
config_file ||= '---'
|
|
52
|
-
config = Gurney::Config.from_yaml(config_file)
|
|
53
|
-
|
|
54
|
-
options.branches ||= config&.branches
|
|
55
|
-
options.branches ||= config&.branches
|
|
56
|
-
options.api_token ||= config&.api_token
|
|
57
|
-
options.api_url ||= config&.api_url
|
|
58
|
-
options.project_id ||= config&.project_id
|
|
59
|
-
options.prefix ||= config&.prefix
|
|
60
|
-
|
|
61
|
-
missing_options = [:project_id, :branches, :api_url, :api_token, :prefix].select { |option| options.send(option).nil? }
|
|
62
|
-
# Use the line below in development
|
|
63
|
-
# missing_options = [:project_id, :branches, :api_token].select { |option| options.send(option).nil? }
|
|
64
|
-
raise Gurney::Error.new("Incomplete config - missing #{missing_options.map(&:inspect).join(', ')}.") unless missing_options.empty?
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def run
|
|
68
|
-
reporting_branches.each do |branch|
|
|
69
|
-
git_file_reader = GitFileReader.new(git, branch, read_from_git: options.hook || options.client_hook, prefix: options.prefix)
|
|
70
|
-
dependencies = DependencyCollector.new(git_file_reader).collect_all
|
|
71
|
-
|
|
72
|
-
api = Gurney::Api.new(base_url: options.api_url, token: options.api_token)
|
|
73
|
-
api.post_dependencies(dependencies: dependencies, branch: branch, project_id: options.project_id, repo_path: git.repo.path)
|
|
74
|
-
|
|
75
|
-
dependency_counts = dependencies.group_by(&:ecosystem).map{|ecosystem, dependencies| "#{ecosystem}: #{dependencies.count}" }.join(', ')
|
|
76
|
-
puts "Gurney: reported dependencies (#{dependency_counts})"
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
private
|
|
81
|
-
|
|
82
|
-
attr_accessor :git, :options
|
|
83
|
-
|
|
84
|
-
def reporting_branches
|
|
85
|
-
branches = []
|
|
86
|
-
if options.hook || options.client_hook
|
|
87
|
-
# We get changed branches and refs via stdin
|
|
88
|
-
# See https://git-scm.com/docs/githooks#post-receive
|
|
89
|
-
$stdin.each_line do |line|
|
|
90
|
-
regex = options.client_hook ? CLIENT_HOOK_STDIN_REGEX : HOOK_STDIN_REGEX
|
|
91
|
-
line.force_encoding(Encoding::UTF_8)
|
|
92
|
-
matches = line.match(regex)
|
|
93
|
-
if matches && matches[:new] != '0' * 40
|
|
94
|
-
if options.branches.include? matches[:ref]
|
|
95
|
-
branches << matches[:ref]
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
else
|
|
100
|
-
current_branch = git.current_branch
|
|
101
|
-
unless options.branches.nil? || options.branches.include?(current_branch)
|
|
102
|
-
raise Gurney::Error.new('The current branch is not specified in the config.')
|
|
103
|
-
end
|
|
104
|
-
branches << current_branch
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
branches
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
end
|
|
111
|
-
end
|
data/lib/gurney/config.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'yaml'
|
|
2
|
-
|
|
3
|
-
module Gurney
|
|
4
|
-
class Config
|
|
5
|
-
|
|
6
|
-
attr_accessor :branches, :api_url, :api_token, :project_id, :prefix
|
|
7
|
-
|
|
8
|
-
def initialize(branches: nil, api_url: nil, api_token: nil, project_id: nil, prefix: '.')
|
|
9
|
-
@branches = branches
|
|
10
|
-
@api_url = api_url
|
|
11
|
-
@api_token = api_token&.to_s
|
|
12
|
-
@project_id = project_id&.to_s
|
|
13
|
-
@prefix = prefix&.to_s
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.from_yaml(yaml)
|
|
17
|
-
config = YAML.load(yaml)&.map{|(k,v)| [k.to_sym,v]}.to_h
|
|
18
|
-
new(**config)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
data/lib/gurney/dependency.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module Gurney
|
|
2
|
-
class Dependency
|
|
3
|
-
|
|
4
|
-
attr_reader :ecosystem, :name, :version
|
|
5
|
-
|
|
6
|
-
def initialize(ecosystem:, name:, version:)
|
|
7
|
-
@ecosystem = ecosystem
|
|
8
|
-
@name = name
|
|
9
|
-
@version = version
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_json(*args)
|
|
13
|
-
{
|
|
14
|
-
ecosystem: @ecosystem,
|
|
15
|
-
name: @name,
|
|
16
|
-
version: @version,
|
|
17
|
-
}.to_json(*args)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def ==(other)
|
|
21
|
-
other.class == self.class &&
|
|
22
|
-
other.ecosystem == ecosystem &&
|
|
23
|
-
other.name == name &&
|
|
24
|
-
other.version == version
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module Gurney
|
|
2
|
-
class DependencyCollector
|
|
3
|
-
|
|
4
|
-
def initialize(git_file_reader)
|
|
5
|
-
@git_file_reader = git_file_reader
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def collect_all
|
|
9
|
-
dependencies = []
|
|
10
|
-
|
|
11
|
-
dependencies.concat npm_dependencies
|
|
12
|
-
dependencies.concat bundler_dependencies
|
|
13
|
-
dependencies.concat ruby_version_dependencies
|
|
14
|
-
|
|
15
|
-
dependencies.compact
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
def bundler_dependencies
|
|
21
|
-
bundler_source = Gurney::Source::Bundler.new(gemfile_lock: @git_file_reader.read('Gemfile.lock'))
|
|
22
|
-
bundler_source.dependencies || []
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def ruby_version_dependencies
|
|
26
|
-
ruby_version_source = Gurney::Source::RubyVersion.new(ruby_version: @git_file_reader.read('.ruby-version'))
|
|
27
|
-
ruby_version_source.dependencies || []
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def npm_dependencies
|
|
31
|
-
npm_dependencies = []
|
|
32
|
-
|
|
33
|
-
if yarn_lock
|
|
34
|
-
yarn_source = Gurney::Source::Yarn.new(yarn_lock: yarn_lock)
|
|
35
|
-
npm_dependencies.concat(yarn_source.dependencies || [])
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
if package_lock_json
|
|
39
|
-
npm_source = Gurney::Source::Npm.new(package_lock_json: package_lock_json)
|
|
40
|
-
npm_dependencies.concat(npm_source.dependencies || [])
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
if pnpm_lock
|
|
44
|
-
pnpm_source = Gurney::Source::Pnpm.new(pnpm_lock: pnpm_lock)
|
|
45
|
-
npm_dependencies.concat(pnpm_source.dependencies || [])
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
npm_dependencies
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def yarn_lock
|
|
52
|
-
@yarn_lock ||= @git_file_reader.read('yarn.lock')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def package_lock_json
|
|
56
|
-
@package_lock_json = @git_file_reader.read('package-lock.json')
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def pnpm_lock
|
|
60
|
-
@pnpm_lock = @git_file_reader.read('pnpm-lock.yaml')
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module Gurney
|
|
2
|
-
class GitFileReader
|
|
3
|
-
|
|
4
|
-
def initialize(git, branch, read_from_git:, prefix: '.')
|
|
5
|
-
@git = git
|
|
6
|
-
@branch = branch
|
|
7
|
-
@read_from_git = read_from_git
|
|
8
|
-
@prefix = prefix
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def read(filename)
|
|
12
|
-
prefixed_filename = File.join(@prefix, filename)
|
|
13
|
-
if @read_from_git
|
|
14
|
-
begin
|
|
15
|
-
@git.show("#{@branch}:#{prefixed_filename}")
|
|
16
|
-
rescue Git::GitExecuteError
|
|
17
|
-
# happens if branch does not exist
|
|
18
|
-
end
|
|
19
|
-
else
|
|
20
|
-
File.read(prefixed_filename) if File.exist?(prefixed_filename)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
end
|
data/lib/gurney/source/base.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'bundler'
|
|
2
|
-
|
|
3
|
-
Bundler.ui.level = 'error'
|
|
4
|
-
|
|
5
|
-
module Gurney
|
|
6
|
-
module Source
|
|
7
|
-
class Bundler < Base
|
|
8
|
-
|
|
9
|
-
def initialize(gemfile_lock:)
|
|
10
|
-
@gemfile_lock = gemfile_lock
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def present?
|
|
14
|
-
!@gemfile_lock.nil?
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def dependencies
|
|
18
|
-
if present?
|
|
19
|
-
Dir.mktmpdir do |dir|
|
|
20
|
-
Dir.chdir dir do
|
|
21
|
-
File.write('Gemfile', '') # LockfileParser requires a Gemfile to be present, can be empty
|
|
22
|
-
lockfile = ::Bundler::LockfileParser.new(@gemfile_lock)
|
|
23
|
-
lockfile.specs.map { |spec| Dependency.new(ecosystem: 'rubygems', name: spec.name, version: spec.version.to_s) }
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
attr_reader :gemfile_lock
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
data/lib/gurney/source/npm.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
require 'colorize'
|
|
3
|
-
|
|
4
|
-
module Gurney
|
|
5
|
-
module Source
|
|
6
|
-
class Npm < Base
|
|
7
|
-
|
|
8
|
-
SUPPORTED_LOCKFILE_VERSIONS = [2, 3].freeze
|
|
9
|
-
|
|
10
|
-
def initialize(package_lock_json:)
|
|
11
|
-
@package_lock_json = package_lock_json
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def present?
|
|
15
|
-
!@package_lock_json&.empty?
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def dependencies
|
|
19
|
-
if present?
|
|
20
|
-
parsed_lock = JSON.parse(@package_lock_json)
|
|
21
|
-
|
|
22
|
-
if SUPPORTED_LOCKFILE_VERSIONS.include?(parsed_lock['lockfileVersion'])
|
|
23
|
-
extract_dependencies(parsed_lock)
|
|
24
|
-
else
|
|
25
|
-
puts "package-lock.json: Lockfile version #{parsed_lock['lockfileVersion']} is unsupported. No npm dependencies reported.".yellow
|
|
26
|
-
[]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
rescue JSON::ParserError => e
|
|
30
|
-
raise Gurney::Error.new("Invalid package-lock.json format: #{e.message}")
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
attr_reader :package_lock_json
|
|
36
|
-
|
|
37
|
-
def extract_dependencies(parsed_lock)
|
|
38
|
-
dependencies = []
|
|
39
|
-
|
|
40
|
-
if parsed_lock['packages']
|
|
41
|
-
parsed_lock['packages'].each do |path_to_package, details|
|
|
42
|
-
next if path_to_package == ''
|
|
43
|
-
|
|
44
|
-
name = path_to_package.sub(/^node_modules\//, '') # remove "node_modules/" prefix to get package name
|
|
45
|
-
dependencies << Dependency.new(
|
|
46
|
-
ecosystem: 'npm',
|
|
47
|
-
name: name,
|
|
48
|
-
version: details['version']
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
dependencies
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
data/lib/gurney/source/pnpm.rb
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'yaml'
|
|
2
|
-
require 'colorize'
|
|
3
|
-
|
|
4
|
-
module Gurney
|
|
5
|
-
module Source
|
|
6
|
-
class Pnpm < Base
|
|
7
|
-
def initialize(pnpm_lock:)
|
|
8
|
-
@pnpm_lock = pnpm_lock
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def present?
|
|
12
|
-
!@pnpm_lock&.empty?
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def dependencies
|
|
16
|
-
if present?
|
|
17
|
-
parsed_lock = YAML.safe_load(@pnpm_lock)
|
|
18
|
-
|
|
19
|
-
major_version = parsed_lock['lockfileVersion'].split('.').first
|
|
20
|
-
if major_version == '9'
|
|
21
|
-
extract_dependencies(parsed_lock)
|
|
22
|
-
else
|
|
23
|
-
puts "pnpm-lock.yaml: Lockfile version #{major_version} is unsupported. No npm dependencies reported.".yellow
|
|
24
|
-
[]
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
rescue Psych::SyntaxError => e
|
|
28
|
-
raise Gurney::Error.new("Invalid pnpm-lock.yaml format: #{e.message}")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
private
|
|
32
|
-
|
|
33
|
-
attr_reader :pnpm_lock
|
|
34
|
-
|
|
35
|
-
def extract_dependencies(parsed_lock)
|
|
36
|
-
dependencies = []
|
|
37
|
-
|
|
38
|
-
# dependency_id has format <scoped_pkg_name>@<pkg_version>
|
|
39
|
-
# see https://github.com/pnpm/spec/blob/master/lockfile/9.0.md#packages
|
|
40
|
-
parsed_lock['packages'].each_key do |dependency_id|
|
|
41
|
-
name, _, version = dependency_id.rpartition('@')
|
|
42
|
-
dependencies << Dependency.new(
|
|
43
|
-
ecosystem: 'npm',
|
|
44
|
-
name: name,
|
|
45
|
-
version: version
|
|
46
|
-
)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
dependencies
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'bundler'
|
|
2
|
-
|
|
3
|
-
module Gurney
|
|
4
|
-
module Source
|
|
5
|
-
class RubyVersion < Base
|
|
6
|
-
|
|
7
|
-
def initialize(ruby_version:)
|
|
8
|
-
@ruby_version = ruby_version&.strip
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def present?
|
|
12
|
-
@ruby_version && @ruby_version.size > 0
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def dependencies
|
|
16
|
-
if present?
|
|
17
|
-
[Dependency.new(ecosystem: 'ruby', name: 'ruby', version: @ruby_version)]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
attr_reader :gemfile_lock
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|