gurney_client 1.0.1 → 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.
metadata CHANGED
@@ -1,159 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gurney_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Schaflitzl
8
- autorequire:
8
+ - Tobias Kraze
9
+ - makandra
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2026-05-21 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: colorize
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.8'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.8'
27
- - !ruby/object:Gem::Dependency
28
- name: httparty
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0.24'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '1.0'
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '0.24'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '1.0'
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "<"
52
- - !ruby/object:Gem::Version
53
- version: '4'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "<"
59
- - !ruby/object:Gem::Version
60
- version: '4'
61
- - !ruby/object:Gem::Dependency
62
- name: git
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.5'
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.5'
75
- - !ruby/object:Gem::Dependency
76
- name: logger
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '1.6'
82
- - - "<"
83
- - !ruby/object:Gem::Version
84
- version: '2.0'
85
- type: :runtime
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '1.6'
92
- - - "<"
93
- - !ruby/object:Gem::Version
94
- version: '2.0'
95
- - !ruby/object:Gem::Dependency
96
- name: ostruct
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0.6'
102
- - - "<"
103
- - !ruby/object:Gem::Version
104
- version: '1.0'
105
- type: :runtime
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0.6'
112
- - - "<"
113
- - !ruby/object:Gem::Version
114
- version: '1.0'
115
- description:
12
+ date: 1980-01-02 00:00:00.000000000 Z
13
+ dependencies: []
116
14
  email:
117
15
  - martin.schaflitzl@makandra.de
16
+ - tobias.kraze@makandra.de
118
17
  executables:
119
18
  - gurney
120
19
  extensions: []
121
20
  extra_rdoc_files: []
122
21
  files:
123
- - ".gitignore"
124
- - ".rspec"
125
- - ".ruby-version"
126
22
  - CHANGELOG.md
127
- - Gemfile
128
- - Gemfile.lock
129
23
  - LICENSE.txt
130
24
  - README.md
131
- - Rakefile
132
25
  - exe/gurney
133
- - git_hook_sample
134
- - gurney.gemspec
135
- - gurney.yml.sample
136
- - lib/gurney.rb
137
- - lib/gurney/api.rb
138
- - lib/gurney/cli.rb
139
- - lib/gurney/cli/option_parser.rb
140
- - lib/gurney/config.rb
141
- - lib/gurney/dependency.rb
142
- - lib/gurney/dependency_collector.rb
143
- - lib/gurney/git_file_reader.rb
144
- - lib/gurney/source/base.rb
145
- - lib/gurney/source/bundler.rb
146
- - lib/gurney/source/npm.rb
147
- - lib/gurney/source/pnpm.rb
148
- - lib/gurney/source/ruby_version.rb
149
- - lib/gurney/source/yarn.rb
150
- - lib/gurney/version.rb
151
- homepage: https://github.com/makandra/gurney
26
+ - lib/gurney_client.rb
27
+ - lib/gurney_client/api.rb
28
+ - lib/gurney_client/cli.rb
29
+ - lib/gurney_client/config.rb
30
+ - lib/gurney_client/report.rb
31
+ - lib/gurney_client/repository.rb
32
+ - lib/gurney_client/version.rb
152
33
  licenses:
153
34
  - MIT
154
35
  metadata:
155
36
  rubygems_mfa_required: 'true'
156
- post_install_message:
157
37
  rdoc_options: []
158
38
  require_paths:
159
39
  - lib
@@ -168,9 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
48
  - !ruby/object:Gem::Version
169
49
  version: '0'
170
50
  requirements: []
171
- rubygems_version: 3.4.19
172
- signing_key:
51
+ rubygems_version: 4.0.20
173
52
  specification_version: 4
174
- summary: Gurney is a small tool to extract yarn and RubyGems dependencies from project
175
- files and report them to a web api.
53
+ summary: Reports the dependency files of a project (Gemfile.lock, package-lock.json,
54
+ …) to Ambulance.
176
55
  test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- .idea/
2
- *.gem
3
- .byebug_history
4
- gurney.yml
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --require spec_helper
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.2
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rspec', '~> 3.10.0'
6
- gem 'byebug'
7
- gem 'rake'
data/Gemfile.lock DELETED
@@ -1,59 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- gurney_client (1.0.1)
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
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/git_hook_sample DELETED
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
-
3
- gurney --hook
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
@@ -1,6 +0,0 @@
1
- project_id: 1
2
- branches:
3
- - master
4
- - production
5
- api_url: http://example.com/dep_reporter/project/<project_id>/branch/<branch>
6
- api_token: 1234567890
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
@@ -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 = @prefix == '.' ? 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
@@ -1,15 +0,0 @@
1
- module Gurney
2
- module Source
3
- class Base
4
-
5
- def present?
6
- raise NotImplementedError
7
- end
8
-
9
- def dependencies
10
- raise NotImplementedError
11
- end
12
-
13
- end
14
- end
15
- end